diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-06-18 14:23:02 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-06-18 14:23:02 -0300 |
commit | bef5980744d260246df81a5cf824c43b9b8080f8 (patch) | |
tree | 6c4befb61dfb8c3a9806196ec8ffb3f7f6aa7d94 /loadlib.c | |
parent | 409741e900d4c13a432f5a768554add1ed2426fa (diff) | |
download | lua-bef5980744d260246df81a5cf824c43b9b8080f8.tar.gz lua-bef5980744d260246df81a5cf824c43b9b8080f8.tar.bz2 lua-bef5980744d260246df81a5cf824c43b9b8080f8.zip |
no more support for old Mac OS systems
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 90 |
1 files changed, 3 insertions, 87 deletions
@@ -1,11 +1,11 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.83 2010/05/31 16:34:19 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.84 2010/06/13 19:36:17 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 | ** |
6 | ** This module contains an implementation of loadlib for Unix systems | 6 | ** This module contains an implementation of loadlib for Unix systems |
7 | ** that have dlfcn, an implementation for Darwin (Mac OS X), an | 7 | ** that have dlfcn, an implementation for Windows, and a stub for other |
8 | ** implementation for Windows, and a stub for other systems. | 8 | ** systems. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | 11 | ||
@@ -188,90 +188,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | |||
188 | /* }====================================================== */ | 188 | /* }====================================================== */ |
189 | 189 | ||
190 | 190 | ||
191 | |||
192 | #elif defined(LUA_DL_DYLD) | ||
193 | /* | ||
194 | ** {====================================================================== | ||
195 | ** Old native Mac OS X - only for old versions of Mac OS (< 10.3) | ||
196 | ** ======================================================================= | ||
197 | */ | ||
198 | |||
199 | #include <mach-o/dyld.h> | ||
200 | |||
201 | |||
202 | /* Mac appends a `_' before C function names */ | ||
203 | #undef POF | ||
204 | #define POF "_" LUA_POF | ||
205 | |||
206 | |||
207 | static void pusherror (lua_State *L) { | ||
208 | const char *err_str; | ||
209 | const char *err_file; | ||
210 | NSLinkEditErrors err; | ||
211 | int err_num; | ||
212 | NSLinkEditError(&err, &err_num, &err_file, &err_str); | ||
213 | lua_pushstring(L, err_str); | ||
214 | } | ||
215 | |||
216 | |||
217 | static const char *errorfromcode (NSObjectFileImageReturnCode ret) { | ||
218 | switch (ret) { | ||
219 | case NSObjectFileImageInappropriateFile: | ||
220 | return "file is not a bundle"; | ||
221 | case NSObjectFileImageArch: | ||
222 | return "library is for wrong CPU type"; | ||
223 | case NSObjectFileImageFormat: | ||
224 | return "bad format"; | ||
225 | case NSObjectFileImageAccess: | ||
226 | return "cannot access file"; | ||
227 | case NSObjectFileImageFailure: | ||
228 | default: | ||
229 | return "unable to load library"; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | |||
234 | static void ll_unloadlib (void *lib) { | ||
235 | NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); | ||
236 | } | ||
237 | |||
238 | |||
239 | static void *ll_load (lua_State *L, const char *path, int seeglb) { | ||
240 | NSObjectFileImage img; | ||
241 | NSObjectFileImageReturnCode ret; | ||
242 | /* this would be a rare case, but prevents crashing if it happens */ | ||
243 | if(!_dyld_present()) { | ||
244 | lua_pushliteral(L, "dyld not present"); | ||
245 | return NULL; | ||
246 | } | ||
247 | ret = NSCreateObjectFileImageFromFile(path, &img); | ||
248 | if (ret == NSObjectFileImageSuccess) { | ||
249 | NSModule mod = NSLinkModule(img, | ||
250 | path, | ||
251 | NSLINKMODULE_OPTION_RETURN_ON_ERROR | | ||
252 | (seeglb ? 0 : NSLINKMODULE_OPTION_PRIVATE)); | ||
253 | NSDestroyObjectFileImage(img); | ||
254 | if (mod == NULL) pusherror(L); | ||
255 | return mod; | ||
256 | } | ||
257 | lua_pushstring(L, errorfromcode(ret)); | ||
258 | return NULL; | ||
259 | } | ||
260 | |||
261 | |||
262 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | ||
263 | NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym); | ||
264 | if (nss == NULL) { | ||
265 | lua_pushfstring(L, "symbol " LUA_QS " not found", sym); | ||
266 | return NULL; | ||
267 | } | ||
268 | return (lua_CFunction)NSAddressOfSymbol(nss); | ||
269 | } | ||
270 | |||
271 | /* }====================================================== */ | ||
272 | |||
273 | |||
274 | |||
275 | #else | 191 | #else |
276 | /* | 192 | /* |
277 | ** {====================================================== | 193 | ** {====================================================== |