3 ;; JSCL is free software: you can redistribute it and/or
4 ;; modify it under the terms of the GNU General Public License as
5 ;; published by the Free Software Foundation, either version 3 of the
6 ;; License, or (at your option) any later version.
8 ;; JSCL is distributed in the hope that it will be useful, but
9 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ;; General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with JSCL. If not, see <http://www.gnu.org/licenses/>.
19 (defun ffi-intern-hook (symbol)
20 (when (eq (symbol-package symbol) *js-package*)
21 (let ((sym-name (symbol-name symbol))
23 ;; Generate a trampoline to call the JS function
24 ;; properly. This trampoline is very inefficient,
25 ;; but it still works. Ideas to optimize this are
26 ;; provide a special lambda keyword
27 ;; cl::&rest-vector to avoid list argument
28 ;; consing, as well as allow inline declarations.
29 (fset symbol (eval `(%js-vref ,sym-name)))
30 ;; Define it as a symbol macro to access to the
31 ;; Javascript variable literally.
32 (%define-symbol-macro symbol `(%js-vref ,(string symbol))))))
34 (setq *intern-hook* #'ffi-intern-hook)