/* * equality of ktap values. ks == NULL means raw equality */ int kp_equalobjv(ktap_state *ks, const ktap_value *t1, const ktap_value *t2) { switch (ttype(t1)) { case KTAP_TNIL: return 1; case KTAP_TNUMBER: return nvalue(t1) == nvalue(t2); case KTAP_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ case KTAP_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case KTAP_TLCF: return fvalue(t1) == fvalue(t2); case KTAP_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2)); case KTAP_TLNGSTR: return kp_tstring_eqlngstr(rawtsvalue(t1), rawtsvalue(t2)); case KTAP_TTABLE: if (hvalue(t1) == hvalue(t2)) return 1; else if (ks == NULL) return 0; #ifdef __KERNEL__ case KTAP_TBTRACE: return kp_btrace_equal(btvalue(t1), btvalue(t2)); #endif default: return gcvalue(t1) == gcvalue(t2); } return 0; }
/* * equality of ktap values. ks == NULL means raw equality */ int kp_equalobjv(ktap_State *ks, const Tvalue *t1, const Tvalue *t2) { switch (ttype(t1)) { case KTAP_TNIL: return 1; case KTAP_TNUMBER: return nvalue(t1) == nvalue(t2); case KTAP_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ case KTAP_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case KTAP_TLCF: return fvalue(t1) == fvalue(t2); case KTAP_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2)); case KTAP_TLNGSTR: return kp_tstring_eqlngstr(rawtsvalue(t1), rawtsvalue(t2)); case KTAP_TUSERDATA: if (uvalue(t1) == uvalue(t2)) return 1; else if (ks == NULL) return 0; case KTAP_TTABLE: if (hvalue(t1) == hvalue(t2)) return 1; else if (ks == NULL) return 0; default: return gcvalue(t1) == gcvalue(t2); } return 0; }
int32 luaO_equalObj(TObject *t1, TObject *t2) { if (ttype(t1) != ttype(t2)) return 0; switch (ttype(t1)) { case LUA_T_NIL: return 1; case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2); case LUA_T_ARRAY: return avalue(t1) == avalue(t2); case LUA_T_PROTO: return tfvalue(t1) == tfvalue(t2); case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2); case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl; case LUA_T_TASK: return nvalue(t1) == nvalue(t2); default: #ifdef LUA_DEBUG LUA_INTERNALERROR("internal error in `lua_equalObj'"); #endif return 0; // UNREACHABLE } }
/* * equality of ktap values. ks == NULL means raw equality */ int kp_obj_equal(ktap_state *ks, const ktap_value *t1, const ktap_value *t2) { switch (ttype(t1)) { case KTAP_TYPE_NIL: return 1; case KTAP_TYPE_NUMBER: return nvalue(t1) == nvalue(t2); case KTAP_TYPE_BOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ case KTAP_TYPE_LIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case KTAP_TYPE_CFUNCTION: return fvalue(t1) == fvalue(t2); case KTAP_TYPE_SHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2)); case KTAP_TYPE_LNGSTR: return kp_str_eqlng(rawtsvalue(t1), rawtsvalue(t2)); case KTAP_TYPE_TABLE: if (hvalue(t1) == hvalue(t2)) return 1; else if (ks == NULL) return 0; case KTAP_TYPE_BTRACE: return btrace_equal(btvalue(t1), btvalue(t2)); default: return gcvalue(t1) == gcvalue(t2); } return 0; }
/* ** equality of Lua values. L == NULL means raw equality (no metamethods) */ int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) { const TValue *tm; lua_assert(ttisequal(t1, t2)); switch (ttype(t1)) { case LUA_TNIL: return 1; case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case LUA_TLCF: return fvalue(t1) == fvalue(t2); case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2)); case LUA_TUSERDATA: { if (uvalue(t1) == uvalue(t2)) return 1; else if (L == NULL) return 0; tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); break; /* will try TM */ } case LUA_TTABLE: { if (hvalue(t1) == hvalue(t2)) return 1; else if (L == NULL) return 0; tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); break; /* will try TM */ } default: lua_assert(iscollectable(t1)); return gcvalue(t1) == gcvalue(t2); } if (tm == NULL) return 0; /* no TM? */ callTM(L, tm, t1, t2, L->top, 1); /* call TM */ return !l_isfalse(L->top); }
void find_script() { lua_Object paramObj = lua_getparam(1); lua_Type type = paramObj == LUA_NOOBJECT ? LUA_T_NIL : ttype(Address(paramObj)); if (paramObj == LUA_NOOBJECT || (type != LUA_T_CPROTO && type != LUA_T_PROTO && type != LUA_T_TASK)) { if (g_grim->getGameType() == GType_GRIM) { lua_error("Bad argument to find_script"); } else { ttype(lua_state->stack.top) = LUA_T_TASK; nvalue(lua_state->stack.top) = lua_state->id; incr_top; lua_pushnumber(1.0f); return; } } if (type == LUA_T_TASK) { uint32 task = (uint32)nvalue(Address(paramObj)); LState *state; for (state = lua_rootState->next; state != NULL; state = state->next) { if (state->id == task) { lua_pushobject(paramObj); lua_pushnumber(1.0f); return; } } } else if (type == LUA_T_PROTO || type == LUA_T_CPROTO) { int task = -1, countTasks = 0; bool match; LState *state; for (state = lua_rootState->next; state != NULL; state = state->next) { if (type == LUA_T_PROTO) { match = (state->taskFunc.ttype == type && tfvalue(&state->taskFunc) == tfvalue(Address(paramObj))); } else { match = (state->taskFunc.ttype == type && fvalue(&state->taskFunc) == fvalue(Address(paramObj))); } if (match) { task = state->id; countTasks++; } } if (countTasks) { assert(task != -1); ttype(lua_state->stack.top) = LUA_T_TASK; nvalue(lua_state->stack.top) = (float)task; incr_top; lua_pushnumber((float)countTasks); return; } } lua_pushnil(); lua_pushnumber(0.0f); }
/* ** Main operation for equality of Lua values; return 't1 == t2'. ** L == NULL means raw equality (no metamethods) */ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { const TValue *tm; if (ttype(t1) != ttype(t2)) { /* not the same variant? */ #ifndef _KERNEL if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER) return 0; /* only numbers can be equal with different variants */ else { /* two numbers with different variants */ lua_Integer i1, i2; /* compare them as integers */ return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2); } #else /* _KERNEL */ return 0; /* numbers have only the integer variant */ #endif /* _KERNEL */ } /* values have same type and same variant */ switch (ttype(t1)) { case LUA_TNIL: return 1; case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2)); #ifndef _KERNEL case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2)); #endif /* _KERNEL */ case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case LUA_TLCF: return fvalue(t1) == fvalue(t2); case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2)); case LUA_TUSERDATA: { if (uvalue(t1) == uvalue(t2)) return 1; else if (L == NULL) return 0; tm = fasttm(L, uvalue(t1)->metatable, TM_EQ); if (tm == NULL) tm = fasttm(L, uvalue(t2)->metatable, TM_EQ); break; /* will try TM */ } case LUA_TTABLE: { if (hvalue(t1) == hvalue(t2)) return 1; else if (L == NULL) return 0; tm = fasttm(L, hvalue(t1)->metatable, TM_EQ); if (tm == NULL) tm = fasttm(L, hvalue(t2)->metatable, TM_EQ); break; /* will try TM */ } default: return gcvalue(t1) == gcvalue(t2); } if (tm == NULL) /* no TM? */ return 0; /* objects are different */ luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */ return !l_isfalse(L->top); }
int lua_equalObj (Object *t1, Object *t2) { if (tag(t1) != tag(t2)) return 0; switch (tag(t1)) { case LUA_T_NIL: return 1; case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); case LUA_T_STRING: return svalue(t1) == svalue(t2); case LUA_T_ARRAY: return avalue(t1) == avalue(t2); case LUA_T_FUNCTION: return t1->value.tf == t2->value.tf; case LUA_T_CFUNCTION: return fvalue(t1) == fvalue(t2); default: return uvalue(t1) == uvalue(t2); } }
int luaO_equalval (TObject *t1, TObject *t2) { switch (ttype(t1)) { case LUA_T_NIL: return 1; case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2); case LUA_T_ARRAY: return avalue(t1) == avalue(t2); case LUA_T_PROTO: return tfvalue(t1) == tfvalue(t2); case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2); case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl; default: LUA_INTERNALERROR("invalid type"); return 0; /* UNREACHABLE */ } }
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { StkId o = index2addr(L, idx); if (ttislcf(o)) return fvalue(o); else if (ttisCclosure(o)) return clCvalue(o)->f; else return NULL; /* not a C function */ }
void kp_obj_dump(ktap_State *ks, const Tvalue *v) { switch (ttype(v)) { case KTAP_TNIL: kp_printf(ks, "NIL"); break; case KTAP_TNUMBER: kp_printf(ks, "NUMBER %d", nvalue(v)); break; case KTAP_TBOOLEAN: kp_printf(ks, "BOOLEAN %d", bvalue(v)); break; case KTAP_TLIGHTUSERDATA: kp_printf(ks, "LIGHTUSERDATA %d", pvalue(v)); break; case KTAP_TLCF: kp_printf(ks, "LIGHTCFCUNTION 0x%x", fvalue(v)); break; case KTAP_TSHRSTR: case KTAP_TLNGSTR: kp_printf(ks, "SHRSTR #%s", svalue(v)); break; case KTAP_TUSERDATA: kp_printf(ks, "USERDATA %d", uvalue(v)); break; case KTAP_TTABLE: kp_printf(ks, "TABLE 0x%x", hvalue(v)); break; default: kp_printf(ks, "GCVALUE 0x%x", gcvalue(v)); break; } }
static long int hashindex (TObject *ref) { long int h; switch (ttype(ref)) { case LUA_T_NUMBER: h = (long int)nvalue(ref); break; case LUA_T_STRING: case LUA_T_USERDATA: h = (IntPoint)tsvalue(ref); break; case LUA_T_ARRAY: h = (IntPoint)avalue(ref); break; case LUA_T_PROTO: h = (IntPoint)tfvalue(ref); break; case LUA_T_CPROTO: h = (IntPoint)fvalue(ref); break; case LUA_T_CLOSURE: h = (IntPoint)clvalue(ref); break; default: lua_error("unexpected type to index table"); h = 0; /* to avoid warnings */ } return (h >= 0 ? h : -(h+1)); }
/* ** Given an object handle, return its cfuntion pointer. On error, return NULL. */ lua_CFunction lua_getcfunction (lua_Object object) { if (object == LUA_NOOBJECT || ((tag(Address(object)) != LUA_T_CFUNCTION) && (tag(Address(object)) != LUA_T_CMARK))) return NULL; else return (fvalue(Address(object))); }
static Node *mainposition (const Table *t, const Tvalue *key) { switch (ttype(key)) { case KTAP_TNUMBER: return hashnum(t, nvalue(key)); case KTAP_TLNGSTR: { Tstring *s = rawtsvalue(key); if (s->tsv.extra == 0) { /* no hash? */ s->tsv.hash = kp_string_hash(getstr(s), s->tsv.len, s->tsv.hash); s->tsv.extra = 1; /* now it has its hash */ } return hashstr(t, rawtsvalue(key)); } case KTAP_TSHRSTR: return hashstr(t, rawtsvalue(key)); case KTAP_TBOOLEAN: return hashboolean(t, bvalue(key)); case KTAP_TLIGHTUSERDATA: return hashpointer(t, pvalue(key)); case KTAP_TLCF: return hashpointer(t, fvalue(key)); default: return hashpointer(t, gcvalue(key)); } }
int lua_equalObj (TObject *t1, TObject *t2) { if (ttype(t1) != ttype(t2)) return 0; switch (ttype(t1)) { case LUA_T_NIL: return 1; case LUA_T_NUMBER: return nvalue(t1) == nvalue(t2); case LUA_T_STRING: case LUA_T_USERDATA: return svalue(t1) == svalue(t2); case LUA_T_ARRAY: return avalue(t1) == avalue(t2); case LUA_T_FUNCTION: return t1->value.tf == t2->value.tf; case LUA_T_CFUNCTION: return fvalue(t1) == fvalue(t2); default: lua_error("internal error in `lua_equalObj'"); return 0; /* UNREACHEABLE */ } }
/* ** Call a function (C or Lua). The parameters must be on the stack, ** between [stack+base,top). The function to be called is at stack+base-1. ** When returns, the results are on the stack, between [stack+base-1,top). ** The number of results is nResults, unless nResults=MULT_RET. */ static void do_call (StkId base, int nResults) { StkId firstResult; Object *func = stack+base-1; int i; if (tag(func) == LUA_T_CFUNCTION) { tag(func) = LUA_T_CMARK; firstResult = callC(fvalue(func), base); } else if (tag(func) == LUA_T_FUNCTION) { tag(func) = LUA_T_MARK; firstResult = lua_execute(func->value.tf->code, base); } else { /* func is not a function */ /* Call the fallback for invalid functions */ open_stack((top-stack)-(base-1)); stack[base-1] = luaI_fallBacks[FB_FUNCTION].function; do_call(base, nResults); return; } /* adjust the number of results */ if (nResults != MULT_RET && top - (stack+firstResult) != nResults) adjust_top(firstResult+nResults); /* move results to base-1 (to erase parameters and function) */ base--; nResults = top - (stack+firstResult); /* actual number of results */ for (i=0; i<nResults; i++) *(stack+base+i) = *(stack+firstResult+i); top -= firstResult-base; }
static int32 hashindex(TObject *r) { int32 h; switch (ttype(r)) { case LUA_T_NUMBER: h = (int32)nvalue(r); break; case LUA_T_USERDATA: h = (int32)r->value.ud.id; case LUA_T_STRING: h = (int32)tsvalue(r); break; case LUA_T_ARRAY: h = (int32)avalue(r); break; case LUA_T_PROTO: h = (int32)tfvalue(r); break; case LUA_T_CPROTO: h = (int32)fvalue(r); break; case LUA_T_CLOSURE: h = (int32)clvalue(r); break; case LUA_T_TASK: h = (int32)nvalue(r); break; default: lua_error("unexpected type to index table"); h = 0; // to avoid warnings } return (h >= 0 ? h : -(h + 1)); }
void kp_obj_dump(ktap_state *ks, const ktap_value *v) { switch (ttype(v)) { case KTAP_TYPE_NIL: kp_puts(ks, "NIL"); break; case KTAP_TYPE_NUMBER: kp_printf(ks, "NUMBER %ld", nvalue(v)); break; case KTAP_TYPE_BOOLEAN: kp_printf(ks, "BOOLEAN %d", bvalue(v)); break; case KTAP_TYPE_LIGHTUSERDATA: kp_printf(ks, "LIGHTUSERDATA 0x%lx", (unsigned long)pvalue(v)); break; case KTAP_TYPE_CFUNCTION: kp_printf(ks, "LIGHTCFCUNTION 0x%lx", (unsigned long)fvalue(v)); break; case KTAP_TYPE_SHRSTR: case KTAP_TYPE_LNGSTR: kp_printf(ks, "SHRSTR #%s", svalue(v)); break; case KTAP_TYPE_TABLE: kp_printf(ks, "TABLE 0x%lx", (unsigned long)hvalue(v)); break; default: kp_printf(ks, "GCVALUE 0x%lx", (unsigned long)gcvalue(v)); break; } }
void kp_obj_dump(ktap_state_t *ks, const ktap_val_t *v) { switch (itype(v)) { case KTAP_TNIL: kp_puts(ks, "NIL"); break; case KTAP_TTRUE: kp_printf(ks, "true"); break; case KTAP_TFALSE: kp_printf(ks, "false"); break; case KTAP_TNUM: kp_printf(ks, "NUM %ld", nvalue(v)); break; case KTAP_TLIGHTUD: kp_printf(ks, "LIGHTUD 0x%lx", (unsigned long)pvalue(v)); break; case KTAP_TFUNC: kp_printf(ks, "FUNCTION 0x%lx", (unsigned long)fvalue(v)); break; case KTAP_TSTR: kp_printf(ks, "STR #%s", svalue(v)); break; case KTAP_TTAB: kp_printf(ks, "TABLE 0x%lx", (unsigned long)hvalue(v)); break; default: kp_printf(ks, "GCVALUE 0x%lx", (unsigned long)gcvalue(v)); break; } }
/* ** Call a function (C or Lua). The parameters must be on the stack, ** between [stack+base,top). The function to be called is at stack+base-1. ** When returns, the results are on the stack, between [stack+base-1,top). ** The number of results is nResults, unless nResults=MULT_RET. */ static void do_call (StkId base, int nResults) { StkId firstResult; TObject *func = stack+base-1; int i; if (ttype(func) == LUA_T_CFUNCTION) { ttype(func) = LUA_T_CMARK; firstResult = callC(fvalue(func), base); } else if (ttype(func) == LUA_T_FUNCTION) { ttype(func) = LUA_T_MARK; firstResult = lua_execute(func->value.tf->code, base); } else { /* func is not a function */ /* Check the tag method for invalid functions */ TObject *im = luaI_getimbyObj(func, IM_FUNCTION); if (ttype(im) == LUA_T_NIL) lua_error("call expression not a function"); open_stack((top-stack)-(base-1)); stack[base-1] = *im; do_call(base, nResults); return; } /* adjust the number of results */ if (nResults != MULT_RET) adjust_top(firstResult+nResults); /* move results to base-1 (to erase parameters and function) */ base--; nResults = top - (stack+firstResult); /* actual number of results */ for (i=0; i<nResults; i++) *(stack+base+i) = *(stack+firstResult+i); top -= firstResult-base; }
void lua_pushCclosure(lua_CFunction fn, int32 n) { if (!fn) lua_error("API error - attempt to push a NULL Cfunction"); checkCparams(n); ttype(lua_state->stack.top) = LUA_T_CPROTO; fvalue(lua_state->stack.top) = fn; incr_top; luaV_closure(n); }
/* ** Call a function (C or Lua). The parameters must be on the stack, ** between [top-nArgs,top). The function to be called is right below the ** arguments. ** When returns, the results are on the stack, between [top-nArgs-1,top). ** The number of results is nResults, unless nResults=MULT_RET. */ void luaD_calln (int nArgs, int nResults) { struct Stack *S = &L->stack; /* to optimize */ StkId base = (S->top-S->stack)-nArgs; TObject *func = S->stack+base-1; StkId firstResult; int i; switch (ttype(func)) { case LUA_T_CPROTO: ttype(func) = LUA_T_CMARK; firstResult = callC(fvalue(func), base); break; case LUA_T_PROTO: ttype(func) = LUA_T_PMARK; firstResult = luaV_execute(NULL, tfvalue(func), base); break; case LUA_T_CLOSURE: { Closure *c = clvalue(func); TObject *proto = &(c->consts[0]); ttype(func) = LUA_T_CLMARK; firstResult = (ttype(proto) == LUA_T_CPROTO) ? callCclosure(c, fvalue(proto), base) : luaV_execute(c, tfvalue(proto), base); break; } default: { /* func is not a function */ /* Check the tag method for invalid functions */ TObject *im = luaT_getimbyObj(func, IM_FUNCTION); if (ttype(im) == LUA_T_NIL) lua_error("call expression not a function"); luaD_callTM(im, (S->top-S->stack)-(base-1), nResults); return; } } /* adjust the number of results */ if (nResults == MULT_RET) nResults = (S->top-S->stack)-firstResult; else luaD_adjusttop(firstResult+nResults); /* move results to base-1 (to erase parameters and function) */ base--; for (i=0; i<nResults; i++) *(S->stack+base+i) = *(S->stack+firstResult+i); S->top -= firstResult-base; }
void lua_pushcclosure (lua_CFunction fn, int n) { if (fn == NULL) lua_error("API error - attempt to push a NULL Cfunction"); checkCparams(n); ttype(L->stack.top) = LUA_T_CPROTO; fvalue(L->stack.top) = fn; incr_top; luaV_closure(n); luaC_checkGC(); }
int luaO_rawequalObj (const TValue *t1, const TValue *t2) { if (ttype(t1) != ttype(t2)) return 0; else switch (ttype(t1)) { case LUA_TNIL: return 1; case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2)); case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case LUA_TROTABLE: return rvalue(t1) == rvalue(t2); case LUA_TLIGHTFUNCTION: return fvalue(t1) == fvalue(t2); default: lua_assert(iscollectable(t1)); return gcvalue(t1) == gcvalue(t2); } }
void kp_obj_show(ktap_state_t *ks, const ktap_val_t *v) { switch (itype(v)) { case KTAP_TNIL: kp_puts(ks, "nil"); break; case KTAP_TTRUE: kp_puts(ks, "true"); break; case KTAP_TFALSE: kp_puts(ks, "false"); break; case KTAP_TNUM: kp_printf(ks, "%ld", nvalue(v)); break; case KTAP_TLIGHTUD: kp_printf(ks, "lightud 0x%lx", (unsigned long)pvalue(v)); break; case KTAP_TCFUNC: kp_printf(ks, "cfunction 0x%lx", (unsigned long)fvalue(v)); break; case KTAP_TFUNC: kp_printf(ks, "function 0x%lx", (unsigned long)gcvalue(v)); break; case KTAP_TSTR: kp_puts(ks, svalue(v)); break; case KTAP_TTAB: kp_printf(ks, "table 0x%lx", (unsigned long)hvalue(v)); break; #ifdef CONFIG_KTAP_FFI case KTAP_TCDATA: kp_cdata_dump(ks, cdvalue(v)); break; #endif case KTAP_TEVENTSTR: /* check event context */ if (!ks->current_event) { kp_error(ks, "cannot stringify event str in invalid context\n"); return; } kp_transport_event_write(ks, ks->current_event); break; case KTAP_TKSTACK: kp_transport_print_kstack(ks, v->val.stack.depth, v->val.stack.skip); break; default: kp_error(ks, "print unknown value type: %d\n", itype(v)); break; } }
void stop_script() { lua_Object paramObj = lua_getparam(1); lua_Type type = ttype(Address(paramObj)); LState *state; if (paramObj == LUA_NOOBJECT || (type != LUA_T_CPROTO && type != LUA_T_PROTO && type != LUA_T_TASK)) lua_error("Bad argument to stop_script"); if (type == LUA_T_TASK) { uint32 task = (uint32)nvalue(Address(paramObj)); for (state = lua_rootState->next; state != NULL; state = state->next) { if (state->id == task) break; } if (state) { if (state != lua_state) { lua_statedeinit(state); luaM_free(state); } } } else if (type == LUA_T_PROTO || type == LUA_T_CPROTO) { for (state = lua_rootState->next; state != NULL;) { bool match; if (type == LUA_T_PROTO) { match = (state->taskFunc.ttype == type && tfvalue(&state->taskFunc) == tfvalue(Address(paramObj))); } else { match = (state->taskFunc.ttype == type && fvalue(&state->taskFunc) == fvalue(Address(paramObj))); } if (match && state != lua_state) { LState *tmp = state->next; lua_statedeinit(state); luaM_free(state); state = tmp; } else { state = state->next; } } } }
int kp_obj_equal(const ktap_val_t *t1, const ktap_val_t *t2) { switch (itype(t1)) { case KTAP_TNIL: return 1; case KTAP_TNUM: return nvalue(t1) == nvalue(t2); case KTAP_TTRUE: case KTAP_TFALSE: return itype(t1) == itype(t2); case KTAP_TLIGHTUD: return pvalue(t1) == pvalue(t2); case KTAP_TFUNC: return fvalue(t1) == fvalue(t2); case KTAP_TSTR: return rawtsvalue(t1) == rawtsvalue(t2); default: return gcvalue(t1) == gcvalue(t2); } return 0; }
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { int status; Closure *f = NULL; CallInfo *ci = NULL; void *plight = NULL; lua_lock(L); if (*what == '>') { StkId func = L->top - 1; luai_apicheck(L, ttisfunction(func) || ttislightfunction(func)); what++; /* skip the '>' */ if (ttisfunction(func)) f = clvalue(func); else plight = fvalue(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) || ttislightfunction(ci->func)); if (ttisfunction(ci->func)) f = clvalue(ci->func); else plight = fvalue(ci->func); } status = auxgetinfo(L, what, ar, f, plight, ci); if (strchr(what, 'f')) { if (f != NULL) setclvalue(L, L->top, f) else if (plight != NULL) setfvalue(L->top, plight) else setnilvalue(L->top); incr_top(L); } if (strchr(what, 'L')) collectvalidlines(L, f); lua_unlock(L); return status; }
static int precall(ktap_state *ks, StkId func, int nresults) { ktap_cfunction f; ktap_callinfo *ci; ktap_proto *p; StkId base; ptrdiff_t funcr = savestack(ks, func); int n; switch (ttype(func)) { case KTAP_TLCF: /* light C function */ f = fvalue(func); goto CFUNC; case KTAP_TCCL: /* C closure */ f = clcvalue(func)->f; CFUNC: checkstack(ks, KTAP_MINSTACK); ci = next_ci(ks); ci->nresults = nresults; ci->func = restorestack(ks, funcr); ci->top = ks->top + KTAP_MINSTACK; ci->callstatus = 0; n = (*f)(ks); poscall(ks, ks->top - n); return 1; case KTAP_TLCL: p = CLVALUE(func)->p; checkstack(ks, p->maxstacksize); func = restorestack(ks, funcr); n = (int)(ks->top - func) - 1; /* number of real arguments */ /* complete missing arguments */ for (; n < p->numparams; n++) setnilvalue(ks->top++); base = (!p->is_vararg) ? func + 1 : adjust_varargs(ks, p, n); ci = next_ci(ks); ci->nresults = nresults; ci->func = func; ci->u.l.base = base; ci->top = base + p->maxstacksize; ci->u.l.savedpc = p->code; /* starting point */ ci->callstatus = CIST_KTAP; ks->top = ci->top; return 0; default: kp_error(ks, "attempt to call nil function\n"); } return 0; }
void kp_obj_show(ktap_state *ks, const ktap_value *v) { switch (ttype(v)) { case KTAP_TYPE_NIL: kp_puts(ks, "nil"); break; case KTAP_TYPE_NUMBER: kp_printf(ks, "%ld", nvalue(v)); break; case KTAP_TYPE_BOOLEAN: kp_puts(ks, (bvalue(v) == 1) ? "true" : "false"); break; case KTAP_TYPE_LIGHTUSERDATA: kp_printf(ks, "0x%lx", (unsigned long)pvalue(v)); break; case KTAP_TYPE_CFUNCTION: kp_printf(ks, "0x%lx", (unsigned long)fvalue(v)); break; case KTAP_TYPE_SHRSTR: case KTAP_TYPE_LNGSTR: kp_puts(ks, svalue(v)); break; case KTAP_TYPE_TABLE: kp_tab_dump(ks, hvalue(v)); break; #ifdef CONFIG_KTAP_FFI case KTAP_TYPE_CDATA: kp_cdata_dump(ks, cdvalue(v)); break; #endif case KTAP_TYPE_EVENT: kp_transport_event_write(ks, evalue(v)); break; case KTAP_TYPE_BTRACE: btrace_dump(ks, btvalue(v)); break; case KTAP_TYPE_PTABLE: kp_ptab_dump(ks, phvalue(v)); break; case KTAP_TYPE_STATDATA: kp_statdata_dump(ks, sdvalue(v)); break; default: kp_error(ks, "print unknown value type: %d\n", ttype(v)); break; } }