diff --git a/scripts/build.sh b/scripts/build.sh index 1a81c68..39868a6 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -30,6 +30,7 @@ if [[ "$1" == "lua-5.0.3" ]]; then -s WASM_ASYNC_COMPILATION=0 \ -s EXPORTED_FUNCTIONS="[ '_luaL_loadbuffer', \ + '_lua_call', \ '_lua_close', \ '_lua_gettable', \ '_lua_gettop', \ @@ -69,6 +70,7 @@ elif [[ "$1" == "lua-5.1.5" ]]; then '_luaL_openlibs', \ '_luaL_loadbuffer', \ '_luaL_loadstring', \ + '_lua_call', \ '_lua_close', \ '_lua_getfield', \ '_lua_gettable', \ @@ -108,6 +110,7 @@ elif [[ "$1" == "lua-5.2.4" ]]; then '_luaL_newstate', \ '_luaL_openlibs', \ '_luaL_loadstring', \ + '_lua_callk', \ '_lua_close', \ '_lua_getfield', \ '_lua_getglobal', \ @@ -148,6 +151,7 @@ else '_luaL_newstate', \ '_luaL_openlibs', \ '_luaL_loadstring', \ + '_lua_callk', \ '_lua_close', \ '_lua_copy', \ '_lua_getfield', \ diff --git a/src/binding-factory.ts b/src/binding-factory.ts index ca5e49b..59d22cb 100644 --- a/src/binding-factory.ts +++ b/src/binding-factory.ts @@ -68,6 +68,10 @@ const luaBindings: Record = { }, "<=5.1.x": function(luaGlue: LuaEmscriptenModule){ return { + lua_call: luaGlue.cwrap("lua_call", "number", ["number", "number", "number"]), + lua_callk: function (_L: LuaState, _nargs: number, _nresults: number, _ctx: number, _k: number) { + throw "callk not supported with Lua 5.1 and lower"; + }, // Need to overwrite because in lua 5.1 this is a function and not a #define (5.2 and higher) lua_pcall: luaGlue.cwrap("lua_pcall", "number", ["number", "number", "number", "number"]), // TODO there might be some way to mimic pcallk behaviour with 5.1 somehow @@ -90,6 +94,10 @@ const luaBindings: Record = { }, ">=5.2.0": function(luaGlue: LuaEmscriptenModule){ return { + lua_call: function (L: LuaState, nargs: number, nresults: number) { + return (this as Lua).lua_callk(L, nargs, nresults, 0, 0); + }, + lua_callk: luaGlue.cwrap("lua_callk", "number", ["number", "number", "number", "number", "number"]), lua_getglobal: luaGlue.cwrap("lua_getglobal", "number", ["number", "string"]), lua_pcall: function (L: LuaState, nargs: number, nresults: number, msgh: number) { return (this as Lua).lua_pcallk(L, nargs, nresults, msgh, 0, 0); diff --git a/src/lua.ts b/src/lua.ts index c27b7d7..deb1f8f 100644 --- a/src/lua.ts +++ b/src/lua.ts @@ -22,6 +22,8 @@ export const LUA_ERRMEM = 4; export const LUA_ERRERR = 5; export interface Lua { + lua_call(L: LuaState, nargs: number, nresults: number): number; + lua_callk(L: LuaState, nargs: number, nresults: number, ctx: number, k: number): number; lua_close(L: LuaState): void; lua_copy(L: LuaState, fromIndex: number, toIndex: number): void; // TODO returns int in some lua versions void in others