From 39024f25b6a5782aef47e70454fd98822af537e6 Mon Sep 17 00:00:00 2001 From: pilaoda <793493083@qq.com> Date: Mon, 25 Aug 2025 22:26:35 +0800 Subject: [PATCH] add lua_gettop api --- scripts/build.sh | 4 ++++ src/binding-factory.ts | 1 + src/lua.ts | 1 + 3 files changed, 6 insertions(+) diff --git a/scripts/build.sh b/scripts/build.sh index edfb87b..1a81c68 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -32,6 +32,7 @@ if [[ "$1" == "lua-5.0.3" ]]; then '_luaL_loadbuffer', \ '_lua_close', \ '_lua_gettable', \ + '_lua_gettop', \ '_lua_insert', \ '_lua_isstring', \ '_lua_open', \ @@ -71,6 +72,7 @@ elif [[ "$1" == "lua-5.1.5" ]]; then '_lua_close', \ '_lua_getfield', \ '_lua_gettable', \ + '_lua_gettop', \ '_lua_insert', \ '_lua_isstring', \ '_lua_pcall', \ @@ -110,6 +112,7 @@ elif [[ "$1" == "lua-5.2.4" ]]; then '_lua_getfield', \ '_lua_getglobal', \ '_lua_gettable', \ + '_lua_gettop', \ '_lua_insert', \ '_lua_isstring', \ '_lua_pcallk', \ @@ -150,6 +153,7 @@ else '_lua_getfield', \ '_lua_getglobal', \ '_lua_gettable', \ + '_lua_gettop', \ '_lua_isstring', \ '_lua_pcallk', \ '_lua_pushstring', \ diff --git a/src/binding-factory.ts b/src/binding-factory.ts index 930c777..ca5e49b 100644 --- a/src/binding-factory.ts +++ b/src/binding-factory.ts @@ -8,6 +8,7 @@ const luaBindings: Record = { return { lua_close: luaGlue.cwrap("lua_close", null, ["number"]), lua_gettable: luaGlue.cwrap("lua_gettable", "number", ["number", "number"]), + lua_gettop: luaGlue.cwrap("lua_gettop", "number", ["number"]), lua_isstring: luaGlue.cwrap("lua_isstring", "number", ["number", "number"]), // #define in all versions lua_pop: function(L: LuaState, n: number) { diff --git a/src/lua.ts b/src/lua.ts index 1a3380b..c27b7d7 100644 --- a/src/lua.ts +++ b/src/lua.ts @@ -29,6 +29,7 @@ export interface Lua { lua_getglobal(L: LuaState, name: string): number; // TODO returns int in some lua versions void in others lua_gettable(L: LuaState, index: number): number; + lua_gettop(L: LuaState): number; lua_insert(L: LuaState, index: number): void; lua_isstring(L: LuaState, index: number): number; lua_pcall(L: LuaState, nargs: number, nresults: number, msgh: number): number;