diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-10-23 17:16:17 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-10-23 17:16:17 -0300 |
commit | e3ce88c9e850b7e79751083014699c5eae1bff31 (patch) | |
tree | e73392a16c560ed532ef2238132f0e58d2eb23b3 /lauxlib.c | |
parent | 5ffcd458f001fce02e5f20a6130e145c6a3caf53 (diff) | |
download | lua-e3ce88c9e850b7e79751083014699c5eae1bff31.tar.gz lua-e3ce88c9e850b7e79751083014699c5eae1bff31.tar.bz2 lua-e3ce88c9e850b7e79751083014699c5eae1bff31.zip |
New function 'lua_numbertostrbuff'
It converts a Lua number to a string in a buffer, without creating
a new Lua string.
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -920,10 +920,9 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { | |||
920 | else { | 920 | else { |
921 | switch (lua_type(L, idx)) { | 921 | switch (lua_type(L, idx)) { |
922 | case LUA_TNUMBER: { | 922 | case LUA_TNUMBER: { |
923 | if (lua_isinteger(L, idx)) | 923 | char buff[LUA_N2SBUFFSZ]; |
924 | lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx)); | 924 | lua_numbertostrbuff(L, idx, buff); |
925 | else | 925 | lua_pushstring(L, buff); |
926 | lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx)); | ||
927 | break; | 926 | break; |
928 | } | 927 | } |
929 | case LUA_TSTRING: | 928 | case LUA_TSTRING: |