Expose JSCL function to Javascript world ?
mmontone opened this issue · comments
Hi.
I would like to expose some of my JSCL functions to Javascript, so that they can be called from JS event handlers.
I know there's jscl.evalString, but I'm wondering if there's another way.
I'm trying with something like:
(setf (jscl::oget #j:window "connect") (jscl::lisp-to-js #'connect))
where connect
is the function I'm trying to expose. But calling connect
from Javascript doesn't work.
Also, some of my functions receive the Javascript event; so jscl.evalString is not sufficient.
You can call lisp functions directly, like:
jscl.packages.CL.symbols.["FORMAT"].fvalue(null,jscl.internals.js_to_lisp(true),jscl.internals.js_to_lisp("Hello!"))
The first argument is used to return multiple values, you may supply null here (if I'm understanding this properly)
Thanks! I'll give it a try.
Now I'm thinking that implementing some JSCL "expose" function that generates that code from a function would be nice.
where connect is the function I'm trying to expose. But calling connect from Javascript doesn't work.
Not working how?
JSCL REPL
CL-USER> (setf #j:lispFromJS (lambda (x y z) (format t "~a ~a ~a~&" x y z)))
#<FUNCTION>
CL-USER> 1 2 3
1 2 3
JS Console
lispFromJS(1,2,3)
false
>var ff = function(a,b,c){ lispFromJS(a,b,c);}
undefined
>ff(1,2,3)
undefined
Thanks! That works.