]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - irrlicht/foreign.scm
Check null objects
[guile-irrlicht.git] / irrlicht / foreign.scm
index ff46223674e7aa73a341b563502c496e40cb2ea1..94aab7c8fe7c7c979c68877b00c24cef922d7e64 100644 (file)
 ;;; <http://www.gnu.org/licenses/>.
 
 
-(define-module (irrlicht foreign))
+(define-module (irrlicht foreign)
+  #:use-module (system foreign)
+  #:use-module (irrlicht base)
+  #:export (get-irrlicht-proc
+            null-pointer?))
 
-(load-extension "libguile-irrlicht" "init_guile_irrlicht")
+;; We use a hash table to store foreign irrlicht methods related with their
+;; classes
+;; This is needed because we need to "simulate" C++ inheritance
+(define remote-proc-table (make-hash-table))
+
+(define (get-irrlicht-proc proc-name . objects)
+  (let* ((name (if (null? objects)
+                   proc-name
+                   (let ((classes (map irr-class objects)))
+                     (string-join (cons (car classes) (cons proc-name (cdr classes))) "_"))))
+         (proc (hash-ref remote-proc-table name)))
+    (cond ((not proc)
+           (load-extension "libguile-irrlicht" "init_guile_irrlicht")
+           (let ((new-proc (eval-string name)))
+             (hash-set! remote-proc-table name new-proc)
+             new-proc))
+          (else
+           proc))))
+
+(define (null-pointer? pointer)
+  (eq? pointer %null-pointer))