33WASM bindings and binaries for Lua 5.1 to 5.4.
44
55Make sure to run ` ./scripts/setup.ts ` (requires emscripten sdk) first before using ` npm run build ` .
6+
67### Important: This currently only includes the bindings used to test TypescriptToLua
78
89In the future Bindings for the complete API may be added.
@@ -14,38 +15,36 @@ import { LUA_OK } from "lua-wasm-bindings/dist/lua";
1415
1516import { lauxlib , lua , lualib } from " lua-wasm-bindings/dist/lua.54" ;
1617
17-
1818const luaCode = ` return "Hello" ` ;
1919consol .log (executeLua (luaCode ));
2020
21- function executeLua (luaCode : string ): string | Error | never {
22- const L = lauxlib .luaL_newstate ();
23- lualib .luaL_openlibs (L );
24-
25- // Optional Load modules
26- // lua.lua_getglobal(L, "package");
27- // lua.lua_getfield(L, -1, "preload");
28- // lauxlib.luaL_loadstring(L, jsonLib); // Load extenal package from string
29- // lua.lua_setfield(L, -2, "json");
30-
31- const status = lauxlib .luaL_dostring (L , luaCode );
32-
33- if (status === LUA_OK ) {
34- if (lua .lua_isstring (L , - 1 )) {
35- const result = lua .lua_tostring (L , - 1 );
36- lua .lua_close (L );
37- return result === null ? undefined : result ;
38- } else {
39- const returnType = lua .lua_typename (L , lua .lua_type (L , - 1 ));
40- lua .lua_close (L );
41- throw new Error (` Unsupported Lua return type: ${returnType } ` );
42- }
21+ function executeLua(luaCode : string ): string | Error | never {
22+ const L = lauxlib .luaL_newstate ();
23+ lualib .luaL_openlibs (L );
24+
25+ // Optional Load modules
26+ // lua.lua_getglobal(L, "package");
27+ // lua.lua_getfield(L, -1, "preload");
28+ // lauxlib.luaL_loadstring(L, jsonLib); // Load extenal package from string
29+ // lua.lua_setfield(L, -2, "json");
30+
31+ const status = lauxlib .luaL_dostring (L , luaCode );
32+
33+ if (status === LUA_OK ) {
34+ if (lua .lua_isstring (L , - 1 )) {
35+ const result = lua .lua_tostring (L , - 1 );
36+ lua .lua_close (L );
37+ return result === null ? undefined : result ;
4338 } else {
44- const luaStackString = lua .lua_tostring (L , - 1 );
45- const message = luaStackString .replace (/ ^ \[ string "(--)? \.\.\. "\] :\d + : / , " " );
46- lua .lua_close (L );
47- return new Error (message );
39+ const returnType = lua .lua_typename (L , lua .lua_type (L , - 1 ));
40+ lua .lua_close (L );
41+ throw new Error (` Unsupported Lua return type: ${returnType } ` );
4842 }
43+ } else {
44+ const luaStackString = lua .lua_tostring (L , - 1 );
45+ const message = luaStackString .replace (/ ^ \[ string "(--)? \.\.\. "\] :\d + : / , " " );
46+ lua .lua_close (L );
47+ return new Error (message );
48+ }
4949}
5050```
51-
0 commit comments