Using WASM mods from Lua
Lua mods can call WASM mods, and WASM mods can call Lua mods. In the Lua direction, look the mod up by id and call its exports:
local mod = sm.allthelanguages.getMod("example.hello")mod:call("add", 2, 3) -- 5, with numeric arguments and resultslocal cb = mod:makeCallback("onChat") -- a Lua function that calls the exportmod:call passes numbers straight through and returns the export's results. It raises a Lua
error if the mod has no export by that name or the call fails.
mod:makeCallback returns a Lua function for an export that takes value handles, the
convention C, C++ and Rust script classes use. Any Lua values can be passed to it, and its
result comes back as a Lua value.
In the other direction, WASM code reaches Lua globals, sm.* functions and other mods through
the GDT: sm.allthelanguages.getMod(id):call(...) works from WASM as well.
The full API is in the Lua API reference.