mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
Replace stack slot for implicit number->string conv. in Lua/C API.
This commit is contained in:
parent
cecbe3c15f
commit
bd758df76a
18
src/lj_api.c
18
src/lj_api.c
@ -437,6 +437,7 @@ LUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len)
|
|||||||
lj_gc_check(L);
|
lj_gc_check(L);
|
||||||
o = index2adr(L, idx); /* GC may move the stack. */
|
o = index2adr(L, idx); /* GC may move the stack. */
|
||||||
s = lj_str_fromnumber(L, o);
|
s = lj_str_fromnumber(L, o);
|
||||||
|
setstrV(L, o, s);
|
||||||
} else {
|
} else {
|
||||||
if (len != NULL) *len = 0;
|
if (len != NULL) *len = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -455,6 +456,7 @@ LUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len)
|
|||||||
lj_gc_check(L);
|
lj_gc_check(L);
|
||||||
o = index2adr(L, idx); /* GC may move the stack. */
|
o = index2adr(L, idx); /* GC may move the stack. */
|
||||||
s = lj_str_fromnumber(L, o);
|
s = lj_str_fromnumber(L, o);
|
||||||
|
setstrV(L, o, s);
|
||||||
} else {
|
} else {
|
||||||
lj_err_argt(L, idx, LUA_TSTRING);
|
lj_err_argt(L, idx, LUA_TSTRING);
|
||||||
}
|
}
|
||||||
@ -476,6 +478,7 @@ LUALIB_API const char *luaL_optlstring(lua_State *L, int idx,
|
|||||||
lj_gc_check(L);
|
lj_gc_check(L);
|
||||||
o = index2adr(L, idx); /* GC may move the stack. */
|
o = index2adr(L, idx); /* GC may move the stack. */
|
||||||
s = lj_str_fromnumber(L, o);
|
s = lj_str_fromnumber(L, o);
|
||||||
|
setstrV(L, o, s);
|
||||||
} else {
|
} else {
|
||||||
lj_err_argt(L, idx, LUA_TSTRING);
|
lj_err_argt(L, idx, LUA_TSTRING);
|
||||||
}
|
}
|
||||||
@ -499,17 +502,20 @@ LUALIB_API int luaL_checkoption(lua_State *L, int idx, const char *def,
|
|||||||
LUA_API size_t lua_objlen(lua_State *L, int idx)
|
LUA_API size_t lua_objlen(lua_State *L, int idx)
|
||||||
{
|
{
|
||||||
TValue *o = index2adr(L, idx);
|
TValue *o = index2adr(L, idx);
|
||||||
if (tvisstr(o))
|
if (tvisstr(o)) {
|
||||||
return strV(o)->len;
|
return strV(o)->len;
|
||||||
else if (tvistab(o))
|
} else if (tvistab(o)) {
|
||||||
return (size_t)lj_tab_len(tabV(o));
|
return (size_t)lj_tab_len(tabV(o));
|
||||||
else if (tvisudata(o))
|
} else if (tvisudata(o)) {
|
||||||
return udataV(o)->len;
|
return udataV(o)->len;
|
||||||
else if (tvisnumber(o))
|
} else if (tvisnumber(o)) {
|
||||||
return lj_str_fromnumber(L, o)->len;
|
GCstr *s = lj_str_fromnumber(L, o);
|
||||||
else
|
setstrV(L, o, s);
|
||||||
|
return s->len;
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)
|
LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user