diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-05-11 21:35:41 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-05-19 23:28:35 +0000 |
commit | dcff9b85a3cef778af60ad4426f91262ba815931 (patch) | |
tree | 8f58cd59a2115ac70cd4df6e462ded09c81375fc /apps/plugins/lua/lauxlib.c | |
parent | 0c6217757528b185c3f8628c062a2a688a8adaf8 (diff) | |
download | rockbox-dcff9b85a3cef778af60ad4426f91262ba815931.tar.gz rockbox-dcff9b85a3cef778af60ad4426f91262ba815931.zip |
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
Diffstat (limited to 'apps/plugins/lua/lauxlib.c')
-rw-r--r-- | apps/plugins/lua/lauxlib.c | 37 |
1 files changed, 22 insertions, 15 deletions
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)*/ } |