macro name change: LUA_PATH->LUA_PATH_VAR, LUA_CPATH->LUA_CPATH_VAR,

LUA_PATHSEP->LUA_PATH_SEP, LUA_EXECDIR->LUA_EXEC_DIR
This commit is contained in:
Roberto Ierusalimschy 2009-12-17 11:06:47 -02:00
parent 46f1429936
commit 2108754e46

View File

@ -1,5 +1,5 @@
/* /*
** $Id: loadlib.c,v 1.68 2009/11/24 12:05:44 roberto Exp roberto $ ** $Id: loadlib.c,v 1.69 2009/12/17 12:26:09 roberto Exp roberto $
** Dynamic library loader for Lua ** Dynamic library loader for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
** **
@ -23,35 +23,35 @@
/* /*
** LUA_PATH and LUA_CPATH are the names of the environment variables that ** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment
** Lua check to set its paths. ** variables that Lua check to set its paths.
*/ */
#if !defined(LUA_PATH) #if !defined(LUA_PATH_VAR)
#define LUA_PATH "LUA_PATH" #define LUA_PATH_VAR "LUA_PATH"
#endif #endif
#if !defined(LUA_CPATH) #if !defined(LUA_CPATH_VAR)
#define LUA_CPATH "LUA_CPATH" #define LUA_CPATH_VAR "LUA_CPATH"
#endif #endif
/* /*
** LUA_PATHSEP is the character that separates templates in a path. ** LUA_PATH_SEP is the character that separates templates in a path.
** LUA_PATH_MARK is the string that marks the substitution points in a ** LUA_PATH_MARK is the string that marks the substitution points in a
** template. ** template.
** LUA_EXECDIR in a Windows path is replaced by the executable's ** LUA_EXEC_DIR in a Windows path is replaced by the executable's
** directory. ** directory.
** LUA_IGMARK is a mark to ignore all before it when building the ** LUA_IGMARK is a mark to ignore all before it when building the
** luaopen_ function name. ** luaopen_ function name.
*/ */
#if !defined (LUA_PATHSEP) #if !defined (LUA_PATH_SEP)
#define LUA_PATHSEP ";" #define LUA_PATH_SEP ";"
#endif #endif
#if !defined (LUA_PATH_MARK) #if !defined (LUA_PATH_MARK)
#define LUA_PATH_MARK "?" #define LUA_PATH_MARK "?"
#endif #endif
#if !defined (LUA_EXECDIR) #if !defined (LUA_EXEC_DIR)
#define LUA_EXECDIR "!" #define LUA_EXEC_DIR "!"
#endif #endif
#if !defined (LUA_IGMARK) #if !defined (LUA_IGMARK)
#define LUA_IGMARK "-" #define LUA_IGMARK "-"
@ -138,7 +138,7 @@ static void setprogdir (lua_State *L) {
luaL_error(L, "unable to get ModuleFileName"); luaL_error(L, "unable to get ModuleFileName");
else { else {
*lb = '\0'; *lb = '\0';
luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff); luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);
lua_remove(L, -2); /* remove original string */ lua_remove(L, -2); /* remove original string */
} }
} }
@ -381,9 +381,9 @@ static int readable (const char *filename) {
static const char *pushnexttemplate (lua_State *L, const char *path) { static const char *pushnexttemplate (lua_State *L, const char *path) {
const char *l; const char *l;
while (*path == *LUA_PATHSEP) path++; /* skip separators */ while (*path == *LUA_PATH_SEP) path++; /* skip separators */
if (*path == '\0') return NULL; /* no more templates */ if (*path == '\0') return NULL; /* no more templates */
l = strchr(path, *LUA_PATHSEP); /* find next separator */ l = strchr(path, *LUA_PATH_SEP); /* find next separator */
if (l == NULL) l = path + strlen(path); if (l == NULL) l = path + strlen(path);
lua_pushlstring(L, path, l - path); /* template */ lua_pushlstring(L, path, l - path); /* template */
return l; return l;
@ -655,8 +655,8 @@ static void setpath (lua_State *L, const char *fieldname, const char *envname,
lua_pushstring(L, def); /* use default */ lua_pushstring(L, def); /* use default */
else { else {
/* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
LUA_PATHSEP AUXMARK LUA_PATHSEP); LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
luaL_gsub(L, path, AUXMARK, def); luaL_gsub(L, path, AUXMARK, def);
lua_remove(L, -2); lua_remove(L, -2);
} }
@ -701,11 +701,11 @@ LUAMOD_API int luaopen_package (lua_State *L) {
lua_rawseti(L, -2, i+1); lua_rawseti(L, -2, i+1);
} }
lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */
setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT); /* set field `path' */
setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT); /* set field `cpath' */
/* store config information */ /* store config information */
lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
LUA_EXECDIR "\n" LUA_IGMARK "\n"); LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
lua_setfield(L, -2, "config"); lua_setfield(L, -2, "config");
/* set field `loaded' */ /* set field `loaded' */
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);