diff options
author | Mike Pall <mike> | 2011-11-21 20:50:27 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-11-21 20:50:27 +0100 |
commit | bd758df76ae7a34a18c6da755b46be1959abeb79 (patch) | |
tree | e5e7ca981c232a0096dbe208859279df5d867f91 | |
parent | cecbe3c15fc62921098f3468b9de86cf0b631b9e (diff) | |
download | luajit-bd758df76ae7a34a18c6da755b46be1959abeb79.tar.gz luajit-bd758df76ae7a34a18c6da755b46be1959abeb79.tar.bz2 luajit-bd758df76ae7a34a18c6da755b46be1959abeb79.zip |
Replace stack slot for implicit number->string conv. in Lua/C API.
-rw-r--r-- | src/lj_api.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lj_api.c b/src/lj_api.c index a6fbb1c6..5ef2dff1 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
@@ -437,6 +437,7 @@ LUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len) | |||
437 | lj_gc_check(L); | 437 | lj_gc_check(L); |
438 | o = index2adr(L, idx); /* GC may move the stack. */ | 438 | o = index2adr(L, idx); /* GC may move the stack. */ |
439 | s = lj_str_fromnumber(L, o); | 439 | s = lj_str_fromnumber(L, o); |
440 | setstrV(L, o, s); | ||
440 | } else { | 441 | } else { |
441 | if (len != NULL) *len = 0; | 442 | if (len != NULL) *len = 0; |
442 | return NULL; | 443 | return NULL; |
@@ -455,6 +456,7 @@ LUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len) | |||
455 | lj_gc_check(L); | 456 | lj_gc_check(L); |
456 | o = index2adr(L, idx); /* GC may move the stack. */ | 457 | o = index2adr(L, idx); /* GC may move the stack. */ |
457 | s = lj_str_fromnumber(L, o); | 458 | s = lj_str_fromnumber(L, o); |
459 | setstrV(L, o, s); | ||
458 | } else { | 460 | } else { |
459 | lj_err_argt(L, idx, LUA_TSTRING); | 461 | lj_err_argt(L, idx, LUA_TSTRING); |
460 | } | 462 | } |
@@ -476,6 +478,7 @@ LUALIB_API const char *luaL_optlstring(lua_State *L, int idx, | |||
476 | lj_gc_check(L); | 478 | lj_gc_check(L); |
477 | o = index2adr(L, idx); /* GC may move the stack. */ | 479 | o = index2adr(L, idx); /* GC may move the stack. */ |
478 | s = lj_str_fromnumber(L, o); | 480 | s = lj_str_fromnumber(L, o); |
481 | setstrV(L, o, s); | ||
479 | } else { | 482 | } else { |
480 | lj_err_argt(L, idx, LUA_TSTRING); | 483 | lj_err_argt(L, idx, LUA_TSTRING); |
481 | } | 484 | } |
@@ -499,16 +502,19 @@ LUALIB_API int luaL_checkoption(lua_State *L, int idx, const char *def, | |||
499 | LUA_API size_t lua_objlen(lua_State *L, int idx) | 502 | LUA_API size_t lua_objlen(lua_State *L, int idx) |
500 | { | 503 | { |
501 | TValue *o = index2adr(L, idx); | 504 | TValue *o = index2adr(L, idx); |
502 | if (tvisstr(o)) | 505 | if (tvisstr(o)) { |
503 | return strV(o)->len; | 506 | return strV(o)->len; |
504 | else if (tvistab(o)) | 507 | } else if (tvistab(o)) { |
505 | return (size_t)lj_tab_len(tabV(o)); | 508 | return (size_t)lj_tab_len(tabV(o)); |
506 | else if (tvisudata(o)) | 509 | } else if (tvisudata(o)) { |
507 | return udataV(o)->len; | 510 | return udataV(o)->len; |
508 | else if (tvisnumber(o)) | 511 | } else if (tvisnumber(o)) { |
509 | return lj_str_fromnumber(L, o)->len; | 512 | GCstr *s = lj_str_fromnumber(L, o); |
510 | else | 513 | setstrV(L, o, s); |
514 | return s->len; | ||
515 | } else { | ||
511 | return 0; | 516 | return 0; |
517 | } | ||
512 | } | 518 | } |
513 | 519 | ||
514 | LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx) | 520 | LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx) |