MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaL_tolstring

Function luaL_tolstring

lib/lua/src/lauxlib.c:898–934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

896
897
898LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
899 idx = lua_absindex(L,idx);
900 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
901 if (!lua_isstring(L, -1))
902 luaL_error(L, "'__tostring' must return a string");
903 }
904 else {
905 switch (lua_type(L, idx)) {
906 case LUA_TNUMBER: {
907 if (lua_isinteger(L, idx))
908 lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
909 else
910 lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx));
911 break;
912 }
913 case LUA_TSTRING:
914 lua_pushvalue(L, idx);
915 break;
916 case LUA_TBOOLEAN:
917 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false"));
918 break;
919 case LUA_TNIL:
920 lua_pushliteral(L, "nil");
921 break;
922 default: {
923 int tt = luaL_getmetafield(L, idx, "__name"); /* try name */
924 const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) :
925 luaL_typename(L, idx);
926 lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx));
927 if (tt != LUA_TNIL)
928 lua_remove(L, -2); /* remove '__name' */
929 break;
930 }
931 }
932 }
933 return lua_tolstring(L, -1, len);
934}
935
936
937/*

Callers 7

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

Calls 13

lua_absindexFunction · 0.85
luaL_callmetaFunction · 0.85
lua_isstringFunction · 0.85
luaL_errorFunction · 0.85
lua_typeFunction · 0.85
lua_isintegerFunction · 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

Tested by

no test coverage detected