Skip to content

Commit 9704912

Browse files
authored
Merge pull request #7 from pilaoda/master
add lua_call, lua_callk api
2 parents 55b76df + 3fa39f7 commit 9704912

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

scripts/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ if [[ "$1" == "lua-5.0.3" ]]; then
3030
-s WASM_ASYNC_COMPILATION=0 \
3131
-s EXPORTED_FUNCTIONS="[
3232
'_luaL_loadbuffer', \
33+
'_lua_call', \
3334
'_lua_close', \
3435
'_lua_gettable', \
3536
'_lua_gettop', \
@@ -69,6 +70,7 @@ elif [[ "$1" == "lua-5.1.5" ]]; then
6970
'_luaL_openlibs', \
7071
'_luaL_loadbuffer', \
7172
'_luaL_loadstring', \
73+
'_lua_call', \
7274
'_lua_close', \
7375
'_lua_getfield', \
7476
'_lua_gettable', \
@@ -108,6 +110,7 @@ elif [[ "$1" == "lua-5.2.4" ]]; then
108110
'_luaL_newstate', \
109111
'_luaL_openlibs', \
110112
'_luaL_loadstring', \
113+
'_lua_callk', \
111114
'_lua_close', \
112115
'_lua_getfield', \
113116
'_lua_getglobal', \
@@ -148,6 +151,7 @@ else
148151
'_luaL_newstate', \
149152
'_luaL_openlibs', \
150153
'_luaL_loadstring', \
154+
'_lua_callk', \
151155
'_lua_close', \
152156
'_lua_copy', \
153157
'_lua_getfield', \

src/binding-factory.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
6868
},
6969
"<=5.1.x": function(luaGlue: LuaEmscriptenModule){
7070
return {
71+
lua_call: luaGlue.cwrap("lua_call", "number", ["number", "number", "number"]),
72+
lua_callk: function (_L: LuaState, _nargs: number, _nresults: number, _ctx: number, _k: number) {
73+
throw "callk not supported with Lua 5.1 and lower";
74+
},
7175
// Need to overwrite because in lua 5.1 this is a function and not a #define (5.2 and higher)
7276
lua_pcall: luaGlue.cwrap("lua_pcall", "number", ["number", "number", "number", "number"]),
7377
// TODO there might be some way to mimic pcallk behaviour with 5.1 somehow
@@ -90,6 +94,10 @@ const luaBindings: Record<string, luaBindingFactoryFunc> = {
9094
},
9195
">=5.2.0": function(luaGlue: LuaEmscriptenModule){
9296
return {
97+
lua_call: function (L: LuaState, nargs: number, nresults: number) {
98+
return (this as Lua).lua_callk(L, nargs, nresults, 0, 0);
99+
},
100+
lua_callk: luaGlue.cwrap("lua_callk", "number", ["number", "number", "number", "number", "number"]),
93101
lua_getglobal: luaGlue.cwrap("lua_getglobal", "number", ["number", "string"]),
94102
lua_pcall: function (L: LuaState, nargs: number, nresults: number, msgh: number) {
95103
return (this as Lua).lua_pcallk(L, nargs, nresults, msgh, 0, 0);

src/lua.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export const LUA_ERRMEM = 4;
2222
export const LUA_ERRERR = 5;
2323

2424
export interface Lua {
25+
lua_call(L: LuaState, nargs: number, nresults: number): number;
26+
lua_callk(L: LuaState, nargs: number, nresults: number, ctx: number, k: number): number;
2527
lua_close(L: LuaState): void;
2628
lua_copy(L: LuaState, fromIndex: number, toIndex: number): void;
2729
// TODO returns int in some lua versions void in others

0 commit comments

Comments
 (0)