Worth noting that this was done as follows, to preserve the project-specific changes we've made:
wget http://www.lua.org/ftp/lua-5.1.2.tar.gz wget http://www.lua.org/ftp/lua-5.1.4.tar.gz tar -xzf lua-5.1.2.tar.gz tar -xzf lua-5.1.4.tar.gz cd lua-5.1.2 git init git add . git commit -sv -m "Lua 5.1.2" rsync –exclude .git ../lua-5.1.4/. . git commit -asv -m "Lua 5.1.4" git checkout -b patched-version HEAD~1 rsync –exclude .git ~/Development/crawl-ref/crawl-ref/source/util/lua/. . git commit -asv -m "patched" git rebase master
And voila, we've rebased our patches with the latest Lua!
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
O36OCWFVX3MACGAMLSBWNCC5S3LK5KEK4PCAXXXORZHBREG2TRQAC
for (; i <= last; i++) {
lua_rawgeti(L, 1, i);
luaL_argcheck(L, lua_isstring(L, -1), 1, "table contains non-strings");
luaL_addvalue(&b);
if (i != last)
luaL_addlstring(&b, sep, lsep);
for (; i < last; i++) {
addfield(L, &b, i);
luaL_addlstring(&b, sep, lsep);
** this function has a separated environment, which defines the
** correct __close for 'popen' files
** function to (not) close the standard files stdin, stdout, and stderr
*/
static int io_noclose (lua_State *L) {
lua_pushnil(L);
lua_pushliteral(L, "cannot close standard file");
return 2;
}
/*
** function to close 'popen' files
lua_setfield(L, -2, fname);
lua_pushvalue(L, -2); /* copy environment */
lua_setfenv(L, -2); /* set it */
lua_setfield(L, -3, fname);
}
static void newfenv (lua_State *L, lua_CFunction cls) {
lua_createtable(L, 0, 1);
lua_pushcfunction(L, cls);
lua_setfield(L, -2, "__close");
lua_assert(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);
lua_assert(!(pt->is_vararg & VARARG_NEEDSARG) ||
check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);
check(!(pt->is_vararg & VARARG_NEEDSARG) ||
/* cannot jump to a setlist count */
Instruction d = pt->code[dest-1];
check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));
int j;
/* check that it does not jump to a setlist count; this
is tricky, because the count from a previous setlist may
have the same value of an invalid setlist; so, we must
go all the way back to the first of them (if any) */
for (j = 0; j < dest; j++) {
Instruction d = pt->code[dest-1-j];
if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;
}
/* if 'j' is even, previous value is not a setlist (even if
it looks like one) */
check((j&1) == 0);
gethooktable(L1);
lua_pushlightuserdata(L1, L1);
lua_rawget(L1, -2); /* get hook */
lua_remove(L1, -2); /* remove hook table */
lua_xmove(L1, L, 1);
gethooktable(L);
lua_pushlightuserdata(L, L1);
lua_rawget(L, -2); /* get hook */
lua_remove(L, -2); /* remove hook table */
if (n <= 0) return 0; /* empty range */
luaL_checkstack(L, n, "table too big to unpack");
for (; i<=e; i++) /* push arg[i...e] */
if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
return luaL_error(L, "too many results to unpack");
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
while (i++ < e) /* push arg[i + 1...e] */
#define CO_RUN 0 /* running */
#define CO_SUS 1 /* suspended */
#define CO_NOR 2 /* 'normal' (it resumed another coroutine) */
#define CO_DEAD 3
static const char *const statnames[] =
{"running", "suspended", "normal", "dead"};
static int costatus (lua_State *L, lua_State *co) {
if (L == co) return CO_RUN;
switch (lua_status(co)) {
case LUA_YIELD:
return CO_SUS;
case 0: {
lua_Debug ar;
if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
return CO_NOR; /* it is running */
else if (lua_gettop(co) == 0)
return CO_DEAD;
else
return CO_SUS; /* initial state */
}
default: /* some error occured */
return CO_DEAD;
}
}
static int luaB_costatus (lua_State *L) {
lua_State *co = lua_tothread(L, 1);
luaL_argcheck(L, co, 1, "coroutine expected");
lua_pushstring(L, statnames[costatus(L, co)]);
return 1;
}
}
static int luaB_costatus (lua_State *L) {
lua_State *co = lua_tothread(L, 1);
luaL_argcheck(L, co, 1, "coroutine expected");
if (L == co) lua_pushliteral(L, "running");
else {
switch (lua_status(co)) {
case LUA_YIELD:
lua_pushliteral(L, "suspended");
break;
case 0: {
lua_Debug ar;
if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
lua_pushliteral(L, "normal"); /* it is running */
else if (lua_gettop(co) == 0)
lua_pushliteral(L, "dead");
else
lua_pushliteral(L, "suspended"); /* initial state */
break;
}
default: /* some error occured */
lua_pushliteral(L, "dead");
break;
}
}
return 1;
if (c == LUA_SIGNATURE[0] && lf.f != stdin) { /* binary file? */
fclose(lf.f);
lf.f = fopen(filename, "rb"); /* reopen in binary mode */
if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
$(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
# use this on Mac OS X 10.4
# $(MAKE) all MYCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" MYLIBS="-lreadline"
$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
# use this on Mac OS X 10.3-
# $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
rem script to build Lua under "Visual Studio .NET Command Prompt".
rem do not run it from this directory, run it from the toplevel: etc\luavs.bat
rem it creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.
@rem Script to build Lua under "Visual Studio .NET Command Prompt".
@rem Do not run from this directory; run it from the toplevel: etc\luavs.bat .
@rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.
@rem (contributed by David Manura and Mike Pall)
@setlocal
@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
@set MYLINK=link /nologo
@set MYMT=mt /nologo
link /DLL /out:lua51.dll l*.obj
cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DLUA_BUILD_AS_DLL lua.c
link /out:lua.exe lua.obj lua51.lib
cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE l*.c print.c
del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj loslib.obj ltablib.obj lstrlib.obj loadlib.obj
link /out:luac.exe *.obj
del *.obj
%MYLINK% /DLL /out:lua51.dll l*.obj
if exist lua51.dll.manifest^
%MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2
%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c
%MYLINK% /out:lua.exe lua.obj lua51.lib
if exist lua.exe.manifest^
%MYMT% -manifest lua.exe.manifest -outputresource:lua.exe
%MYCOMPILE% l*.c print.c
del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^
loslib.obj ltablib.obj lstrlib.obj loadlib.obj
%MYLINK% /out:luac.exe *.obj
if exist luac.exe.manifest^
%MYMT% -manifest luac.exe.manifest -outputresource:luac.exe
del *.obj *.manifest
<link rel="stylesheet" href="lua.css">
<link rel="stylesheet" href="manual.css">
<link rel="stylesheet" type="text/css" href="lua.css">
<link rel="stylesheet" type="text/css" href="manual.css">
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
To put a double (single) quote, a newline, a backslash,
or an embedded zero
inside a literal string enclosed by double (single) quotes
you must use an escape sequence.
Any other character may be directly inserted into the literal.
(Some control characters may cause problems for the file system,
but Lua has no problem with them.)
<p>
A chunk may be stored in a file or in a string inside the host program.
When a chunk is executed, first it is pre-compiled into instructions for
a virtual machine,
and then the compiled code is executed
by an interpreter for the virtual machine.
A chunk can be stored in a file or in a string inside the host program.
To execute a chunk,
Lua first pre-compiles the chunk into instructions for a virtual machine,
and then it executes the compiled code
with an interpreter for the virtual machine.
stat ::= varlist1 `<b>=</b>´ explist1
varlist1 ::= var {`<b>,</b>´ var}
explist1 ::= exp {`<b>,</b>´ exp}
stat ::= varlist `<b>=</b>´ explist
varlist ::= var {`<b>,</b>´ var}
explist ::= exp {`<b>,</b>´ exp}
Both function calls and vararg expressions may result in multiple values.
If the expression is used as a statement (see <a href="#2.4.6">§2.4.6</a>)
(only possible for function calls),
Both function calls and vararg expressions can result in multiple values.
If an expression is used as a statement
(only possible for function calls (see <a href="#2.4.6">§2.4.6</a>)),
Tables and userdata have individual metatables
(although multiple tables and userdata can share their metatables);
values of all other types share one single metatable per type.
So, there is one single metatable for all numbers,
and for all strings, etc.
Tables and full userdata have individual metatables
(although multiple tables and userdata can share their metatables).
Values of all other types share one single metatable per type;
that is, there is one single metatable for all numbers,
one for all strings, etc.
<p>
Threads are created sharing the environment of the creating thread.
Userdata and C functions are created sharing the environment
of the creating C function.
Non-nested Lua functions
(created by <a href="#pdf-loadfile"><code>loadfile</code></a>, <a href="#pdf-loadstring"><code>loadstring</code></a> or <a href="#pdf-load"><code>load</code></a>)
are created sharing the environment of the creating thread.
Nested Lua functions are created sharing the environment of
the creating Lua function.
They are used as the default environment for their threads and
non-nested functions created by the thread
(through <a href="#pdf-loadfile"><code>loadfile</code></a>, <a href="#pdf-loadstring"><code>loadstring</code></a> or <a href="#pdf-load"><code>load</code></a>)
They are used as the default environment for threads and
non-nested Lua functions created by the thread
(that is, these objects that are no longer accessible from Lua).
All objects in Lua are subject to automatic management:
tables, userdata, functions, threads, and strings.
(that is, objects that are no longer accessible from Lua).
All memory used by Lua is subject to automatic management:
tables, userdata, functions, threads, strings, etc.
Values smaller than 1 make the collector too slow and
may result in the collector never finishing a cycle.
The default, 2, means that the collector runs at "twice"
Values smaller than 100 make the collector too slow and
can result in the collector never finishing a cycle.
The default, 200, means that the collector runs at "twice"
The following functions run in protected mode
(that is, they create a protected environment to run),
so they never raise an error:
<a href="#lua_newstate"><code>lua_newstate</code></a>, <a href="#lua_close"><code>lua_close</code></a>, <a href="#lua_load"><code>lua_load</code></a>,
<a href="#lua_pcall"><code>lua_pcall</code></a>, and <a href="#lua_cpcall"><code>lua_cpcall</code></a>.
The documentation for each function indicates whether
it can throw errors.
<p>
The first field, <code>o</code>,
is how many elements the function pops from the stack.
The second field, <code>p</code>,
is how many elements the function pushes onto the stack.
(Any function always pushes its results after popping its arguments.)
A field in the form <code>x|y</code> means the function can push (or pop)
<code>x</code> or <code>y</code> elements,
depending on the situation;
an interrogation mark '<code>?</code>' means that
we cannot know how many elements the function pops/pushes
by looking only at its arguments
(e.g., they may depend on what is on the stack).
The third field, <code>x</code>,
tells whether the function may throw errors:
'<code>-</code>' means the function never throws any error;
'<code>m</code>' means the function may throw an error
only due to not enough memory;
'<code>e</code>' means the function may throw other kinds of errors;
'<code>v</code>' means the function may throw an error on purpose.
<hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3>
<hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p>
<span class="apii">[-0, +1, <em>m</em>]</span>
<pre>void lua_pushliteral (lua_State *L, const char *s);</pre>
<p>
This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>,
but can be used only when <code>s</code> is a literal string.
In these cases, it automatically provides the string length.
<hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3><p>
<span class="apii">[-0, +1, <em>m</em>]</span>
where <code>t</code> is the value at the given valid index <code>index</code>
and <code>v</code> is the value at the top of the stack,
where <code>t</code> is the value at the given valid index
and <code>v</code> is the value at the top of the stack.
where <code>t</code> is the value at the given valid index <code>index</code>
and <code>v</code> is the value at the top of the stack,
where <code>t</code> is the value at the given valid index
and <code>v</code> is the value at the top of the stack.
<hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3>
<pre>lua_Integer lua_tointeger (lua_State *L, int idx);</pre>
<hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p>
<span class="apii">[-0, +0, <em>-</em>]</span>
<pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre>
<hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3>
<pre>const char *luaL_typename (lua_State *L, int idx);</pre>
<hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p>
<span class="apii">[-0, +0, <em>-</em>]</span>
<pre>const char *luaL_typename (lua_State *L, int index);</pre>
<a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O and the Operating System libraries),
<a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O library),
<a name="pdf-luaopen_os"><code>luaopen_os</code></a> (for the Operating System library),
first <code>require</code> queries <code>package.preload[modname]</code>.
<code>require</code> is guided by the <a href="#pdf-package.loaders"><code>package.loaders</code></a> array.
By changing this array,
we can change how <code>require</code> looks for a module.
The following explanation is based on the default configuration
for <a href="#pdf-package.loaders"><code>package.loaders</code></a>.
<p>
First <code>require</code> queries <code>package.preload[modname]</code>.
When loading a C library,
<code>require</code> first uses a dynamic link facility to link the
application with the library.
Then it tries to find a C function inside this library to
be used as the loader.
The name of this C function is the string "<code>luaopen_</code>"
concatenated with a copy of the module name where each dot
is replaced by an underscore.
Moreover, if the module name has a hyphen,
its prefix up to (and including) the first hyphen is removed.
For instance, if the module name is <code>a.v1-b.c</code>,
the function name will be <code>luaopen_b_c</code>.
<p>
If <code>require</code> finds neither a Lua library nor a
C library for a module,
it calls the <em>all-in-one loader</em>.
This loader searches the C path for a library for
the root name of the given module.
For instance, when requiring <code>a.b.c</code>,
it will search for a C library for <code>a</code>.
If found, it looks into it for an open function for
the submodule;
in our example, that would be <code>luaopen_a_b_c</code>.
With this facility, a package can pack several C submodules
into one single library,
with each submodule keeping its original open function.
<p>
<p>
<hr><h3><a name="pdf-package.loaders"><code>package.loaders</code></a></h3>
<p>
A table used by <a href="#pdf-require"><code>require</code></a> to control how to load modules.
<p>
Each entry in this table is a <em>searcher function</em>.
When looking for a module,
<a href="#pdf-require"><code>require</code></a> calls each of these searchers in ascending order,
with the module name (the argument given to <a href="#pdf-require"><code>require</code></a>) as its
sole parameter.
The function can return another function (the module <em>loader</em>)
or a string explaining why it did not find that module
(or <b>nil</b> if it has nothing to say).
Lua initializes this table with four functions.
The second searcher looks for a loader as a Lua library,
using the path stored at <a href="#pdf-package.path"><code>package.path</code></a>.
A path is a sequence of <em>templates</em> separated by semicolons.
For each template,
the searcher will change each interrogation
mark in the template by <code>filename</code>,
which is the module name with each dot replaced by a
"directory separator" (such as "<code>/</code>" in Unix);
then it will try to open the resulting file name.
So, for instance, if the Lua path is the string
<pre>
"./?.lua;./?.lc;/usr/local/?/init.lua"
</pre><p>
the search for a Lua file for module <code>foo</code>
will try to open the files
<code>./foo.lua</code>, <code>./foo.lc</code>, and
<code>/usr/local/foo/init.lua</code>, in that order.
<p>
The third searcher looks for a loader as a C library,
using the path given by the variable <a href="#pdf-package.cpath"><code>package.cpath</code></a>.
For instance,
if the C path is the string
<pre>
"./?.so;./?.dll;/usr/local/?/init.so"
</pre><p>
the searcher for module <code>foo</code>
will try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,
and <code>/usr/local/foo/init.so</code>, in that order.
Once it finds a C library,
this searcher first uses a dynamic link facility to link the
application with the library.
Then it tries to find a C function inside the library to
be used as the loader.
The name of this C function is the string "<code>luaopen_</code>"
concatenated with a copy of the module name where each dot
is replaced by an underscore.
Moreover, if the module name has a hyphen,
its prefix up to (and including) the first hyphen is removed.
For instance, if the module name is <code>a.v1-b.c</code>,
the function name will be <code>luaopen_b_c</code>.
<p>
The fourth searcher tries an <em>all-in-one loader</em>.
It searches the C path for a library for
the root name of the given module.
For instance, when requiring <code>a.b.c</code>,
it will search for a C library for <code>a</code>.
If found, it looks into it for an open function for
the submodule;
in our example, that would be <code>luaopen_a_b_c</code>.
With this facility, a package can pack several C submodules
into one single library,
with each submodule keeping its original open function.
<p>
<p>
A path is a sequence of <em>templates</em> separated by semicolons.
For each template, <a href="#pdf-require"><code>require</code></a> will change each interrogation
mark in the template by <code>filename</code>,
which is <code>modname</code> with each dot replaced by a
"directory separator" (such as "<code>/</code>" in Unix);
then it will try to load the resulting file name.
So, for instance, if the Lua path is
<pre>
"./?.lua;./?.lc;/usr/local/?/init.lua"
</pre><p>
the search for a Lua loader for module <code>foo</code>
will try to load the files
<code>./foo.lua</code>, <code>./foo.lc</code>, and
<code>/usr/local/foo/init.lua</code>, in that order.
a pseudo-random integer in the range <em>[1, m]</em>.
When called with two numbers <code>m</code> and <code>n</code>,
<code>math.random</code> returns a pseudo-random
a uniform pseudo-random integer in the range <em>[1, m]</em>.
When called with two integer numbers <code>m</code> and <code>n</code>,
<code>math.random</code> returns a uniform pseudo-random
the current locate is set to an implementation-defined native locale.
If <code>locate</code> is the string "<code>C</code>",
the current locate is set to the standard C locale.
the current locale is set to an implementation-defined native locale.
If <code>locale</code> is the string "<code>C</code>",
the current locale is set to the standard C locale.
<p>
On some systems (POSIX),
this function also creates a file with that name,
to avoid security risks.
(Someone else might create the file with wrong permissions
in the time between getting the name and creating the file.)
You still have to open the file to use it
and to remove it (even if you do not use it).
<li><b><code>"c"</code>:</b> The hook is called every time Lua calls a function;</li>
<li><b><code>"r"</code>:</b> The hook is called every time Lua returns from a function;</li>
<li><b><code>"l"</code>:</b> The hook is called every time Lua enters a new line of code.</li>
<li><b><code>"c"</code>:</b> the hook is called every time Lua calls a function;</li>
<li><b><code>"r"</code>:</b> the hook is called every time Lua returns from a function;</li>
<li><b><code>"l"</code>:</b> the hook is called every time Lua enters a new line of code.</li>
(the outer pair of quotes is for the shell,
the inner pair is for Lua),
or in any Lua programs by assigning to <code>_PROMPT</code>.
Note the use of <code>-i</code> to enter interactive mode; otherwise,
the program would just end silently right after the assignment to <code>_PROMPT</code>.
(The outer pair of quotes is for the shell,
the inner pair is for Lua.)
Note the use of <code>-i</code> to enter interactive mode;
otherwise,
the program would just end silently
right after the assignment to <code>_PROMPT</code>.
# Where to install. The installation starts in the src directory, so take care
# if INSTALL_TOP is not an absolute path. (Man pages are installed from the
# doc directory.) You may want to make these paths consistent with LUA_ROOT,
# LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc).
#
# Where to install. The installation starts in the src and doc directories,
# so take care if INSTALL_TOP is not an absolute path.
# How to install. You may prefer "install" instead of "cp" if you have it.
# To remove debug information from binaries, use "install -s" in INSTALL_EXEC.
# How to install. If your install program does not support "-p", then you
# may have to run ranlib on the installed liblua.a (do "make ranlib").
INSTALL= install -p
INSTALL_EXEC= $(INSTALL) -m 0755
INSTALL_DATA= $(INSTALL) -m 0644