New function 'lua_numbertostrbuff'

It converts a Lua number to a string in a buffer, without creating
a new Lua string.
This commit is contained in:
Roberto Ierusalimschy
2024-10-23 17:16:17 -03:00
parent 5ffcd458f0
commit e3ce88c9e8
7 changed files with 67 additions and 40 deletions

View File

@@ -920,10 +920,9 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
else {
switch (lua_type(L, idx)) {
case LUA_TNUMBER: {
if (lua_isinteger(L, idx))
lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
else
lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx));
char buff[LUA_N2SBUFFSZ];
lua_numbertostrbuff(L, idx, buff);
lua_pushstring(L, buff);
break;
}
case LUA_TSTRING: