diff options
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.122 2014/11/10 14:28:31 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.123 2014/11/12 13:31:51 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 | ** |
@@ -135,6 +135,18 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym); | |||
135 | 135 | ||
136 | #include <dlfcn.h> | 136 | #include <dlfcn.h> |
137 | 137 | ||
138 | /* | ||
139 | ** Macro to covert pointer to void* to pointer to function. This cast | ||
140 | ** is undefined according to ISO C, but POSIX assumes that it must work. | ||
141 | ** (The '__extension__' in gnu compilers is only to avoid warnings.) | ||
142 | */ | ||
143 | #if defined(__GNUC__) | ||
144 | #define cast_func(p) (__extension__ (lua_CFunction)(p)) | ||
145 | #else | ||
146 | #define cast_func(p) ((lua_CFunction)(p)) | ||
147 | #endif | ||
148 | |||
149 | |||
138 | static void lsys_unloadlib (void *lib) { | 150 | static void lsys_unloadlib (void *lib) { |
139 | dlclose(lib); | 151 | dlclose(lib); |
140 | } | 152 | } |
@@ -148,7 +160,7 @@ static void *lsys_load (lua_State *L, const char *path, int seeglb) { | |||
148 | 160 | ||
149 | 161 | ||
150 | static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { | 162 | static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { |
151 | lua_CFunction f = (lua_CFunction)dlsym(lib, sym); | 163 | lua_CFunction f = cast_func(dlsym(lib, sym)); |
152 | if (f == NULL) lua_pushstring(L, dlerror()); | 164 | if (f == NULL) lua_pushstring(L, dlerror()); |
153 | return f; | 165 | return f; |
154 | } | 166 | } |