本文整理汇总了C++中sethvalue函数的典型用法代码示例。如果您正苦于以下问题:C++ sethvalue函数的具体用法?C++ sethvalue怎么用?C++ sethvalue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sethvalue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ktap_init_registry
static void ktap_init_registry(ktap_state *ks)
{
ktap_value mt;
ktap_table *registry = kp_table_new(ks);
sethvalue(&G(ks)->registry, registry);
kp_table_resize(ks, registry, KTAP_RIDX_LAST, 0);
setthvalue(ks, &mt, ks);
kp_table_setint(ks, registry, KTAP_RIDX_MAINTHREAD, &mt);
sethvalue(&mt, kp_table_new(ks));
kp_table_setint(ks, registry, KTAP_RIDX_GLOBALS, &mt);
}
示例2: init_registry
/*
** Create registry table and its predefined values
*/
static void init_registry (lua_State *L, global_State *g) {
TValue temp;
/* create registry */
Table *registry = luaH_new(L);
sethvalue(L, &g->l_registry, registry);
luaH_resize(L, registry, LUA_RIDX_LAST, 0);
/* registry[LUA_RIDX_MAINTHREAD] = L */
setthvalue(L, &temp, L); /* temp = L */
luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp);
/* registry[LUA_RIDX_GLOBALS] = table of globals */
sethvalue(L, &temp, luaH_new(L)); /* temp = new table (global table) */
luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp);
}
示例3: init_registry
/*
** Create registry table and its predefined values
*/
static void init_registry (LUA_State *L, global_State *g) {
TValue mt;
/* create registry */
Table *registry = LUAH_new(L);
sethvalue(L, &g->l_registry, registry);
LUAH_resize(L, registry, LUA_RIDX_LAST, 0);
/* registry[LUA_RIDX_MAINTHREAD] = L */
setthvalue(L, &mt, L);
LUAH_setint(L, registry, LUA_RIDX_MAINTHREAD, &mt);
/* registry[LUA_RIDX_GLOBALS] = table of globals */
sethvalue(L, &mt, LUAH_new(L));
LUAH_setint(L, registry, LUA_RIDX_GLOBALS, &mt);
}
示例4: lua_newtable
LUA_API void lua_newtable (lua_State *L) {
lua_lock(L);
luaC_checkGC(L);
sethvalue(L->top, luaH_new(L, 0, 0));
api_incr_top(L);
lua_unlock(L);
}
示例5: lua_getmetatable
LUA_API int lua_getmetatable (lua_State *L, int objindex) {
const TObject *obj;
Table *mt = NULL;
int res;
lua_lock(L);
obj = luaA_indexAcceptable(L, objindex);
if (obj != NULL) {
switch (ttype(obj)) {
case LUA_TTABLE:
mt = hvalue(obj)->metatable;
break;
case LUA_TUSERDATA:
mt = uvalue(obj)->uv.metatable;
break;
}
}
if (mt == NULL || mt == hvalue(defaultmeta(L)))
res = 0;
else {
sethvalue(L->top, mt);
api_incr_top(L);
res = 1;
}
lua_unlock(L);
return res;
}
示例6: nilK
/*
** Add nil to list of constants and return its index.
*/
static int nilK (FuncState *fs) {
TValue k, v;
setnilvalue(&v);
/* cannot use nil as key; instead use table itself to represent nil */
sethvalue(fs->ls->L, &k, fs->ls->h);
return addk(fs, &k, &v);
}
示例7: ktap_lib_pairs
static int ktap_lib_pairs(ktap_state *ks)
{
ktap_value *v = kp_arg(ks, 1);
ktap_table *t;
if (G(ks)->mainthread != ks) {
kp_error(ks, "only mainthread can call table pairs\n");
return -1;
}
if (ttistable(v)) {
t = hvalue(v);
} else if (ttisaggrtable(v)) {
t = kp_aggrtable_synthesis(ks, ahvalue(v));
} else if (isnil(v)) {
kp_error(ks, "table is nil in pairs\n");
return 0;
} else {
kp_error(ks, "wrong argument for pairs\n");
return 0;
}
setfvalue(ks->top++, ktap_lib_next);
sethvalue(ks->top++, t);
setnilvalue(ks->top++);
return 3;
}
示例8: f_luaopen
/*
** open parts of the state that may cause memory-allocation errors
*/
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, 1, 0)); /* refs */
setnvalue(&n, 0);
setobj2t(L, luaH_setnum(L, hvalue(&G(L)->l_refs), LUA_RIDX_FASTREF_FREELIST), &n);
setnilvalue(&g->fastrefNilValue);
}
#endif /* LUA_FASTREF_SUPPORT */
luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
luaT_init(L);
luaX_init(L);
/* pre-create memory-error message */
g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
luaS_fix(g->memerrmsg); /* it should never be collected */
g->gcrunning = 1; /* allow gc */
g->version = lua_version(NULL);
luai_userstateopen(L);
}
示例9: ktap_init_arguments
static void ktap_init_arguments(ktap_state *ks, int argc, char **argv)
{
const ktap_value *gt = kp_table_getint(hvalue(&G(ks)->registry),
KTAP_RIDX_GLOBALS);
ktap_table *global_tbl = hvalue(gt);
ktap_table *arg_tbl = kp_table_new(ks);
ktap_value arg_tblval;
ktap_value arg_tsval;
int i;
setsvalue(&arg_tsval, kp_tstring_new(ks, "arg"));
sethvalue(&arg_tblval, arg_tbl);
kp_table_setvalue(ks, global_tbl, &arg_tsval, &arg_tblval);
if (!argc)
return;
kp_table_resize(ks, arg_tbl, 100, 100);
for (i = 0; i < argc; i++) {
int res;
ktap_value val;
if (!kstrtoint(argv[i], 10, &res)) {
setnvalue(&val, res);
} else
setsvalue(&val, kp_tstring_new(ks, argv[i]));
kp_table_setint(ks, arg_tbl, i, &val);
}
}
示例10: kp_register_lib
/* function for register library */
void kp_register_lib(ktap_state *ks, const char *libname, const ktap_Reg *funcs)
{
int i;
ktap_table *target_tbl;
const ktap_value *gt = kp_table_getint(hvalue(&G(ks)->registry),
KTAP_RIDX_GLOBALS);
/* lib is null when register baselib function */
if (libname == NULL)
target_tbl = hvalue(gt);
else {
ktap_value key, val;
target_tbl = kp_table_new(ks);
kp_table_resize(ks, target_tbl, 0,
sizeof(*funcs) / sizeof(ktap_Reg));
setsvalue(&key, kp_tstring_new(ks, libname));
sethvalue(&val, target_tbl);
kp_table_setvalue(ks, hvalue(gt), &key, &val);
}
for (i = 0; funcs[i].name != NULL; i++) {
ktap_value func_name, cl;
setsvalue(&func_name, kp_tstring_new(ks, funcs[i].name));
setfvalue(&cl, funcs[i].func);
kp_table_setvalue(ks, target_tbl, &func_name, &cl);
cfunction_cache_add(ks, &cl);
}
}
示例11: setnilvalue
/*static*/ int FuncState::nilK (/*FuncState *fs*/) {
TValue k, v;
setnilvalue(&v);
/* cannot use nil as key; instead use table itself to represent nil */
sethvalue(ls->L, &k, ls->h);
return addk(&k, &v);
}
示例12: lua_getdefaultmetatable
LUA_API void lua_getdefaultmetatable(lua_State *L, int type)
{
lua_lock(L);
sethvalue(L->top, hvalue(defaultmetatypes(L, type)));
api_incr_top(L);
lua_unlock(L);
}
示例13: lua_getmetatable
LUA_API int lua_getmetatable (lua_State *L, int objindex) {
const TValue *obj;
Table *mt = NULL;
int res;
lua_lock(L);
obj = index2addr(L, objindex);
switch (ttypenv(obj)) {
case LUA_TTABLE:
mt = hvalue(obj)->metatable;
break;
case LUA_TUSERDATA:
mt = uvalue(obj)->metatable;
break;
default:
mt = G(L)->mt[ttypenv(obj)];
break;
}
if (mt == NULL)
res = 0;
else {
sethvalue(L, L->top, mt);
api_incr_top(L);
res = 1;
}
lua_unlock(L);
return res;
}
示例14: nilK
static int nilK(ktap_funcstate *fs)
{
ktap_value k, v;
setnilvalue(&v);
/* cannot use nil as key; instead use table itself to represent nil */
sethvalue(&k, fs->h);
return addk(fs, &k, &v);
}
示例15: ktap_lib_pairs
static int ktap_lib_pairs(ktap_State *ks)
{
Table *t = hvalue(GetArg(ks, 1));
setfvalue(ks->top++, ktap_lib_next);
sethvalue(ks->top++, t);
setnilvalue(ks->top++);
return 3;
}