]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
Use pointers directly from guile to C and viceversa
authorJavier Sancho <jsf@jsancho.org>
Mon, 4 May 2020 07:33:30 +0000 (09:33 +0200)
committerJavier Sancho <jsf@jsancho.org>
Mon, 4 May 2020 07:33:30 +0000 (09:33 +0200)
irrlicht.scm
irrlicht/base.scm
irrlicht/irr.scm
src/device.cpp
src/device.h
src/wrapped.h

index 307cbdf301640ede816dcb27942e7d6842baee49..b08f2f700b06ccce1658d676d81e2eb3937121fd 100644 (file)
@@ -20,4 +20,5 @@
 
 (define-module (irrlicht)
   #:use-module (irrlicht irr)
-  #:re-export (create-device))
+  #:re-export (create-device
+               set-window-caption!))
index bb04442f8a722f310fb73d61d9880bbd25b2bd7e..4f08eefec60e192deb3a85ae478069861d4611a8 100644 (file)
   #:use-module (oop goops)
   #:use-module (system foreign)
   #:export (<irrlicht-base>
-            wrapped-obj))
+            irr-pointer))
 
 (define-class <irrlicht-base> ()
-  (irr-ptr #:init-value %null-pointer #:accessor irrlicht-pointer #:init-keyword #:ptr)
-  (irr-class #:init-value "irrlicht-base" #:getter irrlicht-class)
-  (wrapped-obj #:accessor wrapped-obj #:allocation #:virtual
-               #:slot-ref (lambda (obj)
-                            (cons (slot-ref obj 'irr-class)
-                                  (slot-ref obj 'irr-ptr)))
-               #:slot-set! (lambda (obj wrapped)
-                             (slot-set! obj 'irr-ptr (cdr wrapped)))))
+  (irr-pointer #:init-value %null-pointer #:accessor irr-pointer #:init-keyword #:irr-pointer))
index 8704c1598d07856dd3289084f7b7b4baa183b8a5..8eeae76ed78645c98b4e9265840fdf3fbe01c916 100644 (file)
   #:use-module (irrlicht foreign)
   #:export (<reference-counted>
             <irrlicht-device>
-            create-device))
+            create-device
+            set-window-caption!))
 
 
 ;; IReferenceCounted
-(define-class <reference-counted> (<irrlicht-base>)
-  (irr-class #:init-value "irr::IReferenceCounted" #:getter irrlicht-class))
+(define-class <reference-counted> (<irrlicht-base>))
 
 
 ;; IEventReceiver
-(define-class <event-receiver> (<irrlicht-base>)
-  (irr-class #:init-value "irr::IEventReceiver" #:getter irrlicht-class))
+(define-class <event-receiver> (<irrlicht-base>))
 
 
 ;; IrrlichtDevice
-(define-class <irrlicht-device> (<reference-counted>)
-  (irr-class #:init-value "irr::IrrlichtDevice" #:getter irrlicht-class))
+(define-class <irrlicht-device> (<reference-counted>))
 
 (define* (create-device #:key
                         (device-type 'software)
        receiver))
 
   (make <irrlicht-device>
-    #:ptr
-    (irr_createDevice device-type
-                      window-size
-                      bits
-                      fullscreen
-                      stencilbuffer
-                      vsync
-                      (wrapped-obj receiver))))
+    #:irr-pointer
+    (irr_createDevice
+     device-type
+     window-size
+     bits
+     fullscreen
+     stencilbuffer
+     vsync
+     (irr-pointer receiver))))
+
+(define-method (set-window-caption! (device <irrlicht-device>) text)
+  (irr_IrrlichtDevice_setWindowCaption
+   (irr-pointer device)
+   text))
index 0ecb69435ee3a9ce77b76248f9807ff0c7f47e2f..195ff5dcb13dbe301216f87fd27b67229346bb88 100644 (file)
@@ -31,6 +31,8 @@
 #include "wchar.h"
 #include "wrapped.h"
 
+using namespace irr;
+
 extern "C" {
 
   void
@@ -38,12 +40,13 @@ extern "C" {
   {
     init_device_type ();
     DEFINE_GSUBR ("irr_createDevice", 7, 0, 0, irr_createDevice);
+    DEFINE_GSUBR ("irr_IrrlichtDevice_setWindowCaption", 2, 0, 0,
+                  irr_IrrlichtDevice_setWindowCaption);
     DEFINE_GSUBR ("get-timer", 1, 0, 0, irr_getTimer);
     DEFINE_GSUBR ("is-window-active?", 1, 0, 0, irr_isWindowActive);
     DEFINE_GSUBR ("run", 1, 0, 0, irr_run);
     DEFINE_GSUBR ("set-event-receiver!", 2, 0, 0, irr_setEventReceiver);
     DEFINE_GSUBR ("set-resizable!", 2, 0, 0, irr_setResizable);
-    DEFINE_GSUBR ("set-window-caption!", 2, 0, 0, irr_setWindowCaption);
     DEFINE_GSUBR ("yield", 1, 0, 0, irr_yield);
   }
 
@@ -60,17 +63,24 @@ extern "C" {
                     SCM vsync,
                     SCM receiver)
   {
-    UNWRAP (receiver);
-
-    irr::IrrlichtDevice* device =
-      irr::createDevice (scm_to_driver_type (device_type),
-                         scm_to_dimension2d_u32 (window_size),
-                         scm_to_uint32 (bits),
-                         scm_to_bool (fullscreen),
-                         scm_to_bool (stencilbuffer),
-                         scm_to_bool (vsync),
-                         UNWRAPPED (receiver));
-    return scm_from_pointer (device, NULL);
+    IrrlichtDevice* device =
+      createDevice (scm_to_driver_type (device_type),
+                    scm_to_dimension2d_u32 (window_size),
+                    scm_to_uint32 (bits),
+                    scm_to_bool (fullscreen),
+                    scm_to_bool (stencilbuffer),
+                    scm_to_bool (vsync),
+                    (IEventReceiver*)scm_to_pointer (receiver));
+    return scm_from_pointer ((void*)device, NULL);
+  }
+
+  SCM
+  irr_IrrlichtDevice_setWindowCaption (SCM device,
+                                       SCM text)
+  {
+    ((IrrlichtDevice*)scm_to_pointer (device))->
+      setWindowCaption (scm_to_wide_char_string (text));
+    return SCM_UNSPECIFIED;
   }
 
   SCM
@@ -112,15 +122,6 @@ extern "C" {
     return SCM_UNSPECIFIED;
   }
 
-  SCM
-  irr_setWindowCaption (SCM wrapped_device,
-                        SCM text)
-  {
-    irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
-    device->setWindowCaption (scm_to_wide_char_string (text));
-    return SCM_UNSPECIFIED;
-  }
-
   SCM
   irr_yield (SCM wrapped_device)
   {
index 158e51da1e325d8d72ab867d647ab24535b02670..8bfb217805714b7c24345a27e7d3a9c365662a8d 100644 (file)
@@ -43,6 +43,10 @@ extern "C" {
                     SCM vsync,
                     SCM receiver);
 
+  SCM
+  irr_IrrlichtDevice_setWindowCaption (SCM wrapped_device,
+                                       SCM text);
+
   SCM
   irr_getTimer (SCM wrapped_device);
 
@@ -60,10 +64,6 @@ extern "C" {
   irr_setResizable (SCM wrapped_device,
                     SCM resize);
 
-  SCM
-  irr_setWindowCaption (SCM wrapped_device,
-                        SCM text);
-
   SCM
   irr_yield (SCM wrapped_device);
 
index 4514fa64afbb769c2686bc5f46697b584007b4ac..daaaa25404d07c95e32fd71f7e6d7a927e100353 100644 (file)
     return SCM_IS_A_P (wrapped_obj, wrapped_##INIT);                    \
   }
 
-
-#define UNWRAP(OBJ)                                                     \
-  char* OBJ##_class = scm_to_utf8_stringn (scm_car (OBJ), NULL);        \
-  void* OBJ##_pointer = scm_to_pointer (scm_cdr (OBJ));
-
-
-#define UNWRAPPED(OBJ)                                                  \
-  (!strcmp (OBJ##_class, "irr::IEventReceiver") ? (irr::IEventReceiver*)OBJ##_pointer : 0)
-
 #endif