This page contains LuaPowerPatches for old versions of Lua.
Lua 5.0
Bitwise operators and hexadecimal support
This patch adds the following features to Lua 5.0:
- Hexadecimal support for 0xXXX in numeric literals.
- Hexadecimal support for '\xXX' characters within strings.
- Infix bitwise operators for AND (&), OR (|) and XOR (#).
- Unary bitwise negation using # alone.
NOTE: This patch adds opcodes to the Lua virtual machine. The two major consequences of this are that (1) the result cannot be called 'Lua', and (2) compiled code will not run on interpreters that do not include this patch.
After applying the patch, try running the following:
> hex=function(n) print("0x"..string.format("%X",n)) end
> hex(0x54&0x55)
0x54
> hex(0x54|0x66)
0x76
> hex(0x54#0x66)
0x32
> hex(#0x45)
0xFFFFFFBA
> print("Hel\x6c\x6f world\x21")
Hello world!
>
BUG-REPORT/NOTE: This patch uses the C function strtol(), which on most systems has a maximum input value of 0x7FFFFFFF, so the command hex(0x97F2DA31) will output 0x7FFFFFFF. [ This is easy enough to fix on machines that support 64-bit integers (i.e. long long) by using strtoll() (Posix) or __strtoi64() (Win32) ].
Improved Coroutines
This patch removes the restrictions on yielding coroutines from within metamethods or C functions to largest degree possible without introducing operating system-dependence or reliance on OS facilities such as threading libraries or C stack allocations. See ImprovedCoroutinesPatch.
- Backwards compatible: yes except for one modified error message
- Lines changed/added/deleted: ?
- Lua authors' position: ?
- Author: EricJacobs?
- Last update: 2004-Dec-04
- [download (for Lua 5.0.2)]
__usedindex metatable patch
__newindex
catches creation/assignment to new table indexes, but not to pre-existing ones. What if the old value had a back-reference to its parent? (__gc
is not enough.) What if the changed value should be mirrored in a C data structure?
__usedindex
will act the same as __newindex
, except that table[key]
will exist.
Example:
function used(t,k,v)
local o
o = rawget(t,k)
print("__usedindex",t,k,v,o)
rawset(t,k,v)
end
function new(t,k,v)
print("__newindex",t,k,v)
rawset(t,k,v)
end
- Backwards compatible: yes
- Lines changed/added/deleted: 6/16/0
- Lua authors' position: -
- Author: Christopher.Dunn@Motorola.com
- Last update: 2004-Feb-29
- [download (for Lua 5.0)]
Make superfluous 'do' and 'then' tokens optional
Lua requires 'then' following an if
statement, and 'do' following while
and for
statements. This patch makes them optional.
Lua 4.x
Unix/Win32 Makefiles
Changes the lua-4.1-work4 Makefiles so that it's easy to build the Lua libraries and executables under Win32 with MSVC, using GNU Make, by editing lua/config. Does not hurt Unix compatibility. The main difficulty is that Windows uses different file extensions and a few slightly different archiver/linker/compiler options. By using macros to stand for the file extensions, the config file can configure for either Unix or Win32, without having to edit the actual Makefiles.
- Lua version: lua-4.1-work4
- Backwards compatible: yes, this patch leaves all the existing Lua config defaults and should build under Unix the same as the standard distribution.
- Lines chagned/added/deleted: ?
- Lua authors' position: unknown
- Author: ThatcherUlrich
- Last update: 2002-Feb-18 (initial revision)
- Todo: More testing, and implement building of DLL's under Windows.
- [download]
Block Comments
Adds block comments to Lua: --[[...]]
. Uses the long string parser ([[...]]
) so block comments may be nested. Recommended usage:
--[[---------
Comment...
--]]---------
That has the nice property that a block comment may be disabled by inserting a single space just before the first [
(or by adding a single -
before --[[
).
- Backwards compatible: no, but unlikely to break existing programs.
- Lines changed/added/deleted: 4/10/0
- Lua authors' position: Considering this for Lua 4.1.
- Author: Edgar Toernig
- Last update: 2001-Dec-14
- [4.0 version] [4.1 version]
Lua autoconf patch
Autoconfiscates the Lua distribution (4.1work4).
- Backwards compatible: yes
- Lines changed/added/deleted: unknown
- Lua authors' position: - unlikely to be added to the distribution
- Author: unknown
- Last update: unknown
- [1]
Lua setconstant patch
Add a Lua function setconstant( table ), It will mark a table of strings or numbers as constant, so that the content of this table will never be garbage collected. Note that the table can be nested, and anything other than number and string will not be suited to this function.
yield()
Changes the Lua VM so that calls from Lua to Lua functions are "stackless"; i.e. no execution state is stored on the C stack. Adds a yield()
function to the Lua base library, which can be used to implement latent functions/cooperative multitasking. When a script calls yield()
, the function call to lua_dostring/lua_dofile/lua_dobuffer
from the host program returns with the code LUA_YIELD
. The script's execution state is preserved in the lua_State
structure, and a new API function, lua_resume(L)
, can be used to continue the script's execution at some later time.
As a side benefit, this patch makes Lua's tailcalls (ones that use the OP_TAILCALL
opcode) properly non-recursive.
- Backwards compatible: yes, provided there are no name collisions with "yield()".
- Lines changed/added/deleted: ~400
- Lua authors' position: An improved implementation is available in Lua 5.0.
- Author: Thatcher Ulrich
- Last update: 2002-Jan-16 (fixed some bugs -ThatcherUlrich)
- Todo: There are still some bugs surrounding error handling. For example, from an interactive lua session, if you
'dofile("program.lua")'
, and program.lua
does a yield()
, Lua can crash. If possible, I recommend using the supported implementation in 5.0 instead.
- [download]
(was "sleep patch"; "yield" was deemed a better name for this functionality, so I changed the name. -ThatcherUlrich)
Enhanced table constructors
The record part of table constructors (field=value
) is modified so that function statements are allowed and the comma is optional now. So this becomes valid:
x = {
function foo() end
function bar() end
c=1
d=2
}
and is the same as:
x = {
foo=function() end,
bar=function() end,
c=1,
d=2,
}
The comma is still required in front of [val]=val
records and in list initializers ({ expr, expr })
.
- Backwards compatible: yes
- Lines changed/added/deleted: 4/8/0
- Lua authors' position: Don't know
- Author: Edgar Toernig
- Last update: 2001-Dec-16
- [4.0 version]
Local functions
New syntactic sugar for the local-statement:
local foo(...) ... end
is the same as
local foo foo=function(...) ... end
Note that foo
is visible within the function. In Lua 4.0 that doesn't help a lot (in fact, an error is raised when %foo
is accessed).
- Backwards compatible: yes
- Lines changed/added/deleted: 2/6/0
- Lua authors' position: Don't know
- Author: Edgar Toernig
- Last update: 2001-Dec-16
- [4.0 version]
- I'm not used to Lua 4.1's code generator so that (more useful) version of this patch has to wait a little bit.
lua_getcclosure()
Adds missing function to the API that retrieves closure values of a C function.
(See lua-l message "pushcclosure / tocfunction issue" by John Belmonte, 2000-Oct-7.)
- Backwards compatible: yes
- Lines changed/added/deleted: 0/19/0
- Lua authors' position: Considering this for Lua 4.1. (See lua-l message "Re: pushcclosure / tocfunction issue" by Roberto Ierusalimschy, 2000-Oct-11.)
- Author: John Belmonte
- Last update: 2001-Feb-3
- [download]
Nested Function Names
Changes parser to allow definition function names to be nested in more than one level of tables. (See lua-l message "Re: Son of Lua - Sol" by John Belmonte, 2001-Feb-2.)
The syntax becomes: NAME {'.' NAME} [':' NAME]
- Backwards compatible: yes
- Lines changed/added/deleted: 2/0/0
- Lua authors' position: Will be included in Lua 4.1. (See lua-l message "Re: index tag method" by Roberto Ierusalimschy, 2001-Feb-19.)
- Author: John Belmonte
- Last update: 2001-Feb-3
- [download]
Weak References
Adds weak references to Lua. See http://www.lua.org/notes/ltn006.html.
- Backwards compatible: yes
- Lines changed/added/deleted: 0/77/0
- Lua authors' position: Will add weak tables to Lua 4.1. (See lua-l message "Re: Coroutine support in 4.1 / IPC mechanisms" by Luiz Henrique de Figueiredo, 2001-Apr-20.)
- Author: John Belmonte
- Last update: 2001-Feb-28
- [download]
List Iteration For Construct
Adds another form of the for
construct that iterates lists. Semantically equivalent to the standard library function foreachi
(See lua-l message "list iteration for statement" by John Belmonte, 2001-Apr-26.)
- Backwards compatible: yes
- Lines changed/added/deleted: 5/88/0
- Lua authors' position: -
- Author: John Belmonte
- Last update: 2001-Jun-9
- [download]
lua_dolines patch
Patch to Lua-4.0.1.
Add
lua_dolines(lua_State *L, char *fname, FILE *f, int *lineno)
to the Lua API which executes Lua code from an already
open file until '$' is encountered.
- Backwards compatible: yes
- Lines changed/added/deleted: 79
- Lua authors' position: will be obsoleted by lua_load in 5.0 (See lua-l message " Re: [ANNOUNCE] lua_dolines-1.1.patch" by Luiz Henrique de Figueiredo , 2002-Jul-29)
- Author: JuergenFuhrmann)
- Last update: 2002-Jul-29
- [Download][README]
lua_gc_long patch
Patch to Lua-4.0.1.
This patch changes the way scaled integers are compared to longs. It
actually is a bug fix, as otherwise, on typical 64 bit boxes,
lua_setgcthreshold(L,0) does not work.
- Backwards compatible: yes
- Lines changed/added/deleted: 2
- Lua authors' position: already known, fixed in 5.0b (See lua-l message "Re: gc confusion: now resolved" by Roberto Ierusalimschy , 2003-Feb-20)
- Author: JuergenFuhrmann)
- Last update: 2003-Feb-21
- [Download][README]
RecentChanges · preferences
edit · history
Last edited January 4, 2012 1:36 pm GMT (diff)