--- lua-5.0.2.orig/doc/lua.1 +++ lua-5.0.2/doc/lua.1 @@ -152,6 +152,16 @@ .TP .B \-v show version information. +.TP +.B \-C +load the compatibility library into the interpreter. If you specify +this, then you will also need to specify the +.B \-i +option in order to enter an interactive interpreter. +.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 +173,11 @@ L. H. de Figueiredo, and W. Celes -(lua@tecgraf.puc-rio.br) +.LP +.BI +.LP +Debian modifications to the manpage by +Daniel Silverstone +.LP +.BI .\" EOF --- lua-5.0.2.orig/src/luac/Makefile +++ lua-5.0.2/src/luac/Makefile @@ -12,8 +12,8 @@ all: $T -$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a - $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) +$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a + $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) # print.c needs opcode names from lopcodes.c lopcodes.o: ../lopcodes.c ../lopcodes.h --- lua-5.0.2.orig/src/lib/Makefile +++ lua-5.0.2/src/lib/Makefile @@ -9,16 +9,18 @@ OBJS= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o ltablib.o lstrlib.o loadlib.o SRCS= lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c ltablib.c lstrlib.c loadlib.c -T= $(LIB)/liblualib.a +SOBJS := $(patsubst %.o,%.os,$(OBJS)) + +T= $(LIB)/liblualib.a all: $T -$T: $(OBJS) +$T: $(OBJS) $(SOBJS) $(AR) $@ $(OBJS) $(RANLIB) $@ clean: - rm -f $(OBJS) $T + rm -f $(OBJS) $(SOBJS) $T co: co -q -f -M $(SRCS) --- lua-5.0.2.orig/src/lib/liolib.c +++ lua-5.0.2/src/lib/liolib.c @@ -149,7 +149,14 @@ if (f == stdin || f == stdout || f == stderr) return 0; /* file cannot be closed */ else { - int ok = (pclose(f) != -1) || (fclose(f) == 0); + int ok; + errno = 0; + ok = (pclose(f) != -1); + if (!ok) { + if (errno == ECHILD) ok = 1; /* pclose worked, but could reap child */ + else ok = (fclose(f) == 0); + } + if (ok) *(FILE **)lua_touserdata(L, 1) = NULL; /* mark file as closed */ return ok; --- lua-5.0.2.orig/src/lua/Makefile +++ lua-5.0.2/src/lua/Makefile @@ -12,8 +12,8 @@ all: $T -$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a - $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) +$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a + $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB) $(LIB)/liblua.a: cd ..; $(MAKE) --- lua-5.0.2.orig/src/lua/lua.c +++ lua-5.0.2/src/lua/lua.c @@ -65,7 +65,57 @@ 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[] = { + "~/.lua", + "~/share/lua", + "/usr/share/lua", + "/usr/local/share/lua", + 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); +} static const luaL_reg lualibs[] = { {"base", luaopen_base}, @@ -85,13 +135,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 +154,9 @@ " -i enter interactive mode after executing `script'\n" " -l name load and run library `name'\n" " -v show version information\n" + " -C load the compatibility library before startup\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 +172,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 +250,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 +351,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 +425,18 @@ return 1; /* stop if file fails */ break; } + case 'C': { + const char *filename = "compat.lua"; + if (load_file(filename)) + 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 +498,7 @@ status = handle_luainit(); if (status == 0) { status = handle_argv(s->argv, &interactive); + do_path(); if (status == 0 && interactive) manual_input(); } s->status = status; --- lua-5.0.2.orig/src/Makefile +++ lua-5.0.2/src/Makefile @@ -67,16 +67,19 @@ lvm.h \ lzio.h -T= $(LIB)/liblua.a +T= $(LIB)/liblua.a + +SOBJS := $(patsubst %.o,%.os,$(OBJS)) all: $T -$T: $(OBJS) +$T: $(OBJS) $(SOBJS) $(AR) $@ $(OBJS) $(RANLIB) $@ + clean: - rm -f $(OBJS) $T + rm -f $(OBJS) $(SOBJS) $T co: co -q -f -M $(SRCS) --- lua-5.0.2.orig/lua-config +++ lua-5.0.2/lua-config @@ -0,0 +1,165 @@ +#!/usr/bin/lua +-- -*- Lua -*- + +-- This file is under the terms of the MIT licence. Do as you will. + +-- Process the arg table +function usage() + info(); + io.stderr:write([[Usage: lua-config + + Valid options are: + + --include Outputs the -I switches needed to find etc. + + --static Outputs the full path to the static libraries + + --libs Outputs the -L and -l switches needed to find the library + --libs-only-L Outputs only the -L switches + --libs-only-l Outputs only the -l switches + + --extralibs Outputs the -l switches appropriate to the extra libs needed by lua + + Note that --static is mututally exclusive with the --libs* options + + Also, you can specify the following + + --vmonly Outputs only the switches for finding the VM libraries + --libonly Outputs only the switches for finding the standard libraries + --both Outputs the switches for both [The default] + + Example: + + gcc `lua-config --include` my_prog.c -o my_prog `lua-config --libs` + +]] ); + os.exit(1); +end + +function version() + io.stdout:write( [[5.0.0 +]] ); + os.exit(0); +end + +function info() + io.stdout:write( [[lua-config version 1.10 (c) Daniel Silverstone 2002 + +lua-config was written for the Debian GNU/Linux project. This version +of lua-config will provide switches appropriate to Lua 5.0 + +]] ); +end + +if( table.getn(arg) == 0 ) then + usage() +end + +output_vm = 1 +output_lib = 1 + +output_static = 0 +output_libs_l = 0 +output_libs_L = 0 +output_include = 0 +output_extras = 0 + +table.foreachi( arg, + function(n,param) + if( param == '--version' ) then + version() + end + if( param == '--help' ) then + usage() + end + if( param == '--include' ) then + output_include = 1; + return + end + if( param == '--libs' ) then + output_libs_l = 1; + output_libs_L = 1; + return + end + if( param == '--libs-only-L' ) then + output_libs_L = 1; + return + end + if( param == '--libs-only-l' ) then + output_libs_l = 1; + return + end + if( param == '--extralibs' ) then + output_extras = 1; + return + end + if( param == '--static' ) then + output_static = 1; + return + end + if( param == '--vmonly' ) then + output_vm = 1; + output_lib = 0; + return + end + if( param == '--libonly' ) then + output_lib = 1; + output_vm = 0; + return + end + if( param == '--both' ) then + output_lib = 1; + output_vm = 1; + return + end + io.stderr:write( "Unknown argument ", param ); + usage(); + end ); + +if( (output_extras + output_libs_l + output_libs_L + output_include + output_static) == 0 ) then + usage() +end + +if( (output_static + (output_libs_l or output_libs_L)) > 1 ) then + usage(); +end + +outargs = {} + +if( output_include == 1 ) then + table.insert( outargs, "-I/usr/include/lua" ); +end + +if( output_libs_L == 1 ) then + table.insert( outargs, "-L/usr/include" ); +end + +if( output_libs_l == 1 ) then + if( output_lib == 1 ) then + table.insert( outargs, "-llualib" ); + end + if( output_vm == 1 ) then + table.insert( outargs, "-llua" ); + end +end + +if( output_static == 1 ) then + if( output_lib == 1 ) then + table.insert( outargs, "/usr/lib/liblualib.a" ); + end + if( output_vm == 1 ) then + table.insert( outargs, "/usr/lib/liblua.a" ); + end +end + +if( output_extras == 1 ) then + table.insert( outargs, "-lm" ); +end + +io.stdout:write( outargs[1] ); + +for i=2,table.getn(outargs) do + io.stdout:write( " ", outargs[i] ); +end + +io.stdout:write( "\n" ); --- lua-5.0.2.orig/config +++ lua-5.0.2/config @@ -25,15 +25,15 @@ # interface (e.g., Linux, Solaris, IRIX, BSD, AIX, HPUX, and probably others), # uncomment the next two lines. # -#LOADLIB= -DUSE_DLOPEN=1 -#DLLIB= -ldl +LOADLIB= -DUSE_DLOPEN=1 +DLLIB= -ldl # # In Linux with gcc, you should also uncomment the next definition for # MYLDFLAGS, which passes -E (= -export-dynamic) to the linker. This option # allows dynamic libraries to link back to the `lua' program, so that they do # not need the Lua libraries. (Other systems may have an equivalent facility.) # -#MYLDFLAGS= -Wl,-E +MYLDFLAGS= -Wl,-E # # On Windows systems. support for dynamic loading is enabled by default. # To disable this support, uncomment the next line. @@ -92,7 +92,7 @@ # or if you are using a modified interpreter that does not need them, # then comment the following line or add the appropriates libraries. # -EXTRA_LIBS= -lm +#EXTRA_LIBS= -lm # If you want to customize the stand-alone Lua interpreter, uncomment and # edit the following two lines; also edit etc/saconfig.c to suit your needs. @@ -100,8 +100,8 @@ # to add -lreadline (and perhaps also -lhistory and -lcurses or -lncurses) # to EXTRA_LIBS. # -#USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/saconfig.c"' -DUSE_READLINE -#EXTRA_LIBS= -lm -ldl -lreadline # -lhistory -lcurses -lncurses +USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/saconfig.c"' -DUSE_READLINE +EXTRA_LIBS= -lreadline -lm -ldl # -lhistory -lcurses -lncurses # ------------------------------------------------------------------ C compiler @@ -119,7 +119,7 @@ # debug information. If you only want the shared libraries, you may want to # add -fPIC to MYCFLAGS. # -MYCFLAGS= -O2 +MYCFLAGS= -O3 -g #MYCFLAGS= -O3 -fomit-frame-pointer # -fPIC # Write here any options you may need for your C linker. @@ -148,19 +148,20 @@ # Locations for "make install". You may need to be root do "make install". # -INSTALL_ROOT= /usr/local +INSTALL_ROOT= $(PREFIX)/usr/ INSTALL_BIN= $(INSTALL_ROOT)/bin -INSTALL_INC= $(INSTALL_ROOT)/include +INSTALL_INC= $(INSTALL_ROOT)/include/lua INSTALL_LIB= $(INSTALL_ROOT)/lib -INSTALL_MAN= $(INSTALL_ROOT)/man/man1 +INSTALL_MAN= $(INSTALL_ROOT)/share/man/man1 +INSTALL_SHARE= $(INSTALL_ROOT)/share/lua # You may prefer to use "install" instead of "cp" if you have it. # If you use "install", you may also want to change the permissions after -m. # -INSTALL_EXEC= cp -INSTALL_DATA= cp -#INSTALL_EXEC= install -m 0755 -#INSTALL_DATA= install -m 0644 +#INSTALL_EXEC= cp +#INSTALL_DATA= cp +INSTALL_EXEC= install -m 0755 +INSTALL_DATA= install -m 0644 # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= @@ -173,6 +174,10 @@ INCS= -I$(INC) $(EXTRA_INCS) DEFS= $(NUMBER) $(EXTRA_DEFS) -CFLAGS= $(MYCFLAGS) $(WARN) $(INCS) $(DEFS) +CFLAGS= $(MYCFLAGS) $(WARN) $(INCS) $(DEFS) -DINSTALL_SHARE=\"$(INSTALL_SHARE)\" + +# Extra rule for .os files +%.os: %.c + $(CC) $(CFLAGS) -fPIC -DPIC -o $@ -c $< # (end of config) --- lua-5.0.2.orig/Makefile +++ lua-5.0.2/Makefile @@ -38,9 +38,13 @@ # shared libraries (for Linux) so: - ld -o lib/liblua.so.$V -shared src/*.o - ld -o lib/liblualib.so.$V -shared src/lib/*.o - cd lib; ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so + gcc -o lib/liblua.so.$V -shared -Wl,-soname,liblua.so.$V \ + src/*.os -lc + ln -fs liblua.so.$V lib/liblua-build.so + gcc -o lib/liblualib.so.$V -shared -Wl,-soname,liblualib.so.$V \ + src/lib/*.os -Llib -llua-build -lm -ldl -lc + cd lib; ln -fs liblua.so.$V liblua.so; \ + ln -fs liblualib.so.$V liblualib.so # binaries using shared libraries sobin: --- lua-5.0.2.orig/lua.pc +++ lua-5.0.2/lua.pc @@ -0,0 +1,11 @@ +prefix=/usr +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/ + +Name: lua +Description: The Lua 5.0 programming language +Version: 5.0.0 +Libs: -L${libdir} -llua +Cflags: -I${includedir}/lua + --- lua-5.0.2.orig/lualib.pc +++ lua-5.0.2/lualib.pc @@ -0,0 +1,12 @@ +prefix=/usr +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/ + +Name: lua +Description: The Lua 5.0 programming language addon libraries +Version: 5.0.0 +Requires: lua +Libs: -L${libdir} -llualib +Cflags: -I${includedir}/lua + --- lua-5.0.2.orig/lua-config.1 +++ lua-5.0.2/lua-config.1 @@ -0,0 +1,64 @@ +.\" Manual page for lua-config +.\" Written by Daniel Silverstone +.\" For the Debian GNU/Linux system + +.TH lua-config 1 +.SH NAME +lua-config \- Lua configuration information +.SH SYNOPSIS +Basic usage +.PP +.B gcc +` +.B lua-config +.I \-\-include +` +my_prog.c +.B \-o +my_prog +` +.B lua-config +.I \-\-libs +` + +.SH DESCRIPTION +The lua-config script allows you to determine useful information +about the chosen version of lua running on the Debian GNU/Linux +system in use. +More information can be found by running +.B lua-config +without any arguments. +.SH CAVEATS +This script is unique to Debian and as such you shouldn't rely +on its presence on every system. Lua is an embedded language +by default and different Linux distributions each take a different +approach to making it possible to compile with Lua. The +.B pkg-config +system also provides a way to look for libraries and is more likely +to be supported across different Linux distributions. Debian's +.B pkg-config +name for Lua 5.0 is +.I lua +and the libraries are in +.I lualib. +These +.B pkg-config +files can be found in the +.I liblua-dev +and +.I liblualib-dev +packages. +.SH AUTHOR +lua-config was written by +.B Daniel Silverstone +.BI . + +This manual page was written by +.B Daniel Silverstone +.BI . +For the Debian project. It may be used without restriction in any +other system. +.SH "SEE ALSO" +.IR lua (1) +.IR pkg-config (1) +