]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - irrlicht/foreign.scm
call remote procs from guile code
[guile-irrlicht.git] / irrlicht / foreign.scm
index ff46223674e7aa73a341b563502c496e40cb2ea1..f6e203622f55db18eae8907fce38f3c26533c4dd 100644 (file)
 ;;; <http://www.gnu.org/licenses/>.
 
 
-(define-module (irrlicht foreign))
+(define-module (irrlicht foreign)
+  #:use-module (irrlicht base)
+  #:export (get-irrlicht-proc))
 
-(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))))