MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaL_tolstring

Function luaL_tolstring

third-party/lua-5.5.0/src/lauxlib.c:922–957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

920
921
922LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
923 idx = lua_absindex(L,idx);
924 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
925 if (!lua_isstring(L, -1))
926 luaL_error(L, "'__tostring' must return a string");
927 }
928 else {
929 switch (lua_type(L, idx)) {
930 case LUA_TNUMBER: {
931 char buff[LUA_N2SBUFFSZ];
932 lua_numbertocstring(L, idx, buff);
933 lua_pushstring(L, buff);
934 break;
935 }
936 case LUA_TSTRING:
937 lua_pushvalue(L, idx);
938 break;
939 case LUA_TBOOLEAN:
940 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
941 break;
942 case LUA_TNIL:
943 lua_pushliteral(L, "nil");
944 break;
945 default: {
946 int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
947 const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
948 luaL_typename(L, idx);
949 lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
950 if (tt != LUA_TNIL)
951 lua_remove(L, -2); /* remove '__name' */
952 break;
953 }
954 }
955 }
956 return lua_tolstring(L, -1, len);
957}
958
959
960/*

Callers 6

get_promptFunction · 0.70
luaB_printFunction · 0.70
luaB_tostringFunction · 0.70
addliteralFunction · 0.70
str_formatFunction · 0.70
db_debugFunction · 0.70

Calls 13

lua_absindexFunction · 0.70
luaL_callmetaFunction · 0.70
lua_isstringFunction · 0.70
luaL_errorFunction · 0.70
lua_typeFunction · 0.70
lua_pushstringFunction · 0.70
lua_pushvalueFunction · 0.70
lua_tobooleanFunction · 0.70
luaL_getmetafieldFunction · 0.70
lua_pushfstringFunction · 0.70
lua_topointerFunction · 0.70
lua_tolstringFunction · 0.70

Tested by

no test coverage detected