static void PrintConstant(const LuaProto* f, int i) { LuaValue v = f->constants[i]; if(v.isNil()) { printf("nil"); return; } if(v.isBool()) { printf(v.getBool() ? "true" : "false"); return; } if(v.isNumber()) { printf(LUA_NUMBER_FMT,v.getNumber()); return; } if(v.isString()) { PrintString(v.getString()); return; } printf("? type=%d",v.type()); }
int luaL_ref(LuaThread* L) { LuaTable* registry = L->l_G->getRegistry(); LuaValue val = L->stack_.top_[-1]; L->stack_.pop(); if(val.isNil()) return LUA_REFNIL; LuaValue ref1 = registry->get(LuaValue(freelist)); int ref = ref1.isInteger() ? ref1.getInteger() : 0; if (ref != 0) { // any free element? LuaValue temp = registry->get( LuaValue(ref) ); registry->set( LuaValue(freelist), temp ); registry->set( LuaValue(ref), val ); return ref; } else { // no free elements, get a new reference. ref = (int)registry->getLength() + 1; registry->set( LuaValue(ref), val ); return ref; } }
const char *luaL_tolstring (LuaThread *L, int idx, size_t *len) { THREAD_CHECK(L); if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ LuaValue* pv = index2addr(L, idx); assert(pv); LuaValue v = *pv; if(v.isNumber() || v.isString()) { L->stack_.copy(idx); } else if(v.isBool()) { lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); } else if(v.isNil()) { lua_pushliteral(L, "nil"); } else { lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), lua_topointer(L, idx)); } } return lua_tolstring(L, -1, len); }