Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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', \
Expand Down Expand Up @@ -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', \
Expand Down Expand Up @@ -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', \
Expand Down Expand Up @@ -148,6 +151,7 @@ else
'_luaL_newstate', \
'_luaL_openlibs', \
'_luaL_loadstring', \
'_lua_callk', \
'_lua_close', \
'_lua_copy', \
'_lua_getfield', \
Expand Down
8 changes: 8 additions & 0 deletions src/binding-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
},
"<=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
Expand All @@ -90,6 +94,10 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
},
">=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);
Expand Down
2 changes: 2 additions & 0 deletions src/lua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down