这篇教程C++ ttisnumber函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中ttisnumber函数的典型用法代码示例。如果您正苦于以下问题:C++ ttisnumber函数的具体用法?C++ ttisnumber怎么用?C++ ttisnumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了ttisnumber函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: arrayindex/*** returns the index for `key' if `key' is an appropriate key to live in** the array part of the table, -1 otherwise.*/static int arrayindex (const TValue *key) { if (ttisnumber(key)) { int k; lua_Number n = nvalue(key); lua_number2int(k, n); if (luai_numeq(cast_num(k), n)) return k; } return -1; /* `key' did not match some condition */}
开发者ID:renemilk,项目名称:spring,代码行数:15,
示例2: luaT_trybinTMvoid luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event) { if (!callbinTM(L, p1, p2, res, event)) { switch (event) { case TM_CONCAT: luaG_concaterror(L, p1, p2); /* call never returns, but to avoid warnings: *//* FALLTHROUGH */ case TM_BAND: case TM_BOR: case TM_BXOR: case TM_SHL: case TM_SHR: case TM_BNOT: { if (ttisnumber(p1) && ttisnumber(p2)) luaG_tointerror(L, p1, p2); else luaG_opinterror(L, p1, p2, "perform bitwise operation on"); } /* calls never return, but to avoid warnings: *//* FALLTHROUGH */ default: luaG_opinterror(L, p1, p2, "perform arithmetic on"); } }}
开发者ID:lua,项目名称:lua,代码行数:20,
示例3: arrayindexstatic int arrayindex(const Tvalue *key){ if (ttisnumber(key)) { ktap_Number n = nvalue(key); int k = (int)n; if ((ktap_Number)k == n) return k; } return -1; /* `key' did not match some condition */}
开发者ID:eric-zhu,项目名称:ktap,代码行数:11,
示例4: luaV_tostringint luaV_tostring (lua_State *L, StkId obj) { if (!ttisnumber(obj)) return 0; else { char s[LUAI_MAXNUMBER2STR]; lua_Number n = nvalue(obj); lua_number2str(s, n); setsvalue2s(L, obj, luaS_new(L, s)); return 1; }}
开发者ID:HipsterLion,项目名称:SRB2,代码行数:11,
示例5: luaV_tostring/* 转换成字符串对象 * L lua虚拟机状态 * obj 要转换的对象的栈索引 */int luaV_tostring (lua_State *L, StkId obj) { /* 如果对象不是数字类型对象则失败 */ if (!ttisnumber(obj)) return 0; else { char s[LUAI_MAXNUMBER2STR]; lua_Number n = nvalue(obj); /* 返回整型的值 */ int l = lua_number2str(s, n); setsvalue2s(L, obj, luaS_newlstr(L, s, l)); return 1; }}
开发者ID:devilogic,项目名称:xlua,代码行数:16,
示例6: luaV_lessthanint 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; else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) return res; return luaG_ordererror(L, l, r);}
开发者ID:angryzor,项目名称:luajit-tilepro64,代码行数:12,
示例7: setnvalue/* 转化数字 * obj 要设置的值 * n 要设置的对象 */const TValue *luaV_tonumber (const TValue *obj, TValue *n) { lua_Number num; /* 如果obj是数字类型则直接返回 */ if (ttisnumber(obj)) return obj; if (ttisstring(obj) && luaO_str2d(svalue(obj), tsvalue(obj)->len, &num)) { /* 设置对象的值 */ setnvalue(n, num); return n; } else return NULL;}
开发者ID:devilogic,项目名称:xlua,代码行数:16,
示例8: lua_arithLUA_API void lua_arith (lua_State *L, int op) { StkId o1; /* 1st operand */ StkId o2; /* 2nd operand */ lua_lock(L); if (op != LUA_OPUNM) /* all other operations expect two operands */ api_checknelems(L, 2); else { /* for unary minus, add fake 2nd operand */ api_checknelems(L, 1); setobjs2s(L, L->top, L->top - 1); L->top++; } o1 = L->top - 2; o2 = L->top - 1; if (ttisnumber(o1) && ttisnumber(o2)) { changenvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2))); } else luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD)); L->top--; lua_unlock(L);}
开发者ID:AdunSG,项目名称:Pktgen-DPDK,代码行数:21,
示例9: luaV_lessthanint luaV_lessthan (lua_State *L, const TObject *l, const TObject *r) { int res; if (ttype(l) != ttype(r)) return luaG_ordererror(L, l, r); else if (ttisnumber(l)) return nvalue(l) < nvalue(r); else if (ttisstring(l)) return luaV_strcmp(tsvalue(l), tsvalue(r)) < 0; else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) return res; return luaG_ordererror(L, l, r);}
开发者ID:TheWaWaR,项目名称:my-lua5.0,代码行数:12,
示例10: setnvalueconst TValue *luaV_tonumber (const TValue *obj, TValue *n){ lua_Number num; if (ttisnumber(obj)) return obj; if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { setnvalue(n, num); return n; } else return NULL;}
开发者ID:jiangguang5201314,项目名称:ZNginx,代码行数:12,
示例11: luaV_lessequal/*** Main operation less than or equal to; return 'l <= r'. If it needs** a metamethod and there is no '__le', try '__lt', based on** l <= r iff !(r < l) (assuming a total order). If the metamethod** yields during this substitution, the continuation has to know** about it (to negate the result of r<l); bit CIST_LEQ in the call** status keeps that information.*/int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { int res;#ifndef _KERNEL if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */ return LEnum(l, r);#else /* _KERNEL */ if (ttisinteger(l) && ttisinteger(r)) /* both operands are integers? */ return (ivalue(l) <= ivalue(r));#endif /* _KERNEL */ else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ return l_strcmp(tsvalue(l), tsvalue(r)) <= 0; else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */ return res; else { /* try 'lt': */ L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */ res = luaT_callorderTM(L, r, l, TM_LT); L->ci->callstatus ^= CIST_LEQ; /* clear mark */ if (res < 0) luaG_ordererror(L, l, r); return !res; /* result is negated */ }}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:30,
示例12: luaV_lessequalstatic int luaV_lessequal (lua_State *L, const TObject *l, const TObject *r) { int res; if (ttype(l) != ttype(r)) return luaG_ordererror(L, l, r); else if (ttisnumber(l)) return nvalue(l) <= nvalue(r); else if (ttisstring(l)) return luaV_strcmp(tsvalue(l), tsvalue(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);}
开发者ID:TheWaWaR,项目名称:my-lua5.0,代码行数:14,
示例13: luaV_lessequalint luaV_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);}
开发者ID:angryzor,项目名称:luajit-tilepro64,代码行数:14,
示例14: hashnumconst Tvalue *kp_table_getint(Table *t, int key){ Node *n; if ((unsigned int)(key - 1) < (unsigned int)t->sizearray) return &t->array[key - 1]; n = hashnum(t, key); do { if (ttisnumber(gkey(n)) && nvalue(gkey(n)) == key) return gval(n); else n = gnext(n); } while (n); return ktap_nilobject;}
开发者ID:eric-zhu,项目名称:ktap,代码行数:17,
示例15: luaV_concatvoid luaV_concat (lua_State *L, int total, int last) { lu_mem max_sizet = MAX_SIZET; if (G(L)->memlimit < max_sizet) max_sizet = G(L)->memlimit; do { /* Any call which does a memory allocation may trim the stack, invalidating top unless the stack is fixed duri ng the allocation */ StkId top = L->base + last + 1; fixedstack(L); int n = 2; /* number of elements handled in this pass (at least 2) */ if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { unfixedstack(L); if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) { /* restore 'top' pointer, since stack might have been reallocted */ top = L->base + last + 1; luaG_concaterror(L, top-2, top-1); } } else if (tsvalue(top-1)->len == 0) { /* second op is empty? */ (void)tostring(L, top - 2); /* result is first op (as string) */ } else { /* at least two string values; get as many as possible */ size_t tl = tsvalue(top-1)->len; char *buffer; int i; /* collect total length */ for (n = 1; n < total && tostring(L, top-n-1); n++) { size_t l = tsvalue(top-n-1)->len; if (l >= max_sizet - tl) luaG_runerror(L, "string length overflow"); tl += l; } G(L)->buff.n = tl; buffer = luaZ_openspace(L, &G(L)->buff, tl); tl = 0; for (i=n; i>0; i--) { /* concat all strings */ size_t l = tsvalue(top-i)->len; c_memcpy(buffer+tl, svalue(top-i), l); tl += l; } setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); luaZ_resetbuffer(&G(L)->buff); } total -= n-1; /* got `n' strings to create 1 new */ last -= n-1; unfixedstack(L); } while (total > 1); /* repeat until only 1 result left */}
开发者ID:Dxploto,项目名称:nodemcu-firmware,代码行数:45,
示例16: addkstatic 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++; }}
开发者ID:xiqingping,项目名称:embedded_template,代码行数:18,
示例17: addkstatic 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);}
开发者ID:7568168,项目名称:cheat-engine,代码行数:42,
示例18: luaV_tostringint luaV_tostring (lua_State *L, StkId obj) { if (!ttisnumber(obj)) return 0; else { char buff[MAXNUMBER2STR]; size_t len; if (ttisinteger(obj)) len = lua_integer2str(buff, ivalue(obj)); else { len = lua_number2str(buff, fltvalue(obj)); if (strspn(buff, "-0123456789") == len) { /* look like an integer? */ buff[len++] = '.'; /* add a '.0' */ buff[len++] = '0'; buff[len] = '/0'; } } setsvalue2s(L, obj, luaS_newlstr(L, buff, len)); return 1; }}
开发者ID:UniTN-Mechatronics,项目名称:lua,代码行数:20,
示例19: switch/* * If 'obj' is a string, it is tried to be interpreted as a number. */const TValue *luaV_tonumber ( const TValue *obj, TValue *n) { lua_Number d; lua_Integer i; if (ttisnumber(obj)) return obj; if (ttisstring(obj)) { switch( luaO_str2d( svalue(obj), &d, &i ) ) { case TK_INT: setivalue(n,i); return n; case TK_NUMBER: setnvalue(n,d); return n;#ifdef LNUM_COMPLEX case TK_NUMBER2: /* "N.NNNi", != 0 */ setnvalue_complex_fast(n, d*I); return n;#endif } } return NULL;}
开发者ID:JDuverge,项目名称:windirstat,代码行数:23,
示例20: luaV_concatvoid luaV_concat (lua_State *L, int total, int last){ do { StkId top = L->base + last + 1; int n = 2; /* number of elements handled in this pass (at least 2) */ if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) luaG_concaterror(L, top-2, top-1); } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ (void)tostring(L, top - 2); /* result is first op (as string) */ else { /* at least two string values; get as many as possible */ size_t tl = tsvalue(top-1)->len; char *buffer; int i; /* collect total length */ for (n = 1; n < total && tostring(L, top-n-1); n++) { size_t l = tsvalue(top-n-1)->len; if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); tl += l; } buffer = luaZ_openspace(L, &G(L)->buff, tl); tl = 0; for (i=n; i>0; i--) /* concat all strings */ { size_t l = tsvalue(top-i)->len; memcpy(buffer+tl, svalue(top-i), l); tl += l; } setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); } total -= n-1; /* got `n' strings to create 1 new */ last -= n-1; } while (total > 1); /* repeat until only 1 result left */}
开发者ID:jiangguang5201314,项目名称:ZNginx,代码行数:41,
示例21: luaV_concatvoid luaV_concat (lua_State *L, int total) { lua_assert(total >= 2); do { StkId top = L->top; int n = 2; /* number of elements handled in this pass (at least 2) */ if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) luaG_concaterror(L, top-2, top-1); } else if (tsvalue(top-1)->len == 0) /* second operand is empty? */ (void)tostring(L, top - 2); /* result is first operand */ else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) { setsvalue2s(L, top-2, rawtsvalue(top-1)); /* result is second op. */ } else { /* at least two non-empty string values; get as many as possible */ size_t tl = tsvalue(top-1)->len; char *buffer; int i; /* collect total length */ for (i = 1; i < total && tostring(L, top-i-1); i++) { size_t l = tsvalue(top-i-1)->len; if (l >= (MAX_SIZET/sizeof(char)) - tl) luaG_runerror(L, "string length overflow"); tl += l; } buffer = luaZ_openspace(L, &G(L)->buff, tl); tl = 0; n = i; do { /* concat all strings */ size_t l = tsvalue(top-i)->len; memcpy(buffer+tl, svalue(top-i), l * sizeof(char)); tl += l; } while (--i > 0); setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); } total -= n-1; /* got 'n' strings to create 1 new */ L->top -= n-1; /* popped 'n' strings and pushed one */ } while (total > 1); /* repeat until only 1 result left */}
开发者ID:lriki,项目名称:Volkoff,代码行数:40,
示例22: luaR_next/* next (used for iteration) */void luaR_next(lua_State *L, void *data, TValue *key, TValue *val) { const luaR_entry* pentries = (const luaR_entry*)data; char strkey[LUA_MAX_ROTABLE_NAME + 1], *pstrkey = NULL; luaR_numkey numkey = 0; unsigned keypos; /* Special case: if key is nil, return the first element of the rotable */ if (ttisnil(key)) luaR_next_helper(L, pentries, 0, key, val); else if (ttisstring(key) || ttisnumber(key)) { /* Find the previoud key again */ if (ttisstring(key)) { luaR_getcstr(strkey, rawtsvalue(key), LUA_MAX_ROTABLE_NAME); pstrkey = strkey; } else numkey = (luaR_numkey)nvalue(key); luaR_findentry(data, pstrkey, numkey, &keypos); /* Advance to next key */ keypos ++; luaR_next_helper(L, pentries, keypos, key, val); }}
开发者ID:Theemuts,项目名称:eLuaBrain,代码行数:23,
示例23: ifNAMESPACE_LUA_BEGIN/* limit for table tag-method chains (to avoid loops) */#define MAXTAGLOOP 100const TValue *luaV_tonumber(const TValue *obj, TValue *n){ lua_Number num = 0.0f; if (ttisnumber(obj)) return obj; if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { setnvalue(n, num); return n; } else if (ttiswstring(obj) && luaO_wstr2d(wsvalue(obj), &num)) { setnvalue(n, num); return n; } else return NULL;}
开发者ID:chaosren,项目名称:HHHH,代码行数:23,
示例24: addkstatic int addk (FuncState *fs, TValue *key, TValue *v) { lua_State *L = fs->L; TValue *idx = luaH_set(L, fs->h, key); Proto *f = fs->f; int k, oldsize; if (ttisnumber(idx)) { lua_Number n = nvalue(idx); lua_number2int(k, n); if (luaO_rawequalObj(&f->k[k], v)) return k; /* else may be a collision (e.g., between 0.0 and "/0/0/0/0/0/0/0/0"); go through and create a new entry for this value */ } /* constant not found; create a new entry */ oldsize = f->sizek; k = fs->nk; setnvalue(idx, cast_num(k)); luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); setobj(L, &f->k[k], v); fs->nk++; luaC_barrier(L, f, v); return k;}
开发者ID:mascarenhas,项目名称:lua52-in-leave,代码行数:24,
示例25: luaV_execute//.........这里部分代码省略......... } case OP_SELF: { StkId rb = RB(i); setobjs2s(L, ra+1, rb); Protect(luaV_gettable(L, rb, RKC(i), ra)); continue; } case OP_ADD: { arith_op(luai_numadd, TM_ADD); continue; } case OP_SUB: { arith_op(luai_numsub, TM_SUB); continue; } case OP_MUL: { arith_op(luai_nummul, TM_MUL); continue; } case OP_DIV: { arith_op(luai_numdiv, TM_DIV); continue; } case OP_MOD: { arith_op(luai_nummod, TM_MOD); continue; } case OP_POW: { arith_op(luai_numpow, TM_POW); continue; } case OP_UNM: { TValue *rb = RB(i); if (ttisnumber(rb)) { lua_Number nb = nvalue(rb); setnvalue(ra, luai_numunm(nb)); } else { Protect(luaV_arith(L, ra, rb, rb, TM_UNM)); } continue; } case OP_NOT: { int res = l_isfalse(RB(i)); /* next assignment may change this value */ setbvalue(ra, res); continue; } case OP_LEN: { const TValue *rb = RB(i); switch (ttype(rb)) { case LUA_TTABLE: { setnvalue(ra, cast_num(luaH_getn(hvalue(rb)))); break; } case LUA_TSTRING: { setnvalue(ra, cast_num(tsvalue(rb)->len)); break; } default: { /* try metamethod */ Protect( if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) luaG_typeerror(L, rb, "get length of"); ) } } continue;
开发者ID:angryzor,项目名称:luajit-tilepro64,代码行数:67,
示例26: luaG_concaterrorl_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2) { if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; lua_assert(!ttisstring(p1) && !ttisnumber(p1)); luaG_typeerror(L, p1, "concatenate");}
开发者ID:crazii,项目名称:mameplus,代码行数:5,
示例27: arith_mode1static inline int arith_mode1( const TValue *rb ) { return ttisint(rb) ? TK_INT : ttiscomplex(rb) ? TK_NUMBER2 : ttisnumber(rb) ? TK_NUMBER : 0;}
开发者ID:JDuverge,项目名称:windirstat,代码行数:5,
示例28: arith_modestatic inline int arith_mode( const TValue *rb, const TValue *rc ) { if (ttisint(rb) && ttisint(rc)) return TK_INT; if (ttiscomplex(rb) || ttiscomplex(rc)) return TK_NUMBER2; if (ttisnumber(rb) && ttisnumber(rc)) return TK_NUMBER; return 0;}
开发者ID:JDuverge,项目名称:windirstat,代码行数:6,
示例29: luaV_execute//.........这里部分代码省略......... int b = GETARG_B(i); setobj(cl->upvals[b]->v, ra); /* write barrier */ break; } case OP_SETTABLE: { luaV_settable(L, ra, RKB(i), RKC(i)); break; } case OP_NEWTABLE: { int b = GETARG_B(i); b = fb2int(b); sethvalue(ra, luaH_new(L, b, GETARG_C(i))); luaC_checkGC(L); break; } case OP_SELF: { StkId rb = RB(i); TObject *rc = RKC(i); runtime_check(L, ttisstring(rc)); setobjs2s(ra+1, rb); if (ttistable(rb)) { const TObject *v = luaH_getstr(hvalue(rb), tsvalue(rc)); if (!ttisnil(v)) { setobj2s(ra, v); } else setobj2s(XRA(i), luaV_index(L, rb, rc, 0)); } else setobj2s(XRA(i), luaV_getnotable(L, rb, rc, 0)); break; } case OP_ADD: { TObject *rb = RKB(i); TObject *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { setnvalue(ra, nvalue(rb) + nvalue(rc)); } else Arith(L, ra, rb, rc, TM_ADD); break; } case OP_SUB: { TObject *rb = RKB(i); TObject *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { setnvalue(ra, nvalue(rb) - nvalue(rc)); } else Arith(L, ra, rb, rc, TM_SUB); break; } case OP_MUL: { TObject *rb = RKB(i); TObject *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { setnvalue(ra, nvalue(rb) * nvalue(rc)); } else Arith(L, ra, rb, rc, TM_MUL); break; } case OP_DIV: { TObject *rb = RKB(i); TObject *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { setnvalue(ra, nvalue(rb) / nvalue(rc)); }
开发者ID:TheWaWaR,项目名称:my-lua5.0,代码行数:67,
示例30: Arithstatic void Arith (lua_State *L, StkId ra, const TValue *rb, const TValue *rc, TMS op) { TValue tempb, tempc; const TValue *b, *c;#if LUA_REFCOUNT luarc_newvalue(&tempb); luarc_newvalue(&tempc); if ((b = luaV_tonumber(L, rb, &tempb)) != NULL && (c = luaV_tonumber(L, rc, &tempc)) != NULL) {#else if ((b = luaV_tonumber(rb, &tempb)) != NULL && (c = luaV_tonumber(rc, &tempc)) != NULL) {#endif /* LUA_REFCOUNT */ lua_Number nb = nvalue(b), nc = nvalue(c);#if LUA_REFCOUNT luarc_cleanvalue(&tempb); luarc_cleanvalue(&tempc);#endif /* LUA_REFCOUNT */ switch (op) { case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; default: lua_assert(0); break; } }#if LUA_REFCOUNT else if (!call_binTM(L, rb, rc, ra, op)) { luarc_cleanvalue(&tempb); luarc_cleanvalue(&tempc); luaG_aritherror(L, rb, rc); }#else else if (!call_binTM(L, rb, rc, ra, op)) luaG_aritherror(L, rb, rc);#endif /* LUA_REFCOUNT */}/*** some macros for common tasks in `luaV_execute'*/#define runtime_check(L, c) { if (!(c)) break; }#define RA(i) (base+GETARG_A(i))/* to be used after possible stack reallocation */#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, / ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, / ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))#define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))#define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);}#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }#define arith_op(op,tm) { / TValue *rb = RKB(i); / TValue *rc = RKC(i); / if (ttisnumber(rb) && ttisnumber(rc)) { / lua_Number nb = nvalue(rb), nc = nvalue(rc); / setnvalue(ra, op(nb, nc)); / } / else / Protect(Arith(L, ra, rb, rc, tm)); / }#if LUA_BITFIELD_OPS#define bit_op(op) { / TValue *rb = RKB(i); / TValue *rc = RKC(i); / if (ttisnumber(rb) && ttisnumber(rc)) { / unsigned int nb = (unsigned int)nvalue(rb), nc = (unsigned int)nvalue(rc); / setnvalue(ra, nb op nc); / } / else / luaG_aritherror(L, rb, rc); / }#endif /* LUA_BITFIELD_OPS */void luaV_execute (lua_State *L, int nexeccalls) { LClosure *cl; StkId base; TValue *k; const Instruction *pc; reentry: /* entry point *///.........这里部分代码省略.........
开发者ID:zapline,项目名称:zlib,代码行数:101,
注:本文中的ttisnumber函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ ttisstring函数代码示例 C++ ttisinteger函数代码示例 |