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
This commit is contained in:
parent
0c62177575
commit
dcff9b85a3
4 changed files with 51 additions and 29 deletions
|
@ -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)*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -130,9 +130,11 @@ static int ll_require (lua_State *L) {
|
|||
lua_pushliteral(L, ""); /* error message accumulator */
|
||||
for (i=1; ; i++) {
|
||||
lua_rawgeti(L, -2, i); /* get a loader */
|
||||
if (lua_isnil(L, -1))
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_setfield(L, 2, name); /* _LOADED[name] = nil */
|
||||
luaL_error(L, "module " LUA_QS " not found:%s",
|
||||
name, lua_tostring(L, -2));
|
||||
}
|
||||
lua_pushstring(L, name);
|
||||
lua_call(L, 1, 1); /* call it */
|
||||
if (lua_isfunction(L, -1)) /* did it find module? */
|
||||
|
|
|
@ -603,7 +603,12 @@ static void parlist (LexState *ls) {
|
|||
} while (!f->is_vararg && testnext(ls, ','));
|
||||
}
|
||||
adjustlocalvars(ls, nparams);
|
||||
//f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
|
||||
#if defined(LUA_COMPAT_VARARG)
|
||||
f->numparams = cast_byte(fs->nactvar - (f->is_vararg & VARARG_HASARG));
|
||||
#else
|
||||
f->numparams = cast_byte(fs->nactvar);
|
||||
#endif
|
||||
luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,8 @@ int splash_scroller(int timeout, const char* str)
|
|||
{
|
||||
brk = strpbrk_n(ch+1, max_ch, break_chars);
|
||||
chars_next_break = (brk - ch);
|
||||
if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w)
|
||||
if (brk &&
|
||||
(chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w))
|
||||
{
|
||||
if (!isprint(line[linepos]))
|
||||
{
|
||||
|
@ -226,7 +227,7 @@ int get_current_path(lua_State *L, int level)
|
|||
}
|
||||
}
|
||||
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -250,25 +251,32 @@ int filetol(int fd, long *num)
|
|||
|
||||
while (rb->read(fd, &chbuf, 1) == 1)
|
||||
{
|
||||
if(!isspace(chbuf) || retn == 1)
|
||||
if(retn || !isspace(chbuf))
|
||||
{
|
||||
if(chbuf == '0') /* strip preceeding zeros */
|
||||
switch(chbuf)
|
||||
{
|
||||
*num = 0;
|
||||
retn = 1;
|
||||
}
|
||||
else if(chbuf == '-' && retn != 1)
|
||||
neg = true;
|
||||
else
|
||||
{
|
||||
rb->lseek(fd, -1, SEEK_CUR);
|
||||
break;
|
||||
case '-':
|
||||
{
|
||||
if (retn) /* 0 preceeds, this negative sign must be in error */
|
||||
goto get_digits;
|
||||
neg = true;
|
||||
continue;
|
||||
}
|
||||
case '0': /* strip preceeding zeros */
|
||||
{
|
||||
*num = 0;
|
||||
retn = 1;
|
||||
continue;
|
||||
}
|
||||
default:
|
||||
goto get_digits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (rb->read(fd, &chbuf, 1) == 1)
|
||||
{
|
||||
get_digits:
|
||||
if(!isdigit(chbuf))
|
||||
{
|
||||
rb->lseek(fd, -1, SEEK_CUR);
|
||||
|
|
Loading…
Reference in a new issue