MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / luaL_tolstring

Function luaL_tolstring

3rd/lua-5.4.3/src/lauxlib.c:883–918  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

881
882
883LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
884 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
885 if (!lua_isstring(L, -1))
886 luaL_error(L, "'__tostring' must return a string");
887 }
888 else {
889 switch (lua_type(L, idx)) {
890 case LUA_TNUMBER: {
891 if (lua_isinteger(L, idx))
892 lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
893 else
894 lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx));
895 break;
896 }
897 case LUA_TSTRING:
898 lua_pushvalue(L, idx);
899 break;
900 case LUA_TBOOLEAN:
901 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
902 break;
903 case LUA_TNIL:
904 lua_pushliteral(L, "nil");
905 break;
906 default: {
907 int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
908 const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
909 luaL_typename(L, idx);
910 lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
911 if (tt != LUA_TNIL)
912 lua_remove(L, -2); /* remove '__name' */
913 break;
914 }
915 }
916 }
917 return lua_tolstring(L, -1, len);
918}
919
920
921/*

Callers 6

get_promptFunction · 0.85
luaB_printFunction · 0.85
luaB_tostringFunction · 0.85
addliteralFunction · 0.85
str_formatFunction · 0.85
db_debugFunction · 0.85

Calls 12

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

Tested by

no test coverage detected