diff options
Diffstat (limited to 'src/lj_api.c')
-rw-r--r-- | src/lj_api.c | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/src/lj_api.c b/src/lj_api.c index 3a8448b5..4e41ccc0 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "lj_obj.h" | 12 | #include "lj_obj.h" |
13 | #include "lj_gc.h" | 13 | #include "lj_gc.h" |
14 | #include "lj_err.h" | 14 | #include "lj_err.h" |
15 | #include "lj_debug.h" | ||
15 | #include "lj_str.h" | 16 | #include "lj_str.h" |
16 | #include "lj_tab.h" | 17 | #include "lj_tab.h" |
17 | #include "lj_func.h" | 18 | #include "lj_func.h" |
@@ -27,7 +28,7 @@ | |||
27 | 28 | ||
28 | /* -- Common helper functions --------------------------------------------- */ | 29 | /* -- Common helper functions --------------------------------------------- */ |
29 | 30 | ||
30 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) | 31 | #define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) |
31 | #define api_checkvalidindex(L, i) api_check(L, (i) != niltv(L)) | 32 | #define api_checkvalidindex(L, i) api_check(L, (i) != niltv(L)) |
32 | 33 | ||
33 | static TValue *index2adr(lua_State *L, int idx) | 34 | static TValue *index2adr(lua_State *L, int idx) |
@@ -832,30 +833,10 @@ LUA_API int lua_next(lua_State *L, int idx) | |||
832 | return more; | 833 | return more; |
833 | } | 834 | } |
834 | 835 | ||
835 | static const char *aux_upvalue(cTValue *f, uint32_t idx, TValue **val) | ||
836 | { | ||
837 | GCfunc *fn; | ||
838 | if (!tvisfunc(f)) return NULL; | ||
839 | fn = funcV(f); | ||
840 | if (isluafunc(fn)) { | ||
841 | GCproto *pt = funcproto(fn); | ||
842 | if (idx < pt->sizeuv) { | ||
843 | *val = uvval(&gcref(fn->l.uvptr[idx])->uv); | ||
844 | return strdata(proto_uvname(pt, idx)); | ||
845 | } | ||
846 | } else { | ||
847 | if (idx < fn->c.nupvalues) { | ||
848 | *val = &fn->c.upvalue[idx]; | ||
849 | return ""; | ||
850 | } | ||
851 | } | ||
852 | return NULL; | ||
853 | } | ||
854 | |||
855 | LUA_API const char *lua_getupvalue(lua_State *L, int idx, int n) | 836 | LUA_API const char *lua_getupvalue(lua_State *L, int idx, int n) |
856 | { | 837 | { |
857 | TValue *val; | 838 | TValue *val; |
858 | const char *name = aux_upvalue(index2adr(L, idx), (uint32_t)(n-1), &val); | 839 | const char *name = lj_debug_uvname(index2adr(L, idx), (uint32_t)(n-1), &val); |
859 | if (name) { | 840 | if (name) { |
860 | copyTV(L, L->top, val); | 841 | copyTV(L, L->top, val); |
861 | incr_top(L); | 842 | incr_top(L); |
@@ -1010,7 +991,7 @@ LUA_API const char *lua_setupvalue(lua_State *L, int idx, int n) | |||
1010 | TValue *val; | 991 | TValue *val; |
1011 | const char *name; | 992 | const char *name; |
1012 | api_checknelems(L, 1); | 993 | api_checknelems(L, 1); |
1013 | name = aux_upvalue(f, (uint32_t)(n-1), &val); | 994 | name = lj_debug_uvname(f, (uint32_t)(n-1), &val); |
1014 | if (name) { | 995 | if (name) { |
1015 | L->top--; | 996 | L->top--; |
1016 | copyTV(L, val, L->top); | 997 | copyTV(L, val, L->top); |