31#if !defined (LUA_IGMARK)
42#if !defined(LUA_CSUBSEP)
43#define LUA_CSUBSEP LUA_DIRSEP
46#if !defined(LUA_LSUBSEP)
47#define LUA_LSUBSEP LUA_DIRSEP
52#define LUA_POF "luaopen_"
64#define LIB_FAIL "open"
67#define setprogdir(L) ((void)0)
97#if defined(LUA_USE_DLOPEN)
115#define cast_func(p) (__extension__ (lua_CFunction)(p))
117#define cast_func(p) ((lua_CFunction)(p))
127 void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));
143#elif defined(LUA_DL_DLL)
156#if !defined(LUA_LLE_FLAGS)
157#define LUA_LLE_FLAGS 0
169 char buff[MAX_PATH + 1];
171 DWORD nsize =
sizeof(buff)/
sizeof(
char);
172 DWORD n = GetModuleFileNameA(
NULL, buff, nsize);
173 if (n == 0 || n == nsize || (lb = strrchr(buff,
'\\')) ==
NULL)
174 luaL_error(L,
"unable to get ModuleFileName");
186 int error = GetLastError();
188 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
196 FreeLibrary((HMODULE)lib);
201 HMODULE lib = LoadLibraryExA(path,
NULL, LUA_LLE_FLAGS);
225#define LIB_FAIL "absent"
228#define DLMSG "dynamic libraries not enabled; check your Lua installation"
237 (void)(path); (void)(seeglb);
244 (void)(lib); (void)(sym);
263#if !defined(LUA_PATH_VAR)
264#define LUA_PATH_VAR "LUA_PATH"
267#if !defined(LUA_CPATH_VAR)
268#define LUA_CPATH_VAR "LUA_CPATH"
294 const char *path = getenv(nver);
296 path = getenv(envname);
347 for (; n >= 1; n--) {
417 FILE *f = fopen(filename,
"r");
418 if (f ==
NULL)
return 0;
427 if (*path ==
'\0')
return NULL;
429 if (l ==
NULL) l = path + strlen(path);
438 const char *dirsep) {
463 if (f !=
NULL)
return 1;
474 const char *dirsep) {
479 luaL_error(L,
"'package.%s' must be a string", pname);
490 return luaL_error(L,
"error loading module '%s' from file '%s':\n\t%s",
496 const char *filename;
499 if (filename ==
NULL)
return 1;
513 const char *openfunc;
522 if (stat !=
ERRFUNC)
return stat;
533 if (filename ==
NULL)
return 1;
539 const char *filename;
541 const char *p = strchr(
name,
'.');
543 if (p ==
NULL)
return 0;
546 if (filename ==
NULL)
return 1;
575 luaL_error(L,
"'package.searchers' must be a table");
629#if defined(LUA_COMPAT_MODULE)
639 luaL_error(L,
"'module' not called from a Lua function");
648 for (i = 2; i <= n; i++) {
664 dot = strrchr(modname,
'.');
665 if (dot ==
NULL) dot = modname;
676 luaL_pushmodule(L, modname, 1);
711#if defined(LUA_COMPAT_MODULE)
725#if defined(LUA_COMPAT_MODULE)
740 for (i=0; searchers[i] !=
NULL; i++) {
745#if defined(LUA_COMPAT_LOADERS)
static int pusherror(lua_State *L, const char *info)
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
LUA_API int lua_setmetatable(lua_State *L, int objindex)
LUA_API void lua_pushnil(lua_State *L)
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 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_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 const char * lua_setupvalue(lua_State *L, int funcindex, int n)
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_gettop(lua_State *L)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API const char * luaL_gsub(lua_State *L, const char *s, const char *p, const char *r)
#define luaL_optstring(L, n, d)
#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 void modinit(lua_State *L, const char *modname)
static void dooptions(lua_State *L, int n)
static int ll_seeall(lua_State *L)
static int ll_module(lua_State *L)
#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_upvalueindex(i)
#define lua_tostring(L, i)
#define LUA_CPATH_DEFAULT
static void error(LoadState *S, const char *why)
LUA_API void lua_rawgetp(lua_State *L, int idx, const void *p)
LUA_API void lua_rawsetp(lua_State *L, int idx, const void *p)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)
LUALIB_API int luaL_len(lua_State *L, int idx)
#define luaL_loadfile(L, f)
#define luaL_newlib(L, l)
#define lua_call(L, n, r)
#define lua_pushglobaltable(L)
#define LUA_PRELOAD_TABLE
static int noenv(lua_State *L)
static int ll_require(lua_State *L)
static int searcher_Croot(lua_State *L)
static const luaL_Reg ll_funcs[]
static int ll_searchpath(lua_State *L)
static void * lsys_load(lua_State *L, const char *path, int seeglb)
static const char * pushnexttemplate(lua_State *L, const char *path)
static void createclibstable(lua_State *L)
static int gctm(lua_State *L)
static void lsys_unloadlib(void *lib)
static int searcher_preload(lua_State *L)
static lua_CFunction lsys_sym(lua_State *L, void *lib, const char *sym)
static int searcher_Lua(lua_State *L)
static void createsearcherstable(lua_State *L)
static int loadfunc(lua_State *L, const char *filename, const char *modname)
static int searcher_C(lua_State *L)
static const char * searchpath(lua_State *L, const char *name, const char *path, const char *sep, const char *dirsep)
static int ll_loadlib(lua_State *L)
LUAMOD_API int luaopen_package(lua_State *L)
static int checkload(lua_State *L, int stat, const char *filename)
static void * checkclib(lua_State *L, const char *path)
static const char * findfile(lua_State *L, const char *name, const char *pname, const char *dirsep)
static void setpath(lua_State *L, const char *fieldname, const char *envname, const char *dft)
static int lookforfunc(lua_State *L, const char *path, const char *sym)
static void findloader(lua_State *L, const char *name)
static void addtoclib(lua_State *L, const char *path, void *plib)
static int readable(const char *filename)
static const luaL_Reg pk_funcs[]
#define lua_insert(L, idx)
#define lua_remove(L, idx)