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:
12
lapi.c
12
lapi.c
@@ -368,6 +368,18 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
|
||||
}
|
||||
|
||||
|
||||
LUA_API unsigned (lua_numbertostrbuff) (lua_State *L, int idx, char *buff) {
|
||||
const TValue *o = index2value(L, idx);
|
||||
if (ttisnumber(o)) {
|
||||
unsigned len = luaO_tostringbuff(o, buff);
|
||||
buff[len++] = '\0'; /* add final zero */
|
||||
return len;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) {
|
||||
size_t sz = luaO_str2num(s, s2v(L->top.p));
|
||||
if (sz != 0)
|
||||
|
||||
Reference in New Issue
Block a user