MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / luaL_tolstring

Function luaL_tolstring

extlibs/lua/src/lauxlib.c:859–894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

857
858
859LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
860 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
861 if (!lua_isstring(L, -1))
862 luaL_error(L, "'__tostring' must return a string");
863 }
864 else {
865 switch (lua_type(L, idx)) {
866 case LUA_TNUMBER: {
867 if (lua_isinteger(L, idx))
868 lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
869 else
870 lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx));
871 break;
872 }
873 case LUA_TSTRING:
874 lua_pushvalue(L, idx);
875 break;
876 case LUA_TBOOLEAN:
877 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
878 break;
879 case LUA_TNIL:
880 lua_pushliteral(L, "nil");
881 break;
882 default: {
883 int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
884 const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
885 luaL_typename(L, idx);
886 lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
887 if (tt != LUA_TNIL)
888 lua_remove(L, -2); /* remove '__name' */
889 break;
890 }
891 }
892 }
893 return lua_tolstring(L, -1, len);
894}
895
896
897/*

Callers 4

luaB_printFunction · 0.70
luaB_tostringFunction · 0.70
addliteralFunction · 0.70
str_formatFunction · 0.70

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