static const char *findvararg (CallInfo *ci, int n, StkId *pos) { int nparams = clLvalue(ci->func)->p->sp->numparams; if (n >= cast_int(ci->u.l.base - ci->func) - nparams) return NULL; /* no such vararg */ else { *pos = ci->func + nparams + n; return "(*vararg)"; /* generic name for any vararg */ } }
/* ** converts an integer to a "floating point byte", represented as ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if ** eeeee != 0 and (xxx) otherwise. */ int luaO_int2fb (unsigned int x) { int e = 0; /* exponent */ if (x < 8) return x; while (x >= 0x10) { x = (x+1) >> 1; e++; } return ((e+1) << 3) | (cast_int(x) - 8); }
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++; } }
/* ** converts an integer to a "floating point byte", represented as ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if ** eeeee != 0 and (xxx) otherwise. */ int luaO_int2fb (unsigned int x) { int e = 0; /* expoent */ while (x >= 16) { x = (x+1) >> 1; e++; } if (x < 8) return x; else return ((e+1) << 3) | (cast_int(x) - 8); }
int HiroHand::readAngle(int idx) { int ang; ang = cast_int(this->modules[idx]->getAngle()); if(ang == 0xF000) std::cerr << "Angle Read Error" << std::endl; return ang; }
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { TMS tm = (TMS)0; /* to avoid warnings */ Proto *p = ci_func(ci)->p; /* calling function */ int pc = currentpc(ci); /* calling instruction index */ Instruction i = p->code[pc]; /* calling instruction */ if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */ *name = "?"; return "hook"; } switch (GET_OPCODE(i)) { case OP_CALL: case OP_TAILCALL: /* get function name */ return getobjname(p, pc, GETARG_A(i), name); case OP_TFORCALL: { /* for iterator */ *name = "for iterator"; return "for iterator"; } /* all other instructions can call only through metamethods */ case OP_SELF: case OP_GETTABUP: case OP_GETTABLE: tm = TM_INDEX; break; case OP_SETTABUP: case OP_SETTABLE: tm = TM_NEWINDEX; break; case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD: case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND: case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: { int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD); /* ORDER OP */ tm = cast(TMS, offset + cast_int(TM_ADD)); /* ORDER TM */ break; } case OP_UNM: tm = TM_UNM; break; case OP_BNOT: tm = TM_BNOT; break; case OP_LEN: tm = TM_LEN; break; case OP_CONCAT: tm = TM_CONCAT; break; case OP_EQ: tm = TM_EQ; break; case OP_LT: tm = TM_LT; break; case OP_LE: tm = TM_LE; break; default: lua_assert(0); /* other instructions cannot call a function */ } *name = getstr(G(L)->tmname[tm]); return "metamethod"; }
static void restore_stack_limit(lua_State *L) { lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK - 1); if (L->size_ci > LUAI_MAXCALLS) { /* there was an overflow? */ int inuse = cast_int(L->ci - L->base_ci); if (inuse + 1 < LUAI_MAXCALLS) /* can `undo' overflow? */ luaD_reallocCI(L, LUAI_MAXCALLS); } }
/* ** finish execution of an opcode interrupted by an yield */ void luaV_finishOp (lua_State *L) { CallInfo *ci = L->ci; StkId base = ci->u.l.base; Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */ OpCode op = GET_OPCODE(inst); switch (op) { /* finish its execution */ case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN: case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: { setobjs2s(L, base + GETARG_A(inst), --L->top); break; } case OP_LE: case OP_LT: case OP_EQ: { int res = !l_isfalse(L->top - 1); L->top--; /* metamethod should not be called when operand is K */ lua_assert(!ISK(GETARG_B(inst))); if (op == OP_LE && /* "<=" using "<" instead? */ ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE))) res = !res; /* invert result */ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); if (res != GETARG_A(inst)) /* condition failed? */ ci->u.l.savedpc++; /* skip jump instruction */ break; } case OP_CONCAT: { StkId top = L->top - 1; /* top when 'call_binTM' was called */ int b = GETARG_B(inst); /* first element to concatenate */ int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */ setobj2s(L, top - 2, top); /* put TM result in proper position */ if (total > 1) { /* are there elements to concat? */ L->top = top - 1; /* top is one after last element (at top-2) */ luaV_concat(L, total); /* concat them (may yield again) */ } /* move final result to final position */ setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1); L->top = ci->top; /* restore top */ break; } case OP_TFORCALL: { lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP); L->top = ci->top; /* correct top */ break; } case OP_CALL: { if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */ L->top = ci->top; /* adjust results */ break; } case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE: break; default: lua_assert(0); } }
/* ** returns the index for `key' if `key' is an appropriate key to live in ** the array part of the table, -1 otherwise. ** ** Anything <=0 is taken as not being in the array part. */ static int arrayindex (const TValue *key, int max) { lua_Integer i; switch( ttype(key) ) { #ifdef LUA_TINT case LUA_TINT: i= ivalue(key); break; #endif case LUA_TNUMBER: if (tt_integer_valued(key,&i)) break; default: return -1; /* not to be used as array index */ } return (i <= max) ? cast_int(i) : -1; }
void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { const char *name = NULL; const char *t = luaT_typenames[ttype(o)]; const char *kind = (isinstack(L->ci, o)) ? getobjname(L, L->ci, cast_int(o - L->base), &name) : NULL; if (kind) luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", op, kind, name, t); else luaG_runerror(L, "attempt to %s a %s value", op, t); }
static int searchvar(FuncState *fs, TString *n) { int i; for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) { if (luaS_eqstr(n, getlocvar(fs, i)->varname)) return i; } return -1; /* not found */ }
static const char *varinfo (lua_State *L, const TValue *o) { const char *name = NULL; /* to avoid warnings */ CallInfo *ci = L->ci; const char *kind = NULL; if (isLua(ci)) { kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ if (!kind && isinstack(ci, o)) /* no? try a register */ kind = getobjname(ci_func(ci)->p, currentpc(ci), cast_int(o - ci->u.l.base), &name); } return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : ""; }
double approx(double a, int digits) { digits--; bool neg=false; if(a<0) { neg=true; a=-a; } //cout<<a<<endl; int tpow=0; while(a<pow(10, digits)) { tpow++; a*=10; } while(a>pow(10, digits+1)) { tpow--; a/=10; } if(neg==false) return cast_int(a)/pow(10, tpow); else return -cast_int(a)/pow(10, tpow); }
static int traversestack (global_State *g, lua_State *L) { StkId o = L->stack; if (o == NULL) return 1; /* stack not completely built yet */ for (; o < L->top; o++) markvalue(g, o); if (g->gcstate == GCSatomic) { /* final traversal? */ StkId lim = L->stack + L->stacksize; /* real end of stack */ for (; o < lim; o++) /* clear not-marked stack slice */ setnilvalue(o); } return TRAVCOST + cast_int(o - L->stack); }
/* ** converts an integer to a "floating point byte", represented as ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if ** eeeee != 0 and (xxx) otherwise. */ int luaO_int2fb (unsigned int x) { int e = 0; /* exponent */ if (x < 8) return x; while (x >= (8 << 4)) { /* coarse steps */ x = (x + 0xf) >> 4; /* x = ceil(x / 16) */ e += 4; } while (x >= (8 << 1)) { /* fine steps */ x = (x + 1) >> 1; /* x = ceil(x / 2) */ e++; } return ((e+1) << 3) | (cast_int(x) - 8); }
static int l_hashfloat (lua_Number n) { int i; lua_Integer ni; n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN); if (!lua_numbertointeger(n, &ni)) { /* is 'n' inf/-inf/NaN? */ lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL)); return 0; } else { /* normal case */ unsigned int u = cast_uint(i) + cast_uint(ni); return cast_int(u <= cast_uint(INT_MAX) ? u : ~u); } }
static void DumpString (const TString *s, DumpState *D) { if (s == NULL) DumpByte(0, D); else { size_t size = s->len + 1; /* include trailing '\0' */ if (size < 0xFF) DumpByte(cast_int(size), D); else { DumpByte(0xFF, D); DumpVar(size, D); } DumpVector(getstr(s), size - 1, D); /* no need to save '\0' */ } }
void compute_quantiles(double q, deque<double> & y, deque<double> & qs) { int qv=cast_int((1-q)/2 * y.size()); if(qv<0) qv=0; if(qv>=int(y.size())) qv=y.size()-1; qs.push_back(y[qv]); qv=cast_int((1+q)/2 * y.size()); if(qv<0) qv=0; if(qv>=int(y.size())) qv=y.size()-1; qs.push_back(y[qv]); }
bool Parameters::set(string &flag, string &num) { // false is something goes wrong cout << "setting... " << flag << " " << num << endl; double err; if (!cast_string_to_double(num, err)) { cerr << "\n***********************\nERROR while reading parameters" << endl; return false; } if (flag == command_flags[0]) { if (fabs(err - int(err)) > 1e-8) { cerr << "\n***********************\nERROR: number of nodes must be an integer" << endl; return false; } num_nodes = cast_int(err); } else if (flag == command_flags[1]) { average_k = err; } else if (flag == command_flags[2]) { max_degree = cast_int(err); } else if (flag == command_flags[3]) { mixing_parameter = err; } else if (flag == command_flags[4]) { tau = err; } else if (flag == command_flags[5]) { tau2 = err; } else if (flag == command_flags[6]) { if (fabs(err - int(err)) > 1e-8) { cerr << "\n***********************\nERROR: the minumum community size must be an integer" << endl; return false; } nmin = cast_int(err); } else if (flag == command_flags[7]) { if (fabs(err - int(err)) > 1e-8) { cerr << "\n***********************\nERROR: the maximum community size must be an integer" << endl; return false; } nmax = cast_int(err); } else if (flag == command_flags[8]) { if (fabs(err - int(err)) > 1e-8) { cerr << "\n***********************\nERROR: the number of overlapping nodes must be an integer" << endl; return false; } overlapping_nodes = cast_int(err); } else if (flag == command_flags[9]) { if (fabs(err - int(err)) > 1e-8) { cerr << "\n***********************\nERROR: the number of membership of the overlapping nodes must be an integer" << endl; return false; } overlap_membership = cast_int(err); } else { cerr << "\n***********************\nERROR while reading parameters: " << flag << " is an unknown option" << endl; return false; } return true; }
static int io_file_write(lua_State *L, FILE *fp, int start) { cTValue *tv; int status = 1; for (tv = L->base+start; tv < L->top; tv++) { if (tvisstr(tv)) { MSize len = strV(tv)->len; status = status && (fwrite(strVdata(tv), 1, len, fp) == len); } else if (tvisnum(tv)) { status = status && (fprintf(fp, LUA_NUMBER_FMT, numV(tv)) > 0); } else { lj_err_argt(L, cast_int(tv - L->base) + 1, LUA_TSTRING); } } return io_pushresult(L, status, NULL); }
bool cast_string_to_doubles(string &b, deque<int> & v) { v.clear(); deque<double> d; cast_string_to_doubles(b, d); for(int i=0; i<int(d.size()); i++) v.push_back(cast_int(d[i])); return true; }
void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { //logt("luaG_typeerror"); //logg("operation is '%s'", op ? op : "NULL"); const char *name = NULL; const char *t = luaT_typenames[ttype(o)]; //logg("type name is '%s'", t ? t : "NULL"); const char *kind = (isinstack(L->ci, o)) ? getobjname(L, L->ci, cast_int(o - L->base), &name) : NULL; //logg("kind is '%s'", kind ? kind : "NULL"); if (kind) luaG_runerror_m(L, "attempt to %s %s " LUA_QS " (a %s value)", op, kind, name, t); else luaG_runerror_m(L, "attempt to %s a %s value", op, t); }
/* ** returns the index of a 'key' for table traversals. First goes all ** elements in the array part, then elements in the hash part. The ** beginning of a traversal is signaled by 0. */ static unsigned int findindex (lua_State *L, Table *t, TValue *key, unsigned int asize) { unsigned int i; if (ttisnil(key)) return 0; /* first iteration */ i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0; if (i != 0 && i <= asize) /* is 'key' inside array part? */ return i; /* yes; that's the index */ else { const TValue *n = getgeneric(t, key); if (unlikely(isabstkey(n))) luaG_runerror(L, "invalid key to 'next'"); /* key not found */ i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ /* hash elements are numbered after array ones */ return (i + 1) + asize; } }
/* Call a hook. */ static void callhook(lua_State *L, int event, BCLine line) { global_State *g = G(L); lua_Hook hookf = g->hookf; if (hookf && !hook_active(g)) { lua_Debug ar; lj_trace_abort(g); /* Abort recording on any hook call. */ ar.event = event; ar.currentline = line; ar.i_ci = cast_int((L->base-1) - L->stack); /* Top frame, nextframe=NULL. */ lj_state_checkstack(L, 1+LUA_MINSTACK); hook_enter(g); hookf(L, &ar); lua_assert(hook_active(g)); hook_leave(g); } }
bool Commands::Admin(string nick, AdminFlag Flag) { transform(nick.begin(), nick.end(), nick.begin(), ::tolower); QueryResultPointer db = sVezerlo.GetSQLConn()->Query("SELECT flag FROM adminok WHERE nev = '%s'", nick.c_str()); if(db) { int flag = cast_int(db->Fetch()[0].GetUInt8()); if(Flag != flag) return false; return true; } return false; }
l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { CallInfo *ci = L->ci; const char *name = NULL; const char *t = objtypename(o); const char *kind = NULL; if (isLua(ci)) { kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ if (!kind && isinstack(ci, o)) /* no? try a register */ kind = getobjname(ci_func(ci)->p, currentpc(ci), cast_int(o - ci->u.l.base), &name); } if (kind) luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", op, kind, name, t); else luaG_runerror(L, "attempt to %s a %s value", op, t); }
LUA_API int lua_checkstack (lua_State *L, int size) { int res; CallInfo *ci = L->ci; lua_lock(L); if (L->stack_last - L->top > size) /* stack large enough? */ res = 1; /* yes; check is OK */ else { /* no; need to grow stack */ int inuse = cast_int(L->top - L->stack) + EXTRA_STACK; if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */ res = 0; /* no */ else /* try to grow stack */ res = (luaD_rawrunprotected(L, &growstack, &size) == LUA_OK); } if (res && ci->top < L->top + size) ci->top = L->top + size; /* adjust frame top */ lua_unlock(L); return res; }
void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci, const Proto *p) { int i; int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ int nextra = actual - nfixparams; /* number of extra arguments */ ci->u.l.nextraargs = nextra; checkstackGC(L, p->maxstacksize + 1); /* copy function to the top of the stack */ setobjs2s(L, L->top++, ci->func); /* move fixed parameters to the top of the stack */ for (i = 1; i <= nfixparams; i++) { setobjs2s(L, L->top++, ci->func + i); setnilvalue(s2v(ci->func + i)); /* erase original parameter (for GC) */ } ci->func += actual + 1; ci->top += actual + 1; lua_assert(L->top <= ci->top && ci->top <= L->stack_last); }
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { int status; CallInfo *ci; lua_lock(L); for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) { level--; if (f_isLua(ci)) /* Lua function? */ level -= ci->tailcalls; /* skip lost tail calls */ } if (level == 0 && ci > L->base_ci) { /* level found? */ status = 1; ar->i_ci = cast_int(ci - L->base_ci); } else if (level < 0) { /* level is of a lost tail call? */ status = 1; ar->i_ci = 0; } else status = 0; /* no such level */ lua_unlock(L); return status; }
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); }