Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hi, I'm interested in using hoot, but I'm new to wasm and web dev in general. I have some questions wrt hoot's FFI.

Following the example from the documentation: https://files.spritely.institute/docs/guile-hoot/latest/Foreign-function-interfa..., I created hello.scm as follows:

(use-modules (hoot ffi))
(define-foreign make-text-node 
"document" "createTextNode" 
(ref string) -> (ref extern))

Then, I compiled it to wasm:

guild compile-wasm --bundle -o hello.wasm hello.scm

Then, I loaded it into guile repl:

(use-modules (wasm parse))
(use-modules (hoot reflect))
(hoot-instantiate (call-with-input-file "hello.wasm" parse-wasm)
(("document" .  
(("createTextNode" . ,(lambda (str) (text ,str)))))))  

Then, I tried to use the make-text-node function: 

(define hello (make-text-node "Hello, world!"))

But it always gives me the error: Unbound variable: make-text-node.

I'm not sure if I'm fundamentally missing something. I'm just wondering if there's a way to test these kinds of procedures in a guile repl.

(2 edits)

You're close! The misunderstanding seems to be that your are expecting that instantiating the module will modifiy the top level REPL environment. This is not the case and it would be kinda scary if it did that. Wasm modules are their own separate, isolated things. If you want a reference to the make-text-node procedure then you should return it by referencing it in the final line of the program you're compiling with Hoot. From there, run hoot-load on the instantiated module and if you've done everything correctly, the result will be a reference to the make-text-node procedure. The tutorial in the manual goes through this process in more detail.