aboutsummaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-10 12:28:31 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-10 12:28:31 -0200
commite32079015495f01e470b285a9a1f09552ab5c615 (patch)
tree5d08e487ce10f8ea5df61d7164a1e3b492911524 /loadlib.c
parentfee3aa518d37f55ae93c3039b21c55f5f27d19e5 (diff)
downloadlua-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.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/loadlib.c b/loadlib.c
index 5c0dc9db..3fceaf94 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -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*/
92static 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*/
262static void *checkclib (lua_State *L, const char *path) { 265static 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*/
276static void addtoclib (lua_State *L, const char *path, void *plib) { 279static 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*/
737static void createclibstable (lua_State *L) { 740static 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