diff options
-rw-r--r-- | lauxlib.h | 23 | ||||
-rw-r--r-- | ltests.c | 9 |
2 files changed, 9 insertions, 23 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.110 2010/11/10 17:38:10 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.111 2010/11/10 18:05:36 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -62,6 +62,10 @@ LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); | |||
62 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, | 62 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, |
63 | const char *const lst[]); | 63 | const char *const lst[]); |
64 | 64 | ||
65 | /* pre-defined references */ | ||
66 | #define LUA_NOREF (-2) | ||
67 | #define LUA_REFNIL (-1) | ||
68 | |||
65 | LUALIB_API int (luaL_ref) (lua_State *L, int t); | 69 | LUALIB_API int (luaL_ref) (lua_State *L, int t); |
66 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); | 70 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); |
67 | 71 | ||
@@ -164,23 +168,6 @@ LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, | |||
164 | const luaL_Reg *l, int nup); | 168 | const luaL_Reg *l, int nup); |
165 | 169 | ||
166 | 170 | ||
167 | /* compatibility with ref system */ | ||
168 | |||
169 | /* pre-defined references */ | ||
170 | #define LUA_NOREF (-2) | ||
171 | #define LUA_REFNIL (-1) | ||
172 | |||
173 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ | ||
174 | (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) | ||
175 | |||
176 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) | ||
177 | |||
178 | #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) | ||
179 | |||
180 | |||
181 | #define luaL_reg luaL_Reg | ||
182 | |||
183 | |||
184 | #endif | 171 | #endif |
185 | 172 | ||
186 | 173 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.111 2010/07/02 11:38:13 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.112 2010/07/28 15:51:59 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -727,24 +727,23 @@ static int string_query (lua_State *L) { | |||
727 | 727 | ||
728 | static int tref (lua_State *L) { | 728 | static int tref (lua_State *L) { |
729 | int level = lua_gettop(L); | 729 | int level = lua_gettop(L); |
730 | int lock = luaL_optint(L, 2, 1); | ||
731 | luaL_checkany(L, 1); | 730 | luaL_checkany(L, 1); |
732 | lua_pushvalue(L, 1); | 731 | lua_pushvalue(L, 1); |
733 | lua_pushinteger(L, lua_ref(L, lock)); | 732 | lua_pushinteger(L, luaL_ref(L, LUA_REGISTRYINDEX)); |
734 | lua_assert(lua_gettop(L) == level+1); /* +1 for result */ | 733 | lua_assert(lua_gettop(L) == level+1); /* +1 for result */ |
735 | return 1; | 734 | return 1; |
736 | } | 735 | } |
737 | 736 | ||
738 | static int getref (lua_State *L) { | 737 | static int getref (lua_State *L) { |
739 | int level = lua_gettop(L); | 738 | int level = lua_gettop(L); |
740 | lua_getref(L, luaL_checkint(L, 1)); | 739 | lua_rawgeti(L, LUA_REGISTRYINDEX, luaL_checkint(L, 1)); |
741 | lua_assert(lua_gettop(L) == level+1); | 740 | lua_assert(lua_gettop(L) == level+1); |
742 | return 1; | 741 | return 1; |
743 | } | 742 | } |
744 | 743 | ||
745 | static int unref (lua_State *L) { | 744 | static int unref (lua_State *L) { |
746 | int level = lua_gettop(L); | 745 | int level = lua_gettop(L); |
747 | lua_unref(L, luaL_checkint(L, 1)); | 746 | luaL_unref(L, LUA_REGISTRYINDEX, luaL_checkint(L, 1)); |
748 | lua_assert(lua_gettop(L) == level); | 747 | lua_assert(lua_gettop(L) == level); |
749 | return 0; | 748 | return 0; |
750 | } | 749 | } |