diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-10 12:28:31 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-10 12:28:31 -0200 |
commit | e32079015495f01e470b285a9a1f09552ab5c615 (patch) | |
tree | 5d08e487ce10f8ea5df61d7164a1e3b492911524 /loadlib.c | |
parent | fee3aa518d37f55ae93c3039b21c55f5f27d19e5 (diff) | |
download | lua-e32079015495f01e470b285a9a1f09552ab5c615.tar.gz lua-e32079015495f01e470b285a9a1f09552ab5c615.tar.bz2 lua-e32079015495f01e470b285a9a1f09552ab5c615.zip |
using address instead of string for key for table 'CLIBS' in the
registry
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.120 2014/11/02 19:19:04 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.121 2014/11/03 15:11:10 roberto Exp roberto $ |
3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | ** | 5 | ** |
@@ -85,8 +85,11 @@ | |||
85 | #define LUA_OFSEP "_" | 85 | #define LUA_OFSEP "_" |
86 | 86 | ||
87 | 87 | ||
88 | /* table (in the registry) that keeps handles for all loaded C libraries */ | 88 | /* |
89 | #define CLIBS "_CLIBS" | 89 | ** unique key for table in the registry that keeps handles |
90 | ** for all loaded C libraries | ||
91 | */ | ||
92 | static const int CLIBS = 0; | ||
90 | 93 | ||
91 | #define LIB_FAIL "open" | 94 | #define LIB_FAIL "open" |
92 | 95 | ||
@@ -261,7 +264,7 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { | |||
261 | */ | 264 | */ |
262 | static void *checkclib (lua_State *L, const char *path) { | 265 | static void *checkclib (lua_State *L, const char *path) { |
263 | void *plib; | 266 | void *plib; |
264 | lua_getfield(L, LUA_REGISTRYINDEX, CLIBS); | 267 | lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS); |
265 | lua_getfield(L, -1, path); | 268 | lua_getfield(L, -1, path); |
266 | plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */ | 269 | plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */ |
267 | lua_pop(L, 2); /* pop CLIBS table and 'plib' */ | 270 | lua_pop(L, 2); /* pop CLIBS table and 'plib' */ |
@@ -274,7 +277,7 @@ static void *checkclib (lua_State *L, const char *path) { | |||
274 | ** registry.CLIBS[#CLIBS + 1] = plib -- also keep a list of all libraries | 277 | ** registry.CLIBS[#CLIBS + 1] = plib -- also keep a list of all libraries |
275 | */ | 278 | */ |
276 | static void addtoclib (lua_State *L, const char *path, void *plib) { | 279 | static void addtoclib (lua_State *L, const char *path, void *plib) { |
277 | lua_getfield(L, LUA_REGISTRYINDEX, CLIBS); | 280 | lua_rawgetp(L, LUA_REGISTRYINDEX, &CLIBS); |
278 | lua_pushlightuserdata(L, plib); | 281 | lua_pushlightuserdata(L, plib); |
279 | lua_pushvalue(L, -1); | 282 | lua_pushvalue(L, -1); |
280 | lua_setfield(L, -3, path); /* CLIBS[path] = plib */ | 283 | lua_setfield(L, -3, path); /* CLIBS[path] = plib */ |
@@ -735,11 +738,12 @@ static void createsearcherstable (lua_State *L) { | |||
735 | ** setting a finalizer to close all libraries when closing state. | 738 | ** setting a finalizer to close all libraries when closing state. |
736 | */ | 739 | */ |
737 | static void createclibstable (lua_State *L) { | 740 | static void createclibstable (lua_State *L) { |
738 | luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS); /* create CLIBS table */ | 741 | lua_newtable(L); /* create CLIBS table */ |
739 | lua_createtable(L, 0, 1); /* create metatable for CLIBS */ | 742 | lua_createtable(L, 0, 1); /* create metatable for CLIBS */ |
740 | lua_pushcfunction(L, gctm); | 743 | lua_pushcfunction(L, gctm); |
741 | lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */ | 744 | lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */ |
742 | lua_setmetatable(L, -2); | 745 | lua_setmetatable(L, -2); |
746 | lua_rawsetp(L, LUA_REGISTRYINDEX, &CLIBS); /* set CLIBS table in registry */ | ||
743 | } | 747 | } |
744 | 748 | ||
745 | 749 | ||