From dcff9b85a3cef778af60ad4426f91262ba815931 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Tue, 11 May 2021 21:35:41 -0400 Subject: lua latebound function update return the nextfunction and nil instead of pairs it allows a faster return to lua rather than calling the lua function pcall(fnpairs) from c and returning the result back into lua to kick off the search yeah, no clue why I didn't realize that before.. testing in x86 and ARM.. its more RAM efficient to do the initial creation of the stack in lua code for the __pairs functon its not faster but being that its a one time hit per iter creation the reduced churn alone should be worth it along with a reduced peak RAM usage fix bug where a failed module can not be reloaded optimize filetol fix potential bug in splash scroller when no break character is found Change-Id: I42c922e07039a19138b97c0d0e80cf3cf2426471 --- apps/plugins/lua/lauxlib.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'apps/plugins/lua/lauxlib.c') diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c index acd7e0e636..b8332427f0 100644 --- a/apps/plugins/lua/lauxlib.c +++ b/apps/plugins/lua/lauxlib.c @@ -268,7 +268,8 @@ static int latebind_func_index(lua_State *L) const char *name = lua_tostring(L, -1); lua_pushstring (L, "__latebind");/* basetable;name;__latebind;*/ - lua_rawget (L, -3);/* basetable;name;__latebind(t);*/ + if(lua_istable(L, -3)) + lua_rawget (L, -3);/* basetable;name;__latebind(t);*/ luaL_argcheck(L, lua_istable(L, -3) && lua_istable(L, -1), 1, "__latebind table expected"); @@ -324,25 +325,31 @@ static int latebind_func_pairs(lua_State *L) { /* basetable @ top of stack 1(basetable)-1 */ luaL_argcheck(L, lua_istable(L, 1), 1, "table expected"); - lua_getglobal(L, "pairs"); /* function to be called / returned (btable;pairs) */ - lua_createtable(L, 0, 15); /* btable;pairs;newtable; */ - /* clone base table */ +#if 0 + lua_getglobal(L, "next"); /* function to be called / returned (btable;next) */ + lua_createtable(L, 0, 15); /* btable;next;newtable; */ + lua_pushnil(L); /* nil name retrieves all unbound latebound functions */ lua_pushnil(L); /* first key */ - while(lua_next(L, 1) != 0) { - /* (btable;pairs;ntable;k;v) */ +#else + /* this way is more RAM efficient in testing */ + if(luaL_dostring(L, "return next, {}, nil, nil")!= 0) + lua_error(L); +#endif + /* (btable;next;ntable;nil;nil) */ + /* clone base table */ + while(lua_next(L, 1) > 0) { + /* (btable;next;ntable;nil;k;v) */ lua_pushvalue(L, -2); /* dupe key Stk = (..;k;v -> ..k;v;k)*/ lua_insert(L, -2); /* Stk = (..k;k;v) */ - lua_rawset(L, 3); /* btable;pairs;ntable;k */ + lua_rawset(L, -5); /* btable;next;ntable;nil;k */ } - - lua_pushnil(L); /*nil name retrieves all unbound late bound functions */ - latebind_func_index(L);/* (btable;pairs;ntable;nil) -> (btable;pairs;ntable) */ - - /* (btable;pairs;ntable) */ - lua_call(L, 1, 3); /* pairs(ntable) -> (btable;iter;state;value) */ - - return 3; + /* fill the new table with all the latebound functions */ + /* nil name retrieves all unbound latebound functions */ + latebind_func_index(L);/* (btable;next;ntable;nil) -> (btable;next;ntable) */ + lua_pushnil(L); /*nil initial key for next*/ + /* stack = (btable;next;ntable;nil) */ + return 3; /*(next,ntable,nil)*/ } -- cgit v1.2.3