mirror of
https://github.com/lua/lua.git
synced 2026-06-07 23:53:48 +00:00
new macro 'setnilvalue2s'
This commit is contained in:
12
lapi.c
12
lapi.c
@@ -187,7 +187,7 @@ LUA_API void lua_settop (lua_State *L, int idx) {
|
||||
api_check(L, idx <= ci->top.p - (func + 1), "new top too large");
|
||||
diff = ((func + 1) + idx) - L->top.p;
|
||||
for (; diff > 0; diff--)
|
||||
setnilvalue(s2v(L->top.p++)); /* clear new slots */
|
||||
setnilvalue2s(L->top.p++); /* clear new slots */
|
||||
}
|
||||
else {
|
||||
api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top");
|
||||
@@ -210,7 +210,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) {
|
||||
api_check(L, (L->ci->callstatus & CIST_TBC) && (L->tbclist.p == level),
|
||||
"no variable to close at given level");
|
||||
level = luaF_close(L, level, CLOSEKTOP, 0);
|
||||
setnilvalue(s2v(level));
|
||||
setnilvalue2s(level);
|
||||
lua_unlock(L);
|
||||
}
|
||||
|
||||
@@ -513,7 +513,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) {
|
||||
|
||||
LUA_API void lua_pushnil (lua_State *L) {
|
||||
lua_lock(L);
|
||||
setnilvalue(s2v(L->top.p));
|
||||
setnilvalue2s(L->top.p);
|
||||
api_incr_top(L);
|
||||
lua_unlock(L);
|
||||
}
|
||||
@@ -570,7 +570,7 @@ LUA_API const char *lua_pushexternalstring (lua_State *L,
|
||||
LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
|
||||
lua_lock(L);
|
||||
if (s == NULL)
|
||||
setnilvalue(s2v(L->top.p));
|
||||
setnilvalue2s(L->top.p);
|
||||
else {
|
||||
TString *ts;
|
||||
ts = luaS_new(L, s);
|
||||
@@ -743,7 +743,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
|
||||
|
||||
static int finishrawget (lua_State *L, lu_byte tag) {
|
||||
if (tagisempty(tag)) /* avoid copying empty items to the stack */
|
||||
setnilvalue(s2v(L->top.p));
|
||||
setnilvalue2s(L->top.p);
|
||||
api_incr_top(L);
|
||||
lua_unlock(L);
|
||||
return novariant(tag);
|
||||
@@ -836,7 +836,7 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) {
|
||||
o = index2value(L, idx);
|
||||
api_check(L, ttisfulluserdata(o), "full userdata expected");
|
||||
if (n <= 0 || n > uvalue(o)->nuvalue) {
|
||||
setnilvalue(s2v(L->top.p));
|
||||
setnilvalue2s(L->top.p);
|
||||
t = LUA_TNONE;
|
||||
}
|
||||
else {
|
||||
|
||||
2
ldebug.c
2
ldebug.c
@@ -291,7 +291,7 @@ static int nextline (const Proto *p, int currentline, int pc) {
|
||||
|
||||
static void collectvalidlines (lua_State *L, Closure *f) {
|
||||
if (!LuaClosure(f)) {
|
||||
setnilvalue(s2v(L->top.p));
|
||||
setnilvalue2s(L->top.p);
|
||||
api_incr_top(L);
|
||||
}
|
||||
else {
|
||||
|
||||
10
ldo.c
10
ldo.c
@@ -349,7 +349,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
|
||||
correctstack(L, oldstack); /* change offsets back to pointers */
|
||||
L->stack_last.p = L->stack.p + newsize;
|
||||
for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++)
|
||||
setnilvalue(s2v(newstack + i)); /* erase new segment */
|
||||
setnilvalue2s(newstack + i); /* erase new segment */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ l_sinline void genmoveresults (lua_State *L, StkId res, int nres,
|
||||
for (i = 0; i < nres; i++) /* move all results to correct place */
|
||||
setobjs2s(L, res + i, firstresult + i);
|
||||
for (; i < wanted; i++) /* complete wanted number of results */
|
||||
setnilvalue(s2v(res + i));
|
||||
setnilvalue2s(res + i);
|
||||
L->top.p = res + wanted; /* top points after the last result */
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres,
|
||||
return;
|
||||
case 1 + 1: /* one value needed */
|
||||
if (nres == 0) /* no results? */
|
||||
setnilvalue(s2v(res)); /* adjust with nil */
|
||||
setnilvalue2s(res); /* adjust with nil */
|
||||
else /* at least one result */
|
||||
setobjs2s(L, res, L->top.p - nres); /* move it to proper place */
|
||||
L->top.p = res + 1;
|
||||
@@ -694,7 +694,7 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
|
||||
setobjs2s(L, ci->func.p + i, func + i);
|
||||
func = ci->func.p; /* moved-down function */
|
||||
for (; narg1 <= nfixparams; narg1++)
|
||||
setnilvalue(s2v(func + narg1)); /* complete missing arguments */
|
||||
setnilvalue2s(func + narg1); /* complete missing arguments */
|
||||
ci->top.p = func + 1 + fsize; /* top for new function */
|
||||
lua_assert(ci->top.p <= L->stack_last.p);
|
||||
ci->u.l.savedpc = p->code; /* starting point */
|
||||
@@ -741,7 +741,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
|
||||
L->ci = ci = prepCallInfo(L, func, status, func + 1 + fsize);
|
||||
ci->u.l.savedpc = p->code; /* starting point */
|
||||
for (; narg < nfixparams; narg++)
|
||||
setnilvalue(s2v(L->top.p++)); /* complete missing arguments */
|
||||
setnilvalue2s(L->top.p++); /* complete missing arguments */
|
||||
lua_assert(ci->top.p <= L->stack_last.p);
|
||||
return ci;
|
||||
}
|
||||
|
||||
2
lgc.c
2
lgc.c
@@ -709,7 +709,7 @@ static l_mem traversethread (global_State *g, lua_State *th) {
|
||||
if (!g->gcemergency)
|
||||
luaD_shrinkstack(th); /* do not change stack in emergency cycle */
|
||||
for (o = th->top.p; o < th->stack_last.p + EXTRA_STACK; o++)
|
||||
setnilvalue(s2v(o)); /* clear dead stack slice */
|
||||
setnilvalue2s(o); /* clear dead stack slice */
|
||||
/* 'remarkupvals' may have removed thread from 'twups' list */
|
||||
if (!isintwups(th) && th->openupval != NULL) {
|
||||
th->twups = g->twups; /* link it back to the list */
|
||||
|
||||
@@ -209,6 +209,7 @@ typedef union {
|
||||
|
||||
|
||||
#define setnilvalue(obj) settt_(obj, LUA_VNIL)
|
||||
#define setnilvalue2s(stk) setnilvalue(s2v(stk))
|
||||
|
||||
|
||||
#define isabstkey(v) checktag((v), LUA_VABSTKEY)
|
||||
|
||||
4
lstate.c
4
lstate.c
@@ -151,7 +151,7 @@ LUAI_FUNC void luaE_incCstack (lua_State *L) {
|
||||
static void resetCI (lua_State *L) {
|
||||
CallInfo *ci = L->ci = &L->base_ci;
|
||||
ci->func.p = L->stack.p;
|
||||
setnilvalue(s2v(ci->func.p)); /* 'function' entry for basic 'ci' */
|
||||
setnilvalue2s(ci->func.p); /* 'function' entry for basic 'ci' */
|
||||
ci->top.p = ci->func.p + 1 + LUA_MINSTACK; /* +1 for 'function' entry */
|
||||
ci->u.c.k = NULL;
|
||||
ci->callstatus = CIST_C;
|
||||
@@ -166,7 +166,7 @@ static void stack_init (lua_State *L1, lua_State *L) {
|
||||
L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
|
||||
L1->tbclist.p = L1->stack.p;
|
||||
for (i = 0; i < BASIC_STACK_SIZE + EXTRA_STACK; i++)
|
||||
setnilvalue(s2v(L1->stack.p + i)); /* erase new stack */
|
||||
setnilvalue2s(L1->stack.p + i); /* erase new stack */
|
||||
L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE;
|
||||
/* initialize first ci */
|
||||
resetCI(L1);
|
||||
|
||||
2
ltests.c
2
ltests.c
@@ -1145,7 +1145,7 @@ static int table_query (lua_State *L) {
|
||||
if (!tagisempty(*getArrTag(t, i)))
|
||||
arr2obj(t, cast_uint(i), s2v(L->top.p));
|
||||
else
|
||||
setnilvalue(s2v(L->top.p));
|
||||
setnilvalue2s(L->top.p);
|
||||
api_incr_top(L);
|
||||
lua_pushnil(L);
|
||||
}
|
||||
|
||||
10
ltm.c
10
ltm.c
@@ -262,7 +262,7 @@ static void buildhiddenargs (lua_State *L, CallInfo *ci, const Proto *p,
|
||||
/* move fixed parameters to after the copied function */
|
||||
for (i = 1; i <= nfixparams; i++) {
|
||||
setobjs2s(L, L->top.p++, ci->func.p + i);
|
||||
setnilvalue(s2v(ci->func.p + i)); /* erase original parameter (for GC) */
|
||||
setnilvalue2s(ci->func.p + i); /* erase original parameter (for GC) */
|
||||
}
|
||||
ci->func.p += totalargs + 1; /* 'func' now lives after hidden arguments */
|
||||
ci->top.p += totalargs + 1;
|
||||
@@ -283,7 +283,7 @@ void luaT_adjustvarargs (lua_State *L, CallInfo *ci, const Proto *p) {
|
||||
lua_assert(p->flag & PF_VAHID);
|
||||
buildhiddenargs(L, ci, p, totalargs, nfixparams, nextra);
|
||||
/* set vararg parameter to nil */
|
||||
setnilvalue(s2v(ci->func.p + nfixparams + 1));
|
||||
setnilvalue2s(ci->func.p + nfixparams + 1);
|
||||
lua_assert(L->top.p <= ci->top.p && ci->top.p <= L->stack_last.p);
|
||||
}
|
||||
}
|
||||
@@ -307,7 +307,7 @@ void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
setnilvalue(s2v(ra)); /* else produce nil */
|
||||
setnilvalue2s(ra); /* else produce nil */
|
||||
}
|
||||
|
||||
|
||||
@@ -355,10 +355,10 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted,
|
||||
for (i = 0; i < touse; i++) {
|
||||
lu_byte tag = luaH_getint(h, i + 1, s2v(where + i));
|
||||
if (tagisempty(tag))
|
||||
setnilvalue(s2v(where + i));
|
||||
setnilvalue2s(where + i);
|
||||
}
|
||||
}
|
||||
for (; i < wanted; i++) /* complete required results with nil */
|
||||
setnilvalue(s2v(where + i));
|
||||
setnilvalue2s(where + i);
|
||||
}
|
||||
|
||||
|
||||
2
lvm.c
2
lvm.c
@@ -303,7 +303,7 @@ lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key,
|
||||
else { /* 't' is a table */
|
||||
tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
|
||||
if (tm == NULL) { /* no metamethod? */
|
||||
setnilvalue(s2v(val)); /* result is nil */
|
||||
setnilvalue2s(val); /* result is nil */
|
||||
return LUA_VNIL;
|
||||
}
|
||||
/* else will try the metamethod */
|
||||
|
||||
Reference in New Issue
Block a user