本文整理汇总了C++中rawtsvalue函数的典型用法代码示例。如果您正苦于以下问题:C++ rawtsvalue函数的具体用法?C++ rawtsvalue怎么用?C++ rawtsvalue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rawtsvalue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lessequal
static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
int res;
if (ttype(l) != ttype(r))
return luaG_ordererror(L, l, r);
else if (ttisnumber(l))
return luai_numle(nvalue(l), nvalue(r));
else if (ttisstring(l))
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
return res;
else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
return !res;
return luaG_ordererror(L, l, r);
}
示例2: PrintConstant
static void PrintConstant(const Proto* f, int i)
{
const TValue* o=&f->k[i];
switch (ttype(o))
{
case LUA_TNIL:
printf("nil");
break;
case LUA_TBOOLEAN:
printf(bvalue(o) ? "true" : "false");
break;
case LUA_TINT:
printf(LUA_INTEGER_FMT,ivalue(o));
break;
case LUA_TNUMBER:
#ifdef LNUM_COMPLEX
// TBD: Do we get complex values here?
{ lua_Number b= nvalue_img_fast(o);
printf( LUA_NUMBER_FMT "%s" LUA_NUMBER_FMT "i", nvalue_fast(o), b>=0 ? "+":"", b ); }
#endif
printf(LUA_NUMBER_FMT,nvalue_fast(o));
break;
case LUA_TSTRING:
PrintString(rawtsvalue(o));
break;
default: /* cannot happen */
printf("? type=%d",ttype(o));
break;
}
}
示例3: luaV_lessthan
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
int res;
if (ttype(l) != ttype(r))
return luaG_ordererror(L, l, r);
else if (ttisnumber(l))
return luai_numlt(nvalue(l), nvalue(r));
else if (ttisstring(l))
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
#if LUA_WIDESTRING
else if (ttiswstring(l))
return l_wstrcmp(rawtwsvalue(l), rawtwsvalue(r)) < 0;
#endif /* LUA_WIDESTRING */
else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
return res;
return luaG_ordererror(L, l, r);
}
示例4: DumpConstants
static void DumpConstants(const Proto* f, DumpState* D)
{
int i,n=f->sizek;
DumpInt(n,D);
for (i=0; i<n; i++)
{
const TValue* o=&f->k[i];
DumpChar(ttype(o),D);
switch (ttype(o))
{
case LUA_TNIL:
break;
case LUA_TBOOLEAN:
DumpChar(bvalue(o),D);
break;
case LUA_TNUMBER:
DumpNumber(nvalue(o),D);
break;
case LUA_TSTRING:
DumpString(rawtsvalue(o),D);
break;
default:
lua_assert(0); /* cannot happen */
break;
}
}
n=f->sizep;
DumpInt(n,D);
for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
}
示例5: DumpConstants
static void DumpConstants(const ktap_proto *f, DumpState *D)
{
int i, n = f->sizek;
DumpInt(n, D);
for (i = 0; i < n; i++) {
const ktap_value* o=&f->k[i];
DumpChar(ttypenv(o), D);
switch (ttypenv(o)) {
case KTAP_TNIL:
break;
case KTAP_TBOOLEAN:
DumpChar(bvalue(o), D);
break;
case KTAP_TNUMBER:
DumpNumber(nvalue(o), D);
break;
case KTAP_TSTRING:
DumpString(rawtsvalue(o), D);
break;
default:
printf("ktap: DumpConstants with unknown vaule type %d\n", ttypenv(o));
ktap_assert(0);
}
}
n = f->sizep;
DumpInt(n, D);
for (i = 0; i < n; i++)
DumpFunction(f->p[i], D);
}
示例6: switch
/*
* main search function
*/
const Tvalue *kp_table_get(Table *t, const Tvalue *key)
{
switch (ttype(key)) {
case KTAP_TNIL:
return ktap_nilobject;
case KTAP_TSHRSTR:
return kp_table_getstr(t, rawtsvalue(key));
case KTAP_TNUMBER: {
ktap_Number n = nvalue(key);
int k = (int)n;
if ((ktap_Number)k == nvalue(key)) /* index is int? */
return kp_table_getint(t, k); /* use specialized version */
/* else go through */
}
default: {
Node *n = mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
if (rawequalobj(gkey(n), key))
return gval(n); /* that's it */
else
n = gnext(n);
} while (n);
return ktap_nilobject;
}
}
}
示例7: switch
/*
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
**
** Floating point numbers with integer value give the hash position of the
** integer (so they use the same table position).
*/
static Node *mainposition (const Table *t, const TValue *key) {
switch (ttype(key)) {
#ifdef LUA_TINT
case LUA_TINT:
return hashint(t,ivalue(key));
#endif
case LUA_TNUMBER: {
#ifdef LUA_TINT
lua_Integer i;
if (tt_integer_valued(key,&i))
return hashint(t, i);
# ifdef LNUM_COMPLEX
/* Complex numbers are hashed by their scalar part. Pure imaginary values
* with scalar 0 or -0 should give same hash.
*/
if (nvalue_img_fast(key)!=0 && luai_numeq(nvalue_fast(key),0))
return gnode(t, 0); /* 0 and -0 to give same hash */
# endif
#else
if (luai_numeq(nvalue(key),0)) return gnode(t, 0); /* 0 and -0 to give same hash */
#endif
return hashnum(t,nvalue_fast(key));
}
case LUA_TSTRING:
return hashstr(t, rawtsvalue(key));
case LUA_TBOOLEAN:
return hashboolean(t, bvalue(key));
case LUA_TLIGHTUSERDATA:
return hashpointer(t, pvalue(key));
default:
return hashpointer(t, gcvalue(key));
}
}
示例8: debug_getsize
int debug_getsize(lua_State* L)
{
TValue* o = L->base;
switch (o->tt) {
/* Container types */
case LUA_TTABLE: {
Table *h = hvalue(o);
lua_pushinteger(L, sizeof(Table) + sizeof(TValue) * h->sizearray +
sizeof(Node) * sizenode(h));
break;
}
case LUA_TFUNCTION: {
Closure *cl = clvalue(o);
lua_pushinteger(L, (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :
sizeLclosure(cl->l.nupvalues));
break;
}
case LUA_TTHREAD: {
lua_State *th = thvalue(o);
lua_pushinteger(L, sizeof(lua_State) + sizeof(TValue) * th->stacksize +
sizeof(CallInfo) * th->size_ci);
break;
}
case LUA_TPROTO: {
Proto *p = pvalue(o);
lua_pushinteger(L, sizeof(Proto) + sizeof(Instruction) * p->sizecode +
sizeof(Proto *) * p->sizep +
sizeof(TValue) * p->sizek +
sizeof(int) * p->sizelineinfo +
sizeof(LocVar) * p->sizelocvars +
sizeof(TString *) * p->sizeupvalues);
break;
}
/* Non-containers */
case LUA_TUSERDATA: {
lua_pushnumber(L, uvalue(o)->len);
break;
}
case LUA_TLIGHTUSERDATA: {
lua_pushnumber(L, sizeof(void*));
break;
}
case LUA_TSTRING: {
TString *s = rawtsvalue(o);
lua_pushinteger(L, sizeof(TString) + s->tsv.len + 1);
break;
}
case LUA_TNUMBER: {
lua_pushinteger(L, sizeof(lua_Number));
break;
}
case LUA_TBOOLEAN: {
lua_pushinteger(L, sizeof(int));
break;
}
default: return 0;
}
return 1;
}
示例9: iscleared
/*
** tells whether a key or value can be cleared from a weak
** table. Non-collectable objects are never removed from weak
** tables. Strings behave as `values', so are never removed too. for
** other objects: if really collected, cannot keep them; for objects
** being finalized, keep them in keys, but not in values
*/
static int iscleared (const TValue *o) {
if (!iscollectable(o)) return 0;
else if (ttisstring(o)) {
stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */
return 0;
}
else return iswhite(gcvalue(o));
}
示例10: iscleared
/*
** tells whether a key or value can be cleared from a weak
** table. Non-collectable objects are never removed from weak
** tables. Strings behave as `values', so are never removed too. for
** other objects: if really collected, cannot keep them; for objects
** being finalized, keep them in keys, but not in values
*/
static int iscleared (global_State *g, const TValue *o) {
if (!iscollectable(o)) return 0;
else if (ttisstring(o)) {
markobject(g, rawtsvalue(o)); /* strings are `values', so are never weak */
return 0;
}
else return iswhite(gcvalue(o));
}
示例11: luaV_lessthan
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
int res;
int tl= ttype(l);
if (tl == ttype(r)) {
switch(tl) {
#ifdef LUA_TINT
case LUA_TINT:
return ivalue(l) < ivalue(r);
#endif
case LUA_TNUMBER:
#ifdef LNUM_COMPLEX
if ( (nvalue_img_fast(l)!=0) || (nvalue_img_fast(r)!=0) )
error_complex( L, l, r );
#endif
return luai_numlt(nvalue_fast(l), nvalue_fast(r));
case LUA_TSTRING:
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
}
if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
return res;
/* fall through to 'luaG_ordererror()' */
}
#ifdef LUA_TINT
else if (ttype_ext(l) == ttype_ext(r)) {
lua_Integer tmp;
/* Avoid accuracy losing casts: if 'r' is integer by value, do comparisons
* in integer realm. Only otherwise cast 'l' to FP (which might change its
* value).
*/
# ifdef LNUM_COMPLEX
if ( (nvalue_img(l)!=0) || (nvalue_img(r)!=0) )
error_complex( L, l, r );
# endif
if (tl==LUA_TINT) { /* l:int, r:num */
return tt_integer_valued(r,&tmp) ? (ivalue(l) < tmp)
: luai_numlt( cast_num(ivalue(l)), nvalue_fast(r) );
} else { /* l:num, r:int */
return tt_integer_valued(l,&tmp) ? (tmp < ivalue(r))
: luai_numlt( nvalue_fast(l), cast_num(ivalue(r)) );
}
}
#endif
return luaG_ordererror(L, l, r);
}
示例12: lua_pushlstring
TString *createString(lua_State *luaState, const char *str, size_t len) {
TString *res;
lua_pushlstring(luaState, str, len);
res = rawtsvalue(luaState->top - 1);
lua_pop(luaState, 1);
return res;
}
示例13: iscleared
/*
** The next function tells whether a key or value can be cleared from
** a weak table. Non-collectable objects are never removed from weak
** tables. Strings behave as `values', so are never removed too. for
** other objects: if really collected, cannot keep them; for userdata
** being finalized, keep them in keys, but not in values
*/
static int iscleared (const TValue *o, int iskey) {
if (!iscollectable(o)) return 0;
if (ttisstring(o)) {
stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */
return 0;
}
return iswhite(gcvalue(o)) ||
(ttisuserdata(o) && (!iskey && isfinalized(uvalue(o))));
}
示例14: lessequal
static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
int res;
int tl= ttype(l);
if (tl == ttype(r)) {
switch(tl) {
#ifdef LUA_TINT
case LUA_TINT:
return ivalue(l) <= ivalue(r);
#endif
case LUA_TNUMBER:
#ifdef LNUM_COMPLEX
if ( (nvalue_img_fast(l)!=0) || (nvalue_img_fast(r)!=0) )
error_complex( L, l, r );
#endif
return luai_numle(nvalue_fast(l), nvalue_fast(r));
case LUA_TSTRING:
return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
}
if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
return res;
else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
return !res;
/* fall through to 'luaG_ordererror()' */
}
#ifdef LUA_TINT
else if (ttype_ext(l) == ttype_ext(r)) {
lua_Integer tmp;
# ifdef LNUM_COMPLEX
if ( (nvalue_img(l)!=0) || (nvalue_img(r)!=0) )
error_complex( L, l, r );
# endif
if (tl==LUA_TINT) { /* l:int, r:num */
return tt_integer_valued(r,&tmp) ? (ivalue(l) <= tmp)
: luai_numle( cast_num(ivalue(l)), nvalue_fast(r) );
} else { /* l:num, r:int */
return tt_integer_valued(l,&tmp) ? (tmp <= ivalue(r))
: luai_numle( nvalue_fast(l), cast_num(ivalue(r)) );
}
}
#endif
return luaG_ordererror(L, l, r);
}
示例15: gkey
const ktap_val_t *kp_tab_getstr(ktap_tab_t *t, const ktap_str_t *ts)
{
int i;
for (i = 0; i <= t->hmask; i++) {
ktap_val_t *v = gkey(gnode(t, i));
if (is_string(v) && (ts == rawtsvalue(v)))
return gval(gnode(t, i));
}
return niltv;
}