From e08da97cf2c9e69a3955f0327efeed1f9a237768 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 28 Nov 2024 12:07:33 +0000 Subject: simplify convenience wrapper logic --- run.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/run.c b/run.c index 85e2793..49b96b6 100644 --- a/run.c +++ b/run.c @@ -184,18 +184,17 @@ int convienience_wrapper(lua_State *L) { if (tlen == 0) return luaL_error(L, "run's argument can't have 0 length"); int ty = lua_rawgeti(L, 1, 1); lua_pop(L, 1); - if (ty == LUA_TSTRING) { + if (ty != LUA_TTABLE) { // x1 = {"a","b","c",input="ahaha"} - // x2 := {x1,input="ahaha"} + // x2 := {"a","b","c"} lua_newtable(L); - lua_pushvalue(L, 1); - lua_rawseti(L, 2, 1); - lua_pushliteral(L, "input"); - lua_pushliteral(L, "input"); - lua_rawget(L, 1); - lua_rawset(L, 2); - lua_replace(L, 1); + for (int i = 1; i <= tlen; i++) { + lua_rawgeti(L, 1, i); lua_rawseti(L, 2, i); + lua_pushnil(L); lua_rawseti(L, 1, i); + } + lua_rawseti(L, 1, 1); } + return do_the_thing(L); } -- cgit v1.2.3