static int luaB_tostring (lua_State *L) { luaL_checkany(L, 1); if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ return 1; /* use its value */ switch (lua_type(L, 1)) { case LUA_TNUMBER: lua_pushstring(L, lua_tostring(L, 1)); break; case LUA_TSTRING: lua_pushvalue(L, 1); break; case LUA_TBOOLEAN: lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); break; case LUA_TNIL: lua_pushliteral(L, "nil"); break; default: lua_pushfstring(L, "%s: %p", luaL_typename(L, 1), lua_topointer(L, 1)); break; } return 1; }
static int tostring(lua_State *L, int n) { luaL_checkany(L, n); switch (lua_type(L, n)) { case LUA_TNUMBER: lua_pushstring(L, lua_tostring(L, n)); break; case LUA_TSTRING: lua_pushvalue(L, n); break; case LUA_TBOOLEAN: lua_pushstring(L, (lua_toboolean(L, n) ? "true" : "false")); break; case LUA_TNIL: lua_pushliteral(L, "nil"); break; default: lua_pushfstring(L, "%s: %p", luaL_typename(L, n), lua_topointer(L, n)); break; } return 1; }
static int lcurl_share_setopt(lua_State *L){ lcurl_share_t *p = lcurl_getshare(L); int opt; luaL_checkany(L, 2); if(lua_type(L, 2) == LUA_TTABLE){ int ret = lcurl_utils_apply_options(L, 2, 1, 0, p->err_mode, LCURL_ERROR_SHARE, CURLSHE_BAD_OPTION); if(ret) return ret; lua_settop(L, 1); return 1; } opt = luaL_checklong(L, 2); lua_remove(L, 2); #define OPT_ENTRY(l, N, T, S) case CURLSHOPT_##N: return lcurl_share_set_##N(L); switch(opt){ #include "lcoptshare.h" } #undef OPT_ENTRY return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_SHARE, CURLSHE_BAD_OPTION); }
static int luaB_tostring(lua_State * L) { char buff[128]; luaL_checkany(L, 1); if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */ return 1; /* use its value */ switch (lua_type(L, 1)) { case LUA_TNUMBER: lua_pushstring(L, lua_tostring(L, 1)); return 1; case LUA_TSTRING: lua_pushvalue(L, 1); return 1; case LUA_TBOOLEAN: lua_pushstring(L, (lua_toboolean(L, 1) ? "true" : "false")); return 1; case LUA_TTABLE: sprintf(buff, "table: %p", lua_topointer(L, 1)); break; case LUA_TFUNCTION: sprintf(buff, "function: %p", lua_topointer(L, 1)); break; case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA: sprintf(buff, "userdata: %p", lua_touserdata(L, 1)); break; case LUA_TTHREAD: sprintf(buff, "thread: %p", (void *)lua_tothread(L, 1)); break; case LUA_TNIL: lua_pushliteral(L, "nil"); return 1; } lua_pushstring(L, buff); return 1; }
static int t_find (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); luaL_checkany(L, 2); #if 1 lua_settop(L, 3); if (!lua_find(L, 1)) { lua_pushnil(L); } #else if (!lua_isnoneornil(L, 3)) lua_pushvalue(L, 3); else lua_pushnil(L); while (lua_next(L, 1)) { if (lua_equal(L, -1, 2)) { lua_pop(L, 1); return 1; } lua_pop(L, 1); } lua_pushnil(L); #endif return 1; }
static int l_siplua_AVP_get(lua_State *L) { struct usr_avp *first_avp; int name; str s; int_str val; int flags = 0; luaL_checkany(L, 1); s.s = (char *) lua_tostring(L, 1); s.len = strlen(s.s); name = get_avp_id(&s); first_avp = search_first_avp(flags, name, &val, NULL); if (first_avp != NULL) { if (is_avp_str_val(first_avp)) lua_pushlstring(L, val.s.s, val.s.len); else lua_pushinteger(L, val.n); } else lua_pushnil(L); return 1; }
int luaT_lua_version(lua_State *L) { luaL_checkany(L, 1); if(luaT_iscdata(L, 1)) { const char *tname = luaT_cdataname(L, 1, NULL); if(tname) { luaT_pushmetatable(L, tname); lua_pushstring(L, "__version"); lua_rawget(L, -2); return 1; } return 0; } else if(lua_getmetatable(L, 1)) { lua_pushstring(L, "__version"); lua_rawget(L, -2); return 1; } return 0; }
static int objectAppendComponent(lua_State* L) { luaL_checkany(L, 2); auto obj = checkarg<GameObject*>(L, 1); auto& comp = checkarg<std::string&>(L, 2); std::pair<Component*, bool> result; if (lua_gettop(L) == 2 || lua_isnil(L, 3)) { result = obj->appendComponent(comp); } else { LuaRef tableRef = LuaRef::fromIndex(L, 3); LuaProperties param(tableRef); result = obj->appendComponent(comp, param); } if (!result.first || !result.first->accept(PushComponentVisitor(L))) lua_pushnil(L); push<bool>(L, result.second); return 2; }
static int luaB_assert (lua_State *L) { luaL_checkany(L, 1); if (lua_isnil(L, 1)) luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); return 0; }
void LuaState::CheckAny(int narg) { luaL_checkany(m_state, narg); }
static int lhiredis_unwrap_reply(lua_State * L) { int type = 0; luaL_checkany(L, 1); luaL_checkstack(L, 3, "not enough stack to push reply"); if (!lua_istable(L, 1)) { if (lua_isnil(L, 1) && !lua_isnoneornil(L, 2)) { lua_pushvalue(L, 1); lua_pushvalue(L, 2); return 2; } lua_pushvalue(L, 1); return 1; } if (!lua_getmetatable(L, 1)) { lua_pushvalue(L, 1); return 1; } luaL_getmetatable(L, LUAHIREDIS_CONST_MT); if (!lua_rawequal(L, -1, -2)) { lua_pop(L, 2); /* both metatables */ lua_pushvalue(L, 1); return 1; } lua_pop(L, 2); /* both metatables */ lua_getfield(L, 1, "type"); if (lua_type(L, -1) != LUA_TNUMBER) { lua_pop(L, 1); /* t.type */ lua_pushvalue(L, 1); return 1; } type = lua_tonumber(L, -1); lua_pop(L, 1); /* t.type */ if (type == REDIS_REPLY_STATUS) { lua_getfield(L, 1, "name"); if (!lua_isstring(L, -1)) { /* We promised to users that this wouldn't be nil */ return luaL_error(L, "lua-hiredis internal error: bad const-object"); } lua_pushinteger(L, REDIS_REPLY_STATUS); return 2; } else if (type == REDIS_REPLY_ERROR) { lua_pushnil(L); lua_getfield(L, 1, "name"); if (!lua_isstring(L, -1)) { /* We promised to users that this wouldn't be nil */ return luaL_error(L, "lua-hiredis internal error: bad const-object"); } return 2; } /* Note that NIL is not unwrapped */ lua_pushvalue(L, 1); return 1; }
static int db_getfenv (lua_State *L) { luaL_checkany(L, 1); lua_getfenv(L, 1); return 1; }
static int luaB_rawget (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); luaL_checkany(L, 2); lua_rawget(L, 1); return 1; }
static int db_setupvalue (lua_State *L) { luaL_checkany(L, 3); return auxupvalue(L, 0); }
static int luaB_type (lua_State *L) { luaL_checkany(L, 1); lua_pushstring(L, luaL_typename(L, 1)); return 1; }
JNIEXPORT void JNICALL Java_m_lua_Lua_LcheckAny (JNIEnv* env, jobject thiz, jlong nativeObj, jint nArg) { pushJNIEnv(env, nativeObj); luaL_checkany((lua_State*) nativeObj, nArg); }
void LuaState::CheckAny(int index) const { luaL_checkany(m_state, index); }
static int luaB_tag (lua_State *L) { luaL_checkany(L, 1); lua_pushnumber(L, lua_tag(L, 1)); return 1; }
static int luaB_setglobal (lua_State *L) { luaL_checkany(L, 2); lua_setglobal(L, luaL_check_string(L, 1)); return 0; }
static int test_len (lua_State *L) { luaL_checkany(L, 1); lua_len(L, 1); return 1; }
void NzLuaInstance::CheckAny(int index) const { luaL_checkany(m_state, index); }
int CEntityBase::lTable2Insert(lua_State* L) { //param 1 is userdata uint32_t nCbId = (uint32_t)luaL_checkint(L, 2); //callback id const char* pszTbl = luaL_checkstring(L, 3); //table name luaL_checkany(L, 4); //table if(!lua_istable(L, 4)) { lua_pushstring(L, "tableInsert,param 4 need a table."); lua_error(L); return 0; } world* the_world = GetWorld(); CMailBox* mb = the_world->GetServerMailbox(SERVER_DBMGR); if(mb == NULL) { return 0; } CDefParser& def = the_world->GetDefParser(); const SEntityDef* pDef = def.GetEntityDefByName(pszTbl); if(pDef == NULL) { lua_pushfstring(L, "error entity name:%s", pszTbl); lua_error(L); return 0; } CPluto* u = new CPluto; u->Encode(MSGID_DBMGR_TABLE2_INSERT) << m_mymb.m_nServerMailboxId << m_id << nCbId << def.GetTypeId(pszTbl); lua_pushnil(L); while(lua_next(L, 4) != 0) { const char* pszKey = luaL_checkstring(L, -2); map<string, _SEntityDefProperties*>::const_iterator iter = pDef->m_properties.find(pszKey); if(iter != pDef->m_properties.end()) { _SEntityDefProperties* p = iter->second; if(p && p->m_bSaveDb) { u->FillField<uint16_t>(pDef->m_propertiesMap.GetIntByStr(pszKey)); u->FillPlutoFromLua(p->m_nType, L, 6); lua_pop(L, 1); continue; } } delete u; lua_pushfstring(L, "%s hasn't field %s or field not need to save.", pszTbl, pszKey); lua_error(L); return 0; } u->endPluto(); //print_hex_pluto(*u); mb->PushPluto(u); return 0; }
static int lp_P (lua_State *L) { luaL_checkany(L, 1); getpatt(L, 1, NULL); lua_settop(L, 1); return 1; }
static int test_len (lua_State *L) { luaL_checkany(L, 1); lua_len(L, 1); lua_pushinteger(L, luaL_len(L, 1)); return 2; }
static int luaB_tostring (lua_State *L) { luaL_checkany(L, 1); luaL_tolstring(L, 1, NULL); return 1; }
/* ** This function has all type names as upvalues, to maximize performance. */ static int luaB_type (lua_State *L) { luaL_checkany(L, 1); lua_pushvalue(L, lua_upvalueindex(lua_type(L, 1) + 1)); return 1; }
static int luaB_rawequal (lua_State *L) { luaL_checkany(L, 1); luaL_checkany(L, 2); lua_pushboolean(L, lua_rawequal(L, 1, 2)); return 1; }
static int vec2_index(lua_State* L) { Vector2f* v = check_vec2(L, 1); luaL_checkany(L, 2); int key_type = lua_type(L, 2); if (key_type == LUA_TNUMBER) { lua_Integer i = lua_tointeger(L, 2); if (i > 0 && i <= 2) { lua_pushnumber(L, (*v)[i-1]); return 1; } // error lua_pushstring(L, "vec2: num index out of range, must be 1 or 2"); lua_error(L); } else if (key_type == LUA_TSTRING) { size_t size; const char* s = lua_tolstring(L, 2, &size); if (size == 1) { switch (s[0]) { case 'x': lua_pushnumber(L, v->x); return 1; case 'y': lua_pushnumber(L, v->y); return 1; } } else { // search for string key in vec2_method_funcs array. int i = 0; while (vec2_method_funcs[i].name) { if (!strcmp(s, vec2_method_funcs[i].name)) { lua_pushcfunction(L, vec2_method_funcs[i].func); return 1; } i++; } } // error lua_pushstring(L, "vec2: unknown string key, must be x or y"); lua_error(L); } else { // error lua_pushstring(L, "vec2: unsupported key"); lua_error(L); } return 0; }
static int luaB_assert (lua_State *L) { luaL_checkany(L, 1); if (!lua_toboolean(L, 1)) return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); return lua_gettop(L); }
/** * Set debug in Lua */ int set_debug(lua_State *_l) { luaL_checkany(_l, 1); /* anything can be boolean in lua, just make sure we got something */ debug_on = lua_toboolean(_l, 1); return 0; }