本文整理汇总了C++中clvalue函数的典型用法代码示例。如果您正苦于以下问题:C++ clvalue函数的具体用法?C++ clvalue怎么用?C++ clvalue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clvalue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lua_getinfo
LUA_API int lua_getinfo(lua_State* L, const char* what, lua_Debug* ar)
{
int status;
Closure* f = NULL;
CallInfo* ci = NULL;
lua_lock(L);
if (*what == '>')
{
StkId func = L->top - 1;
luai_apicheck(L, ttisfunction(func));
what++; /* skip the '>' */
f = clvalue(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));
f = clvalue(ci->func);
}
status = auxgetinfo(L, what, ar, f, ci);
if (strchr(what, 'f'))
{
if (f == NULL) setnilvalue(L->top);
else setclvalue(L, L->top, f);
incr_top(L);
}
if (strchr(what, 'L'))
collectvalidlines(L, f);
lua_unlock(L);
return status;
}
示例2: vm_OP_TAILCALL
int vm_OP_TAILCALL(lua_State *L, int a, int b) {
TValue *func = L->base + a;
Closure *cl;
CallInfo *ci;
StkId st, cur_func;
Proto *p;
int aux;
int tail_recur;
if (b != 0) L->top = func+b; /* else previous instruction set top */
/* current function index */
ci = L->ci;
cur_func = ci->func;
/* check for tail recursive call */
if(gcvalue(func) == gcvalue(cur_func)) {
cl = clvalue(func);
p = cl->l.p;
/* if is not a vararg function. */
tail_recur = !p->is_vararg;
L->savedpc = p->code;
} else {
tail_recur=0;
ci->savedpc = L->savedpc;
if (!ttisfunction(func)) /* `func' is not a function? */
func = luaD_tryfuncTM(L, func); /* check the `function' tag method */
cl = clvalue(func);
#ifndef NDEBUG
if(cl->l.isC) { /* can't tailcall into C functions. Causes problems with getfenv() */
luaD_precall(L, func, LUA_MULTRET);
vm_OP_RETURN(L, a, 0);
return PCRC;
}
#endif
}
/* clean up current frame to prepare to tailcall into next function. */
if (L->openupval) luaF_close(L, ci->base);
for (aux = 0; func+aux < L->top; aux++) /* move frame down */
setobjs2s(L, cur_func+aux, func+aux);
L->top = cur_func+aux;
/* JIT function calling it's self. */
if(tail_recur) {
for (st = L->top; st < ci->top; st++)
setnilvalue(st);
return PCRTAILRECUR;
}
L->base = cur_func; /* point base at new function to call. This is needed by luaD_precall. */
/* unwind stack back to luaD_precall */
return PCRTAILCALL;
}
示例3: luaO_equalval
int luaO_equalval (const TObject *t1, const TObject *t2) {
switch (ttype(t1)) {
case TAG_NUMBER:
return nvalue(t1) == nvalue(t2);
case TAG_STRING: case TAG_USERDATA:
return svalue(t1) == svalue(t2);
case TAG_TABLE:
return avalue(t1) == avalue(t2);
case TAG_CCLOSURE: case TAG_LCLOSURE:
return clvalue(t1) == clvalue(t2);
default:
LUA_ASSERT(L, ttype(t1) == TAG_NIL, "invalid type");
return 1; /* TAG_NIL */
}
}
示例4: setnormalized
static void setnormalized (TObject *d, const TObject *s) {
if (ttype(s) == LUA_TMARK) {
clvalue(d) = infovalue(s)->func;
ttype(d) = LUA_TFUNCTION;
}
else *d = *s;
}
示例5: lua_combine
static int lua_combine( lua_State* L) {
int n = lua_gettop( L); /* Number of functions to combine */
if( 1 == n) {
return 1; /* Only one function, nothing to combine */
} else {
int i, pc = 3*n + 1;
Proto* f = luaF_newproto( L);
setptvalue2s( L,L->top,f);
incr_top( L);
f->source = luaS_newliteral( L,"=(combiner)");
f->maxstacksize = 2;
f->is_vararg = VARARG_ISVARARG;
f->code = luaM_newvector(L, pc, Instruction);
f->sizecode = pc;
f->p = luaM_newvector( L, n, Proto*);
f->sizep = n;
for( i = pc = 0; i < n; i ++) {
int proto_idx = i-n-1;
Proto *p = clvalue( L->top + proto_idx)->l.p;
f->p[i] = p;
f->code[pc++] = CREATE_ABx( OP_CLOSURE, 0, i);
f->code[pc++] = CREATE_ABx( OP_VARARG, 1, 0);
f->code[pc++] = CREATE_ABC( OP_CALL, 0, 0, 1);
}
f->code[pc++] = CREATE_ABC( OP_RETURN, 0, 1, 0);
return 1;
}
}
示例6: lua_getref
int CScriptSystem::GetFunctionParamName(HSCRIPTFUNCTION hFunc, XmlNodeRef& funcNode)
{
lua_getref(m_pLS, (int)hFunc);
StkId func = m_pLS->top - 1;
Closure* cl;
if (ttype(func) != LUA_TFUNCTION)
{
lua_pop(m_pLS, 1);
return -1;
}
cl = clvalue(func);
int numParams = cl->l.p->numparams;
int validParams = numParams;
for (int j = 0, i = 0 ; j < numParams; j++)
{
const char* name = luaF_getlocalname(cl->l.p, j + 1, 0);
BEHAVIAC_ASSERT(name);
if (!string_icmp(name, "self"))
{
validParams--;
continue;
}
// There is no value for now, so store the index as the value
funcNode->setAttr(name, i);
++i;
}
lua_pop(m_pLS, 1); // lua_getref pop
return validParams;
}
示例7: luaV_setglobal
void luaV_setglobal (lua_State *L, TString *s) {
const TObject *oldvalue = luaH_getstr(L->gt, s);
Closure *tm = luaT_gettmbyObj(L, oldvalue, TM_SETGLOBAL);
if (tm == NULL) { /* is there a tag method? */
if (oldvalue != &luaO_nilobject) {
/* cast to remove `const' is OK, because `oldvalue' != luaO_nilobject */
*(TObject *)oldvalue = *(L->top - 1);
}
else {
TObject key;
ttype(&key) = LUA_TSTRING;
tsvalue(&key) = s;
*luaH_set(L, L->gt, &key) = *(L->top - 1);
}
}
else {
luaD_checkstack(L, 3);
*(L->top+2) = *(L->top-1); /* new value */
*(L->top+1) = *oldvalue;
ttype(L->top) = LUA_TSTRING;
tsvalue(L->top) = s;
clvalue(L->top-1) = tm;
ttype(L->top-1) = LUA_TFUNCTION;
L->top += 3;
luaD_call(L, L->top - 4, 0);
}
}
示例8: write_function
// Dump bytecode representation of function onto stack and send. This
// implementation uses eLua's crosscompile dump to match match the
// bytecode representation to the client/server negotiated format.
static void write_function( Transport *tpt, lua_State *L, int var_index )
{
TValue *o;
luaL_Buffer b;
DumpTargetInfo target;
target.little_endian=tpt->net_little;
target.sizeof_int=sizeof(int);
target.sizeof_strsize_t=sizeof(strsize_t);
target.sizeof_lua_Number=tpt->lnum_bytes;
target.lua_Number_integral=tpt->net_intnum;
target.is_arm_fpa=0;
// push function onto stack, serialize to string
lua_pushvalue( L, var_index );
luaL_buffinit( L, &b );
lua_lock(L);
o = L->top - 1;
luaU_dump_crosscompile(L,clvalue(o)->l.p,writer,&b,0,target);
lua_unlock(L);
// put string representation on stack and send it
luaL_pushresult( &b );
write_variable( tpt, L, lua_gettop( L ) );
// Remove function & dumped string from stack
lua_pop( L, 2 );
}
示例9: switch
/*
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
*/
Node *luaH_mainposition (const Hash *t, const TObject *key) {
unsigned h;
switch (ttype(key)) {
case LUA_TNUMBER:
h = (unsigned)(int)nvalue(key);
break;
case LUA_TSTRING:
h = tsvalue(key)->u.s.hash;
break;
case LUA_TUSERDATA:
h = IntPoint(tsvalue(key));
break;
case LUA_TTABLE:
h = IntPoint(hvalue(key));
break;
case LUA_TFUNCTION:
h = IntPoint(clvalue(key));
break;
default:
return NULL; /* invalid key */
}
LUA_ASSERT(h%(unsigned int)t->size == (h&((unsigned int)t->size-1)),
"a&(x-1) == a%x, for x power of 2");
return &t->node[h&(t->size-1)];
}
示例10: kplib_sort_pairs
static int kplib_sort_pairs(ktap_state *ks)
{
ktap_value *v = kp_arg(ks, 1);
ktap_closure *cmp_func = NULL;
ktap_tab *t;
if (is_table(v)) {
t = hvalue(v);
} else if (is_ptable(v)) {
t = kp_ptab_synthesis(ks, phvalue(v));
} else if (is_nil(v)) {
kp_error(ks, "table is nil in pairs\n");
return 0;
} else {
kp_error(ks, "wrong argument for pairs\n");
return 0;
}
if (kp_arg_nr(ks) > 1) {
kp_arg_check(ks, 2, KTAP_TYPE_FUNCTION);
cmp_func = clvalue(kp_arg(ks, 2));
}
kp_tab_sort(ks, t, cmp_func);
set_cfunction(ks->top++, table_sort_iter_next);
set_table(ks->top++, t);
set_nil(ks->top++);
return 3;
}
示例11: lua_getinfo
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
int status;
Closure *cl;
CallInfo *ci;
StkId func;
lua_lock(L);
if (*what == '>') {
ci = NULL;
func = L->top - 1;
api_check(L, ttisfunction(func), "function expected");
what++; /* skip the '>' */
L->top--; /* pop function */
}
else {
ci = ar->i_ci;
func = ci->func;
lua_assert(ttisfunction(ci->func));
}
cl = ttisclosure(func) ? clvalue(func) : NULL;
status = auxgetinfo(L, what, ar, cl, ci);
if (strchr(what, 'f')) {
setobjs2s(L, L->top, func);
api_incr_top(L);
}
if (strchr(what, 'L'))
collectvalidlines(L, cl);
lua_unlock(L);
return status;
}
示例12: hvalue
/*
** Function to index a table.
** Receives the table at `t' and the key at top.
*/
const TObject *luaV_gettable (lua_State *L, StkId t) {
Closure *tm;
int tg;
if (ttype(t) == LUA_TTABLE && /* `t' is a table? */
((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */
luaT_gettm(L, tg, TM_GETTABLE) == NULL)) { /* or no TM? */
/* do a primitive get */
const TObject *h = luaH_get(L, hvalue(t), L->top-1);
/* result is no nil or there is no `index' tag method? */
if (ttype(h) != LUA_TNIL || ((tm=luaT_gettm(L, tg, TM_INDEX)) == NULL))
return h; /* return result */
/* else call `index' tag method */
}
else { /* try a `gettable' tag method */
tm = luaT_gettmbyObj(L, t, TM_GETTABLE);
}
if (tm != NULL) { /* is there a tag method? */
luaD_checkstack(L, 2);
*(L->top+1) = *(L->top-1); /* key */
*L->top = *t; /* table */
clvalue(L->top-1) = tm; /* tag method */
ttype(L->top-1) = LUA_TFUNCTION;
L->top += 2;
luaD_call(L, L->top - 3, 1);
return L->top - 1; /* call result */
}
else { /* no tag method */
luaG_typeerror(L, t, "index");
return NULL; /* to avoid warnings */
}
}
示例13: ju_stats
/* local stats = jit.util.stats(func) */
static int ju_stats(lua_State *L)
{
if (!(L->top > L->base))
luaL_argerror(L, 1, "Lua function expected");
if (isLfunction(L->base)) {
Proto *pt = clvalue(L->base)->l.p;
lua_createtable(L, 0, 11);
setintfield("status", pt->jit_status);
setintfield("stackslots", pt->maxstacksize);
setintfield("params", pt->numparams);
setintfield("bytecodes", pt->sizecode);
setintfield("consts", pt->sizek);
setintfield("upvalues", pt->nups);
setintfield("subs", pt->sizep);
lua_pushboolean(L, pt->is_vararg);
lua_setfield(L, -2, "isvararg");
lua_getfenv(L, 1);
lua_setfield(L, -2, "env");
if (pt->jit_szmcode != 0) {
setintfield("mcodesize", (int)mcodesize(pt));
lua_pushnumber(L, (lua_Number)(size_t)pt->jit_mcode);
lua_setfield(L, -2, "mcodeaddr");
}
return 1;
} else {
return 0; /* Don't throw an error like the other util functions. */
}
}
示例14: luaO_equalObj
int luaO_equalObj (const TObject *t1, const TObject *t2) {
if (ttype(t1) != ttype(t2)) return 0;
switch (ttype(t1)) {
case LUA_TNUMBER:
return nvalue(t1) == nvalue(t2);
case LUA_TSTRING: case LUA_TUSERDATA:
return tsvalue(t1) == tsvalue(t2);
case LUA_TTABLE:
return hvalue(t1) == hvalue(t2);
case LUA_TFUNCTION:
return clvalue(t1) == clvalue(t2);
default:
LUA_ASSERT(ttype(t1) == LUA_TNIL, "invalid type");
return 1; /* LUA_TNIL */
}
}
示例15: luaD_callTM
void luaD_callTM (lua_State *L, Closure *f, int nParams, int nResults) {
StkId base = L->top - nParams;
luaD_openstack(L, base);
clvalue(base) = f;
ttype(base) = LUA_TFUNCTION;
luaD_call(L, base, nResults);
}