diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib_package.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/lib_package.c b/src/lib_package.c index ca5a5a16..1794a3d4 100644 --- a/src/lib_package.c +++ b/src/lib_package.c | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h | 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h |
| 4 | ** | 4 | ** |
| 5 | ** Major portions taken verbatim or adapted from the Lua interpreter. | 5 | ** Major portions taken verbatim or adapted from the Lua interpreter. |
| 6 | ** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h | 6 | ** Copyright (C) 1994-2012 Lua.org, PUC-Rio. See Copyright Notice in lua.h |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #define lib_package_c | 9 | #define lib_package_c |
| @@ -41,9 +41,9 @@ static void ll_unloadlib(void *lib) | |||
| 41 | dlclose(lib); | 41 | dlclose(lib); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | static void *ll_load(lua_State *L, const char *path) | 44 | static void *ll_load(lua_State *L, const char *path, int gl) |
| 45 | { | 45 | { |
| 46 | void *lib = dlopen(path, RTLD_NOW); | 46 | void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL)); |
| 47 | if (lib == NULL) lua_pushstring(L, dlerror()); | 47 | if (lib == NULL) lua_pushstring(L, dlerror()); |
| 48 | return lib; | 48 | return lib; |
| 49 | } | 49 | } |
| @@ -112,10 +112,11 @@ static void ll_unloadlib(void *lib) | |||
| 112 | FreeLibrary((HINSTANCE)lib); | 112 | FreeLibrary((HINSTANCE)lib); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | static void *ll_load(lua_State *L, const char *path) | 115 | static void *ll_load(lua_State *L, const char *path, int gl) |
| 116 | { | 116 | { |
| 117 | HINSTANCE lib = LoadLibraryA(path); | 117 | HINSTANCE lib = LoadLibraryA(path); |
| 118 | if (lib == NULL) pusherror(L); | 118 | if (lib == NULL) pusherror(L); |
| 119 | UNUSED(gl); | ||
| 119 | return lib; | 120 | return lib; |
| 120 | } | 121 | } |
| 121 | 122 | ||
| @@ -149,26 +150,26 @@ static const char *ll_bcsym(void *lib, const char *sym) | |||
| 149 | 150 | ||
| 150 | static void ll_unloadlib(void *lib) | 151 | static void ll_unloadlib(void *lib) |
| 151 | { | 152 | { |
| 152 | (void)lib; | 153 | UNUSED(lib); |
| 153 | } | 154 | } |
| 154 | 155 | ||
| 155 | static void *ll_load(lua_State *L, const char *path) | 156 | static void *ll_load(lua_State *L, const char *path, int gl) |
| 156 | { | 157 | { |
| 157 | (void)path; | 158 | UNUSED(path); UNUSED(gl); |
| 158 | lua_pushliteral(L, DLMSG); | 159 | lua_pushliteral(L, DLMSG); |
| 159 | return NULL; | 160 | return NULL; |
| 160 | } | 161 | } |
| 161 | 162 | ||
| 162 | static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) | 163 | static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym) |
| 163 | { | 164 | { |
| 164 | (void)lib; (void)sym; | 165 | UNUSED(lib); UNUSED(sym); |
| 165 | lua_pushliteral(L, DLMSG); | 166 | lua_pushliteral(L, DLMSG); |
| 166 | return NULL; | 167 | return NULL; |
| 167 | } | 168 | } |
| 168 | 169 | ||
| 169 | static const char *ll_bcsym(void *lib, const char *sym) | 170 | static const char *ll_bcsym(void *lib, const char *sym) |
| 170 | { | 171 | { |
| 171 | (void)lib; (void)sym; | 172 | UNUSED(lib); UNUSED(sym); |
| 172 | return NULL; | 173 | return NULL; |
| 173 | } | 174 | } |
| 174 | 175 | ||
| @@ -211,9 +212,12 @@ static const char *mksymname(lua_State *L, const char *modname, | |||
| 211 | static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) | 212 | static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) |
| 212 | { | 213 | { |
| 213 | void **reg = ll_register(L, path); | 214 | void **reg = ll_register(L, path); |
| 214 | if (*reg == NULL) *reg = ll_load(L, path); | 215 | if (*reg == NULL) *reg = ll_load(L, path, (*name == '*')); |
| 215 | if (*reg == NULL) { | 216 | if (*reg == NULL) { |
| 216 | return PACKAGE_ERR_LIB; /* unable to load library */ | 217 | return PACKAGE_ERR_LIB; /* Unable to load library. */ |
| 218 | } else if (*name == '*') { /* Only load library into global namespace. */ | ||
| 219 | lua_pushboolean(L, 1); | ||
| 220 | return 0; | ||
| 217 | } else { | 221 | } else { |
| 218 | const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF); | 222 | const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF); |
| 219 | lua_CFunction f = ll_sym(L, *reg, sym); | 223 | lua_CFunction f = ll_sym(L, *reg, sym); |
| @@ -230,7 +234,7 @@ static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r) | |||
| 230 | return 0; | 234 | return 0; |
| 231 | } | 235 | } |
| 232 | } | 236 | } |
| 233 | return PACKAGE_ERR_FUNC; /* unable to find function */ | 237 | return PACKAGE_ERR_FUNC; /* Unable to find function. */ |
| 234 | } | 238 | } |
| 235 | } | 239 | } |
| 236 | 240 | ||
