#! /bin/sh /usr/share/dpatch/dpatch-run
## Makefile.dpatch by John V. Belmonte <jbelmonte@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Add support for Debian package to makefiles.
@DPATCH@
diff -urNad trunk~/doc/lua.1 trunk/doc/lua.1
--- trunk~/doc/lua.1 2006-09-14 10:44:04.000000000 +0200
+++ trunk/doc/lua.1 2006-09-14 10:44:05.000000000 +0200
@@ -152,6 +152,10 @@
.TP
.B \-v
show version information.
+.TP
+.B \-P
+suppress the creation of a standard LUA_PATH variable. Use this if
+you need to run scripts which conflict with system-installed libraries.
.SH "SEE ALSO"
.BR luac (1)
.br
@@ -163,5 +167,11 @@
L. H. de Figueiredo,
and
W. Celes
-(lua@tecgraf.puc-rio.br)
+.LP
+.BI <lua@tecgraf.puc-rio.br>
+.LP
+Debian modifications to the manpage by
+Daniel Silverstone
+.LP
+.BI <dsilvers@debian.org>
.\" EOF
diff -urNad trunk~/src/lua/lua.c trunk/src/lua/lua.c
--- trunk~/src/lua/lua.c 2006-09-14 10:44:04.000000000 +0200
+++ trunk/src/lua/lua.c 2006-09-14 10:44:38.000000000 +0200
@@ -65,7 +65,100 @@
static const char *progname = PROGNAME;
+/* These bits are added for Debian's -P functionality */
+
+static int done_path = 0;
+static int suppress_path = 0;
+
+static const char* paths[] = {
+ "~/.lua50",
+ "~/share/lua/50", // backward compatibility for the lua package
+ "~/share/lua50",
+ "/usr/share/lua/50",
+ "/usr/share/lua50", // backward compatibility for the lua package
+ "/usr/local/share/lua50",
+ NULL
+};
+
+static const char* cpaths[] = {
+ "~/.lua50",
+ "~/lib/lua/50",
+ "~/lib/lua50", // backward compatibility for the lua package
+ "/usr/lib/lua/50",
+ "/usr/lib/lua50", // backward compatibility for the lua package
+ "/usr/local/lib/lua50",
+ NULL
+};
+static void do_path()
+{
+ const char** p = paths;
+ int any;
+ if( done_path || suppress_path ) return;
+ if( ! L ) return;
+ done_path = 1;
+ lua_pushliteral(L,"LUA_PATH");
+ lua_pushliteral(L,"");
+ while( *p ) {
+ any = 0;
+ if( **p == '~' ) {
+ const char* home = getenv("HOME");
+ if( home ) {
+ lua_pushstring(L,home);
+ lua_pushstring(L,*p+1);
+ lua_pushliteral(L,"/?.lua;");
+ lua_pushstring(L,home);
+ lua_pushstring(L,*p+1);
+ lua_pushliteral(L,"/?;");
+ any = 6;
+ }
+ } else {
+ lua_pushstring(L,*p);
+ lua_pushliteral(L,"/?.lua;");
+ lua_pushstring(L,*p);
+ lua_pushliteral(L,"/?;");
+ any = 4;
+ }
+ if( any ) {
+ lua_concat(L,any+1);
+ }
+ p++;
+ }
+ lua_pushliteral(L, "?.lua;?");
+ lua_concat(L,2);
+ lua_settable(L, LUA_GLOBALSINDEX);
+ p=cpaths;
+ lua_pushliteral(L,"LUA_CPATH");
+ lua_pushliteral(L,"");
+ while( *p ) {
+ any = 0;
+ if( **p == '~' ) {
+ const char* home = getenv("HOME");
+ if( home ) {
+ lua_pushstring(L,home);
+ lua_pushstring(L,*p+1);
+ lua_pushliteral(L,"/?.so;");
+ lua_pushstring(L,home);
+ lua_pushstring(L,*p+1);
+ lua_pushliteral(L,"/?;");
+ any = 6;
+ }
+ } else {
+ lua_pushstring(L,*p);
+ lua_pushliteral(L,"/?.so;");
+ lua_pushstring(L,*p);
+ lua_pushliteral(L,"/?;");
+ any = 4;
+ }
+ if( any ) {
+ lua_concat(L,any+1);
+ }
+ p++;
+ }
+ lua_pushliteral(L, "?.so;?");
+ lua_concat(L,2);
+ lua_settable(L, LUA_GLOBALSINDEX);
+}
static const luaL_reg lualibs[] = {
{"base", luaopen_base},
@@ -85,13 +178,12 @@
static void lstop (lua_State *l, lua_Debug *ar) {
(void)ar; /* unused arg. */
lua_sethook(l, NULL, 0, 0);
- luaL_error(l, "interrupted!");
+ lua_pushnil(l);
+ lua_error(l);
}
static void laction (int i) {
- signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
- terminate process (default action) */
lua_sethook(L, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
}
@@ -105,6 +197,8 @@
" -i enter interactive mode after executing `script'\n"
" -l name load and run library `name'\n"
" -v show version information\n"
+ " -P suppress the setting of LUA_PATH. If not specified\n"
+ " very early, this setting may not take effect.\n"
" -- stop handling options\n" ,
progname);
}
@@ -120,23 +214,42 @@
const char *msg;
if (status) {
msg = lua_tostring(L, -1);
- if (msg == NULL) msg = "(error with no message)";
- l_message(progname, msg);
+ if (msg == NULL) {
+ const char *str;
+ lua_getglobal(L, "LUA_DEFAULT_ERROR"); /* try global variable */
+ str = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ if (str) {
+ if (*str != '\0') msg = str;
+ } else msg = "(error with no message)";
+ }
+ if (msg) l_message(progname, msg);
lua_pop(L, 1);
}
return status;
}
+static void sig_catch(int sig, void (*handler)(int))
+{
+ struct sigaction sa;
+ sa.sa_handler = handler;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(sig, &sa, 0); /* XXX ignores errors */
+}
+
static int lcall (int narg, int clear) {
int status;
int base = lua_gettop(L) - narg; /* function index */
+ do_path();
+ //lua_settop(L,base);
lua_pushliteral(L, "_TRACEBACK");
lua_rawget(L, LUA_GLOBALSINDEX); /* get traceback function */
lua_insert(L, base); /* put it under chunk and args */
- signal(SIGINT, laction);
+ sig_catch(SIGINT, laction);
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
- signal(SIGINT, SIG_DFL);
+ sig_catch(SIGINT, SIG_DFL);
lua_remove(L, base); /* remove traceback function */
return status;
}
@@ -179,6 +292,7 @@
static int load_file (const char *name) {
+ do_path();
lua_pushliteral(L, "require");
lua_rawget(L, LUA_GLOBALSINDEX);
if (!lua_isfunction(L, -1)) { /* no `require' defined? */
@@ -279,6 +393,7 @@
int status;
const char *oldprogname = progname;
progname = NULL;
+ do_path();
while ((status = load_string()) != -1) {
if (status == 0) status = lcall(0, 0);
report(status);
@@ -352,6 +467,12 @@
return 1; /* stop if file fails */
break;
}
+ case 'P': {
+ if( done_path )
+ l_message(progname, "option `-P' is too late, ignored");
+ suppress_path = 1;
+ break;
+ }
case 'c': {
l_message(progname, "option `-c' is deprecated");
break;
@@ -413,6 +534,7 @@
status = handle_luainit();
if (status == 0) {
status = handle_argv(s->argv, &interactive);
+ do_path();
if (status == 0 && interactive) manual_input();
}
s->status = status;