summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/lauxlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/lauxlib.c')
-rw-r--r--apps/plugins/lua/lauxlib.c37
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)
268 const char *name = lua_tostring(L, -1); 268 const char *name = lua_tostring(L, -1);
269 269
270 lua_pushstring (L, "__latebind");/* basetable;name;__latebind;*/ 270 lua_pushstring (L, "__latebind");/* basetable;name;__latebind;*/
271 lua_rawget (L, -3);/* basetable;name;__latebind(t);*/ 271 if(lua_istable(L, -3))
272 lua_rawget (L, -3);/* basetable;name;__latebind(t);*/
272 273
273 luaL_argcheck(L, lua_istable(L, -3) && lua_istable(L, -1), 1, 274 luaL_argcheck(L, lua_istable(L, -3) && lua_istable(L, -1), 1,
274 "__latebind table expected"); 275 "__latebind table expected");
@@ -324,25 +325,31 @@ static int latebind_func_pairs(lua_State *L)
324{ 325{
325 /* basetable @ top of stack 1(basetable)-1 */ 326 /* basetable @ top of stack 1(basetable)-1 */
326 luaL_argcheck(L, lua_istable(L, 1), 1, "table expected"); 327 luaL_argcheck(L, lua_istable(L, 1), 1, "table expected");
327 lua_getglobal(L, "pairs"); /* function to be called / returned (btable;pairs) */
328 328
329 lua_createtable(L, 0, 15); /* btable;pairs;newtable; */ 329#if 0
330 /* clone base table */ 330 lua_getglobal(L, "next"); /* function to be called / returned (btable;next) */
331 lua_createtable(L, 0, 15); /* btable;next;newtable; */
332 lua_pushnil(L); /* nil name retrieves all unbound latebound functions */
331 lua_pushnil(L); /* first key */ 333 lua_pushnil(L); /* first key */
332 while(lua_next(L, 1) != 0) { 334#else
333 /* (btable;pairs;ntable;k;v) */ 335 /* this way is more RAM efficient in testing */
336 if(luaL_dostring(L, "return next, {}, nil, nil")!= 0)
337 lua_error(L);
338#endif
339 /* (btable;next;ntable;nil;nil) */
340 /* clone base table */
341 while(lua_next(L, 1) > 0) {
342 /* (btable;next;ntable;nil;k;v) */
334 lua_pushvalue(L, -2); /* dupe key Stk = (..;k;v -> ..k;v;k)*/ 343 lua_pushvalue(L, -2); /* dupe key Stk = (..;k;v -> ..k;v;k)*/
335 lua_insert(L, -2); /* Stk = (..k;k;v) */ 344 lua_insert(L, -2); /* Stk = (..k;k;v) */
336 lua_rawset(L, 3); /* btable;pairs;ntable;k */ 345 lua_rawset(L, -5); /* btable;next;ntable;nil;k */
337 } 346 }
338 347 /* fill the new table with all the latebound functions */
339 lua_pushnil(L); /*nil name retrieves all unbound late bound functions */ 348 /* nil name retrieves all unbound latebound functions */
340 latebind_func_index(L);/* (btable;pairs;ntable;nil) -> (btable;pairs;ntable) */ 349 latebind_func_index(L);/* (btable;next;ntable;nil) -> (btable;next;ntable) */
341 350 lua_pushnil(L); /*nil initial key for next*/
342 /* (btable;pairs;ntable) */ 351 /* stack = (btable;next;ntable;nil) */
343 lua_call(L, 1, 3); /* pairs(ntable) -> (btable;iter;state;value) */ 352 return 3; /*(next,ntable,nil)*/
344
345 return 3;
346} 353}
347 354
348 355