Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: fanf2/lua-5
...
head fork: fanf2/lua-5
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 56 files changed
  • 0 commit comments
  • 1 contributor
Showing with 3,041 additions and 2,017 deletions.
  1. +1 −1  README
  2. +17 −11 doc/contents.html
  3. +21 −1 doc/lua.css
  4. +896 −623 doc/manual.html
  5. +21 −15 doc/readme.html
  6. +26 −21 src/Makefile
  7. +88 −74 src/lapi.c
  8. +76 −13 src/lauxlib.c
  9. +8 −2 src/lauxlib.h
  10. +79 −115 src/lbaselib.c
  11. +67 −21 src/lbitlib.c
  12. +42 −38 src/lcode.c
  13. +3 −4 src/lcode.h
  14. +24 −20 src/lctype.c
  15. +51 −6 src/lctype.h
  16. +8 −19 src/ldblib.c
  17. +74 −36 src/ldebug.c
  18. +4 −1 src/ldebug.h
  19. +64 −66 src/ldo.c
  20. +3 −3 src/ldump.c
  21. +79 −58 src/lgc.c
  22. +8 −9 src/lgc.h
  23. +5 −5 src/linit.c
  24. +151 −185 src/liolib.c
  25. +56 −41 src/llex.c
  26. +8 −8 src/llex.h
  27. +21 −12 src/llimits.h
  28. +5 −6 src/lmathlib.c
  29. +5 −9 src/lmem.c
  30. +71 −61 src/loadlib.c
  31. +85 −38 src/lobject.c
  32. +241 −87 src/lobject.h
  33. +5 −5 src/lopcodes.c
  34. +6 −7 src/lopcodes.h
  35. +12 −21 src/loslib.c
  36. +326 −145 src/lparser.c
  37. +34 −11 src/lparser.h
  38. +12 −8 src/lstate.c
  39. +11 −7 src/lstate.h
  40. +4 −3 src/lstring.c
  41. +38 −21 src/lstrlib.c
  42. +10 −8 src/ltable.c
  43. +16 −22 src/ltablib.c
  44. +4 −4 src/ltm.c
  45. +2 −2 src/ltm.h
  46. +10 −11 src/lua.c
  47. +5 −5 src/lua.h
  48. +19 −14 src/luac.c
  49. +61 −6 src/luaconf.h
  50. +2 −2 src/lualib.h
  51. +31 −24 src/lundump.c
  52. +7 −4 src/lundump.h
  53. +97 −53 src/lvm.c
  54. +7 −4 src/lvm.h
  55. +12 −18 src/lzio.c
  56. +2 −3 src/lzio.h
View
2  README
@@ -1,5 +1,5 @@
-This is Lua 5.2 (alpha), released on 23 Nov 2010.
+This is Lua 5.2 (beta), released on 05 Jul 2011.
For installation instructions, license details, and
further information about Lua, see doc/readme.html.
View
28 doc/contents.html
@@ -22,7 +22,7 @@
<P>
<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
-<EM>This is an alpha version of Lua 5.2.
+<EM>This is a beta version of Lua 5.2.
Some details may change in the final version.</EM>
<P>
@@ -38,9 +38,9 @@
<A HREF="#index">index</A>
<HR>
<SMALL>
-Copyright &copy; 2010 Lua.org, PUC-Rio.
+Copyright &copy; 2011 Lua.org, PUC-Rio.
Freely available under the terms of the
-<a href="http://www.lua.org/license.html#5">Lua license</a>.
+<A HREF="http://www.lua.org/license.html#5">Lua license</A>.
</SMALL>
<H2><A NAME="contents">Contents</A></H2>
@@ -120,7 +120,7 @@
</UL>
<LI><A HREF="manual.html#6.5">6.5 &ndash; Table Manipulation</A>
<LI><A HREF="manual.html#6.6">6.6 &ndash; Mathematical Functions</A>
-<LI><A HREF="manual.html#6.7">6.7 &ndash; Bitwise operations</A>
+<LI><A HREF="manual.html#6.7">6.7 &ndash; Bitwise Operations</A>
<LI><A HREF="manual.html#6.8">6.8 &ndash; Input and Output Facilities</A>
<LI><A HREF="manual.html#6.9">6.9 &ndash; Operating System Facilities</A>
<LI><A HREF="manual.html#6.10">6.10 &ndash; The Debug Library</A>
@@ -146,6 +146,8 @@
<P>
<A HREF="manual.html#pdf-_G">_G</A><BR>
<A HREF="manual.html#pdf-_VERSION">_VERSION</A><BR>
+
+<P>
<A HREF="manual.html#pdf-assert">assert</A><BR>
<A HREF="manual.html#pdf-collectgarbage">collectgarbage</A><BR>
<A HREF="manual.html#pdf-dofile">dofile</A><BR>
@@ -154,14 +156,13 @@
<A HREF="manual.html#pdf-ipairs">ipairs</A><BR>
<A HREF="manual.html#pdf-load">load</A><BR>
<A HREF="manual.html#pdf-loadfile">loadfile</A><BR>
-<A HREF="manual.html#pdf-loadin">loadin</A><BR>
-<A HREF="manual.html#pdf-loadstring">loadstring</A><BR>
<A HREF="manual.html#pdf-next">next</A><BR>
<A HREF="manual.html#pdf-pairs">pairs</A><BR>
<A HREF="manual.html#pdf-pcall">pcall</A><BR>
<A HREF="manual.html#pdf-print">print</A><BR>
<A HREF="manual.html#pdf-rawequal">rawequal</A><BR>
<A HREF="manual.html#pdf-rawget">rawget</A><BR>
+<A HREF="manual.html#pdf-rawlen">rawlen</A><BR>
<A HREF="manual.html#pdf-rawset">rawset</A><BR>
<A HREF="manual.html#pdf-require">require</A><BR>
<A HREF="manual.html#pdf-select">select</A><BR>
@@ -178,8 +179,10 @@
<A HREF="manual.html#pdf-bit32.bor">bit32.bor</A><BR>
<A HREF="manual.html#pdf-bit32.btest">bit32.btest</A><BR>
<A HREF="manual.html#pdf-bit32.bxor">bit32.bxor</A><BR>
+<A HREF="manual.html#pdf-bit32.extract">bit32.extract</A><BR>
<A HREF="manual.html#pdf-bit32.lrotate">bit32.lrotate</A><BR>
<A HREF="manual.html#pdf-bit32.lshift">bit32.lshift</A><BR>
+<A HREF="manual.html#pdf-bit32.replace">bit32.replace</A><BR>
<A HREF="manual.html#pdf-bit32.rrotate">bit32.rrotate</A><BR>
<A HREF="manual.html#pdf-bit32.rshift">bit32.rshift</A><BR>
@@ -285,10 +288,10 @@
<A HREF="manual.html#pdf-package.config">package.config</A><BR>
<A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR>
<A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR>
-<A HREF="manual.html#pdf-package.loaders">package.loaders</A><BR>
<A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR>
<A HREF="manual.html#pdf-package.path">package.path</A><BR>
<A HREF="manual.html#pdf-package.preload">package.preload</A><BR>
+<A HREF="manual.html#pdf-package.searchers">package.searchers</A><BR>
<A HREF="manual.html#pdf-package.searchpath">package.searchpath</A><BR>
<P>
@@ -475,15 +478,18 @@
<A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR>
<A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR>
<A HREF="manual.html#luaL_error">luaL_error</A><BR>
-<A HREF="manual.html#luaL_findtable">luaL_findtable</A><BR>
+<A HREF="manual.html#luaL_execresult">luaL_execresult</A><BR>
+<A HREF="manual.html#luaL_fileresult">luaL_fileresult</A><BR>
<A HREF="manual.html#luaL_getmetafield">luaL_getmetafield</A><BR>
<A HREF="manual.html#luaL_getmetatable">luaL_getmetatable</A><BR>
+<A HREF="manual.html#luaL_getsubtable">luaL_getsubtable</A><BR>
<A HREF="manual.html#luaL_gsub">luaL_gsub</A><BR>
<A HREF="manual.html#luaL_len">luaL_len</A><BR>
<A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR>
<A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR>
<A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR>
<A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR>
+<A HREF="manual.html#luaL_newlibtable">luaL_newlibtable</A><BR>
<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
<A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR>
@@ -514,12 +520,12 @@
</TABLE>
<HR>
-<SMALL>
+<SMALL CLASS="footer">
Last update:
-Mon Nov 22 16:38:54 BRST 2010
+Tue Jun 28 14:53:13 BRT 2011
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (alpha)
+Last change: revised for Lua 5.2.0 (beta)
-->
</BODY>
View
22 doc/lua.css
@@ -2,12 +2,14 @@ body {
color: #000000 ;
background-color: #FFFFFF ;
font-family: sans-serif ;
+ font-family: Helvetica, Arial, sans-serif ;
text-align: justify ;
margin-right: 20px ;
margin-left: 20px ;
}
h1, h2, h3, h4 {
+ font-family: Verdana, Geneva, sans-serif ;
font-weight: normal ;
font-style: italic ;
}
@@ -27,7 +29,7 @@ h3 {
table h3 {
padding-left: 0px ;
- border-left: none ;
+ border-left: none ;
}
a:link {
@@ -62,3 +64,21 @@ hr {
padding: 8px ;
border: solid #a0a0a0 2px ;
}
+
+.footer {
+ color: gray ;
+ font-size: small ;
+}
+
+input[type=text] {
+ border: solid #a0a0a0 2px ;
+ border-radius: 2em ;
+ -moz-border-radius: 2em ;
+ background-image: url('images/search.png') ;
+ background-repeat: no-repeat;
+ background-position: left center ;
+ background-position: 4px center ;
+ padding-left: 20px ;
+ height: 2em ;
+}
+
View
1,519 doc/manual.html
896 additions, 623 deletions not shown
View
36 doc/readme.html
@@ -27,12 +27,12 @@
<HR>
<H1>
<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
-Welcome to Lua 5.2 (alpha)
+Welcome to Lua 5.2 (beta)
</H1>
<P>
<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
-<EM>This is an alpha version of Lua 5.2.
+<EM>This is a beta version of Lua 5.2.
Some details may change in the final version.</EM>
<P>
@@ -145,9 +145,7 @@
<P>
<LI>
To check that Lua has been built correctly, do "<KBD>make test</KBD>"
- after building Lua. This will run the interpreter on a simple "Hello world"
- Lua program from the test directory.
- You may want to try other example programs in that directory.
+ after building Lua. This will run the interpreter and print its version string.
</OL>
<H3>Installing Lua</H3>
@@ -162,7 +160,7 @@
where xxx is your platform name.
<P>
- To install Lua locally, then do "<KBD>make local</KBD>".
+ To install Lua locally, do "<KBD>make local</KBD>".
This will create a directory <TT>install</TT> with subdirectories
<TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>,
and install Lua as listed below.
@@ -278,11 +276,13 @@
<H3>Main changes</H3>
<UL>
<LI> yieldable pcall and metamethods
-<LI> new <CODE>_ENV</CODE> scheme
+<LI> new lexical scheme for globals
<LI> ephemeron tables
<LI> new library for bitwise operations
<LI> light C functions
<LI> emergency garbage collector
+<LI> <CODE>goto</CODE> statement
+<LI> finalizers for tables
</UL>
Here are the other changes introduced in Lua 5.2:
@@ -291,29 +291,34 @@
<LI> no more fenv for threads or functions
<LI> tables honor the <CODE>__len</CODE> metamethod
<LI> hex and <CODE>\*</CODE> escapes in strings
+<LI> support for hexadecimal floats
<LI> order metamethods work for different types
<LI> no more verification of opcode consistency
<LI> hook event "tail return" replaced by "tail call"
<LI> empty statement
+<LI> <CODE>break</CODE> statement may appear in the middle of a block
</UL>
<H3>Libraries</H3>
<UL>
-<LI> new metamethods <CODE>__pairs</CODE> and <CODE>__ipairs</CODE>
<LI> arguments for function called through <CODE>xpcall</CODE>
<LI> optional 'mode' argument to load (to control binary x text)
-<LI> new function <CODE>loadin</CODE>
+<LI> optional 'env' argument to load (environment for loaded chunk)
<LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL)
<LI> new function <CODE>package.searchpath</CODE>
+<LI> modules receive their paths when loaded
<LI> optional base in <CODE>math.log</CODE>
+<LI> optional separator in <CODE>string.rep</CODE>
<LI> <CODE>file:write</CODE> returns <CODE>file</CODE>
<LI> closing a pipe returns exit status
<LI> <CODE>os.exit</CODE> may close state
+<LI> new metamethods <CODE>__pairs</CODE> and <CODE>__ipairs</CODE>
<LI> new option 'isrunning' for <CODE>collectgarbage</CODE> and <CODE>lua_gc</CODE>
<LI> frontier patterns
<LI> <CODE>\0</CODE> in patterns
<LI> new option <CODE>*L</CODE> for <CODE>io.read</CODE>
<LI> options for <CODE>io.lines</CODE>
+<LI> <CODE>debug.getlocal</CODE> can access function varargs
</UL>
<H3>C API</H3>
@@ -321,14 +326,14 @@
<LI> main thread predefined in the registry
<LI> new constants <CODE>LUA_OK</CODE> and <CODE>LUA_ERRGCMM</CODE>
<LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE>
-<LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE>
+<LI> new <CODE>lua_version</CODE> and <CODE>luaL_checkversion</CODE>
<LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string
<LI> new <CODE>luaL_testudata</CODE> and <CODE>luaL_setmetatable</CODE>
<LI> new <CODE>luaL_tolstring</CODE>
<LI> new <CODE>lua_copy</CODE>
<LI> new <CODE>lua_absindex</CODE>
<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>
-<LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API
+<LI> <CODE>nparams</CODE> and <CODE>isvararg</CODE> available in debug API
<LI> new <CODE>lua_Unsigned</CODE>
</UL>
@@ -343,6 +348,7 @@
<LI> new hash for floats
<LI> handling of non-string error messages in the standalone interpreter
<LI> generational mode for garbage collection (experimental)
+<LI> NaN trick (experimental)
</UL>
<H2><A NAME="license">License</A></H2>
@@ -364,7 +370,7 @@
<A HREF="http://www.lua.org/license.html">this</A>.
<BLOCKQUOTE>
-Copyright &copy; 1994&ndash;2010 Lua.org, PUC-Rio.
+Copyright &copy; 1994&ndash;2011 Lua.org, PUC-Rio.
<P>
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -389,12 +395,12 @@
</BLOCKQUOTE>
<HR>
-<SMALL>
+<SMALL CLASS="footer">
Last update:
-Sat Nov 20 19:23:14 BRST 2010
+Fri Jun 24 11:30:57 BRT 2011
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (alpha)
+Last change: revised for Lua 5.2.0 (beta)
-->
</BODY>
View
47 src/Makefile
@@ -7,16 +7,22 @@
PLAT= none
CC= gcc
-CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(MYCFLAGS)
-LIBS= -lm $(MYLIBS)
+CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS)
+LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
+LIBS= -lm $(SYSLIBS) $(MYLIBS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
+SYSCFLAGS=
+SYSLDFLAGS=
+SYSLIBS=
+
MYCFLAGS=
MYLDFLAGS=
MYLIBS=
+MYOBJS=
# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======
@@ -28,6 +34,7 @@ CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
ltm.o lundump.o lvm.o lzio.o
LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
lmathlib.o loslib.o lstrlib.o ltablib.o lpeg.o loadlib.o linit.o
+BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
LUA_T= lua
LUA_O= lua.o
@@ -35,7 +42,7 @@ LUA_O= lua.o
LUAC_T= luac
LUAC_O= luac.o
-ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
+ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
ALL_A= $(LUA_A)
@@ -48,15 +55,15 @@ o: $(ALL_O)
a: $(ALL_A)
-$(LUA_A): $(CORE_O) $(LIB_O)
+$(LUA_A): $(BASE_O)
$(AR) $@ $?
$(RANLIB) $@
$(LUA_T): $(LUA_O) $(LUA_A)
- $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
+ $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
$(LUAC_T): $(LUAC_O) $(LUA_A)
- $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
+ $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
clean:
$(RM) $(ALL_T) $(ALL_O)
@@ -68,12 +75,11 @@ echo:
@echo "PLAT= $(PLAT)"
@echo "CC= $(CC)"
@echo "CFLAGS= $(CFLAGS)"
+ @echo "LDFLAGS= $(SYSLDFLAGS)"
+ @echo "LIBS= $(LIBS)"
@echo "AR= $(AR)"
@echo "RANLIB= $(RANLIB)"
@echo "RM= $(RM)"
- @echo "MYCFLAGS= $(MYCFLAGS)"
- @echo "MYLDFLAGS= $(MYLDFLAGS)"
- @echo "MYLIBS= $(MYLIBS)"
# Convenience targets for popular platforms
ALL= all
@@ -83,35 +89,35 @@ none:
@echo " $(PLATS)"
aix:
- $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"
+ $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall"
ansi:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_ANSI"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI"
bsd:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E"
freebsd:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline"
generic: $(ALL)
linux:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -lncurses"
macosx:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline"
mingw:
$(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \
"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
- "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
+ "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
posix:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
solaris:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl"
+ $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl"
# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) default o a clean depend echo none
@@ -126,7 +132,7 @@ lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
- lstring.h ltable.h
+ lstring.h ltable.h lvm.h
lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h
lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h
ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h
@@ -165,7 +171,7 @@ lstring.o: lstring.c lua.h luaconf.h lmem.h llimits.h lobject.h lstate.h \
ltm.h lzio.h lstring.h lgc.h
lstrlib.o: lstrlib.c lua.h luaconf.h lauxlib.h lualib.h
ltable.o: ltable.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \
- ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h
+ ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h
ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
lmem.h lstring.h lgc.h ltable.h
@@ -179,4 +185,3 @@ lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
lzio.h
-# (end of Makefile)
View
162 src/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 2.140 2010/11/03 15:16:17 roberto Exp $
+** $Id: lapi.c,v 2.149 2011/06/13 14:13:06 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -59,9 +59,9 @@ static TValue *index2addr (lua_State *L, int idx) {
if (ttislcf(ci->func)) /* light C function? */
return cast(TValue *, luaO_nilobject); /* it has no upvalues */
else {
- Closure *func = clvalue(ci->func);
- return (idx <= func->c.nupvalues)
- ? &func->c.upvalue[idx-1]
+ CClosure *func = clCvalue(ci->func);
+ return (idx <= func->nupvalues)
+ ? &func->upvalue[idx-1]
: cast(TValue *, luaO_nilobject);
}
}
@@ -195,10 +195,8 @@ static void moveto (lua_State *L, TValue *fr, int idx) {
TValue *to = index2addr(L, idx);
api_checkvalidindex(L, to);
setobj(L, to, fr);
- if (idx < LUA_REGISTRYINDEX) { /* function upvalue? */
- lua_assert(ttisclosure(L->ci->func));
- luaC_barrier(L, clvalue(L->ci->func), fr);
- }
+ if (idx < LUA_REGISTRYINDEX) /* function upvalue? */
+ luaC_barrier(L, clCvalue(L->ci->func), fr);
/* LUA_REGISTRYINDEX does not need gc barrier
(collector revisits it before finishing collection) */
}
@@ -251,7 +249,7 @@ LUA_API const char *lua_typename (lua_State *L, int t) {
LUA_API int lua_iscfunction (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
- return (ttislcf(o) || (ttisclosure(o) && clvalue(o)->c.isC));
+ return (ttislcf(o) || (ttisCclosure(o)));
}
@@ -278,20 +276,28 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
StkId o1 = index2addr(L, index1);
StkId o2 = index2addr(L, index2);
return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0
- : luaO_rawequalObj(o1, o2);
+ : luaV_rawequalobj(o1, o2);
}
LUA_API void lua_arith (lua_State *L, int op) {
+ StkId o1; /* 1st operand */
+ StkId o2; /* 2nd operand */
lua_lock(L);
- api_checknelems(L, 2);
- if (ttisnumber(L->top - 2) && ttisnumber(L->top - 1)) {
- changenvalue(L->top - 2,
- luaO_arith(op, nvalue(L->top - 2), nvalue(L->top - 1)));
+ if (op != LUA_OPUNM) /* all other operations expect two operands */
+ api_checknelems(L, 2);
+ else { /* for unary minus, add fake 2nd operand */
+ api_checknelems(L, 1);
+ setobjs2s(L, L->top, L->top - 1);
+ L->top++;
+ }
+ o1 = L->top - 2;
+ o2 = L->top - 1;
+ if (ttisnumber(o1) && ttisnumber(o2)) {
+ changenvalue(o1, luaO_arith(op, nvalue(o1), nvalue(o2)));
}
else
- luaV_arith(L, L->top - 2, L->top - 2, L->top - 1,
- cast(TMS, op - LUA_OPADD + TM_ADD));
+ luaV_arith(L, o1, o1, o2, cast(TMS, op - LUA_OPADD + TM_ADD));
L->top--;
lua_unlock(L);
}
@@ -390,7 +396,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
LUA_API size_t lua_rawlen (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
- switch (ttype(o)) {
+ switch (ttypenv(o)) {
case LUA_TSTRING: return tsvalue(o)->len;
case LUA_TUSERDATA: return uvalue(o)->len;
case LUA_TTABLE: return luaH_getn(hvalue(o));
@@ -402,15 +408,15 @@ LUA_API size_t lua_rawlen (lua_State *L, int idx) {
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
if (ttislcf(o)) return fvalue(o);
- else if (ttisclosure(o) && clvalue(o)->c.isC)
- return clvalue(o)->c.f;
+ else if (ttisCclosure(o))
+ return clCvalue(o)->f;
else return NULL; /* not a C function */
}
LUA_API void *lua_touserdata (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
- switch (ttype(o)) {
+ switch (ttypenv(o)) {
case LUA_TUSERDATA: return (rawuvalue(o) + 1);
case LUA_TLIGHTUSERDATA: return pvalue(o);
default: return NULL;
@@ -428,7 +434,8 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
switch (ttype(o)) {
case LUA_TTABLE: return hvalue(o);
- case LUA_TFUNCTION: return clvalue(o);
+ case LUA_TLCL: return clLvalue(o);
+ case LUA_TCCL: return clCvalue(o);
case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
case LUA_TTHREAD: return thvalue(o);
case LUA_TUSERDATA:
@@ -456,6 +463,8 @@ LUA_API void lua_pushnil (lua_State *L) {
LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
lua_lock(L);
setnvalue(L->top, n);
+ luai_checknum(L, L->top,
+ luaG_runerror(L, "C API - attempt to push a signaling NaN"));
api_incr_top(L);
lua_unlock(L);
}
@@ -548,7 +557,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
L->top -= n;
while (n--)
setobj2n(L, &cl->c.upvalue[n], L->top + n);
- setclvalue(L, L->top, cl);
+ setclCvalue(L, L->top, cl);
}
api_incr_top(L);
lua_unlock(L);
@@ -648,7 +657,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
int res;
lua_lock(L);
obj = index2addr(L, objindex);
- switch (ttype(obj)) {
+ switch (ttypenv(obj)) {
case LUA_TTABLE:
mt = hvalue(obj)->metatable;
break;
@@ -755,18 +764,19 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
api_check(L, ttistable(L->top - 1), "table expected");
mt = hvalue(L->top - 1);
}
- switch (ttype(obj)) {
+ switch (ttypenv(obj)) {
case LUA_TTABLE: {
hvalue(obj)->metatable = mt;
if (mt)
luaC_objbarrierback(L, gcvalue(obj), mt);
+ luaC_checkfinalizer(L, gcvalue(obj), mt);
break;
}
case LUA_TUSERDATA: {
uvalue(obj)->metatable = mt;
if (mt) {
luaC_objbarrier(L, rawuvalue(obj), mt);
- luaC_checkfinalizer(L, rawuvalue(obj));
+ luaC_checkfinalizer(L, gcvalue(obj), mt);
}
break;
}
@@ -912,15 +922,14 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
luaZ_init(L, &z, reader, data);
status = luaD_protectedparser(L, &z, chunkname);
if (status == LUA_OK) { /* no errors? */
- Closure *f = clvalue(L->top - 1); /* get newly created function */
- lua_assert(!f->c.isC);
- if (f->l.nupvalues == 1) { /* does it have one upvalue? */
+ LClosure *f = clLvalue(L->top - 1); /* get newly created function */
+ if (f->nupvalues == 1) { /* does it have one upvalue? */
/* get global table from registry */
Table *reg = hvalue(&G(L)->l_registry);
const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
/* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
- setobj(L, f->l.upvals[0]->v, gt);
- luaC_barrier(L, f->l.upvals[0], gt);
+ setobj(L, f->upvals[0]->v, gt);
+ luaC_barrier(L, f->upvals[0], gt);
}
}
lua_unlock(L);
@@ -959,11 +968,12 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
g = G(L);
switch (what) {
case LUA_GCSTOP: {
- stopgc(g);
+ g->gcrunning = 0;
break;
}
case LUA_GCRESTART: {
- g->GCdebt = 0;
+ luaE_setdebt(g, 0);
+ g->gcrunning = 1;
break;
}
case LUA_GCCOLLECT: {
@@ -972,30 +982,27 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
}
case LUA_GCCOUNT: {
/* GC values are expressed in Kbytes: #bytes/2^10 */
- res = cast_int(g->totalbytes >> 10);
+ res = cast_int(gettotalbytes(g) >> 10);
break;
}
case LUA_GCCOUNTB: {
- res = cast_int(g->totalbytes & 0x3ff);
+ res = cast_int(gettotalbytes(g) & 0x3ff);
break;
}
case LUA_GCSTEP: {
- int stopped = gcstopped(g);
if (g->gckind == KGC_GEN) { /* generational mode? */
res = (g->lastmajormem == 0); /* 1 if will do major collection */
- luaC_step(L); /* do a single step */
+ luaC_forcestep(L); /* do a single step */
}
else {
while (data-- >= 0) {
- luaC_step(L);
+ luaC_forcestep(L);
if (g->gcstate == GCSpause) { /* end of cycle? */
res = 1; /* signal it */
break;
}
}
}
- if (stopped) /* collector was stopped? */
- stopgc(g); /* keep it that way */
break;
}
case LUA_GCSETPAUSE: {
@@ -1014,7 +1021,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
break;
}
case LUA_GCISRUNNING: {
- res = !gcstopped(g);
+ res = g->gcrunning;
break;
}
case LUA_GCGEN: { /* change collector to generational mode */
@@ -1124,25 +1131,27 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
static const char *aux_upvalue (StkId fi, int n, TValue **val,
GCObject **owner) {
- Closure *f;
- if (!ttisclosure(fi)) return NULL;
- f = clvalue(fi);
- if (f->c.isC) {
- if (!(1 <= n && n <= f->c.nupvalues)) return NULL;
- *val = &f->c.upvalue[n-1];
- if (owner) *owner = obj2gco(f);
- return "";
- }
- else {
- const char *name;
- Proto *p = f->l.p;
- if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
- *val = f->l.upvals[n-1]->v;
- if (owner) *owner = obj2gco(f->l.upvals[n - 1]);
- name = getstr(p->upvalues[n-1].name);
- if (name == NULL) /* no debug information? */
- name = "";
- return name;
+ switch (ttype(fi)) {
+ case LUA_TCCL: { /* C closure */
+ CClosure *f = clCvalue(fi);
+ if (!(1 <= n && n <= f->nupvalues)) return NULL;
+ *val = &f->upvalue[n-1];
+ if (owner) *owner = obj2gco(f);
+ return "";
+ }
+ case LUA_TLCL: { /* Lua closure */
+ LClosure *f = clLvalue(fi);
+ const char *name;
+ Proto *p = f->p;
+ if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
+ *val = f->upvals[n-1]->v;
+ if (owner) *owner = obj2gco(f->upvals[n - 1]);
+ name = getstr(p->upvalues[n-1].name);
+ if (name == NULL) /* no debug information? */
+ name = "";
+ return name;
+ }
+ default: return NULL; /* not a closure */
}
}
@@ -1180,34 +1189,39 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
}
-static UpVal **getupvalref (lua_State *L, int fidx, int n, Closure **pf) {
- Closure *f;
+static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {
+ LClosure *f;
StkId fi = index2addr(L, fidx);
- api_check(L, ttisclosure(fi), "Lua function expected");
- f = clvalue(fi);
- api_check(L, !f->c.isC, "Lua function expected");
- api_check(L, (1 <= n && n <= f->l.p->sizeupvalues), "invalid upvalue index");
+ api_check(L, ttisLclosure(fi), "Lua function expected");
+ f = clLvalue(fi);
+ api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
if (pf) *pf = f;
- return &f->l.upvals[n - 1]; /* get its upvalue pointer */
+ return &f->upvals[n - 1]; /* get its upvalue pointer */
}
LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) {
- Closure *f;
StkId fi = index2addr(L, fidx);
- api_check(L, ttisclosure(fi), "function expected");
- f = clvalue(fi);
- if (f->c.isC) {
- api_check(L, 1 <= n && n <= f->c.nupvalues, "invalid upvalue index");
- return &f->c.upvalue[n - 1];
+ switch (ttype(fi)) {
+ case LUA_TLCL: { /* lua closure */
+ return *getupvalref(L, fidx, n, NULL);
+ }
+ case LUA_TCCL: { /* C closure */
+ CClosure *f = clCvalue(fi);
+ api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
+ return &f->upvalue[n - 1];
+ }
+ default: {
+ api_check(L, 0, "closure expected");
+ return NULL;
+ }
}
- else return *getupvalref(L, fidx, n, NULL);
}
LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
int fidx2, int n2) {
- Closure *f1;
+ LClosure *f1;
UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
*up1 = *up2;
View
89 src/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.227 2010/11/10 18:05:36 roberto Exp $
+** $Id: lauxlib.c,v 1.233 2011/06/16 14:11:04 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -203,6 +203,63 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
return lua_error(L);
}
+
+LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
+ int en = errno; /* calls to Lua API may change this value */
+ if (stat) {
+ lua_pushboolean(L, 1);
+ return 1;
+ }
+ else {
+ lua_pushnil(L);
+ if (fname)
+ lua_pushfstring(L, "%s: %s", fname, strerror(en));
+ else
+ lua_pushfstring(L, "%s", strerror(en));
+ lua_pushinteger(L, en);
+ return 3;
+ }
+}
+
+
+#if !defined(inspectstat) /* { */
+
+#if defined(LUA_USE_POSIX)
+
+#include <sys/wait.h>
+
+/*
+** use appropriate macros to interpret 'pclose' return status
+*/
+#define inspectstat(stat,what) \
+ if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \
+ else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; }
+
+#else
+
+#define inspectstat(stat,what) /* no op */
+
+#endif
+
+#endif /* } */
+
+
+LUALIB_API int luaL_execresult (lua_State *L, int stat) {
+ const char *what = "exit"; /* type of termination */
+ if (stat == -1) /* error? */
+ return luaL_fileresult(L, 0, NULL);
+ else {
+ inspectstat(stat, what); /* interpret result */
+ if (*what == 'e' && stat == 0) /* successful termination? */
+ lua_pushboolean(L, 1);
+ else
+ lua_pushnil(L);
+ lua_pushstring(L, what);
+ lua_pushinteger(L, stat);
+ return 3; /* return true/nil,what,code */
+ }
+}
+
/* }====================================================== */
@@ -384,8 +441,10 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
newsize = B->n + sz;
if (newsize < B->n || newsize - B->n < sz)
luaL_error(L, "buffer too large");
- newbuff = (char *)lua_newuserdata(L, newsize); /* create larger buffer */
- memcpy(newbuff, B->b, B->n); /* move content to new buffer */
+ /* create larger buffer */
+ newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char));
+ /* move content to new buffer */
+ memcpy(newbuff, B->b, B->n * sizeof(char));
if (buffonstack(B))
lua_remove(L, -2); /* remove old buffer */
B->b = newbuff;
@@ -397,7 +456,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
char *b = luaL_prepbuffsize(B, l);
- memcpy(b, s, l);
+ memcpy(b, s, l * sizeof(char));
luaL_addsize(B, l);
}
@@ -700,8 +759,8 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
*/
#if defined(LUA_COMPAT_MODULE)
-static const char *luaL_findtablex (lua_State *L, int idx,
- const char *fname, int szhint) {
+static const char *luaL_findtable (lua_State *L, int idx,
+ const char *fname, int szhint) {
const char *e;
if (idx) lua_pushvalue(L, idx);
do {
@@ -745,13 +804,13 @@ static int libsize (const luaL_Reg *l) {
*/
LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
int sizehint) {
- luaL_findtablex(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */
lua_getfield(L, -1, modname); /* get _LOADED[modname] */
if (!lua_istable(L, -1)) { /* not found? */
lua_pop(L, 1); /* remove previous result */
/* try global variable (and create one if it does not exist) */
lua_pushglobaltable(L);
- if (luaL_findtablex(L, 0, modname, sizehint) != NULL)
+ if (luaL_findtable(L, 0, modname, sizehint) != NULL)
luaL_error(L, "name conflict for module " LUA_QS, modname);
lua_pushvalue(L, -1);
lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */
@@ -767,7 +826,10 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */
lua_insert(L, -(nup + 1)); /* move library table to below upvalues */
}
- luaL_setfuncs(L, l, nup);
+ if (l)
+ luaL_setfuncs(L, l, nup);
+ else
+ lua_pop(L, nup); /* remove upvalues */
}
#endif
@@ -780,7 +842,7 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
*/
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup, "too many upvalues");
- for (; l && l->name; l++) { /* fill the table with given functions */
+ for (; l->name != NULL; l++) { /* fill the table with given functions */
int i;
for (i = 0; i < nup; i++) /* copy upvalues to the top */
lua_pushvalue(L, -nup);
@@ -795,15 +857,16 @@ LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
** ensure that stack[idx][fname] has a table and push that table
** into the stack
*/
-LUALIB_API void luaL_findtable (lua_State *L, int idx, const char *fname) {
+LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {
lua_getfield(L, idx, fname);
- if (lua_istable(L, -1)) return; /* table already there */
+ if (lua_istable(L, -1)) return 1; /* table already there */
else {
idx = lua_absindex(L, idx);
lua_pop(L, 1); /* remove previous result */
lua_newtable(L);
lua_pushvalue(L, -1); /* copy to be left at top */
lua_setfield(L, idx, fname); /* assign new table to field */
+ return 0; /* false, because did not find table there */
}
}
@@ -819,7 +882,7 @@ LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
lua_pushcfunction(L, openf);
lua_pushstring(L, modname); /* argument to open function */
lua_call(L, 1, 1); /* open module */
- luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED");
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
lua_pushvalue(L, -2); /* make copy of module (call result) */
lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
lua_pop(L, 1); /* remove _LOADED table */
View
10 src/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.h,v 1.113 2010/11/16 19:20:01 roberto Exp $
+** $Id: lauxlib.h,v 1.117 2011/06/16 14:10:12 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -62,6 +62,9 @@ LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
const char *const lst[]);
+LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
+LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
+
/* pre-defined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
@@ -83,7 +86,7 @@ LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
-LUALIB_API void (luaL_findtable) (lua_State *L, int idx, const char *fname);
+LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
@@ -161,6 +164,7 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
/* compatibility with old module system */
+#if defined(LUA_COMPAT_MODULE)
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
@@ -169,6 +173,8 @@ LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
+#endif
+
#endif
View
194 src/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.251 2010/10/28 15:36:30 roberto Exp $
+** $Id: lbaselib.c,v 1.264 2011/07/05 12:49:35 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -32,44 +32,54 @@ static int luaB_print (lua_State *L) {
lua_call(L, 1, 1);
s = lua_tolstring(L, -1, &l); /* get result */
if (s == NULL)
- return luaL_error(L, LUA_QL("tostring") " must return a string to "
- LUA_QL("print"));
+ return luaL_error(L,
+ LUA_QL("tostring") " must return a string to " LUA_QL("print"));
if (i>1) luai_writestring("\t", 1);
luai_writestring(s, l);
lua_pop(L, 1); /* pop result */
}
- luai_writestring("\n", 1);
+ luai_writeline();
return 0;
}
+#define SPACECHARS " \f\n\r\t\v"
+
static int luaB_tonumber (lua_State *L) {
int base = luaL_optint(L, 2, 10);
+ luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
if (base == 10) { /* standard conversion */
luaL_checkany(L, 1);
if (lua_isnumber(L, 1)) {
lua_pushnumber(L, lua_tonumber(L, 1));
return 1;
- }
+ } /* else not a number */
}
else {
- const char *s1 = luaL_checkstring(L, 1);
- char *s2;
- unsigned long n;
+ size_t l;
+ const char *s = luaL_checklstring(L, 1, &l);
+ const char *e = s + l; /* end point for 's' */
int neg = 0;
- luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
- while (isspace((unsigned char)(*s1))) s1++; /* skip initial spaces */
- if (*s1 == '-') { s1++; neg = 1; }
- n = strtoul(s1, &s2, base);
- if (s1 != s2) { /* at least one valid digit? */
- while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
- if (*s2 == '\0') { /* no invalid trailing characters? */
- lua_pushnumber(L, (neg) ? -(lua_Number)n : (lua_Number)n);
+ s += strspn(s, SPACECHARS); /* skip initial spaces */
+ if (*s == '-') { s++; neg = 1; } /* handle signal */
+ else if (*s == '+') s++;
+ if (isalnum((unsigned char)*s)) {
+ lua_Number n = 0;
+ do {
+ int digit = (isdigit((unsigned char)*s)) ? *s - '0'
+ : toupper((unsigned char)*s) - 'A' + 10;
+ if (digit >= base) break; /* invalid numeral; force a fail */
+ n = n * (lua_Number)base + (lua_Number)digit;
+ s++;
+ } while (isalnum((unsigned char)*s));
+ s += strspn(s, SPACECHARS); /* skip trailing spaces */
+ if (s == e) { /* no invalid trailing characters? */
+ lua_pushnumber(L, (neg) ? -n : n);
return 1;
- }
- }
+ } /* else not a number */
+ } /* else not a number */
}
- lua_pushnil(L); /* else not a number */
+ lua_pushnil(L); /* not a number */
return 1;
}
@@ -110,13 +120,6 @@ static int luaB_setmetatable (lua_State *L) {
}
-static int luaB_getfenv (lua_State *L) {
- return luaL_error(L, "getfenv/setfenv deprecated");
-}
-
-#define luaB_setfenv luaB_getfenv
-
-
static int luaB_rawequal (lua_State *L) {
luaL_checkany(L, 1);
luaL_checkany(L, 2);
@@ -125,6 +128,15 @@ static int luaB_rawequal (lua_State *L) {
}
+static int luaB_rawlen (lua_State *L) {
+ int t = lua_type(L, 1);
+ luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
+ "table or string expected");
+ lua_pushinteger(L, lua_rawlen(L, 1));
+ return 1;
+}
+
+
static int luaB_rawget (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
luaL_checkany(L, 2);
@@ -251,6 +263,18 @@ static int luaB_loadfile (lua_State *L) {
** =======================================================
*/
+
+typedef struct {
+char c;
+ const char *mode;
+} loaddata;
+
+
+/*
+** check whether a chunk (prefix in 's') satisfies given 'mode'
+** ('t' for text, 'b' for binary). Returns error message (also
+** pushed on the stack) in case of errors.
+*/
static const char *checkrights (lua_State *L, const char *mode, const char *s) {
if (strchr(mode, 'b') == NULL && *s == LUA_SIGNATURE[0])
return lua_pushstring(L, "attempt to load a binary chunk");
@@ -261,10 +285,11 @@ static const char *checkrights (lua_State *L, const char *mode, const char *s) {
/*
-** reserves a slot, above all arguments, to hold a copy of the returned
-** string to avoid it being collected while parsed
+** reserved slot, above all arguments, to hold a copy of the returned
+** string to avoid it being collected while parsed. 'load' has four
+** optional arguments (chunk, source name, mode, and environment).
*/
-#define RESERVEDSLOT 4
+#define RESERVEDSLOT 5
/*
@@ -273,25 +298,20 @@ static const char *checkrights (lua_State *L, const char *mode, const char *s) {
** stack top. Instead, it keeps its resulting string in a
** reserved slot inside the stack.
*/
-typedef struct { /* reader state */
- int f; /* position of reader function on stack */
- const char *mode; /* allowed modes (binary/text) */
-} Readstat;
-
static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
const char *s;
- Readstat *stat = (Readstat *)ud;
+ loaddata *ld = (loaddata *)ud;
luaL_checkstack(L, 2, "too many nested functions");
- lua_pushvalue(L, stat->f); /* get function */
+ lua_pushvalue(L, 1); /* get function */
lua_call(L, 0, 1); /* call it */
if (lua_isnil(L, -1)) {
*size = 0;
return NULL;
}
else if ((s = lua_tostring(L, -1)) != NULL) {
- if (stat->mode != NULL) { /* first time? */
- s = checkrights(L, stat->mode, s); /* check mode */
- stat->mode = NULL; /* to avoid further checks */
+ if (ld->mode != NULL) { /* first time? */
+ s = checkrights(L, ld->mode, s); /* check mode */
+ ld->mode = NULL; /* to avoid further checks */
if (s) luaL_error(L, s);
}
lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
@@ -304,52 +324,32 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
}
-static int luaB_load_aux (lua_State *L, int farg) {
+static int luaB_load (lua_State *L) {
int status;
- Readstat stat;
size_t l;
- const char *s = lua_tolstring(L, farg, &l);
- stat.mode = luaL_optstring(L, farg + 2, "bt");
+ int top = lua_gettop(L);
+ const char *s = lua_tolstring(L, 1, &l);
+ const char *mode = luaL_optstring(L, 3, "bt");
if (s != NULL) { /* loading a string? */
- const char *chunkname = luaL_optstring(L, farg + 1, s);
- status = (checkrights(L, stat.mode, s) != NULL)
+ const char *chunkname = luaL_optstring(L, 2, s);
+ status = (checkrights(L, mode, s) != NULL)
|| luaL_loadbuffer(L, s, l, chunkname);
}
else { /* loading from a reader function */
- const char *chunkname = luaL_optstring(L, farg + 1, "=(load)");
- luaL_checktype(L, farg, LUA_TFUNCTION);
- stat.f = farg;
+ const char *chunkname = luaL_optstring(L, 2, "=(load)");
+ loaddata ld;
+ ld.mode = mode;
+ luaL_checktype(L, 1, LUA_TFUNCTION);
lua_settop(L, RESERVEDSLOT); /* create reserved slot */
- status = lua_load(L, generic_reader, &stat, chunkname);
+ status = lua_load(L, generic_reader, &ld, chunkname);
}
- return load_aux(L, status);
-}
-
-
-static int luaB_load (lua_State *L) {
- return luaB_load_aux(L, 1);
-}
-
-
-static int luaB_loadin (lua_State *L) {
- int n;
- luaL_checkany(L, 1);
- n = luaB_load_aux(L, 2);
- if (n == 1) { /* success? */
- lua_pushvalue(L, 1); /* environment for loaded function */
- if (lua_setupvalue(L, -2, 1) == NULL)
- luaL_error(L, "loaded chunk does not have an upvalue");
+ if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */
+ lua_pushvalue(L, 4); /* environment for loaded function */
+ lua_setupvalue(L, -2, 1); /* set it as 1st upvalue */
}
- return n;
+ return load_aux(L, status);
}
-
-static int luaB_loadstring (lua_State *L) {
- lua_settop(L, 2);
- lua_pushliteral(L, "tb");
- return luaB_load(L); /* dostring(s, n) == load(s, n, "tb") */
-
-}
/* }====================================================== */
@@ -391,7 +391,7 @@ static int luaB_select (lua_State *L) {
static int pcallcont (lua_State *L) {
- int errfunc; /* call has an error function in bottom of the stack */
+ int errfunc = 0; /* =0 to avoid warnings */
int status = lua_getctx(L, &errfunc);
lua_assert(status != LUA_OK);
lua_pushboolean(L, (status == LUA_YIELD)); /* first result (status) */
@@ -436,55 +436,27 @@ static int luaB_tostring (lua_State *L) {
}
-static int luaB_newproxy (lua_State *L) {
- lua_settop(L, 1);
- lua_newuserdata(L, 0); /* create proxy */
- if (lua_toboolean(L, 1) == 0)
- return 1; /* no metatable */
- else if (lua_isboolean(L, 1)) {
- lua_createtable(L, 0, 1); /* create a new metatable `m' ... */
- lua_pushboolean(L, 1);
- lua_setfield(L, -2, "__gc"); /* ... m.__gc = false (HACK!!)... */
- lua_pushvalue(L, -1); /* ... and mark `m' as a valid metatable */
- lua_pushboolean(L, 1);
- lua_rawset(L, lua_upvalueindex(1)); /* weaktable[m] = true */
- }
- else {
- int validproxy = 0; /* to check if weaktable[metatable(u)] == true */
- if (lua_getmetatable(L, 1)) {
- lua_rawget(L, lua_upvalueindex(1));
- validproxy = lua_toboolean(L, -1);
- lua_pop(L, 1); /* remove value */
- }
- luaL_argcheck(L, validproxy, 1, "boolean or proxy expected");
- lua_getmetatable(L, 1); /* metatable is valid; get it */
- }
- lua_setmetatable(L, 2);
- return 1;
-}
-
-
static const luaL_Reg base_funcs[] = {
{"assert", luaB_assert},
{"collectgarbage", luaB_collectgarbage},
{"dofile", luaB_dofile},
{"error", luaB_error},
- {"getfenv", luaB_getfenv},
{"getmetatable", luaB_getmetatable},
{"ipairs", luaB_ipairs},
{"loadfile", luaB_loadfile},
{"load", luaB_load},
- {"loadin", luaB_loadin},
- {"loadstring", luaB_loadstring},
+#if defined(LUA_COMPAT_LOADSTRING)
+ {"loadstring", luaB_load},
+#endif
{"next", luaB_next},
{"pairs", luaB_pairs},
{"pcall", luaB_pcall},
{"print", luaB_print},
{"rawequal", luaB_rawequal},
+ {"rawlen", luaB_rawlen},
{"rawget", luaB_rawget},
{"rawset", luaB_rawset},
{"select", luaB_select},
- {"setfenv", luaB_setfenv},
{"setmetatable", luaB_setmetatable},
{"tonumber", luaB_tonumber},
{"tostring", luaB_tostring},
@@ -503,14 +475,6 @@ LUAMOD_API int luaopen_base (lua_State *L) {
luaL_setfuncs(L, base_funcs, 0);
lua_pushliteral(L, LUA_VERSION);
lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */
- /* `newproxy' needs a weaktable as upvalue */
- lua_createtable(L, 0, 1); /* new table `w' */
- lua_pushvalue(L, -1); /* `w' will be its own metatable */
- lua_setmetatable(L, -2);
- lua_pushliteral(L, "kv");
- lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
- lua_pushcclosure(L, luaB_newproxy, 1);
- lua_setfield(L, -2, "newproxy"); /* set global `newproxy' */
return 1;
}
View
88 src/lbitlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbitlib.c,v 1.13 2010/11/22 18:06:33 roberto Exp $
+** $Id: lbitlib.c,v 1.16 2011/06/20 16:35:23 roberto Exp $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
*/
@@ -14,25 +14,30 @@
/* number of bits to consider in a number */
-#define NBITS 32
+#if !defined(LUA_NBITS)
+#define LUA_NBITS 32
+#endif
-#define ALLONES (~(((~(lua_Unsigned)0) << (NBITS - 1)) << 1))
-/* mask to trim extra bits */
+#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1))
+
+/* macro to trim extra bits */
#define trim(x) ((x) & ALLONES)
-typedef lua_Unsigned b_uint;
+/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */
+#define mask(n) (~((ALLONES << 1) << ((n) - 1)))
+
+typedef lua_Unsigned b_uint;
-#define getuintarg(L,arg) luaL_checkunsigned(L,arg)
static b_uint andaux (lua_State *L) {
int i, n = lua_gettop(L);
b_uint r = ~(b_uint)0;
for (i = 1; i <= n; i++)
- r &= getuintarg(L, i);
+ r &= luaL_checkunsigned(L, i);
return trim(r);
}
@@ -55,7 +60,7 @@ static int b_or (lua_State *L) {
int i, n = lua_gettop(L);
b_uint r = 0;
for (i = 1; i <= n; i++)
- r |= getuintarg(L, i);
+ r |= luaL_checkunsigned(L, i);
lua_pushunsigned(L, trim(r));
return 1;
}
@@ -65,14 +70,14 @@ static int b_xor (lua_State *L) {
int i, n = lua_gettop(L);
b_uint r = 0;
for (i = 1; i <= n; i++)
- r ^= getuintarg(L, i);
+ r ^= luaL_checkunsigned(L, i);
lua_pushunsigned(L, trim(r));
return 1;
}
static int b_not (lua_State *L) {
- b_uint r = ~getuintarg(L, 1);
+ b_uint r = ~luaL_checkunsigned(L, 1);
lua_pushunsigned(L, trim(r));
return 1;
}
@@ -82,11 +87,11 @@ static int b_shift (lua_State *L, b_uint r, int i) {
if (i < 0) { /* shift right? */
i = -i;
r = trim(r);
- if (i >= NBITS) r = 0;
+ if (i >= LUA_NBITS) r = 0;
else r >>= i;
}
else { /* shift left */
- if (i >= NBITS) r = 0;
+ if (i >= LUA_NBITS) r = 0;
else r <<= i;
r = trim(r);
}
@@ -96,22 +101,22 @@ static int b_shift (lua_State *L, b_uint r, int i) {
static int b_lshift (lua_State *L) {
- return b_shift(L, getuintarg(L, 1), luaL_checkint(L, 2));
+ return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2));
}
static int b_rshift (lua_State *L) {
- return b_shift(L, getuintarg(L, 1), -luaL_checkint(L, 2));
+ return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2));
}
static int b_arshift (lua_State *L) {
- b_uint r = getuintarg(L, 1);
+ b_uint r = luaL_checkunsigned(L, 1);
int i = luaL_checkint(L, 2);
- if (i < 0 || !(r & ((b_uint)1 << (NBITS - 1))))
+ if (i < 0 || !(r & ((b_uint)1 << (LUA_NBITS - 1))))
return b_shift(L, r, -i);
else { /* arithmetic shift for 'negative' number */
- if (i >= NBITS) r = ALLONES;
+ if (i >= LUA_NBITS) r = ALLONES;
else
r = trim((r >> i) | ~(~(b_uint)0 >> i)); /* add signal bit */
lua_pushunsigned(L, r);
@@ -121,10 +126,10 @@ static int b_arshift (lua_State *L) {
static int b_rot (lua_State *L, int i) {
- b_uint r = getuintarg(L, 1);
- i &= (NBITS - 1); /* i = i % NBITS */
+ b_uint r = luaL_checkunsigned(L, 1);
+ i &= (LUA_NBITS - 1); /* i = i % NBITS */
r = trim(r);
- r = (r << i) | (r >> (NBITS - i));
+ r = (r << i) | (r >> (LUA_NBITS - i));
lua_pushunsigned(L, trim(r));
return 1;
}
@@ -140,17 +145,58 @@ static int b_rrot (lua_State *L) {
}
+/*
+** get field and width arguments for field-manipulation functions,
+** checking whether they are valid
+*/
+static int fieldargs (lua_State *L, int farg, int *width) {
+ int f = luaL_checkint(L, farg);
+ int w = luaL_optint(L, farg + 1, 1);
+ luaL_argcheck(L, 0 <= f, farg, "field cannot be negative");
+ luaL_argcheck(L, 0 < w, farg + 1, "width must be positive");
+ if (f + w > LUA_NBITS)
+ luaL_error(L, "trying to access non-existent bits");
+ *width = w;
+ return f;
+}
+
+
+static int b_extract (lua_State *L) {
+ int w;
+ b_uint r = luaL_checkunsigned(L, 1);
+ int f = fieldargs(L, 2, &w);
+ r = (r >> f) & mask(w);
+ lua_pushunsigned(L, r);
+ return 1;
+}
+
+
+static int b_replace (lua_State *L) {
+ int w;
+ b_uint r = luaL_checkunsigned(L, 1);
+ b_uint v = luaL_checkunsigned(L, 2);
+ int f = fieldargs(L, 3, &w);
+ int m = mask(w);
+ v &= m; /* erase bits outside given width */
+ r = (r & ~(m << f)) | (v << f);
+ lua_pushunsigned(L, r);
+ return 1;
+}
+
+
static const luaL_Reg bitlib[] = {
{"arshift", b_arshift},
{"band", b_and},
{"bnot", b_not},
{"bor", b_or},
{"bxor", b_xor},
+ {"btest", b_test},
+ {"extract", b_extract},
{"lrotate", b_lrot},
{"lshift", b_lshift},
+ {"replace", b_replace},
{"rrotate", b_rrot},
{"rshift", b_rshift},
- {"btest", b_test},
{NULL, NULL}
};
View
80 src/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 2.49 2010/07/07 16:27:29 roberto Exp $
+** $Id: lcode.c,v 2.56 2011/05/31 18:27:56 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -23,6 +23,7 @@
#include "lparser.h"
#include "lstring.h"
#include "ltable.h"
+#include "lvm.h"
#define hasjumps(e) ((e)->t != (e)->f)
@@ -35,19 +36,23 @@ static int isnumeral(expdesc *e) {
void luaK_nil (FuncState *fs, int from, int n) {
Instruction *previous;
+ int l = from + n - 1; /* last register to set nil */
if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
previous = &fs->f->code[fs->pc-1];
if (GET_OPCODE(*previous) == OP_LOADNIL) {
int pfrom = GETARG_A(*previous);
- int pto = GETARG_B(*previous);
- if (pfrom <= from && from <= pto+1) { /* can connect both? */
- if (from+n-1 > pto)
- SETARG_B(*previous, from+n-1);
+ int pl = pfrom + GETARG_B(*previous);
+ if ((pfrom <= from && from <= pl + 1) ||
+ (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
+ if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
+ if (pl > l) l = pl; /* l = max(l, pl) */
+ SETARG_A(*previous, from);
+ SETARG_B(*previous, l - from);
return;
}
- }
+ } /* else go through */
}
- luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */
+ luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
}
@@ -171,6 +176,19 @@ void luaK_patchlist (FuncState *fs, int list, int target) {
}
+LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level) {
+ level++; /* argument is +1 to reserve 0 as non-op */
+ while (list != NO_JUMP) {
+ int next = getjump(fs, list);
+ lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP &&
+ (GETARG_A(fs->f->code[list]) == 0 ||
+ GETARG_A(fs->f->code[list]) >= level));
+ SETARG_A(fs->f->code[list], level);
+ list = next;
+ }
+}
+
+
void luaK_patchtohere (FuncState *fs, int list) {
luaK_getlabel(fs);
luaK_concat(fs, &fs->jpc, list);
@@ -229,11 +247,11 @@ static int codeextraarg (FuncState *fs, int a) {
}
-int luaK_codeABxX (FuncState *fs, OpCode o, int reg, int k) {
- if (k < MAXARG_Bx)
- return luaK_codeABx(fs, o, reg, k + 1);
+int luaK_codek (FuncState *fs, int reg, int k) {
+ if (k <= MAXARG_Bx)
+ return luaK_codeABx(fs, OP_LOADK, reg, k);
else {
- int p = luaK_codeABx(fs, o, reg, 0);
+ int p = luaK_codeABx(fs, OP_LOADKX, reg, 0);
codeextraarg(fs, k);
return p;
}
@@ -278,7 +296,7 @@ static int addk (FuncState *fs, TValue *key, TValue *v) {
if (ttisnumber(idx)) {
lua_Number n = nvalue(idx);
lua_number2int(k, n);
- if (luaO_rawequalObj(&f->k[k], v))
+ if (luaV_rawequalobj(&f->k[k], v))
return k;
/* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
go through and create a new entry for this value */
@@ -564,15 +582,15 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
- int func;
+ int ereg;
luaK_exp2anyreg(fs, e);
+ ereg = e->u.info; /* register where 'e' was placed */
freeexp(fs, e);
- func = fs->freereg;
- luaK_codeABC(fs, OP_SELF, func, e->u.info, luaK_exp2RK(fs, key));
- freeexp(fs, key);
- luaK_reserveregs(fs, 2);
- e->u.info = func;
+ e->u.info = fs->freereg; /* base register for op_self */
e->k = VNONRELOC;
+ luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
+ luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));
+ freeexp(fs, key);
}
@@ -603,21 +621,14 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) {
int pc; /* pc of last jump */
luaK_dischargevars(fs, e);
switch (e->k) {
- case VK: case VKNUM: case VTRUE: {
- pc = NO_JUMP; /* always true; do nothing */
- break;
- }
case VJMP: {
invertjump(fs, e);
pc = e->u.info;
break;
}
- case VFALSE: {
- if (!hasjumps(e)) {
- pc = luaK_jump(fs); /* always jump */
- break;
- }
- /* else go through */
+ case VK: case VKNUM: case VTRUE: {
+ pc = NO_JUMP; /* always true; do nothing */
+ break;
}
default: {
pc = jumponcond(fs, e, 0);
@@ -634,20 +645,13 @@ static void luaK_goiffalse (FuncState *fs, expdesc *e) {
int pc; /* pc of last jump */
luaK_dischargevars(fs, e);
switch (e->k) {
- case VNIL: case VFALSE: {
- pc = NO_JUMP; /* always false; do nothing */
- break;
- }
case VJMP: {
pc = e->u.info;
break;
}
- case VTRUE: {
- if (!hasjumps(e)) {
- pc = luaK_jump(fs); /* always jump */
- break;
- }
- /* else go through */
+ case VNIL: case VFALSE: {
+ pc = NO_JUMP; /* always false; do nothing */
+ break;
}
default: {
pc = jumponcond(fs, e, 1);
View
7 src/lcode.h
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.h,v 1.55 2010/07/02 20:42:40 roberto Exp $
+** $Id: lcode.h,v 1.57 2011/04/07 18:14:12 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -44,11 +44,9 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
-#define luaK_codek(fs,reg,k) luaK_codeABxX(fs, OP_LOADK, reg, k)
-
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
-LUAI_FUNC int luaK_codeABxX (FuncState *fs, OpCode o, int reg, int k);
+LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k);
LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
@@ -71,6 +69,7 @@ LUAI_FUNC int luaK_jump (FuncState *fs);
LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
+LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level);
LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
LUAI_FUNC int luaK_getlabel (FuncState *fs);
LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);
View
44 src/lctype.c
@@ -1,45 +1,49 @@
/*
-** $Id: lctype.c,v 1.8 2009/11/19 19:06:52 roberto Exp $
+** $Id: lctype.c,v 1.10 2011/06/24 12:25:33 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
*/
-#include <limits.h>
-
#include "lctype.h"
+#if !LUA_USE_CTYPE /* { */
+
+#include <limits.h>
+
LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
0x00, /* EOZ */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+ 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
- 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
+ 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */
0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
- 0x04, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x25,
- 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25,
- 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25,
- 0x25, 0x25, 0x25, 0x04, 0x04, 0x04, 0x04, 0x05,
- 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05,
+ 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */
+ 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
+ 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
+ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
+
+#endif /* } */
View
57 src/lctype.h
@@ -1,5 +1,5 @@
/*
-** $Id: lctype.h,v 1.8 2009/11/19 19:06:52 roberto Exp $
+** $Id: lctype.h,v 1.11 2011/06/27 18:22:46 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
*/
@@ -7,10 +7,31 @@
#ifndef lctype_h
#define lctype_h
+#include "lua.h"
-#include <limits.h>
-#include "lua.h"
+/*
+** WARNING: the functions defined here do not necessarily correspond
+** to the similar functions in the standard C ctype.h. They are
+** optimized for the specific needs of Lua
+*/
+
+#if !defined(LUA_USE_CTYPE)
+
+#if 'A' == 65 && '0' == 48
+/* ASCII case: can use its own tables; faster and fixed */
+#define LUA_USE_CTYPE 0
+#else
+/* must use standard C ctype */
+#define LUA_USE_CTYPE 1
+#endif
+
+#endif
+
+
+#if !LUA_USE_CTYPE /* { */
+
+#include <limits.h>
#include "llimits.h"
@@ -20,7 +41,6 @@
#define PRINTBIT 2
#define SPACEBIT 3
#define XDIGITBIT 4
-#define UPPERBIT 5
#define MASK(B) (1 << (B))
@@ -36,15 +56,40 @@
*/
#define lislalpha(c) testprop(c, MASK(ALPHABIT))
#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
-#define lisupper(c) testprop(c, MASK(UPPERBIT))
#define lisdigit(c) testprop(c, MASK(DIGITBIT))
#define lisspace(c) testprop(c, MASK(SPACEBIT))
#define lisprint(c) testprop(c, MASK(PRINTBIT))
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
+/*
+** this 'ltolower' only works for alphabetic characters
+*/
+#define ltolower(c) ((c) | ('A' ^ 'a'))
-/* one more entry for 0 and one more for -1 (EOZ) */
+
+/* two more entries for 0 and -1 (EOZ) */
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
+
+#else /* }{ */
+
+/*
+** use standard C ctypes
+*/
+
+#include <ctype.h>
+
+
+#define lislalpha(c) (isalpha(c) || (c) == '_')
+#define lislalnum(c) (isalnum(c) || (c) == '_')
+#define lisdigit(c) (isdigit(c))
+#define lisspace(c) (isspace(c))
+#define lisprint(c) (isprint(c))
+#define lisxdigit(c) (isxdigit(c))
+
+#define ltolower(c) (tolower(c))
+
+#endif /* } */
+
#endif
View
27 src/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.126 2010/11/16 18:01:28 roberto Exp $
+** $Id: ldblib.c,v 1.130 2011/04/08 19:17:36 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -18,6 +18,9 @@
#include "lualib.h"
+#define HOOKKEY "_HKEY"
+
+
static int db_getregistry (lua_State *L) {
lua_pushvalue(L, LUA_REGISTRYINDEX);
@@ -39,8 +42,8 @@ static int db_setmetatable (lua_State *L) {
luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
"nil or table expected");
lua_settop(L, 2);
- lua_pushboolean(L, lua_setmetatable(L, 1));
- return 1;
+ lua_setmetatable(L, 1);
+ return 1; /* return 1st argument */
}
@@ -250,14 +253,13 @@ static int db_upvaluejoin (lua_State *L) {
}
-static const char KEY_HOOK = 'h';
+#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY);
static void hookf (lua_State *L, lua_Debug *ar) {
static const char *const hooknames[] =
{"call", "return", "line", "count", "tail call"};
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_rawget(L, LUA_REGISTRYINDEX);
+ gethooktable(L);
lua_pushlightuserdata(L, L);
lua_rawget(L, -2);
if (lua_isfunction(L, -1)) {
@@ -291,19 +293,6 @@ static char *unmakemask (int mask, char *smask) {
}
-static void gethooktable (lua_State *L) {
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_rawget(L, LUA_REGISTRYINDEX);
- if (!lua_istable(L, -1)) {
- lua_pop(L, 1);
- lua_createtable(L, 0, 1);
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_pushvalue(L, -2);
- lua_rawset(L, LUA_REGISTRYINDEX);
- }
-}
-
-
static int db_sethook (lua_State *L) {
int arg, mask, count;
lua_Hook func;
View
110 src/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 2.74 2010/10/11 20:24:42 roberto Exp $
+** $Id: ldebug.c,v 2.82 2011/06/02 19:31:40 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -35,12 +35,12 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
static int currentpc (CallInfo *ci) {
lua_assert(isLua(ci));
- return pcRel(ci->u.l.savedpc, ci_func(ci)->l.p);
+ return pcRel(ci->u.l.savedpc, ci_func(ci)->p);
}
static int currentline (CallInfo *ci) {
- return getfuncline(ci_func(ci)->l.p, currentpc(ci));
+ return getfuncline(ci_func(ci)->p, currentpc(ci));
}
@@ -94,13 +94,28 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
}
+static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
+ int nparams = clLvalue(ci->func)->p->numparams;
+ if (n >= ci->u.l.base - ci->func - nparams)
+ return NULL; /* no such vararg */
+ else {
+ *pos = ci->func + nparams + n;
+ return "(*vararg)"; /* generic name for any vararg */
+ }
+}
+
+
static const char *findlocal (lua_State *L, CallInfo *ci, int n,
StkId *pos) {
const char *name = NULL;
StkId base;
if (isLua(ci)) {
- base = ci->u.l.base;
- name = luaF_getlocalname(ci_func(ci)->l.p, n, currentpc(ci));
+ if (n < 0) /* access to vararg values? */
+ return findvararg(ci, -n, pos);
+ else {
+ base = ci->u.l.base;
+ name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
+ }
}
else
base = ci->func + 1;
@@ -108,10 +123,8 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
StkId limit = (ci == L->ci) ? L->top : ci->next->func;
if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
name = "(*temporary)"; /* generic name for any valid slot */
- else {
- *pos = base; /* to avoid warnings */
+ else
return NULL; /* no name */
- }
}
*pos = base + (n - 1);
return name;
@@ -125,10 +138,10 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
if (!isLfunction(L->top - 1)) /* not a Lua function? */
name = NULL;
else /* consider live variables at function start (parameters) */
- name = luaF_getlocalname(clvalue(L->top - 1)->l.p, n, 0);
+ name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
}
else { /* active function; get information through 'ar' */
- StkId pos;
+ StkId pos = 0; /* to avoid warnings */
name = findlocal(L, ar->i_ci, n, &pos);
if (name) {
setobj2s(L, L->top, pos);
@@ -141,11 +154,11 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
- StkId pos;
+ StkId pos = 0; /* to avoid warnings */
const char *name = findlocal(L, ar->i_ci, n, &pos);
lua_lock(L);
if (name)
- setobjs2s(L, pos, L->top - 1);
+ setobjs2s(L, pos, L->top - 1);
L->top--; /* pop value */
lua_unlock(L);
return name;
@@ -243,7 +256,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
if (*what == '>') {
ci = NULL;
func = L->top - 1;
- luai_apicheck(L, ttisfunction(func));
+ api_check(L, ttisfunction(func), "function expected");
what++; /* skip the '>' */
L->top--; /* pop function */
}
@@ -271,21 +284,38 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
** =======================================================
*/
+static const char *getobjname (lua_State *L, CallInfo *ci, int reg,