mirror of https://github.com/rusefi/lua.git
better implementation for luaV_pack
This commit is contained in:
parent
ac12f4db4b
commit
4e56c0d514
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbuiltin.c,v 1.122 2000/08/28 17:57:04 roberto Exp roberto $
|
** $Id: lbuiltin.c,v 1.123 2000/08/29 14:33:31 roberto Exp roberto $
|
||||||
** Built-in functions
|
** Built-in functions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -333,7 +333,6 @@ int luaB_call (lua_State *L) {
|
||||||
for (i=0; i<n; i++)
|
for (i=0; i<n; i++)
|
||||||
*(L->top++) = *luaH_getnum(arg, i+1);
|
*(L->top++) = *luaH_getnum(arg, i+1);
|
||||||
status = lua_call(L, n, LUA_MULTRET);
|
status = lua_call(L, n, LUA_MULTRET);
|
||||||
n = lua_gettop(L) - oldtop; /* number of results */
|
|
||||||
if (err != 0) { /* restore old error method */
|
if (err != 0) { /* restore old error method */
|
||||||
lua_pushobject(L, err);
|
lua_pushobject(L, err);
|
||||||
lua_setglobal(L, LUA_ERRORMESSAGE);
|
lua_setglobal(L, LUA_ERRORMESSAGE);
|
||||||
|
@ -347,12 +346,11 @@ int luaB_call (lua_State *L) {
|
||||||
}
|
}
|
||||||
else { /* no errors */
|
else { /* no errors */
|
||||||
if (strchr(options, 'p')) { /* pack results? */
|
if (strchr(options, 'p')) { /* pack results? */
|
||||||
luaV_pack(L, luaA_index(L, oldtop+1), n, L->top);
|
luaV_pack(L, luaA_index(L, oldtop+1));
|
||||||
incr_top;
|
|
||||||
return 1; /* only table is returned */
|
return 1; /* only table is returned */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return n; /* results are already on the stack */
|
return lua_gettop(L) - oldtop; /* results are already on the stack */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
lvm.c
27
lvm.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 1.128 2000/08/22 20:49:29 roberto Exp roberto $
|
** $Id: lvm.c,v 1.129 2000/08/22 20:53:30 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -313,30 +313,25 @@ static void strconc (lua_State *L, int total, StkId top) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaV_pack (lua_State *L, StkId firstelem, int nvararg, TObject *tab) {
|
void luaV_pack (lua_State *L, StkId firstelem) {
|
||||||
int i;
|
int i;
|
||||||
Hash *htab;
|
Hash *htab = luaH_new(L, 0);
|
||||||
htab = hvalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */
|
for (i=0; firstelem+i<L->top; i++)
|
||||||
ttype(tab) = TAG_TABLE;
|
|
||||||
for (i=0; i<nvararg; i++)
|
|
||||||
*luaH_setint(L, htab, i+1) = *(firstelem+i);
|
*luaH_setint(L, htab, i+1) = *(firstelem+i);
|
||||||
/* store counter in field `n' */
|
/* store counter in field `n' */
|
||||||
luaH_setstrnum(L, htab, luaS_new(L, "n"), nvararg);
|
luaH_setstrnum(L, htab, luaS_new(L, "n"), i);
|
||||||
|
L->top = firstelem; /* remove elements from the stack */
|
||||||
|
ttype(L->top) = TAG_TABLE;
|
||||||
|
hvalue(L->top) = htab;
|
||||||
|
incr_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
|
static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
|
||||||
TObject arg;
|
|
||||||
int nvararg = (L->top-base) - nfixargs;
|
int nvararg = (L->top-base) - nfixargs;
|
||||||
if (nvararg < 0) {
|
if (nvararg < 0)
|
||||||
luaV_pack(L, base, 0, &arg);
|
|
||||||
luaD_adjusttop(L, base, nfixargs);
|
luaD_adjusttop(L, base, nfixargs);
|
||||||
}
|
luaV_pack(L, base+nfixargs);
|
||||||
else {
|
|
||||||
luaV_pack(L, base+nfixargs, nvararg, &arg);
|
|
||||||
L->top = base+nfixargs;
|
|
||||||
}
|
|
||||||
*L->top++ = arg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
4
lvm.h
4
lvm.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lvm.h,v 1.22 2000/05/08 19:32:53 roberto Exp roberto $
|
** $Id: lvm.h,v 1.23 2000/06/06 16:31:41 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
#define tostring(L,o) ((ttype(o) != TAG_STRING) && (luaV_tostring(L, o) != 0))
|
#define tostring(L,o) ((ttype(o) != TAG_STRING) && (luaV_tostring(L, o) != 0))
|
||||||
|
|
||||||
|
|
||||||
void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab);
|
void luaV_pack (lua_State *L, StkId firstel);
|
||||||
int luaV_tonumber (TObject *obj);
|
int luaV_tonumber (TObject *obj);
|
||||||
int luaV_tostring (lua_State *L, TObject *obj);
|
int luaV_tostring (lua_State *L, TObject *obj);
|
||||||
void luaV_gettable (lua_State *L, StkId top);
|
void luaV_gettable (lua_State *L, StkId top);
|
||||||
|
|
Loading…
Reference in New Issue