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()); }
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); }
static void DumpConstants(const LuaProto* f, DumpState* D) { int n = (int)f->constants.size(); DumpInt(n,D); for(int i=0; i < n; i++) { LuaValue v = f->constants[i]; DumpChar(v.type(),D); if(v.isBool()) { DumpChar(v.getBool() ? 1 : 0,D); } else if(v.isNumber()) { DumpNumber(v.getNumber(),D); } else if(v.isString()) { DumpString(v.getString(),D); } } n = (int)f->subprotos_.size(); DumpInt(n,D); for (int i=0; i < n; i++) { DumpFunction(f->subprotos_[i],D); } }