31 #if !defined (LUA_IGMARK) 32 #define 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_" 62 static const char *
const CLIBS =
"_CLIBS";
64 #define LIB_FAIL "open" 67 #define setprogdir(L) ((void)0) 104 #if defined(LUA_USE_DLOPEN) 121 #if defined(__GNUC__) 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));
150 #elif defined(LUA_DL_DLL) 163 #if !defined(LUA_LLE_FLAGS) 164 #define LUA_LLE_FLAGS 0 176 char buff[MAX_PATH + 1];
178 DWORD nsize =
sizeof(buff)/
sizeof(
char);
179 DWORD n = GetModuleFileNameA(NULL, buff, nsize);
180 if (n == 0 || n == nsize || (lb = strrchr(buff,
'\\')) == NULL)
181 luaL_error(L,
"unable to get ModuleFileName");
193 int error = GetLastError();
195 if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
196 NULL, error, 0, buffer,
sizeof(buffer)/
sizeof(
char), NULL))
203 FreeLibrary((HMODULE)lib);
208 HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);
210 if (lib == NULL) pusherror(L);
217 if (f == NULL) pusherror(L);
232 #define LIB_FAIL "absent" 235 #define DLMSG "dynamic libraries not enabled; check your Lua installation" 270 #if !defined(LUA_PATH_VAR) 271 #define LUA_PATH_VAR "LUA_PATH" 274 #if !defined(LUA_CPATH_VAR) 275 #define LUA_CPATH_VAR "LUA_CPATH" 300 const char *path = getenv(nver);
302 path = getenv(envname);
303 if (path == NULL ||
noenv(L))
308 size_t len = strlen(path);
311 if (path < dftmark) {
316 if (dftmark < path + len - 2) {
363 for (; n >= 1; n--) {
392 if (reg == NULL)
return ERRLIB;
433 FILE *f = fopen(filename,
"r");
434 if (f == NULL)
return 0;
450 else if (*name ==
'\0') {
482 const char *dirsep) {
486 const char *filename;
488 if (*sep !=
'\0' && strchr(name, *sep) != NULL)
511 if (f != NULL)
return 1;
522 const char *dirsep) {
527 luaL_error(L,
"'package.%s' must be a string", pname);
528 return searchpath(L, name, path,
".", dirsep);
538 return luaL_error(L,
"error loading module '%s' from file '%s':\n\t%s",
544 const char *filename;
547 if (filename == NULL)
return 1;
561 const char *openfunc;
570 if (stat !=
ERRFUNC)
return stat;
581 if (filename == NULL)
return 1;
587 const char *filename;
589 const char *p = strchr(name,
'.');
591 if (p == NULL)
return 0;
594 if (filename == NULL)
return 1;
595 if ((stat =
loadfunc(L, filename, name)) != 0) {
627 luaL_error(L,
"'package.searchers' must be a table");
714 for (i=0; searchers[i] != NULL; i++) {
LUA_API int lua_isstring(lua_State *L, int idx)
static int searcher_C(lua_State *L)
#define lua_pushcfunction(L, f)
static int ll_require(lua_State *L)
static int searcher_Lua(lua_State *L)
LUALIB_API void luaL_addgsub(luaL_Buffer *b, const char *s, const char *p, const char *r)
LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)
#define LUA_CPATH_DEFAULT
LUA_API int lua_rawgeti(lua_State *L, int idx, lua_Integer n)
static int gctm(lua_State *L)
LUA_API int lua_setmetatable(lua_State *L, int objindex)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API void * lua_touserdata(lua_State *L, int idx)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
#define LUA_PRELOAD_TABLE
#define lua_remove(L, idx)
static void pusherrornotfound(lua_State *L, const char *path)
LUALIB_API const char * luaL_gsub(lua_State *L, const char *s, const char *p, const char *r)
LUAMOD_API int luaopen_package(lua_State *L)
static const luaL_Reg ll_funcs[]
static const luaL_Reg pk_funcs[]
static l_noret error(LoadState *S, const char *why)
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
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)
static void addtoclib(lua_State *L, const char *path, void *plib)
LUA_API void lua_pushvalue(lua_State *L, int idx)
#define luaL_loadfile(L, f)
static int noenv(lua_State *L)
LUA_API void lua_settop(lua_State *L, int idx)
#define lua_upvalueindex(i)
static int loadfunc(lua_State *L, const char *filename, const char *modname)
int(* lua_CFunction)(lua_State *L)
#define luaL_buffsub(B, s)
static void * checkclib(lua_State *L, const char *path)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUA_API void lua_pushboolean(lua_State *L, int b)
#define lua_pushglobaltable(L)
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
static int ll_searchpath(lua_State *L)
#define luaL_addchar(B, c)
static void createclibstable(lua_State *L)
static void setpath(lua_State *L, const char *fieldname, const char *envname, const char *dft)
#define lua_pushliteral(L, s)
LUALIB_API lua_Integer luaL_len(lua_State *L, int idx)
static void * lsys_load(lua_State *L, const char *path, int seeglb)
static int ll_loadlib(lua_State *L)
#define lua_isfunction(L, n)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
static void createsearcherstable(lua_State *L)
#define luaL_buffaddr(bf)
static int checkload(lua_State *L, int stat, const char *filename)
static lua_CFunction lsys_sym(lua_State *L, void *lib, const char *sym)
#define lua_tostring(L, i)
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
static int readable(const char *filename)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
#define luaL_newlib(L, l)
#define lua_call(L, n, r)
LUA_API void lua_rotate(lua_State *L, int idx, int n)
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
static const char * findfile(lua_State *L, const char *name, const char *pname, const char *dirsep)
LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname)
#define LUA_REGISTRYINDEX
static int searcher_preload(lua_State *L)
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
static const char * getnextfilename(char **path, char *end)
static int searcher_Croot(lua_State *L)
static void lsys_unloadlib(void *lib)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
static const char * searchpath(lua_State *L, const char *name, const char *path, const char *sep, const char *dirsep)
#define lua_insert(L, idx)
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
LUA_API int lua_getfield(lua_State *L, int idx, const char *k)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
static void findloader(lua_State *L, const char *name)
static const char *const CLIBS
#define luaL_optstring(L, n, d)
static int lookforfunc(lua_State *L, const char *path, const char *sym)
#define luaL_checkstring(L, n)