本文整理汇总了C++中setnilvalue函数的典型用法代码示例。如果您正苦于以下问题:C++ setnilvalue函数的具体用法?C++ setnilvalue怎么用?C++ setnilvalue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setnilvalue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: preinit_state
static void preinit_state (lua_State *L, global_State *g) {
G(L) = g;
L->stack = NULL;
L->stacksize = 0;
L->errorJmp = NULL;
L->hook = NULL;
L->hookmask = 0;
L->basehookcount = 0;
L->allowhook = 1;
resethookcount(L);
L->openupval = NULL;
L->size_ci = 0;
L->nCcalls = L->baseCcalls = 0;
L->status = 0;
L->base_ci = L->ci = NULL;
L->savedpc = NULL;
L->errfunc = 0;
setnilvalue(gt(L));
}
示例2: traversestack
static void traversestack (GCState *st, lua_State *L1) {
StkId o, lim;
CallInfo *ci;
lua_State *L = st->L;
(void)L;
markobject(st, gt(L1));
lim = L1->top;
for (ci = L1->base_ci; ci <= L1->ci; ci++) {
lua_assert(ci->top <= L1->stack_last);
lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));
if (lim < ci->top)
lim = ci->top;
}
for (o = L1->stack; o < L1->top; o++)
markobject(st, o);
for (; o <= lim; o++)
setnilvalue(o);
checkstacksizes(L1, lim);
}
示例3: addk
static int addk (FuncState *fs, TValue *k, TValue *v) {
lua_State *L = fs->L;
TValue *idx = luaH_set(L, fs->h, k);
Proto *f = fs->f;
int oldsize = f->sizek;
if (ttisnumber(idx)) {
lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
return cast_int(nvalue(idx));
}
else { /* constant not found; create a new entry */
setnvalue(idx, cast_num(fs->nk));
luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
MAXARG_Bx, "constant table overflow");
while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
setobj(L, &f->k[fs->nk], v);
luaC_barrier(L, f, v);
return fs->nk++;
}
}
示例4: lua_pushcclosure
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
Closure *cl;
lua_lock(L);
luaC_checkGC(L);
api_checknelems(L, n);
cl = luaF_newCclosure(L, n);
cl->c.f = fn;
L->top -= n;
while (n--)
{
setobj2n(&cl->c.upvalue[n], L->top+n);
#if LUA_REFCOUNT
setnilvalue(L->top+n);
#endif LUA_REFCOUNT
}
setclvalue(L->top, cl);
api_incr_top(L);
lua_unlock(L);
}
示例5: cleartablevalues
/*
** clear collected values from weaktables
*/
static void cleartablevalues (lua_State *L, GCObject *l) {
while (l) {
Table *h = gcotoh(l);
int i = h->sizearray;
lua_assert(h->marked & VALUEWEAK);
while (i--) {
TObject *o = &h->array[i];
if (!valismarked(o)) /* value was collected? */
setnilvalue(o); /* remove value */
}
i = sizenode(h);
while (i--) {
Node *n = gnode(h, i);
if (!valismarked(gval(n))) /* value was collected? */
removekey(L, n); /* remove entry from table */
}
l = h->gclist;
}
}
示例6: addk
static int addk (FuncState *fs, TValue *k, TValue *v) {
lua_State *L = fs->L;
TValue *idx = luaH_set(L, fs->h, k);
#ifdef LUA_TINT
/* Note: Integer-valued LUA_TNUMBER's are handled as in unpatched Lua (below)
*/
if (ttype(idx)==LUA_TINT) {
int i;
# ifdef LNUM_INT64
lua_assert( (int)ivalue(idx) == ivalue(idx) ); /* make sure no data is lost in the casting */
# endif
i= (int)ivalue(idx);
lua_assert(luaO_rawequalObj(&fs->f->k[i], v));
return i;
}
else if (ttype(idx)==LUA_TNUMBER) {
#else
if (ttisnumber(idx)) {
#endif
int i= cast_int(nvalue_fast(idx));
lua_assert(luaO_rawequalObj(&fs->f->k[i], v));
return i;
}
else { /* constant not found; create a new entry */
Proto *f = fs->f;
int oldsize = f->sizek;
setivalue(idx, fs->nk);
luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
MAXARG_Bx, "constant table overflow");
while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
setobj(L, &f->k[fs->nk], v);
luaC_barrier(L, f, v);
return fs->nk++;
}
}
int luaK_stringK (FuncState *fs, TString *s) {
TValue o;
setsvalue(fs->L, &o, s);
return addk(fs, &o, &o);
}
示例7: nilK
static int nilK (FuncState *fs) {
TValue k, v;
#if LUA_REFCOUNT
lua_State *L = fs->L;
int ret;
setnilvalue2n(L, &v);
luarc_newvalue(&k);
/* cannot use nil as key; instead use table itself to represent nil */
sethvalue(fs->L, &k, fs->h);
ret = addk(fs, &k, &v);
luarc_cleanvalue(&k);
luarc_cleanvalue(&v);
return ret;
#else
setnilvalue(&v);
/* cannot use nil as key; instead use table itself to represent nil */
sethvalue(fs->L, &k, fs->h);
return addk(fs, &k, &v);
#endif /* LUA_REFCOUNT */
}
示例8: traversestack
static lu_mem traversestack (global_State *g, lua_State *th) {
int n = 0;
StkId o = th->stack;
if (o == NULL)
return 1; /* stack not completely built yet */
for (; o < th->top; o++) /* mark live elements in the stack */
markvalue(g, o);
if (g->gcstate == GCSatomic) { /* final traversal? */
StkId lim = th->stack + th->stacksize; /* real end of stack */
for (; o < lim; o++) /* clear not-marked stack slice */
setnilvalue(o);
}
else { /* count call infos to compute size */
CallInfo *ci;
for (ci = &th->base_ci; ci != th->ci; ci = ci->next)
n++;
}
return sizeof(lua_State) + sizeof(TValue) * th->stacksize +
sizeof(CallInfo) * n;
}
示例9: php_deserialize
int php_deserialize( rabbit * r, rawbuffer * buf, TValue * tv )
{
if(!buf || !tv) {
return -1;
}
setnilvalue(tv);
int c = decode_read_byte( buf );
switch( c ) {
case PHP_NULL:
// kLOG(r, 0,"php decode nil\n");
return decode_null( r, buf, tv );
case PHP_INT:
// kLOG(r, 0,"php decode int\n");
return decode_int( r, buf, tv );
case PHP_DOUBLE:
// kLOG(r, 0,"php decode double\n");
return decode_double(r, buf, tv);
case PHP_STRING:
// kLOG(r, 0,"php decode string\n");
return decode_string(r, buf, tv);
case PHP_ARRAY:
// kLOG(r, 0,"php decode array\n");
return decode_array(r, buf, tv);
case PHP_BOOL:
return decode_bool(r, buf, tv);
default:
kLOG(r, 0, "php decode unknow:%c\n",c);
break;
}
return -1;
}
示例10: vm_OP_VARARG
void vm_OP_VARARG(lua_State *L, LClosure *cl, int a, int b) {
TValue *base = L->base;
TValue *ra = base + a;
int j;
CallInfo *ci = L->ci;
int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
b -= 1;
if (b == LUA_MULTRET) {
Protect(luaD_checkstack(L, n));
ra = base + a; /* previous call may change the stack */
b = n;
L->top = ra + n;
}
for (j = 0; j < b; j++) {
if (j < n) {
setobjs2s(L, ra + j, ci->base - n + j);
}
else {
setnilvalue(ra + j);
}
}
}
示例11: luaV_settable
void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
int loop;
TValue temp;
setnilvalue(L->top);
L->top++;
fixedstack(L);
for (loop = 0; loop < MAXTAGLOOP; loop++) {
const TValue *tm;
if (ttistable(t) || ttisrotable(t)) { /* `t' is a table? */
void *h = ttistable(t) ? hvalue(t) : rvalue(t);
TValue *oldval = ttistable(t) ? luaH_set(L, (Table*)h, key) : NULL; /* do a primitive set */
if ((oldval && !ttisnil(oldval)) || /* result is no nil? */
(tm = fasttm(L, ttistable(t) ? ((Table*)h)->metatable : (Table*)luaR_getmeta(h), TM_NEWINDEX)) == NULL) { /* or no TM? */
if(oldval) {
L->top--;
unfixedstack(L);
setobj2t(L, oldval, val);
((Table *)h)->flags = 0;
luaC_barriert(L, (Table*)h, val);
}
return;
}
/* else will try the tag method */
}
else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
luaG_typeerror(L, t, "index");
if (ttisfunction(tm) || ttislightfunction(tm)) {
L->top--;
unfixedstack(L);
callTM(L, tm, t, key, val);
return;
}
/* else repeat with `tm' */
setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */
t = &temp;
setobj2s(L, L->top-1, t); /* need to protect value from EGC. */
}
luaG_runerror(L, "loop in settable");
}
示例12: traversethread
static lu_mem traversethread (global_State *g, lua_State *th) {
StkId o = th->stack;
if (o == NULL)
return 1; /* stack not completely built yet */
lua_assert(g->gcstate == GCSinsideatomic ||
th->openupval == NULL || isintwups(th));
for (; o < th->top; o++) /* mark live elements in the stack */
markvalue(g, o);
if (g->gcstate == GCSinsideatomic) { /* final traversal? */
StkId lim = th->stack + th->stacksize; /* real end of stack */
for (; o < lim; o++) /* clear not-marked stack slice */
setnilvalue(o);
/* 'remarkupvals' may have removed thread from 'twups' list */
if (!isintwups(th) && th->openupval != NULL) {
th->twups = g->twups; /* link it back to the list */
g->twups = th;
}
}
else if (g->gckind != KGC_EMERGENCY)
luaD_shrinkstack(th); /* do not change stack in emergency cycle */
return (sizeof(lua_State) + sizeof(TValue) * th->stacksize);
}
示例13: lua_getinfo
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar)
{
int status;
Closure *f = NULL;
CallInfo *ci = NULL;
void *plight = NULL;
lua_lock(L);
if (*what == '>') {
StkId func = L->top - 1;
luai_apicheck(L, ttisfunction(func) || ttislightfunction(func));
what++; /* skip the '>' */
if (ttisfunction(func))
f = clvalue(func);
else
plight = fvalue(func);
L->top--; /* pop function */
} else if (ar->i_ci != 0) { /* no tail call? */
ci = L->base_ci + ar->i_ci;
lua_assert(ttisfunction(ci->func) || ttislightfunction(ci->func));
if (ttisfunction(ci->func))
f = clvalue(ci->func);
else
plight = fvalue(ci->func);
}
status = auxgetinfo(L, what, ar, f, plight, ci);
if (strchr(what, 'f')) {
if (f != NULL)
setclvalue(L, L->top, f)
else if (plight != NULL)
setfvalue(L->top, plight)
else
setnilvalue(L->top);
incr_top(L);
}
if (strchr(what, 'L'))
collectvalidlines(L, f);
lua_unlock(L);
return status;
}
示例14: lua_setmetatable
LUA_API int lua_setmetatable (lua_State *L, int objindex) {
TObject *obj, *mt;
int res = 1;
lua_lock(L);
api_checknelems(L, 1);
obj = luaA_index(L, objindex);
mt = (!ttisnil(L->top - 1)) ? L->top - 1 : defaultmeta(L);
api_check(L, ttistable(mt));
switch (ttype(obj)) {
case LUA_TTABLE: {
#if LUA_REFCOUNT
__AddRefDirect(hvalue(mt));
__ReleaseDirect(L, hvalue(obj)->metatable);
#endif LUA_REFCOUNT
hvalue(obj)->metatable = hvalue(mt); /* write barrier */
break;
}
case LUA_TUSERDATA: {
#if LUA_REFCOUNT
__AddRefDirect(hvalue(mt));
__ReleaseDirect(L, &uvalue(obj)->uv.metatable);
#endif LUA_REFCOUNT
uvalue(obj)->uv.metatable = hvalue(mt); /* write barrier */
break;
}
default: {
res = 0; /* cannot set */
break;
}
}
#if LUA_REFCOUNT
setnilvalue(--L->top);
#else !LUA_REFCOUNT
L->top--;
#endif LUA_REFCOUNT
lua_unlock(L);
return res;
}
示例15: f_luaopen
/*
** open parts of the state that may cause memory-allocation errors.
** ('g->version' != NULL flags that the state was completely build)
*/
static void f_luaopen (lua_State *L, void *ud) {
global_State *g = G(L);
UNUSED(ud);
stack_init(L, L); /* init stack */
init_registry(L, g);
#if LUA_FASTREF_SUPPORT
{
TValue n;
sethvalue(L, &G(L)->l_refs, luaH_new(L)); /* refs */
setivalue(&n, 0);
luaH_setint(L, hvalue(&G(L)->l_refs), LUA_RIDX_FASTREF_FREELIST, &n);
setnilvalue(&g->fastrefNilValue);
}
#endif /* LUA_FASTREF_SUPPORT */
luaS_init(L);
luaT_init(L);
luaX_init(L);
g->gcrunning = 1; /* allow gc */
g->version = lua_version(NULL);
luai_userstateopen(L);
}