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_"
62static const char *
const CLIBS =
"_CLIBS";
64#define LIB_FAIL "open"
67#define setprogdir(L) ((void)0)
104#if defined(LUA_USE_DLOPEN)
122#define cast_func(p) (__extension__ (lua_CFunction)(p))
124#define cast_func(p) ((lua_CFunction)(p))
134 void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL));
135 if (l_unlikely(lib ==
NULL))
143 if (l_unlikely(f ==
NULL))
152#elif defined(LUA_DL_DLL)
165#if !defined(LUA_LLE_FLAGS)
166#define LUA_LLE_FLAGS 0
178 char buff[MAX_PATH + 1];
180 DWORD nsize =
sizeof(buff)/
sizeof(
char);
181 DWORD n = GetModuleFileNameA(
NULL, buff, nsize);
182 if (n == 0 || n == nsize || (lb = strrchr(buff,
'\\')) ==
NULL)
183 luaL_error(L,
"unable to get ModuleFileName");
195 int error = GetLastError();
197 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
205 FreeLibrary((HMODULE)lib);
210 HMODULE lib = LoadLibraryExA(path,
NULL, LUA_LLE_FLAGS);
234#define LIB_FAIL "absent"
237#define DLMSG "dynamic libraries not enabled; check your Lua installation"
246 (void)(path); (void)(seeglb);
253 (void)(lib); (void)(sym);
272#if !defined(LUA_PATH_VAR)
273#define LUA_PATH_VAR "LUA_PATH"
276#if !defined(LUA_CPATH_VAR)
277#define LUA_CPATH_VAR "LUA_CPATH"
302 const char *path = getenv(nver);
304 path = getenv(envname);
310 size_t len = strlen(path);
313 if (path < dftmark) {
318 if (dftmark < path + len - 2) {
365 for (; n >= 1; n--) {
415 if (l_likely(stat == 0))
435 FILE *f = fopen(filename,
"r");
436 if (f ==
NULL)
return 0;
452 else if (*
name ==
'\0') {
484 const char *dirsep) {
488 const char *filename;
490 if (*sep !=
'\0' && strchr(
name, *sep) !=
NULL)
513 if (f !=
NULL)
return 1;
524 const char *dirsep) {
528 if (l_unlikely(path ==
NULL))
529 luaL_error(L,
"'package.%s' must be a string", pname);
535 if (l_likely(stat)) {
540 return luaL_error(L,
"error loading module '%s' from file '%s':\n\t%s",
546 const char *filename;
549 if (filename ==
NULL)
return 1;
563 const char *openfunc;
572 if (stat !=
ERRFUNC)
return stat;
583 if (filename ==
NULL)
return 1;
589 const char *filename;
591 const char *p = strchr(
name,
'.');
593 if (p ==
NULL)
return 0;
596 if (filename ==
NULL)
return 1;
630 luaL_error(L,
"'package.searchers' must be a table");
717 for (i=0; searchers[i] !=
NULL; i++) {
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 const char * lua_pushfstring(lua_State *L, const char *fmt,...)
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_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 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)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)
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)
LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)
#define luaL_addchar(B, c)
#define luaL_optstring(L, n, d)
#define luaL_checkstring(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_upvalueindex(i)
#define lua_tostring(L, i)
#define LUA_CPATH_DEFAULT
static void error(LoadState *S, const char *why)
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)
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)
LUA_API void lua_rotate(lua_State *L, int idx, int n)
#define LUA_PRELOAD_TABLE
#define lua_insert(L, idx)
#define lua_remove(L, idx)
LUALIB_API void luaL_addgsub(luaL_Buffer *b, const char *s, const char *p, const char *r)
#define luaL_buffsub(B, s)
#define luaL_buffaddr(bf)
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 void createclibstable(lua_State *L)
static int gctm(lua_State *L)
static const char * getnextfilename(char **path, char *end)
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 const char *const CLIBS
static int searcher_Lua(lua_State *L)
static void pusherrornotfound(lua_State *L, const char *path)
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[]