diff options
| author | Mike Pall <mike> | 2012-09-20 17:36:15 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2012-09-20 17:36:15 +0200 |
| commit | 8352335c745eb7053cdc39d949b036f90724a0fb (patch) | |
| tree | bc2fc36e71bbda6b573ba104ffccfaa113246837 /src | |
| parent | a9baead59f0521b289ba39e4d56ca92b0359e31e (diff) | |
| download | luajit-8352335c745eb7053cdc39d949b036f90724a0fb.tar.gz luajit-8352335c745eb7053cdc39d949b036f90724a0fb.tar.bz2 luajit-8352335c745eb7053cdc39d949b036f90724a0fb.zip | |
From Lua 5.2: Add debug.upvalueid() and debug.upvaluejoin().
Ditto for lua_upvalueid() and lua_upvaluejoin().
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib_debug.c | 31 | ||||
| -rw-r--r-- | src/lj_api.c | 20 | ||||
| -rw-r--r-- | src/lj_errmsg.h | 1 | ||||
| -rw-r--r-- | src/lua.h | 5 |
4 files changed, 56 insertions, 1 deletions
diff --git a/src/lib_debug.c b/src/lib_debug.c index d90c422f..0330f1d2 100644 --- a/src/lib_debug.c +++ b/src/lib_debug.c | |||
| @@ -224,6 +224,37 @@ LJLIB_CF(debug_setupvalue) | |||
| 224 | return debug_getupvalue(L, 0); | 224 | return debug_getupvalue(L, 0); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | LJLIB_CF(debug_upvalueid) | ||
| 228 | { | ||
| 229 | GCfunc *fn = lj_lib_checkfunc(L, 1); | ||
| 230 | int32_t n = lj_lib_checkint(L, 2) - 1; | ||
| 231 | if ((uint32_t)n >= fn->l.nupvalues) | ||
| 232 | lj_err_arg(L, 2, LJ_ERR_IDXRNG); | ||
| 233 | setlightudV(L->top-1, isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) : | ||
| 234 | (void *)&fn->c.upvalue[n]); | ||
| 235 | return 1; | ||
| 236 | } | ||
| 237 | |||
| 238 | LJLIB_CF(debug_upvaluejoin) | ||
| 239 | { | ||
| 240 | GCfunc *fn[2]; | ||
| 241 | GCRef *p[2]; | ||
| 242 | int i; | ||
| 243 | for (i = 0; i < 2; i++) { | ||
| 244 | int32_t n; | ||
| 245 | fn[i] = lj_lib_checkfunc(L, 2*i+1); | ||
| 246 | if (!isluafunc(fn[i])) | ||
| 247 | lj_err_arg(L, 2*i+1, LJ_ERR_NOLFUNC); | ||
| 248 | n = lj_lib_checkint(L, 2*i+2) - 1; | ||
| 249 | if ((uint32_t)n >= fn[i]->l.nupvalues) | ||
| 250 | lj_err_arg(L, 2*i+2, LJ_ERR_IDXRNG); | ||
| 251 | p[i] = &fn[i]->l.uvptr[n]; | ||
| 252 | } | ||
| 253 | setgcrefr(*p[0], *p[1]); | ||
| 254 | lj_gc_objbarrier(L, fn[0], gcref(*p[1])); | ||
| 255 | return 0; | ||
| 256 | } | ||
| 257 | |||
| 227 | /* ------------------------------------------------------------------------ */ | 258 | /* ------------------------------------------------------------------------ */ |
| 228 | 259 | ||
| 229 | static const char KEY_HOOK = 'h'; | 260 | static const char KEY_HOOK = 'h'; |
diff --git a/src/lj_api.c b/src/lj_api.c index bfd471d2..a9ea38d8 100644 --- a/src/lj_api.c +++ b/src/lj_api.c | |||
| @@ -852,6 +852,26 @@ LUA_API const char *lua_getupvalue(lua_State *L, int idx, int n) | |||
| 852 | return name; | 852 | return name; |
| 853 | } | 853 | } |
| 854 | 854 | ||
| 855 | LUA_API void *lua_upvalueid(lua_State *L, int idx, int n) | ||
| 856 | { | ||
| 857 | GCfunc *fn = funcV(index2adr(L, idx)); | ||
| 858 | n--; | ||
| 859 | api_check(L, (uint32_t)n < fn->l.nupvalues); | ||
| 860 | return isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) : | ||
| 861 | (void *)&fn->c.upvalue[n]; | ||
| 862 | } | ||
| 863 | |||
| 864 | LUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2) | ||
| 865 | { | ||
| 866 | GCfunc *fn1 = funcV(index2adr(L, idx1)); | ||
| 867 | GCfunc *fn2 = funcV(index2adr(L, idx2)); | ||
| 868 | n1--; n2--; | ||
| 869 | api_check(L, isluafunc(fn1) && (uint32_t)n1 < fn1->l.nupvalues); | ||
| 870 | api_check(L, isluafunc(fn2) && (uint32_t)n2 < fn2->l.nupvalues); | ||
| 871 | setgcrefr(fn1->l.uvptr[n1], fn2->l.uvptr[n2]); | ||
| 872 | lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1])); | ||
| 873 | } | ||
| 874 | |||
| 855 | LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname) | 875 | LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname) |
| 856 | { | 876 | { |
| 857 | cTValue *o = index2adr(L, idx); | 877 | cTValue *o = index2adr(L, idx); |
diff --git a/src/lj_errmsg.h b/src/lj_errmsg.h index c07d4387..28c5ca08 100644 --- a/src/lj_errmsg.h +++ b/src/lj_errmsg.h | |||
| @@ -44,6 +44,7 @@ ERRDEF(BADVAL, "invalid value") | |||
| 44 | ERRDEF(NOVAL, "value expected") | 44 | ERRDEF(NOVAL, "value expected") |
| 45 | ERRDEF(NOCORO, "coroutine expected") | 45 | ERRDEF(NOCORO, "coroutine expected") |
| 46 | ERRDEF(NOTABN, "nil or table expected") | 46 | ERRDEF(NOTABN, "nil or table expected") |
| 47 | ERRDEF(NOLFUNC, "Lua function expected") | ||
| 47 | ERRDEF(NOFUNCL, "function or level expected") | 48 | ERRDEF(NOFUNCL, "function or level expected") |
| 48 | ERRDEF(NOSFT, "string/function/table expected") | 49 | ERRDEF(NOSFT, "string/function/table expected") |
| 49 | ERRDEF(NOPROXY, "boolean or proxy expected") | 50 | ERRDEF(NOPROXY, "boolean or proxy expected") |
| @@ -336,12 +336,15 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); | |||
| 336 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); | 336 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); |
| 337 | LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); | 337 | LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); |
| 338 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); | 338 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); |
| 339 | |||
| 340 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); | 339 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); |
| 341 | LUA_API lua_Hook lua_gethook (lua_State *L); | 340 | LUA_API lua_Hook lua_gethook (lua_State *L); |
| 342 | LUA_API int lua_gethookmask (lua_State *L); | 341 | LUA_API int lua_gethookmask (lua_State *L); |
| 343 | LUA_API int lua_gethookcount (lua_State *L); | 342 | LUA_API int lua_gethookcount (lua_State *L); |
| 344 | 343 | ||
| 344 | /* From Lua 5.2. */ | ||
| 345 | LUA_API void *lua_upvalueid (lua_State *L, int idx, int n); | ||
| 346 | LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2); | ||
| 347 | |||
| 345 | 348 | ||
| 346 | struct lua_Debug { | 349 | struct lua_Debug { |
| 347 | int event; | 350 | int event; |
