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 /lapi.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 'lapi.c')
-rw-r--r-- | lapi.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -368,6 +368,18 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | LUA_API unsigned (lua_numbertostrbuff) (lua_State *L, int idx, char *buff) { | ||
372 | const TValue *o = index2value(L, idx); | ||
373 | if (ttisnumber(o)) { | ||
374 | unsigned len = luaO_tostringbuff(o, buff); | ||
375 | buff[len++] = '\0'; /* add final zero */ | ||
376 | return len; | ||
377 | } | ||
378 | else | ||
379 | return 0; | ||
380 | } | ||
381 | |||
382 | |||
371 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { | 383 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { |
372 | size_t sz = luaO_str2num(s, s2v(L->top.p)); | 384 | size_t sz = luaO_str2num(s, s2v(L->top.p)); |
373 | if (sz != 0) | 385 | if (sz != 0) |