Skip to content

Commit 9e90ee2

Browse files
committedJan 13, 2017
update to 5.3.4 rc3
1 parent 8bc018f commit 9e90ee2

File tree

3 files changed

+101
-94
lines changed

3 files changed

+101
-94
lines changed
 

Diff for: ‎3rd/lua/loadlib.c

+92-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: loadlib.c,v 1.129 2016/12/04 20:17:24 roberto Exp $
2+
** $Id: loadlib.c,v 1.130 2017/01/12 17:14:26 roberto Exp $
33
** Dynamic library loader for Lua
44
** See Copyright Notice in lua.h
55
**
@@ -64,6 +64,9 @@ static const int CLIBS = 0;
6464
#define LIB_FAIL "open"
6565

6666

67+
#define setprogdir(L) ((void)0)
68+
69+
6770
/*
6871
** system-dependent functions
6972
*/
@@ -155,6 +158,30 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {
155158
#endif
156159

157160

161+
#undef setprogdir
162+
163+
164+
/*
165+
** Replace in the path (on the top of the stack) any occurrence
166+
** of LUA_EXEC_DIR with the executable's path.
167+
*/
168+
static void setprogdir (lua_State *L) {
169+
char buff[MAX_PATH + 1];
170+
char *lb;
171+
DWORD nsize = sizeof(buff)/sizeof(char);
172+
DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */
173+
if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
174+
luaL_error(L, "unable to get ModuleFileName");
175+
else {
176+
*lb = '\0'; /* cut name on the last '\\' to get the path */
177+
luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);
178+
lua_remove(L, -2); /* remove original string */
179+
}
180+
}
181+
182+
183+
184+
158185
static void pusherror (lua_State *L) {
159186
int error = GetLastError();
160187
char buffer[128];
@@ -223,6 +250,67 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {
223250
#endif /* } */
224251

225252

253+
/*
254+
** {==================================================================
255+
** Set Paths
256+
** ===================================================================
257+
*/
258+
259+
/*
260+
** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment
261+
** variables that Lua check to set its paths.
262+
*/
263+
#if !defined(LUA_PATH_VAR)
264+
#define LUA_PATH_VAR "LUA_PATH"
265+
#endif
266+
267+
#if !defined(LUA_CPATH_VAR)
268+
#define LUA_CPATH_VAR "LUA_CPATH"
269+
#endif
270+
271+
272+
#define AUXMARK "\1" /* auxiliary mark */
273+
274+
275+
/*
276+
** return registry.LUA_NOENV as a boolean
277+
*/
278+
static int noenv (lua_State *L) {
279+
int b;
280+
lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
281+
b = lua_toboolean(L, -1);
282+
lua_pop(L, 1); /* remove value */
283+
return b;
284+
}
285+
286+
287+
/*
288+
** Set a path
289+
*/
290+
static void setpath (lua_State *L, const char *fieldname,
291+
const char *envname,
292+
const char *dft) {
293+
const char *nver = lua_pushfstring(L, "%s%s", envname, LUA_VERSUFFIX);
294+
const char *path = getenv(nver); /* use versioned name */
295+
if (path == NULL) /* no environment variable? */
296+
path = getenv(envname); /* try unversioned name */
297+
if (path == NULL || noenv(L)) /* no environment variable? */
298+
lua_pushstring(L, dft); /* use default */
299+
else {
300+
/* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
301+
path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
302+
LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
303+
luaL_gsub(L, path, AUXMARK, dft);
304+
lua_remove(L, -2); /* remove result from 1st 'gsub' */
305+
}
306+
setprogdir(L);
307+
lua_setfield(L, -3, fieldname); /* package[fieldname] = path value */
308+
lua_pop(L, 1); /* pop versioned variable name */
309+
}
310+
311+
/* }================================================================== */
312+
313+
226314
/*
227315
** return registry.CLIBS[path]
228316
*/
@@ -680,10 +768,9 @@ LUAMOD_API int luaopen_package (lua_State *L) {
680768
createclibstable(L);
681769
luaL_newlib(L, pk_funcs); /* create 'package' table */
682770
createsearcherstable(L);
683-
lua_pushstring(L, LUA_PATH_DEFAULT);
684-
lua_setfield(L, -2, "path"); /* package.path = default path */
685-
lua_pushstring(L, LUA_CPATH_DEFAULT);
686-
lua_setfield(L, -2, "cpath"); /* package.cpath = default cpath */
771+
/* set paths */
772+
setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT);
773+
setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);
687774
/* store config information */
688775
lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
689776
LUA_EXEC_DIR "\n" LUA_IGMARK "\n");

Diff for: ‎3rd/lua/lua.c

+5-88
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lua.c,v 1.229 2016/12/22 13:08:50 roberto Exp $
2+
** $Id: lua.c,v 1.230 2017/01/12 17:14:26 roberto Exp $
33
** Lua stand-alone interpreter
44
** See Copyright Notice in lua.h
55
*/
@@ -21,8 +21,6 @@
2121
#include "lstring.h"
2222

2323

24-
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
25-
2624

2725
#if !defined(LUA_PROMPT)
2826
#define LUA_PROMPT "> "
@@ -535,88 +533,6 @@ static int runargs (lua_State *L, char **argv, int n) {
535533

536534

537535

538-
/*
539-
** {==================================================================
540-
** Set Paths
541-
** ===================================================================
542-
*/
543-
544-
/*
545-
** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment
546-
** variables that Lua check to set its paths.
547-
*/
548-
#if !defined(LUA_PATH_VAR)
549-
#define LUA_PATH_VAR "LUA_PATH"
550-
#endif
551-
552-
#if !defined(LUA_CPATH_VAR)
553-
#define LUA_CPATH_VAR "LUA_CPATH"
554-
#endif
555-
556-
#define LUA_PATHVARVERSION LUA_PATH_VAR LUA_VERSUFFIX
557-
#define LUA_CPATHVARVERSION LUA_CPATH_VAR LUA_VERSUFFIX
558-
559-
560-
#define AUXMARK "\1" /* auxiliary mark */
561-
562-
563-
#if defined(LUA_USE_WINDOWS)
564-
565-
566-
/*
567-
** Replace in the path (on the top of the stack) any occurrence
568-
** of LUA_EXEC_DIR with the executable's path.
569-
*/
570-
static void setprogdir (lua_State *L) {
571-
char buff[MAX_PATH + 1];
572-
char *lb;
573-
DWORD nsize = sizeof(buff)/sizeof(char);
574-
DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */
575-
if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
576-
luaL_error(L, "unable to get ModuleFileName");
577-
else {
578-
*lb = '\0'; /* cut name on the last '\\' to get the path */
579-
luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff);
580-
lua_remove(L, -2); /* remove original string */
581-
}
582-
}
583-
584-
#else
585-
586-
#define setprogdir(L) ((void)0)
587-
588-
#endif
589-
590-
/*
591-
** Change a path according to corresponding environment variables
592-
*/
593-
static void chgpath (lua_State *L, const char *fieldname,
594-
const char *envname1,
595-
const char *envname2,
596-
int noenv) {
597-
const char *path = getenv(envname1);
598-
lua_getglobal(L, LUA_LOADLIBNAME); /* get 'package' table */
599-
lua_getfield(L, -1, fieldname); /* get original path */
600-
if (path == NULL) /* no environment variable? */
601-
path = getenv(envname2); /* try alternative name */
602-
if (path == NULL || noenv) /* no environment variable? */
603-
lua_pushvalue(L, -1); /* use original value */
604-
else {
605-
const char *def = lua_tostring(L, -1); /* default path */
606-
/* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
607-
path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
608-
LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
609-
luaL_gsub(L, path, AUXMARK, def);
610-
lua_remove(L, -2); /* remove result from 1st 'gsub' */
611-
}
612-
setprogdir(L);
613-
lua_setfield(L, -3, fieldname); /* set path value */
614-
lua_pop(L, 2); /* pop 'package' table and original path */
615-
}
616-
617-
/* }================================================================== */
618-
619-
620536
static int handle_luainit (lua_State *L) {
621537
const char *name = "=" LUA_INITVARVERSION;
622538
const char *init = getenv(name + 1);
@@ -649,10 +565,11 @@ static int pmain (lua_State *L) {
649565
}
650566
if (args & has_v) /* option '-v'? */
651567
print_version();
568+
if (args & has_E) { /* option '-E'? */
569+
lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
570+
lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
571+
}
652572
luaL_openlibs(L); /* open standard libraries */
653-
/* change paths according to env variables */
654-
chgpath(L, "path", LUA_PATHVARVERSION, LUA_PATH_VAR, (args & has_E));
655-
chgpath(L, "cpath", LUA_CPATHVARVERSION, LUA_CPATH_VAR, (args & has_E));
656573
createargtable(L, argv, argc, script); /* create table 'arg' */
657574
if (!(args & has_E)) { /* no option '-E'? */
658575
if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */

Diff for: ‎3rd/lua/lualib.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $
2+
** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $
33
** Lua standard libraries
44
** See Copyright Notice in lua.h
55
*/
@@ -11,6 +11,9 @@
1111
#include "lua.h"
1212

1313

14+
/* version suffix for environment variable names */
15+
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
16+
1417

1518
LUAMOD_API int (luaopen_base) (lua_State *L);
1619

0 commit comments

Comments
 (0)