26#define LUA_POF "luaopen_"
32#define LIBPREFIX "LOADLIB: "
35#define LIB_FAIL "open"
42#define setprogdir(L) ((void)0)
51#if defined(LUA_DL_DLOPEN)
69 void *lib = dlopen(path, RTLD_NOW);
85#elif defined(LUA_DL_DLL)
98 char buff[MAX_PATH + 1];
100 DWORD nsize =
sizeof(buff)/
sizeof(
char);
101 DWORD n = GetModuleFileNameA(
NULL, buff, nsize);
102 if (n == 0 || n == nsize || (lb = strrchr(buff,
'\\')) ==
NULL)
103 luaL_error(L,
"unable to get ModuleFileName");
113 int error = GetLastError();
115 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
123 FreeLibrary((HINSTANCE)lib);
128 HINSTANCE lib = LoadLibraryA(path);
144#elif defined(LUA_DL_DYLD)
151#include <mach-o/dyld.h>
156#define POF "_" LUA_POF
161 const char *err_file;
162 NSLinkEditErrors err;
164 NSLinkEditError(&err, &err_num, &err_file, &err_str);
169static const char *errorfromcode (NSObjectFileImageReturnCode ret) {
171 case NSObjectFileImageInappropriateFile:
172 return "file is not a bundle";
173 case NSObjectFileImageArch:
174 return "library is for wrong CPU type";
175 case NSObjectFileImageFormat:
177 case NSObjectFileImageAccess:
178 return "cannot access file";
179 case NSObjectFileImageFailure:
181 return "unable to load library";
187 NSUnLinkModule((NSModule)lib, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
192 NSObjectFileImage img;
193 NSObjectFileImageReturnCode ret;
195 if(!_dyld_present()) {
199 ret = NSCreateObjectFileImageFromFile(path, &img);
200 if (ret == NSObjectFileImageSuccess) {
201 NSModule mod = NSLinkModule(img, path, NSLINKMODULE_OPTION_PRIVATE |
202 NSLINKMODULE_OPTION_RETURN_ON_ERROR);
203 NSDestroyObjectFileImage(img);
213 NSSymbol nss = NSLookupSymbolInModule((NSModule)lib, sym);
233#define LIB_FAIL "absent"
236#define DLMSG "dynamic libraries not enabled; check your Lua installation"
252 (void)lib; (void)sym;
333 FILE *f = fopen(filename,
"r");
334 if (f ==
NULL)
return 0;
343 if (*path ==
'\0')
return NULL;
345 if (l ==
NULL) l = path + strlen(path);
361 const char *filename;
381 const char *filename;
384 if (filename ==
NULL)
return 1;
393 const char *mark = strchr(modname, *
LUA_IGMARK);
394 if (mark) modname = mark + 1;
406 if (filename ==
NULL)
return 1;
416 const char *filename;
418 const char *p = strchr(
name,
'.');
420 if (p ==
NULL)
return 0;
423 if (filename ==
NULL)
return 1;
448#define sentinel ((void *)&sentinel_)
521 for (i = 2; i <= n; i++) {
535 dot = strrchr(modname,
'.');
536 if (dot ==
NULL) dot = modname;
594 const char *path = getenv(envname);
635#if defined(LUA_COMPAT_LOADLIB)
static int pusherror(lua_State *L, const char *info)
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API int lua_setmetatable(lua_State *L, int objindex)
LUA_API void lua_pushnil(lua_State *L)
LUA_API void lua_concat(lua_State *L, int n)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API int lua_iscfunction(lua_State *L, int idx)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API void lua_settable(lua_State *L, int idx)
LUA_API int lua_getmetatable(lua_State *L, int objindex)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API void lua_gettable(lua_State *L, int idx)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
LUA_API int lua_isstring(lua_State *L, int idx)
LUA_API void * lua_touserdata(lua_State *L, int idx)
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
LUA_API int lua_setfenv(lua_State *L, int idx)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
LUALIB_API const char * luaL_findtable(lua_State *L, int idx, const char *fname, int szhint)
LUALIB_API void * luaL_checkudata(lua_State *L, int ud, const char *tname)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API void luaL_register(lua_State *L, const char *libname, const luaL_Reg *l)
LUALIB_API const char * luaL_gsub(lua_State *L, const char *s, const char *p, const char *r)
#define luaL_getmetatable(L, n)
#define luaL_checkstring(L, n)
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
static int ll_require(lua_State *L)
static void modinit(lua_State *L, const char *modname)
static int ll_loadfunc(lua_State *L, const char *path, const char *sym)
static const int sentinel_
static const luaL_Reg ll_funcs[]
static int loader_Lua(lua_State *L)
static int loader_C(lua_State *L)
static const char * pushnexttemplate(lua_State *L, const char *path)
static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
static void loaderror(lua_State *L, const char *filename)
static int gctm(lua_State *L)
static const char * findfile(lua_State *L, const char *name, const char *pname)
static void * ll_load(lua_State *L, const char *path)
static void setfenv(lua_State *L)
static void dooptions(lua_State *L, int n)
static void ** ll_register(lua_State *L, const char *path)
static const lua_CFunction loaders[]
static int loader_preload(lua_State *L)
LUALIB_API int luaopen_package(lua_State *L)
static void setpath(lua_State *L, const char *fieldname, const char *envname, const char *def)
static int ll_seeall(lua_State *L)
static int ll_loadlib(lua_State *L)
static int ll_module(lua_State *L)
static void ll_unloadlib(void *lib)
static int loader_Croot(lua_State *L)
static int readable(const char *filename)
static const char * mkfuncname(lua_State *L, const char *modname)
static const luaL_Reg pk_funcs[]
static int funcname(LexState *ls, expdesc *v)
#define lua_istable(L, n)
#define lua_pushcfunction(L, f)
#define LUA_REGISTRYINDEX
#define lua_pushliteral(L, s)
#define lua_isfunction(L, n)
int(* lua_CFunction)(lua_State *L)
#define lua_tostring(L, i)
#define LUA_CPATH_DEFAULT
static void error(LoadState *S, const char *why)
#define luaL_loadfile(L, f)
#define lua_call(L, n, r)
#define lua_replace(L, idx)
#define lua_insert(L, idx)
#define lua_remove(L, idx)
#define lua_newuserdata(L, s)