History

Lua 5.2.0-work5

Lua Team committed 16 years ago

Commit 2ce62c01 parent 6ff498440 files · +1099 −765Browse files

Unified · Split

40 files
  1. Makefile +1 −1
  2. README +3 −3
  3. doc/Makefile +0 −9
  4. doc/contents.html +18 −12
  5. doc/manual.html +331 −159
  6. doc/readme.html +63 −65
  7. src/Makefile +5 −9
  8. src/lapi.c +43 −7
  9. src/lauxlib.c +55 −20
  10. src/lauxlib.h +4 −1
  11. src/lbaselib.c +11 −7
  12. src/lbitlib.c +49 −33
  13. src/ldebug.c +12 −6
  14. src/ldo.c +5 −4
  15. src/ldump.c +6 −9
  16. src/lgc.c +3 −3
  17. src/linit.c +2 −2
  18. src/liolib.c +2 −2
  19. src/llex.c +6 −8
  20. src/lmathlib.c +2 −2
  21. src/loadlib.c +4 −6
  22. src/lobject.c +12 −7
  23. src/lopcodes.c +3 −3
  24. src/lopcodes.h +5 −4
  25. src/loslib.c +6 −2
  26. src/lparser.c +16 −11
  27. src/lstate.c +6 −1
  28. src/lstate.h +4 −3
  29. src/lstrlib.c +4 −4
  30. src/ltablib.c +3 −2
  31. src/lua.c +7 −6
  32. src/lua.h +12 −5
  33. src/luac.c +273 −39
  34. src/luaconf.h +85 −30
  35. src/lualib.h +3 −3
  36. src/lundump.c +30 −29
  37. src/lundump.h +2 −13
  38. src/lvm.c +3 −3
  39. src/print.c +0 −229
  40. test/hello.lua +0 −3
Makefile+1−1
@@ -55,7 +55,7 @@ $(PLATS) clean: · 54 unmodified lines
5555 cd src && $(MAKE) $@
5656
5757 test: dummy
58− src/lua test/hello.lua
58+ src/lua -v
5959
6060 install: dummy
6161 cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
README+3−3
@@ -1,6 +1,6 @@
11
2−This is Lua 5.2 (work4), released on 30 July 2010.
2+This is Lua 5.2 (work5), released on 30 Oct 2010.
33
4−For information about Lua, including installation instructions and
5−license details, see doc/readme.html.
4+For installation instructions, license details, and
5+further information about Lua, see doc/readme.html.
66
doc/Makefile+0−9
@@ -1,9 +0,0 @@
1−R= readme
2−T= $R.txt
3−H= $R.html
4−
5−$T: $H
6− lynx -dump $? >$@
7−
8−clean:
9− -rm -f $T
doc/contents.html+18−12
@@ -126,7 +126,7 @@ Freely available under the terms of the · 125 unmodified lines
126126 <LI><A HREF="manual.html#6.10">6.10 &ndash; The Debug Library</A>
127127 </UL>
128128 <P>
129−<LI><A HREF="manual.html#7">7 &ndash; Lua Stand-alone</A>
129+<LI><A HREF="manual.html#7">7 &ndash; Lua Standalone</A>
130130 <P>
131131 <LI><A HREF="manual.html#8">8 &ndash; Incompatibilities with the Previous Version</A>
132132 <UL>
@@ -172,15 +172,16 @@ Freely available under the terms of the · 39 unmodified lines
172172 <A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
173173
174174 <P>
175−<A HREF="manual.html#pdf-bit.band">bit.band</A><BR>
176−<A HREF="manual.html#pdf-bit.bnot">bit.bnot</A><BR>
177−<A HREF="manual.html#pdf-bit.bor">bit.bor</A><BR>
178−<A HREF="manual.html#pdf-bit.btest">bit.btest</A><BR>
179−<A HREF="manual.html#pdf-bit.bxor">bit.bxor</A><BR>
180−<A HREF="manual.html#pdf-bit.lshift">bit.lshift</A><BR>
181−<A HREF="manual.html#pdf-bit.rol">bit.rol</A><BR>
182−<A HREF="manual.html#pdf-bit.ror">bit.ror</A><BR>
183−<A HREF="manual.html#pdf-bit.rshift">bit.rshift</A><BR>
175+<A HREF="manual.html#pdf-bit32.AND">bit32.AND</A><BR>
176+<A HREF="manual.html#pdf-bit32.NOT">bit32.NOT</A><BR>
177+<A HREF="manual.html#pdf-bit32.OR">bit32.OR</A><BR>
178+<A HREF="manual.html#pdf-bit32.ROL">bit32.ROL</A><BR>
179+<A HREF="manual.html#pdf-bit32.ROR">bit32.ROR</A><BR>
180+<A HREF="manual.html#pdf-bit32.SAR">bit32.SAR</A><BR>
181+<A HREF="manual.html#pdf-bit32.SHL">bit32.SHL</A><BR>
182+<A HREF="manual.html#pdf-bit32.SHR">bit32.SHR</A><BR>
183+<A HREF="manual.html#pdf-bit32.TEST">bit32.TEST</A><BR>
184+<A HREF="manual.html#pdf-bit32.XOR">bit32.XOR</A><BR>
184185
185186 <P>
186187 <A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>
@@ -326,6 +327,7 @@ Freely available under the terms of the · 139 unmodified lines
326327 <A HREF="manual.html#lua_Number">lua_Number</A><BR>
327328 <A HREF="manual.html#lua_Reader">lua_Reader</A><BR>
328329 <A HREF="manual.html#lua_State">lua_State</A><BR>
330+<A HREF="manual.html#lua_Unsigned">lua_Unsigned</A><BR>
329331 <A HREF="manual.html#lua_Writer">lua_Writer</A><BR>
330332
331333 <P>
@@ -426,6 +428,8 @@ Freely available under the terms of the · 94 unmodified lines
426428 <A HREF="manual.html#lua_topointer">lua_topointer</A><BR>
427429 <A HREF="manual.html#lua_tostring">lua_tostring</A><BR>
428430 <A HREF="manual.html#lua_tothread">lua_tothread</A><BR>
431+<A HREF="manual.html#lua_tounsigned">lua_tounsigned</A><BR>
432+<A HREF="manual.html#lua_tounsignedx">lua_tounsignedx</A><BR>
429433 <A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
430434 <A HREF="manual.html#lua_type">lua_type</A><BR>
431435 <A HREF="manual.html#lua_typename">lua_typename</A><BR>
@@ -465,6 +469,7 @@ Freely available under the terms of the · 33 unmodified lines
465469 <A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
466470 <A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
467471 <A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
472+<A HREF="manual.html#luaL_checkunsigned">luaL_checkunsigned</A><BR>
468473 <A HREF="manual.html#luaL_checkversion">luaL_checkversion</A><BR>
469474 <A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR>
470475 <A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR>
@@ -487,6 +492,7 @@ Freely available under the terms of the · 16 unmodified lines
487492 <A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
488493 <A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
489494 <A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>
495+<A HREF="manual.html#luaL_optunsigned">luaL_optunsigned</A><BR>
490496 <A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
491497 <A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
492498 <A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
@@ -506,10 +512,10 @@ Freely available under the terms of the · 13 unmodified lines
506512 <HR>
507513 <SMALL>
508514 Last update:
509−Fri Jul 30 15:13:14 BRT 2010
515+Sat Oct 30 21:34:44 BRST 2010
510516 </SMALL>
511517 <!--
512−Last change: revised for Lua 5.2.0 (work4)
518+Last change: revised for Lua 5.2.0 (work5)
513519 -->
514520
515521 </BODY>
doc/manual.html+331−159
@@ -38,12 +38,12 @@ Freely available under the terms of the · 37 unmodified lines
3838 <!-- ====================================================================== -->
3939 <p>
4040
41−<!-- $Id: manual.of,v 1.58 2010/07/30 19:05:32 roberto Exp $ -->
41+<!-- $Id: manual.of,v 1.61 2010/10/29 12:51:39 roberto Exp $ -->
4242
4343
4444
4545
46−<h1>1 - <a name="1">Introduction</a></h1>
46+<h1>1 &ndash; <a name="1">Introduction</a></h1>
4747
4848 <p>
4949 Lua is an extension programming language designed to support
@@ -68,7 +68,7 @@ Through the use of C&nbsp;functions, Lua can be augmented to cope with · 18 unmodified lines
6868 a wide range of different domains,
6969 thus creating customized programming languages sharing a syntactical framework.
7070 The Lua distribution includes a sample host program called <code>lua</code>,
71−which uses the Lua library to offer a complete, stand-alone Lua interpreter.
71+which uses the Lua library to offer a complete, standalone Lua interpreter.
7272
7373
7474 <p>
@@ -89,14 +89,14 @@ see Roberto's book, <em>Programming in Lua (Second Edition)</em>. · 14 unmodified lines
8989
9090
9191
92−<h1>2 - <a name="2">Basic Concepts</a></h1>
92+<h1>2 &ndash; <a name="2">Basic Concepts</a></h1>
9393
9494 <p>
9595 This section describes some basic concepts of the language.
9696
9797
9898
99−<h2>2.1 - <a name="2.1">Values and Types</a></h2>
99+<h2>2.1 &ndash; <a name="2.1">Values and Types</a></h2>
100100
101101 <p>
102102 Lua is a <em>dynamically typed language</em>.
@@ -205,14 +205,29 @@ of a given value. · 102 unmodified lines
205205
206206
207207
208−<h2>2.2 - <a name="2.2">Environments and the Global Environment</a></h2>
208+<h2>2.2 &ndash; <a name="2.2">Environments and the Global Environment</a></h2>
209209
210210 <p>
211211 As discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
212212 any reference to a global name <code>var</code> is syntactically translated
213213 to <code>_ENV.var</code>.
214214 Moreover, any chunk is compiled in the scope of an external
215−variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>).
215+variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>),
216+so <code>_ENV</code> itself is never a global name in a chunk.
217+
218+
219+<p>
220+Despite the existence of this external <code>_ENV</code> variable and
221+the translation of global names,
222+<code>_ENV</code> is a completely regular name.
223+In particular,
224+you can define new variables and parameters with that name.
225+Each reference to a global name uses the <code>_ENV</code> that is
226+visible at that point in the program,
227+following the usual visibility rules of Lua.
228+
229+
230+<p>
216231 Any table used as the value of <code>_ENV</code> is usually called
217232 an <em>environment</em>.
218233
@@ -250,7 +265,7 @@ is never updated by Lua. · 31 unmodified lines
250265
251266
252267
253−<h2>2.3 - <a name="2.3">Error Handling</a></h2>
268+<h2>2.3 &ndash; <a name="2.3">Error Handling</a></h2>
254269
255270 <p>
256271 Because Lua is an embedded extension language,
@@ -272,7 +287,7 @@ you can use the <a href="#pdf-pcall"><code>pcall</code></a> function. · 15 unmodified lines
272287
273288
274289
275−<h2>2.4 - <a name="2.4">Metatables</a></h2>
290+<h2>2.4 &ndash; <a name="2.4">Metatables</a></h2>
276291
277292 <p>
278293 Every value in Lua can have a <em>metatable</em>.
@@ -282,7 +297,7 @@ under certain special operations. · 3 unmodified lines
282297 You can change several aspects of the behavior
283298 of operations over a value by setting specific fields in its metatable.
284299 For instance, when a non-numeric value is the operand of an addition,
285−Lua checks for a function in the field <code>"__add"</code> in its metatable.
300+Lua checks for a function in the field "<code>__add</code>" in its metatable.
286301 If it finds one,
287302 Lua calls this function to perform the addition.
288303
@@ -337,7 +352,7 @@ Each operation is identified by its corresponding name. · 48 unmodified lines
337352 The key for each operation is a string with its name prefixed by
338353 two underscores, '<code>__</code>';
339354 for instance, the key for operation "add" is the
340−string <code>"__add"</code>.
355+string "<code>__add</code>".
341356 The semantics of these operations is better explained by a Lua function
342357 describing how the interpreter executes the operation.
343358
@@ -684,7 +699,7 @@ called when Lua calls a value. · 340 unmodified lines
684699
685700
686701
687−<h2>2.5 - <a name="2.5">Garbage Collection</a></h2>
702+<h2>2.5 &ndash; <a name="2.5">Garbage Collection</a></h2>
688703
689704 <p>
690705 Lua performs automatic memory management.
@@ -748,7 +763,7 @@ the collector directly (e.g., stop and restart it). · 57 unmodified lines
748763
749764
750765
751−<h3>2.5.1 - <a name="2.5.1">Garbage-Collection Metamethods</a></h3>
766+<h3>2.5.1 &ndash; <a name="2.5.1">Garbage-Collection Metamethods</a></h3>
752767
753768 <p>
754769 Using the C&nbsp;API,
@@ -761,9 +776,22 @@ or freeing your own memory). · 6 unmodified lines
761776
762777
763778 <p>
764−Garbage userdata with a field <code>__gc</code> in their metatables are not
765−collected immediately by the garbage collector.
766−Instead, Lua puts them in a list.
779+For a userdata to be finalized when collected,
780+you must <em>mark</em> it first.
781+
782+You mark a userdata for finalization when you set its metatable
783+and the metatable has a field indexed by the string "<code>__gc</code>".
784+Note that if you set a metatable without a <code>__gc</code> field
785+and later create that field,
786+the userdata will not be marked for finalization.
787+However, after a userdata is marked,
788+you can freely change the <code>__gc</code> field of its metatable.
789+
790+
791+<p>
792+When a marked userdata becomes garbage,
793+it is not collected immediately by the garbage collector.
794+Instead, Lua puts it in a list.
767795 After the collection,
768796 Lua does the equivalent of the following function
769797 for each userdata in that list:
@@ -771,7 +799,7 @@ for each userdata in that list: · 1 unmodified line
771799 <pre>
772800 function gc_event (udata)
773801 local h = metatable(udata).__gc
774− if h then
802+ if type(h) == "function" then
775803 h(udata)
776804 end
777805 end
@@ -779,18 +807,18 @@ for each userdata in that list: · 1 unmodified line
779807
780808 <p>
781809 At the end of each garbage-collection cycle,
782−the finalizers for userdata are called in <em>reverse</em>
783−order of their creation,
784−among those collected in that cycle.
785−That is, the first finalizer to be called is the one associated
786−with the userdata created last in the program.
787−The userdata itself is freed only in the next garbage-collection cycle.
810+the finalizers for userdata are called in
811+the reverse order that they were marked for collection,
812+among those collected in that cycle;
813+that is, the first finalizer to be called is the one associated
814+with the userdata marked last in the program.
815+The userdata memory is freed only in the next garbage-collection cycle.
788816
789817
790818
791819
792820
793−<h3>2.5.2 - <a name="2.5.2">Weak Tables</a></h3>
821+<h3>2.5.2 &ndash; <a name="2.5.2">Weak Tables</a></h3>
794822
795823 <p>
796824 A <em>weak table</em> is a table whose elements are
@@ -823,7 +851,7 @@ is also called an <em>ephemeron table</em>. · 26 unmodified lines
823851 In an ephemeron table,
824852 a value is considered reachable only if its key is reachable.
825853 In particular,
826−if the only reference to a key comes from its value,
854+if the only reference to a key comes through its value,
827855 the pair is removed.
828856
829857
@@ -845,8 +873,8 @@ Lua treats strings and light C functions as non-object values. · 15 unmodified lines
845873
846874
847875 <p>
848−Userdata with finalizers has a special behavior in weak tables.
849−When a userdata is a value in a weak table,
876+Userdata marked for finalization has a special behavior in weak tables.
877+When a marked userdata is a value in a weak table,
850878 it is removed from the table the first time it is collected,
851879 before running its finalizer.
852880 When it is a key, however,
@@ -861,7 +889,7 @@ associated with the userdata through weak tables. · 8 unmodified lines
861889
862890
863891
864−<h2>2.6 - <a name="2.6">Coroutines</a></h2>
892+<h2>2.6 &ndash; <a name="2.6">Coroutines</a></h2>
865893
866894 <p>
867895 Lua supports coroutines,
@@ -980,7 +1008,7 @@ and <a href="#lua_yield"><code>lua_yield</code></a>. · 112 unmodified lines
9801008
9811009
9821010
983−<h1>3 - <a name="3">The Language</a></h1>
1011+<h1>3 &ndash; <a name="3">The Language</a></h1>
9841012
9851013 <p>
9861014 This section describes the lexis, the syntax, and the semantics of Lua.
@@ -1004,7 +1032,7 @@ at the end of this manual. · 17 unmodified lines
10041032
10051033
10061034
1007−<h2>3.1 - <a name="3.1">Lexical Conventions</a></h2>
1035+<h2>3.1 &ndash; <a name="3.1">Lexical Conventions</a></h2>
10081036
10091037 <p>
10101038 Lua is a free-form language.
@@ -1073,7 +1101,7 @@ results in a newline in the string. · 62 unmodified lines
10731101 The escape sequence '<code>\*</code>' skips the following span
10741102 of white-space characters,
10751103 including line breaks;
1076−it is particularly useful to break and ident a string
1104+it is particularly useful to break and indent a long string
10771105 into multiple lines without adding the newlines and spaces
10781106 into the string contents.
10791107
@@ -1161,7 +1189,7 @@ Long comments are frequently used to disable code temporarily. · 81 unmodified lines
11611189
11621190
11631191
1164−<h2>3.2 - <a name="3.2">Variables</a></h2>
1192+<h2>3.2 &ndash; <a name="3.2">Variables</a></h2>
11651193
11661194 <p>
11671195 Variables are places that store values.
@@ -1226,7 +1254,7 @@ Due to the way that chunks are compiled, · 58 unmodified lines
12261254
12271255
12281256
1229−<h2>3.3 - <a name="3.3">Statements</a></h2>
1257+<h2>3.3 &ndash; <a name="3.3">Statements</a></h2>
12301258
12311259 <p>
12321260 Lua supports an almost conventional set of statements,
@@ -1237,7 +1265,7 @@ and variable declarations. · 4 unmodified lines
12371265
12381266
12391267
1240−<h3>3.3.1 - <a name="3.3.1">Blocks</a></h3>
1268+<h3>3.3.1 &ndash; <a name="3.3.1">Blocks</a></h3>
12411269
12421270 <p>
12431271 A block is a list of statements,
@@ -1271,7 +1299,7 @@ of another block (see <a href="#3.3.4">&sect;3.3.4</a>). · 27 unmodified lines
12711299
12721300
12731301
1274−<h3>3.3.2 - <a name="3.3.2">Chunks</a></h3>
1302+<h3>3.3.2 &ndash; <a name="3.3.2">Chunks</a></h3>
12751303
12761304 <p>
12771305 The unit of execution of Lua is called a <em>chunk</em>.
@@ -1290,6 +1318,8 @@ As such, chunks can define local variables, · 12 unmodified lines
12901318 receive arguments, and return values.
12911319 Moreover, such anonymous function is compiled as in the
12921320 scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">&sect;2.2</a>).
1321+The resulting function always has <code>_ENV</code> as its only upvalue,
1322+even if it does not use that variable.
12931323
12941324
12951325 <p>
@@ -1311,7 +1341,7 @@ Lua automatically detects the file type and acts accordingly. · 15 unmodified lines
13111341
13121342
13131343
1314−<h3>3.3.3 - <a name="3.3.3">Assignment</a></h3>
1344+<h3>3.3.3 &ndash; <a name="3.3.3">Assignment</a></h3>
13151345
13161346 <p>
13171347 Lua allows multiple assignments.
@@ -1388,7 +1418,7 @@ is equivalent to the assignment · 70 unmodified lines
13881418
13891419
13901420
1391−<h3>3.3.4 - <a name="3.3.4">Control Structures</a></h3><p>
1421+<h3>3.3.4 &ndash; <a name="3.3.4">Control Structures</a></h3><p>
13921422 The control structures
13931423 <b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and
13941424 familiar syntax:
@@ -1458,7 +1488,7 @@ their (inner) blocks. · 63 unmodified lines
14581488
14591489
14601490
1461−<h3>3.3.5 - <a name="3.3.5">For Statement</a></h3>
1491+<h3>3.3.5 &ndash; <a name="3.3.5">For Statement</a></h3>
14621492
14631493 <p>
14641494
@@ -1589,7 +1619,7 @@ then assign them to other variables before breaking or exiting the loop. · 124 unmodified lines
15891619
15901620
15911621
1592−<h3>3.3.6 - <a name="3.3.6">Function Calls as Statements</a></h3><p>
1622+<h3>3.3.6 &ndash; <a name="3.3.6">Function Calls as Statements</a></h3><p>
15931623 To allow possible side-effects,
15941624 function calls can be executed as statements:
15951625
@@ -1603,7 +1633,7 @@ Function calls are explained in <a href="#3.4.9">&sect;3.4.9</a>. · 7 unmodified lines
16031633
16041634
16051635
1606−<h3>3.3.7 - <a name="3.3.7">Local Declarations</a></h3><p>
1636+<h3>3.3.7 &ndash; <a name="3.3.7">Local Declarations</a></h3><p>
16071637 Local variables can be declared anywhere inside a block.
16081638 The declaration can include an initial assignment:
16091639
@@ -1630,7 +1660,7 @@ The visibility rules for local variables are explained in <a href="#3.5">&sect;3 · 20 unmodified lines
16301660
16311661
16321662
1633−<h2>3.4 - <a name="3.4">Expressions</a></h2>
1663+<h2>3.4 &ndash; <a name="3.4">Expressions</a></h2>
16341664
16351665 <p>
16361666 The basic expressions in Lua are the following:
@@ -1716,7 +1746,7 @@ or <b>nil</b> if <code>f</code> does not return any values.) · 79 unmodified lines
17161746
17171747
17181748
1719−<h3>3.4.1 - <a name="3.4.1">Arithmetic Operators</a></h3><p>
1749+<h3>3.4.1 &ndash; <a name="3.4.1">Arithmetic Operators</a></h3><p>
17201750 Lua supports the usual arithmetic operators:
17211751 the binary <code>+</code> (addition),
17221752 <code>-</code> (subtraction), <code>*</code> (multiplication),
@@ -1739,7 +1769,7 @@ the quotient towards minus infinity. · 16 unmodified lines
17391769
17401770
17411771
1742−<h3>3.4.2 - <a name="3.4.2">Coercion</a></h3>
1772+<h3>3.4.2 &ndash; <a name="3.4.2">Coercion</a></h3>
17431773
17441774 <p>
17451775 Lua provides automatic conversion between
@@ -1756,7 +1786,7 @@ use the <code>format</code> function from the string library · 10 unmodified lines
17561786
17571787
17581788
1759−<h3>3.4.3 - <a name="3.4.3">Relational Operators</a></h3><p>
1789+<h3>3.4.3 &ndash; <a name="3.4.3">Relational Operators</a></h3><p>
17601790 The relational operators in Lua are
17611791
17621792 <pre>
@@ -1812,7 +1842,7 @@ and <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>. · 49 unmodified lines
18121842
18131843
18141844
1815−<h3>3.4.4 - <a name="3.4.4">Logical Operators</a></h3><p>
1845+<h3>3.4.4 &ndash; <a name="3.4.4">Logical Operators</a></h3><p>
18161846 The logical operators in Lua are
18171847 <b>and</b>, <b>or</b>, and <b>not</b>.
18181848 Like the control structures (see <a href="#3.3.4">&sect;3.3.4</a>),
@@ -1850,7 +1880,7 @@ Here are some examples: · 31 unmodified lines
18501880
18511881
18521882
1853−<h3>3.4.5 - <a name="3.4.5">Concatenation</a></h3><p>
1883+<h3>3.4.5 &ndash; <a name="3.4.5">Concatenation</a></h3><p>
18541884 The string concatenation operator in Lua is
18551885 denoted by two dots ('<code>..</code>').
18561886 If both operands are strings or numbers, then they are converted to
@@ -1861,7 +1891,7 @@ Otherwise, the "concat" metamethod is called (see <a href="#2.4">&sect;2.4</a>). · 4 unmodified lines
18611891
18621892
18631893
1864−<h3>3.4.6 - <a name="3.4.6">The Length Operator</a></h3>
1894+<h3>3.4.6 &ndash; <a name="3.4.6">The Length Operator</a></h3>
18651895
18661896 <p>
18671897 The length operator is denoted by the unary prefix operator <code>#</code>.
@@ -1895,7 +1925,7 @@ any value but strings through metamethods (see <a href="#2.4">&sect;2.4</a>). · 27 unmodified lines
18951925
18961926
18971927
1898−<h3>3.4.7 - <a name="3.4.7">Precedence</a></h3><p>
1928+<h3>3.4.7 &ndash; <a name="3.4.7">Precedence</a></h3><p>
18991929 Operator precedence in Lua follows the table below,
19001930 from lower to higher priority:
19011931
@@ -1919,7 +1949,7 @@ All other binary operators are left associative. · 17 unmodified lines
19191949
19201950
19211951
1922−<h3>3.4.8 - <a name="3.4.8">Table Constructors</a></h3><p>
1952+<h3>3.4.8 &ndash; <a name="3.4.8">Table Constructors</a></h3><p>
19231953 Table constructors are expressions that create tables.
19241954 Every time a constructor is evaluated, a new table is created.
19251955 A constructor can be used to create an empty table
@@ -1981,7 +2011,7 @@ as a convenience for machine-generated code. · 55 unmodified lines
19812011
19822012
19832013
1984−<h3>3.4.9 - <a name="3.4.9">Function Calls</a></h3><p>
2014+<h3>3.4.9 &ndash; <a name="3.4.9">Function Calls</a></h3><p>
19852015 A function call in Lua has the following syntax:
19862016
19872017 <pre>
@@ -2056,7 +2086,7 @@ So, none of the following examples are tail calls: · 68 unmodified lines
20562086
20572087
20582088
2059−<h3>3.4.10 - <a name="3.4.10">Function Definitions</a></h3>
2089+<h3>3.4.10 &ndash; <a name="3.4.10">Function Definitions</a></h3>
20602090
20612091 <p>
20622092 The syntax for function definition is
@@ -2206,7 +2236,7 @@ is syntactic sugar for · 143 unmodified lines
22062236
22072237
22082238
2209−<h2>3.5 - <a name="3.5">Visibility Rules</a></h2>
2239+<h2>3.5 &ndash; <a name="3.5">Visibility Rules</a></h2>
22102240
22112241 <p>
22122242
@@ -2268,7 +2298,7 @@ while all of them share the same <code>x</code>. · 55 unmodified lines
22682298
22692299
22702300
2271−<h1>4 - <a name="4">The Application Program Interface</a></h1>
2301+<h1>4 &ndash; <a name="4">The Application Program Interface</a></h1>
22722302
22732303 <p>
22742304
@@ -2296,7 +2326,7 @@ in file <code>luaconf.h</code>. · 21 unmodified lines
22962326
22972327
22982328
2299−<h2>4.1 - <a name="4.1">The Stack</a></h2>
2329+<h2>4.1 &ndash; <a name="4.1">The Stack</a></h2>
23002330
23012331 <p>
23022332 Lua uses a <em>virtual stack</em> to pass values to and from C.
@@ -2338,10 +2368,10 @@ if it lies between&nbsp;1 and the stack top · 35 unmodified lines
23382368
23392369
23402370
2341−<h2>4.2 - <a name="4.2">Stack Size</a></h2>
2371+<h2>4.2 &ndash; <a name="4.2">Stack Size</a></h2>
23422372
23432373 <p>
2344−When you interact with Lua API,
2374+When you interact with the Lua API,
23452375 you are responsible for ensuring consistency.
23462376 In particular,
23472377 <em>you are responsible for controlling stack overflow</em>.
@@ -2384,7 +2414,7 @@ Note that 0 is never an acceptable index. · 36 unmodified lines
23842414
23852415
23862416
2387−<h2>4.3 - <a name="4.3">Pseudo-Indices</a></h2>
2417+<h2>4.3 &ndash; <a name="4.3">Pseudo-Indices</a></h2>
23882418
23892419 <p>
23902420 Unless otherwise noted,
@@ -2399,7 +2429,7 @@ and the upvalues of a C&nbsp;function (see <a href="#4.4">&sect;4.4</a>). · 8 unmodified lines
23992429
24002430
24012431
2402−<h2>4.4 - <a name="4.4">C Closures</a></h2>
2432+<h2>4.4 &ndash; <a name="4.4">C Closures</a></h2>
24032433
24042434 <p>
24052435 When a C&nbsp;function is created,
@@ -2426,7 +2456,7 @@ produces an acceptable (but invalid) index. · 20 unmodified lines
24262456
24272457
24282458
2429−<h2>4.5 - <a name="4.5">Registry</a></h2>
2459+<h2>4.5 &ndash; <a name="4.5">Registry</a></h2>
24302460
24312461 <p>
24322462 Lua provides a <em>registry</em>,
@@ -2437,8 +2467,12 @@ This table is always located at pseudo-index · 4 unmodified lines
24372467 Any C&nbsp;library can store data into this table,
24382468 but it should take care to choose keys different from those used
24392469 by other libraries, to avoid collisions.
2440−Typically, you should use as key a string containing your library name
2441−or a light userdata with the address of a C&nbsp;object in your code.
2470+Typically, you should use as key a string containing your library name,
2471+or a light userdata with the address of a C&nbsp;object in your code,
2472+or any Lua object created by your code.
2473+As with global names,
2474+string keys starting with an underscore followed by
2475+uppercase letters are reserved for Lua.
24422476
24432477
24442478 <p>
@@ -2470,7 +2504,7 @@ This is the C&nbsp;equivalent to the <a href="#pdf-_G"><code>_G</code></a> globa · 25 unmodified lines
24702504
24712505
24722506
2473−<h2>4.6 - <a name="4.6">Error Handling in C</a></h2>
2507+<h2>4.6 &ndash; <a name="4.6">Error Handling in C</a></h2>
24742508
24752509 <p>
24762510 Internally, Lua uses the C <code>longjmp</code> facility to handle errors.
@@ -2509,7 +2543,7 @@ Inside a C&nbsp;function you can throw an error by calling <a href="#lua_error"> · 32 unmodified lines
25092543
25102544
25112545
2512−<h2>4.7 - <a name="4.7">Handling Yields in C</a></h2>
2546+<h2>4.7 &ndash; <a name="4.7">Handling Yields in C</a></h2>
25132547
25142548 <p>
25152549 Internally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.
@@ -2522,7 +2556,7 @@ because the <code>longjmp</code> removes its frame from the C stack. · 6 unmodified lines
25222556
25232557 <p>
25242558 To avoid this kind of problem,
2525−Lua raises an error whenever it tries to yield accross an API call,
2559+Lua raises an error whenever it tries to yield across an API call,
25262560 except for three functions:
25272561 <a href="#lua_yieldk"><code>lua_yieldk</code></a>, <a href="#lua_callk"><code>lua_callk</code></a>, and <a href="#lua_pcallk"><code>lua_pcallk</code></a>.
25282562 All those functions receive a <em>continuation function</em>
@@ -2577,7 +2611,7 @@ and its continuation is the result of a call to <a href="#lua_getctx"><code>lua_ · 48 unmodified lines
25772611
25782612
25792613
2580−<h2>4.8 - <a name="4.8">Functions and Types</a></h2>
2614+<h2>4.8 &ndash; <a name="4.8">Functions and Types</a></h2>
25812615
25822616 <p>
25832617 Here we list all functions and types from the C&nbsp;API in
@@ -2731,7 +2765,7 @@ The value of <code>op</code> must be one of the following constants: · 147 unmodified lines
27312765 <li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>:</b>performs multiplication (<code>*</code>)</li>
27322766 <li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>:</b>performs division (<code>/</code>)</li>
27332767 <li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>:</b>performs modulo (<code>%</code>)</li>
2734−<li><b><a name="pdf-LUA_OPPOw"><code>LUA_OPPOw</code></a>:</b>performs exponentiation (<code>^</code>)</li>
2768+<li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>:</b>performs exponentiation (<code>^</code>)</li>
27352769 <li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>:</b>performs mathematical negation (unary <code>-</code>)</li>
27362770
27372771 </ul>
@@ -3264,7 +3298,7 @@ because a pseudo-index is not an actual stack position. · 526 unmodified lines
32643298 <pre>typedef ptrdiff_t lua_Integer;</pre>
32653299
32663300 <p>
3267−The type used by the Lua API to represent integral values.
3301+The type used by the Lua API to represent signed integral values.
32683302
32693303
32703304 <p>
@@ -3493,8 +3527,8 @@ which is used for error messages and in debug information (see <a href="#4.9">&s · 222 unmodified lines
34933527
34943528
34953529 <p>
3496−If the resulting function has upvalues,
3497−the first upvalue is set to the value of the global environment
3530+If the resulting function has one upvalue,
3531+this upvalue is set to the value of the global environment
34983532 stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">&sect;4.5</a>).
34993533 (When loading main chunks,
35003534 this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).)
@@ -4334,7 +4368,7 @@ or <a name="pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the thread is suspended · 833 unmodified lines
43344368 You can only call functions in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.
43354369 You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>
43364370 (to start a new coroutine) or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a>
4337−(to resume a corotine).
4371+(to resume a coroutine).
43384372
43394373
43404374
@@ -4517,6 +4551,46 @@ otherwise, the function returns <code>NULL</code>. · 176 unmodified lines
45174551
45184552
45194553
4554+<hr><h3><a name="lua_tounsigned"><code>lua_tounsigned</code></a></h3><p>
4555+<span class="apii">[-0, +0, <em>-</em>]</span>
4556+<pre>lua_Unsigned lua_tounsigned (lua_State *L, int index);</pre>
4557+
4558+<p>
4559+A macro equivalent to <code>lua_tounsignedx(L, index, NULL)</code>.
4560+
4561+
4562+
4563+
4564+
4565+<hr><h3><a name="lua_tounsignedx"><code>lua_tounsignedx</code></a></h3><p>
4566+<span class="apii">[-0, +0, <em>-</em>]</span>
4567+<pre>lua_Unsigned lua_tounsignedx (lua_State *L, int index, int *isnum);</pre>
4568+
4569+<p>
4570+Converts the Lua value at the given acceptable index
4571+to the unsigned integral type <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
4572+The Lua value must be a number or a string convertible to a number
4573+(see <a href="#3.4.2">&sect;3.4.2</a>);
4574+otherwise, <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> returns&nbsp;0.
4575+
4576+
4577+<p>
4578+If the number is not an integer,
4579+it is truncated in some non-specified way.
4580+If the number is outside the range of representable values,
4581+it is normalized to the remainder of its division by
4582+one more than the maximum representable value.
4583+
4584+
4585+<p>
4586+If <code>isnum</code> is different from <code>NULL</code>,
4587+its referent is assigned a boolean value that
4588+indicates whether the operation succeeded.
4589+
4590+
4591+
4592+
4593+
45204594 <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>
45214595 <span class="apii">[-0, +0, <em>-</em>]</span>
45224596 <pre>void *lua_touserdata (lua_State *L, int index);</pre>
@@ -4569,6 +4643,22 @@ which must be one the values returned by <a href="#lua_type"><code>lua_type</cod · 46 unmodified lines
45694643
45704644
45714645
4646+<hr><h3><a name="lua_Unsigned"><code>lua_Unsigned</code></a></h3>
4647+<pre>typedef unsigned long lua_Unsigned;</pre>
4648+
4649+<p>
4650+The type used by the Lua API to represent unsigned integral values.
4651+It must have at least 32 bits.
4652+
4653+
4654+<p>
4655+By default it is an <code>unsigned int</code> or an <code>unsigned long</code>,
4656+whichever can hold 32-bit values.
4657+
4658+
4659+
4660+
4661+
45724662 <hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p>
45734663 <span class="apii">[-0, +0, <em>v</em>]</span>
45744664 <pre>const lua_Number *lua_version (lua_State *L);</pre>
@@ -4681,7 +4771,7 @@ by calling <a href="#lua_getctx"><code>lua_getctx</code></a>. · 106 unmodified lines
46814771
46824772
46834773
4684−<h2>4.9 - <a name="4.9">The Debug Interface</a></h2>
4774+<h2>4.9 &ndash; <a name="4.9">The Debug Interface</a></h2>
46854775
46864776 <p>
46874777 Lua has no built-in debugging facilities.
@@ -5165,16 +5255,19 @@ will return identical ids for those upvalue indices. · 477 unmodified lines
51655255
51665256 <hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3>
51675257 <pre>void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
5168− int fidx2, int n2);</pre><p>
5169−TO BE DONE!!
5258+ int fidx2, int n2);</pre>
51705259
5260+<p>
5261+Make the <code>n1</code>-th upvalue of the Lua closure at index <code>fidx1</code>
5262+refer to the <code>n2</code>-th upvalue of the Lua closure at index <code>fidx2</code>.
51715263
51725264
51735265
51745266
51755267
51765268
5177−<h1>5 - <a name="5">The Auxiliary Library</a></h1>
5269+
5270+<h1>5 &ndash; <a name="5">The Auxiliary Library</a></h1>
51785271
51795272 <p>
51805273
@@ -5220,7 +5313,7 @@ always throw an error if the check is not satisfied. · 39 unmodified lines
52205313
52215314
52225315
5223−<h2>5.1 - <a name="5.1">Functions and Types</a></h2>
5316+<h2>5.1 &ndash; <a name="5.1">Functions and Types</a></h2>
52245317
52255318 <p>
52265319 Here we list all functions and types from the auxiliary library
@@ -5591,6 +5684,18 @@ returns the userdata address (see <a href="#lua_touserdata"><code>lua_touserdata · 364 unmodified lines
55915684
55925685
55935686
5687+<hr><h3><a name="luaL_checkunsigned"><code>luaL_checkunsigned</code></a></h3><p>
5688+<span class="apii">[-0, +0, <em>v</em>]</span>
5689+<pre>lua_Unsigned luaL_checkunsigned (lua_State *L, int narg);</pre>
5690+
5691+<p>
5692+Checks whether the function argument <code>narg</code> is a number
5693+and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
5694+
5695+
5696+
5697+
5698+
55945699 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
55955700 <span class="apii">[-0, +0, <em>-</em>]</span>
55965701 <pre>void *luaL_checkversion (lua_State *L);</pre>
@@ -5959,7 +6064,7 @@ Otherwise, raises an error. · 362 unmodified lines
59596064
59606065 <p>
59616066 If <code>l</code> is not <code>NULL</code>,
5962−fills the position <code>*l</code> with the results's length.
6067+fills the position <code>*l</code> with the result's length.
59636068
59646069
59656070
@@ -5997,6 +6102,23 @@ Otherwise, raises an error. · 31 unmodified lines
59976102
59986103
59996104
6105+<hr><h3><a name="luaL_optunsigned"><code>luaL_optunsigned</code></a></h3><p>
6106+<span class="apii">[-0, +0, <em>v</em>]</span>
6107+<pre>lua_Unsigned luaL_optunsigned (lua_State *L,
6108+ int narg,
6109+ lua_Unsigned u);</pre>
6110+
6111+<p>
6112+If the function argument <code>narg</code> is a number,
6113+returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
6114+If this argument is absent or is <b>nil</b>,
6115+returns <code>u</code>.
6116+Otherwise, raises an error.
6117+
6118+
6119+
6120+
6121+
60006122 <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p>
60016123 <span class="apii">[-0, +0, <em>-</em>]</span>
60026124 <pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>
@@ -6222,7 +6344,7 @@ This function is used to build a prefix for error messages. · 219 unmodified lines
62226344
62236345
62246346
6225−<h1>6 - <a name="6">Standard Libraries</a></h1>
6347+<h1>6 &ndash; <a name="6">Standard Libraries</a></h1>
62266348
62276349 <p>
62286350 The standard Lua libraries provide useful functions
@@ -6291,7 +6413,7 @@ e.g., by using <a href="#lua_call"><code>lua_call</code></a>. · 62 unmodified lines
62916413
62926414
62936415
6294−<h2>6.1 - <a name="6.1">Basic Functions</a></h2>
6416+<h2>6.1 &ndash; <a name="6.1">Basic Functions</a></h2>
62956417
62966418 <p>
62976419 The basic library provides some core functions to Lua.
@@ -6513,7 +6635,8 @@ The default is "<code>bt</code>". · 215 unmodified lines
65136635 This function is similar to <a href="#pdf-load"><code>load</code></a>,
65146636 but sets <code>env</code> as the value of the first upvalue
65156637 of the created function in case of success.
6516−(Usually this first upvalue will be <code>_ENV</code> (see <a href="#2.2">&sect;2.2</a>).)
6638+(When loading main chunks,
6639+this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).)
65176640 The parameters after <code>env</code> are similar to those of <a href="#pdf-load"><code>load</code></a>, too.
65186641
65196642
@@ -6797,7 +6920,7 @@ except that it sets a new error handler <code>err</code>. · 277 unmodified lines
67976920
67986921
67996922
6800−<h2>6.2 - <a name="6.2">Coroutine Manipulation</a></h2>
6923+<h2>6.2 &ndash; <a name="6.2">Coroutine Manipulation</a></h2>
68016924
68026925 <p>
68036926 The operations related to coroutines comprise a sub-library of
@@ -6907,7 +7030,7 @@ Any arguments to <code>yield</code> are passed as extra results to <code>resume< · 103 unmodified lines
69077030
69087031
69097032
6910−<h2>6.3 - <a name="6.3">Modules</a></h2>
7033+<h2>6.3 &ndash; <a name="6.3">Modules</a></h2>
69117034
69127035 <p>
69137036 The package library provides basic
@@ -6954,9 +7077,9 @@ it tries an <em>all-in-one</em> loader (see <a href="#pdf-package.loaders"><code · 40 unmodified lines
69547077 <p>
69557078 Once a loader is found,
69567079 <code>require</code> calls the loader with a single argument, <code>modname</code>.
6957−If the loader returns any value,
7080+If the loader returns any non-nil value,
69587081 <code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.
6959−If the loader returns no value and
7082+If the loader does not return a non-nil value and
69607083 has not assigned any value to <code>package.loaded[modname]</code>,
69617084 then <code>require</code> assigns <b>true</b> to this entry.
69627085 In any case, <code>require</code> returns the
@@ -6995,7 +7118,7 @@ Default is '<code>?</code>'.</li> · 32 unmodified lines
69957118 is replaced by the executable's directory.
69967119 Default is '<code>!</code>'.</li>
69977120
6998−<li>The fifth line is a mark to ignore all before it when bulding the
7121+<li>The fifth line is a mark to ignore all before it when building the
69997122 <code>luaopen_</code> function name.
70007123 Default is '<code>-</code>'.</li>
70017124
@@ -7227,7 +7350,7 @@ or <b>nil</b> plus an error message if none succeeds. · 225 unmodified lines
72277350
72287351
72297352
7230−<h2>6.4 - <a name="6.4">String Manipulation</a></h2>
7353+<h2>6.4 &ndash; <a name="6.4">String Manipulation</a></h2>
72317354
72327355 <p>
72337356 This library provides generic functions for string manipulation,
@@ -7556,7 +7679,7 @@ The definition of what a lowercase letter is depends on the current locale. · 322 unmodified lines
75567679
75577680
75587681
7559−<h3>6.4.1 - <a name="6.4.1">Patterns</a></h3>
7682+<h3>6.4.1 &ndash; <a name="6.4.1">Patterns</a></h3>
75607683
75617684
75627685 <h4>Character Class:</h4><p>
@@ -7605,7 +7728,8 @@ when used to represent itself in a pattern. · 42 unmodified lines
76057728 represents the class which is the union of all
76067729 characters in <em>set</em>.
76077730 A range of characters can be specified by
7608−separating the end characters of the range with a '<code>-</code>'.
7731+separating the end characters of the range,
7732+in ascending order, with a '<code>-</code>',
76097733 All classes <code>%</code><em>x</em> described above can also be used as
76107734 components in <em>set</em>.
76117735 All other characters in <em>set</em> represent themselves.
@@ -7699,7 +7823,7 @@ such item matches an empty string at any position such that · 87 unmodified lines
76997823 the next character belongs to <em>set</em>
77007824 and the previous character does not belong to <em>set</em>.
77017825 The set <em>set</em> is interpreted as previously described.
7702−The beggining and the end of the subject are handled as if
7826+The beginning and the end of the subject are handled as if
77037827 they were the character '<code>\0</code>'.
77047828 </li>
77057829
@@ -7750,7 +7874,7 @@ string <code>"flaaap"</code>, there will be two captures: 3&nbsp;and&nbsp;5. · 44 unmodified lines
77507874
77517875
77527876
7753−<h2>6.5 - <a name="6.5">Table Manipulation</a></h2><p>
7877+<h2>6.5 &ndash; <a name="6.5">Table Manipulation</a></h2><p>
77547878 This library provides generic functions for table manipulation.
77557879 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>.
77567880
@@ -7858,7 +7982,7 @@ as defined by the length operator (see <a href="#3.4.6">&sect;3.4.6</a>). · 101 unmodified lines
78587982
78597983
78607984
7861−<h2>6.6 - <a name="6.6">Mathematical Functions</a></h2>
7985+<h2>6.6 &ndash; <a name="6.6">Mathematical Functions</a></h2>
78627986
78637987 <p>
78647988 This library is an interface to the standard C&nbsp;math library.
@@ -8187,22 +8311,30 @@ Returns the hyperbolic tangent of <code>x</code>. · 322 unmodified lines
81878311
81888312
81898313
8190−<h2>6.7 - <a name="6.7">Bitwise operations</a></h2>
8314+<h2>6.7 &ndash; <a name="6.7">Bitwise operations</a></h2>
81918315
81928316 <p>
81938317 This library provides bitwise operations.
8194−It provides all its functions inside the table <a name="pdf-bit"><code>bit</code></a>.
8318+It provides all its functions inside the table <a name="pdf-bit32"><code>bit32</code></a>.
8319+It uses upper case for function names to avoid collision with
8320+some reserved words (<b>and</b>, <b>or</b>, and <b>not</b>).
8321+
8322+
8323+<p>
81958324 Unless otherwise stated,
8196−all functions accept as arguments and return numbers
8197−in the range <em>[0,2^32 - 1]</em>.
8198−Standard Lua does not use 2-complement representation for numbers,
8199−so in standard Lua (that is, with floating-point numbers) you
8200−cannot use negative numbers with this library.
8201−In particular, -1 is not the same as 0xffffffff.
8325+all functions accept numeric arguments in the range
8326+<em>(-2<sup>51</sup>,+2<sup>51</sup>)</em>;
8327+each argument is normalized to
8328+the remainder of its division by <em>2<sup>32</sup></em>
8329+and truncated to an integer (in some unspecified way),
8330+so that its final value falls in the range <em>[0,2<sup>32</sup> - 1]</em>.
8331+Similarly, all results are in the range <em>[0,2<sup>32</sup> - 1]</em>.
8332+Note that <code>bit32.NOT(0)</code> is <code>0xFFFFFFFF</code>,
8333+which is different from <code>-1</code>.
82028334
82038335
82048336 <p>
8205−<hr><h3><a name="pdf-bit.band"><code>bit.band (&middot;&middot;&middot;)</code></a></h3>
8337+<hr><h3><a name="pdf-bit32.AND"><code>bit32.AND (&middot;&middot;&middot;)</code></a></h3>
82068338
82078339
82088340 <p>
@@ -8212,22 +8344,22 @@ Returns the bitwise and of its operands. · 3 unmodified lines
82128344
82138345
82148346 <p>
8215−<hr><h3><a name="pdf-bit.bnot"><code>bit.bnot (x)</code></a></h3>
8347+<hr><h3><a name="pdf-bit32.NOT"><code>bit32.NOT (x)</code></a></h3>
82168348
82178349
82188350 <p>
82198351 Returns the bitwise negation of <code>x</code>.
8220−For any valid <code>x</code>,
8352+For any integer <code>x</code>,
82218353 the following identity holds:
82228354
82238355 <pre>
8224− assert(bit.bnot(x) == 2^32 - 1 - x)
8356+ assert(bit32.NOT(x) == (-1 - x) % 2^32)
82258357 </pre>
82268358
82278359
82288360
82298361 <p>
8230−<hr><h3><a name="pdf-bit.bor"><code>bit.bor (&middot;&middot;&middot;)</code></a></h3>
8362+<hr><h3><a name="pdf-bit32.OR"><code>bit32.OR (&middot;&middot;&middot;)</code></a></h3>
82318363
82328364
82338365 <p>
@@ -8237,7 +8369,7 @@ Returns the bitwise or of its operands. · 3 unmodified lines
82378369
82388370
82398371 <p>
8240−<hr><h3><a name="pdf-bit.btest"><code>bit.btest (&middot;&middot;&middot;)</code></a></h3>
8372+<hr><h3><a name="pdf-bit32.TEST"><code>bit32.TEST (&middot;&middot;&middot;)</code></a></h3>
82418373
82428374
82438375 <p>
@@ -8248,7 +8380,7 @@ whether the bitwise and of its operands is different from zero. · 4 unmodified lines
82488380
82498381
82508382 <p>
8251−<hr><h3><a name="pdf-bit.bxor"><code>bit.bxor (&middot;&middot;&middot;)</code></a></h3>
8383+<hr><h3><a name="pdf-bit32.XOR"><code>bit32.XOR (&middot;&middot;&middot;)</code></a></h3>
82528384
82538385
82548386 <p>
@@ -8258,36 +8390,33 @@ Returns the bitwise exclusive or of its operands. · 3 unmodified lines
82588390
82598391
82608392 <p>
8261−<hr><h3><a name="pdf-bit.lshift"><code>bit.lshift (x, disp)</code></a></h3>
8393+<hr><h3><a name="pdf-bit32.ROL"><code>bit32.ROL (x, disp)</code></a></h3>
82628394
82638395
82648396 <p>
8265−Returns the number <code>x</code> shifted <code>disp</code> bits to the left.
8397+Returns the number <code>x</code> rotated <code>disp</code> bits to the left.
82668398 The number <code>disp</code> may be any representable integer.
8267−Negative displacements shift to the right.
8268−In any direction, vacant bits are filled with zeros.
8269−In particular,
8270−displacements with absolute values higher than
8271−the total number of bits in the representation of <code>x</code>
8272−result in zero (all bits are shifted out).
82738399
82748400
82758401 <p>
8276−For positive displacements,
8277−the following equality holds:
8402+For any valid displacement,
8403+the following identity holds:
82788404
82798405 <pre>
8280− assert(bit.lshift(b, disp) == (b * 2^disp) % 2^32)
8281−</pre>
8406+ assert(bit32.ROL(x, disp) == bit32.ROL(x, disp % 32))
8407+</pre><p>
8408+In particular,
8409+negative displacements rotate to the right.
8410+
82828411
82838412
82848413
82858414 <p>
8286−<hr><h3><a name="pdf-bit.rol"><code>bit.rol (x, disp)</code></a></h3>
8415+<hr><h3><a name="pdf-bit32.ROR"><code>bit32.ROR (x, disp)</code></a></h3>
82878416
82888417
82898418 <p>
8290−Returns the number <code>x</code> rotated <code>disp</code> bits to the left.
8419+Returns the number <code>x</code> rotated <code>disp</code> bits to the right.
82918420 The number <code>disp</code> may be any representable integer.
82928421
82938422
@@ -8296,38 +8425,62 @@ For any valid displacement, · 2 unmodified lines
82968425 the following identity holds:
82978426
82988427 <pre>
8299− assert(bit.rol(x, disp) == bit.rol(x, disp % 32))
8428+ assert(bit32.ROR(x, disp) == bit32.ROR(x, disp % 32))
83008429 </pre><p>
83018430 In particular,
8302−negative displacements rotate to the right.
8431+negative displacements rotate to the left.
83038432
83048433
83058434
83068435
83078436 <p>
8308−<hr><h3><a name="pdf-bit.ror"><code>bit.ror (x, disp)</code></a></h3>
8437+<hr><h3><a name="pdf-bit32.SAR"><code>bit32.SAR (x, disp)</code></a></h3>
83098438
83108439
83118440 <p>
8312−Returns the number <code>x</code> rotated <code>disp</code> bits to the right.
8441+Returns the number <code>x</code> shifted <code>disp</code> bits to the right.
83138442 The number <code>disp</code> may be any representable integer.
8443+Negative displacements shift to the left.
83148444
83158445
83168446 <p>
8317−For any valid displacement,
8318−the following identity holds:
8447+This shift operation is what is called arithmetic shift.
8448+Vacant bits on the left are filled
8449+with copies of the higher bit of <code>x</code>;
8450+vacant bits on the right are filled with zeros.
8451+In particular,
8452+displacements with absolute values higher than 31
8453+result in zero or <code>0xFFFFFFFF</code> (all bits are shifted out).
83198454
8320−<pre>
8321− assert(bit.ror(x, disp) == bit.ror(x, disp % 32))
8322−</pre><p>
8455+
8456+
8457+
8458+<p>
8459+<hr><h3><a name="pdf-bit32.SHL"><code>bit32.SHL (x, disp)</code></a></h3>
8460+
8461+
8462+<p>
8463+Returns the number <code>x</code> shifted <code>disp</code> bits to the left.
8464+The number <code>disp</code> may be any representable integer.
8465+Negative displacements shift to the right.
8466+In any direction, vacant bits are filled with zeros.
83238467 In particular,
8324−negative displacements rotate to the left.
8468+displacements with absolute values higher than 31
8469+result in zero (all bits are shifted out).
83258470
83268471
8472+<p>
8473+For positive displacements,
8474+the following equality holds:
8475+
8476+<pre>
8477+ assert(bit32.SHL(b, disp) == (b * 2^disp) % 2^32)
8478+</pre>
8479+
83278480
83288481
83298482 <p>
8330−<hr><h3><a name="pdf-bit.rshift"><code>bit.rshift (x, disp)</code></a></h3>
8483+<hr><h3><a name="pdf-bit32.SHR"><code>bit32.SHR (x, disp)</code></a></h3>
83318484
83328485
83338486 <p>
@@ -8336,8 +8489,7 @@ The number <code>disp</code> may be any representable integer. · 2 unmodified lines
83368489 Negative displacements shift to the left.
83378490 In any direction, vacant bits are filled with zeros.
83388491 In particular,
8339−displacements with absolute values higher than
8340−the total number of bits in the representation of <code>x</code>
8492+displacements with absolute values higher than 31
83418493 result in zero (all bits are shifted out).
83428494
83438495
@@ -8346,13 +8498,11 @@ For positive displacements, · 2 unmodified lines
83468498 the following equality holds:
83478499
83488500 <pre>
8349− assert(bit.rshift(b, disp) == math.floor(b * 2^-disp))
8501+ assert(bit32.SHR(b, disp) == math.floor(b % 2^32 / 2^disp))
83508502 </pre>
83518503
83528504 <p>
83538505 This shift operation is what is called logical shift.
8354−For an arithmetic shift,
8355−you should use the arithmetic operators.
83568506
83578507
83588508
@@ -8360,7 +8510,7 @@ you should use the arithmetic operators. · 1 unmodified line
83608510
83618511
83628512
8363−<h2>6.8 - <a name="6.8">Input and Output Facilities</a></h2>
8513+<h2>6.8 &ndash; <a name="6.8">Input and Output Facilities</a></h2>
83648514
83658515 <p>
83668516 The I/O library provides two different styles for file manipulation.
@@ -8584,7 +8734,7 @@ but that takes an unpredictable amount of time to happen. · 217 unmodified lines
85848734
85858735 <p>
85868736 If <code>file</code> was created with <a href="#pdf-io.popen"><code>io.popen</code></a>,
8587−a sucessful close returns the exit status of the process.
8737+a successful close returns the exit status of the process.
85888738
85898739
85908740
@@ -8768,7 +8918,7 @@ Otherwise it returns <b>nil</b> plus a string describing the error. · 177 unmodified lines
87688918
87698919
87708920
8771−<h2>6.9 - <a name="6.9">Operating System Facilities</a></h2>
8921+<h2>6.9 &ndash; <a name="6.9">Operating System Facilities</a></h2>
87728922
87738923 <p>
87748924 This library is implemented through table <a name="pdf-os"><code>os</code></a>.
@@ -8860,9 +9010,13 @@ and zero otherwise. · 85 unmodified lines
88609010
88619011
88629012 <p>
8863−Calls the C&nbsp;function <code>exit</code>,
8864−with an optional <code>code</code>,
8865−to terminate the host program.
9013+Calls the C&nbsp;function <code>exit</code> to terminate the host program.
9014+If <code>code</code> is <b>true</b>,
9015+the returned status is <code>EXIT_SUCCESS</code>;
9016+if <code>code</code> is <b>false</b>,
9017+the returned status is <code>EXIT_FAILURE</code>.
9018+if <code>code</code> is a number,
9019+the returned status is this number.
88669020 The default value for <code>code</code> is the success code.
88679021
88689022
@@ -8994,7 +9148,7 @@ which automatically removes the file when the program ends. · 125 unmodified lines
89949148
89959149
89969150
8997−<h2>6.10 - <a name="6.10">The Debug Library</a></h2>
9151+<h2>6.10 &ndash; <a name="6.10">The Debug Library</a></h2>
89989152
89999153 <p>
90009154 This library provides
@@ -9305,11 +9459,12 @@ will return identical ids for those upvalue indices. · 304 unmodified lines
93059459
93069460
93079461 <p>
9308−<hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin ()</code></a></h3>
9462+<hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (func1, n1, func2, n2)</code></a></h3>
93099463
93109464
93119465 <p>
9312−TO BE DONE!!
9466+Make the <code>n1</code>-th upvalue of the Lua closure <code>func1</code>
9467+refer to the <code>n2</code>-th upvalue of the Lua closure <code>func2</code>.
93139468
93149469
93159470
@@ -9317,16 +9472,16 @@ TO BE DONE!! · 1 unmodified line
93179472
93189473
93199474
9320−<h1>7 - <a name="7">Lua Stand-alone</a></h1>
9475+<h1>7 &ndash; <a name="7">Lua Standalone</a></h1>
93219476
93229477 <p>
93239478 Although Lua has been designed as an extension language,
93249479 to be embedded in a host C&nbsp;program,
9325−it is also frequently used as a stand-alone language.
9326−An interpreter for Lua as a stand-alone language,
9480+it is also frequently used as a standalone language.
9481+An interpreter for Lua as a standalone language,
93279482 called simply <code>lua</code>,
93289483 is provided with the standard distribution.
9329−The stand-alone interpreter includes
9484+The standalone interpreter includes
93309485 all standard libraries, including the debug library.
93319486 Its usage is:
93329487
@@ -9443,7 +9598,7 @@ right after the assignment to <code>_PROMPT</code>. · 110 unmodified lines
94439598 <p>
94449599 To allow the use of Lua as a
94459600 script interpreter in Unix systems,
9446−the stand-alone interpreter skips
9601+the standalone interpreter skips
94479602 the first line of a chunk if it starts with <code>#</code>.
94489603 Therefore, Lua scripts can be made into executable programs
94499604 by using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,
@@ -9464,7 +9619,7 @@ is a more portable solution.) · 14 unmodified lines
94649619
94659620
94669621
9467−<h1>8 - <a name="8">Incompatibilities with the Previous Version</a></h1>
9622+<h1>8 &ndash; <a name="8">Incompatibilities with the Previous Version</a></h1>
94689623
94699624 <p>
94709625 Here we list the incompatibilities that you can find when moving a program
@@ -9476,7 +9631,7 @@ all these compatibility options will be removed in the next version of Lua. · 5 unmodified lines
94769631
94779632
94789633
9479−<h2>8.1 - <a name="8.1">Changes in the Language</a></h2>
9634+<h2>8.1 &ndash; <a name="8.1">Changes in the Language</a></h2>
94809635 <ul>
94819636
94829637 <li>
@@ -9500,7 +9655,7 @@ All threads share a single fixed environment. · 17 unmodified lines
95009655 <li>
95019656 The event <em>tail return</em> in debug hooks was removed.
95029657 Instead, tail calls generate a special new event,
9503−<em>tail call</em>, so that the debuger can know there will
9658+<em>tail call</em>, so that the debugger can know there will
95049659 not be a corresponding return event.
95059660 </li>
95069661
@@ -9509,7 +9664,7 @@ not be a corresponding return event. · 2 unmodified lines
95099664
95109665
95119666
9512−<h2>8.2 - <a name="8.2">Changes in the Libraries</a></h2>
9667+<h2>8.2 &ndash; <a name="8.2">Changes in the Libraries</a></h2>
95139668 <ul>
95149669
95159670 <li>
@@ -9566,7 +9721,7 @@ to restrict it to loading textual chunks. · 50 unmodified lines
95669721
95679722
95689723
9569−<h2>8.3 - <a name="8.3">Changes in the API</a></h2>
9724+<h2>8.3 &ndash; <a name="8.3">Changes in the API</a></h2>
95709725 <ul>
95719726
95729727 <li>
@@ -9593,6 +9748,24 @@ use the new functions · 20 unmodified lines
95939748 <a href="#lua_getuservalue"><code>lua_getuservalue</code></a> and <a href="#lua_setuservalue"><code>lua_setuservalue</code></a>.
95949749 </li>
95959750
9751+<li>
9752+Function <code>luaL_register</code> is deprecated.
9753+Use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> so that your module does not
9754+create globals anymore.
9755+(Modules are not expected to set global variables anymore.)
9756+</li>
9757+
9758+<li>
9759+Finalizers ("<code>__gc</code>" metamethods) for userdata are called in the
9760+reverse order that they were marked,
9761+not that they were created (see <a href="#2.5.1">&sect;2.5.1</a>).
9762+(Most userdata are marked immediately after they are created.)
9763+Moreover,
9764+if the metatable does not have a "<code>__gc</code>" field when set,
9765+the finalizer will not be called,
9766+even if it is set later.
9767+</li>
9768+
95969769 <li>
95979770 <code>luaL_typerror</code> was renamed <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>,
95989771 to have a correct spelling.
@@ -9618,7 +9791,7 @@ Function <code>lua_objlen</code> was renamed <a href="#lua_rawlen"><code>lua_raw · 19 unmodified lines
96189791
96199792
96209793
9621−<h1>9 - <a name="9">The Complete Syntax of Lua</a></h1>
9794+<h1>9 &ndash; <a name="9">The Complete Syntax of Lua</a></h1>
96229795
96239796 <p>
96249797 Here is the complete syntax of Lua in extended BNF.
@@ -9644,8 +9817,7 @@ Here is the complete syntax of Lua in extended BNF. · 19 unmodified lines
96449817 <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> |
96459818 <b>function</b> funcname funcbody |
96469819 <b>local</b> <b>function</b> Name funcbody |
9647− <b>local</b> namelist [&lsquo<b>=</b>&rsquo; explist] |
9648− <b>in</b> exp <b>do</b> block <b>end</b>
9820+ <b>local</b> namelist [&lsquo<b>=</b>&rsquo; explist]
96499821
96509822 laststat ::= <b>return</b> [explist] | <b>break</b>
96519823
@@ -9701,10 +9873,10 @@ Here is the complete syntax of Lua in extended BNF. · 49 unmodified lines
97019873 <HR>
97029874 <SMALL>
97039875 Last update:
9704−Fri Jul 30 16:41:34 BRT 2010
9876+Sat Oct 30 21:36:20 BRST 2010
97059877 </SMALL>
97069878 <!--
9707−Last change: revised for Lua 5.2.0 (work4)
9879+Last change: revised for Lua 5.2.0 (work5)
97089880 -->
97099881
97109882 </body></html>
doc/readme.html+63−65
@@ -27,7 +27,7 @@ tt, kbd, code { · 26 unmodified lines
2727 <HR>
2828 <H1>
2929 <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
30−Welcome to Lua 5.2 (work4)
30+Welcome to Lua 5.2 (work5)
3131 </H1>
3232
3333 <P>
@@ -89,12 +89,10 @@ because · 55 unmodified lines
8989 Lua is implemented in pure ANSI C, and compiles unmodified in all known
9090 platforms that have an ANSI C compiler.
9191 Lua also compiles unmodified as C++.
92−
93−<P>
94−The instructions below are for Unix-like platforms.
95−There are also
96−<A HREF="#other">instructions for other systems</A>.
97−See below for
92+The instructions given below for building Lua are for Unix-like platforms.
93+See also
94+<A HREF="#other">instructions for other systems</A>
95+and
9896 <A HREF="#customization">customization options</A>.
9997
10098 <P>
@@ -250,7 +248,7 @@ interpreter: · 149 unmodified lines
250248 <DT>
251249 compiler:
252250 <DD>
253− library, luac.c print.c
251+ library, luac.c
254252 </DL>
255253
256254 <P>
@@ -258,7 +256,7 @@ compiler: · 1 unmodified line
258256 create and use libraries with your compiler. Moreover, to dynamically load
259257 C libraries for Lua you'll need to know how to create dynamic libraries
260258 and you'll need to make sure that the Lua API functions are accessible to
261− those dynamic libraries &mdash; but you do <EM>not</EM> want to link the Lua library
259+ those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library
262260 into each dynamic library. For Unix, we recommend that the Lua library
263261 be linked statically into the host program and its symbols exported for
264262 dynamic linking; src/Makefile does this for the Lua interpreter.
@@ -268,18 +266,6 @@ compiler: · 3 unmodified lines
268266 As mentioned above, you may edit src/luaconf.h to customize
269267 some features before building Lua.
270268
271−<H2><A NAME="changes">Changes since Lua 5.2.0 (work3)</A></H2>
272−
273−<UL>
274−<LI> <CODE>module</CODE> and <CODE>luaL_register</CODE> deprecated, replaced by <CODE>luaL_newlib</CODE> and <CODE>luaL_setfuncs</CODE>.
275−<LI> new function <CODE>luaL_requiref</CODE>.
276−<LI> caching of Lua closures for resue.
277−<LI> version-specific environment variables (<CODE>LUA_PATH_5_2</CODE>, etc.).
278−<LI> new class '%g' in patterns.
279−<LI> <CODE>debug.getlocal</CODE> gets parameter names of inactive functions.
280−<LI> new functions <CODE>lua_tonumberx</CODE> and <CODE>lua_tointegerx</CODE>.
281−</UL>
282−
283269 <H2><A NAME="changes">Changes since Lua 5.1</A></H2>
284270
285271 <P>
@@ -289,61 +275,73 @@ The · 3 unmodified lines
289275 lists the
290276 <A HREF="manual.html#8">incompatibilities</A> that had to be introduced.
291277
292−<H3>Language</H3>
278+<H3>Main changes</H3>
293279 <UL>
294−<LI> new lexical environments.
295−<LI> no more fenv for threads.
280+<LI> yieldable pcall and metamethods
281+<LI> new <CODE>_ENV</CODE> scheme
296282 <LI> ephemeron tables
297− (tables with weak keys only visit value when key is accessible).
298−<LI> yieldable pcall and metamethods.
299−<LI> tables honor the <CODE>__len</CODE> metamethod.
300−<LI> max constants per function raised to 2^26.
301−<LI> hex escapes in strings.
302−<LI> no more verification of opcode consistency.
283+<LI> new library for bitwise operations
284+<LI> light C functions
285+<LI> emergency garbage collector
286+</UL>
287+
288+Here are the other changes introduced in Lua 5.2:
289+<H3>Language</H3>
290+<UL>
291+<LI> no more fenv for threads or functions
292+<LI> tables honor the <CODE>__len</CODE> metamethod
293+<LI> hex and <CODE>\*</CODE> escapes in strings
294+<LI> order metamethods work for different types
295+<LI> no more verification of opcode consistency
296+<LI> hook event "tail return" replaced by "tail call"
297+<LI> empty statement
303298 </UL>
304299
305300 <H3>Libraries</H3>
306301 <UL>
307−<LI> new library for bitwise operations.
308−<LI> new metamethods <CODE>__pairs</CODE> and <CODE>__ipairs</CODE>.
309−<LI> arguments for function called through <CODE>xpcall</CODE>.
310−<LI> optional argument to load (to control binary x text).
311−<LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL).
312−<LI> new function <CODE>package.searchpath</CODE>.
313−<LI> optional base in <CODE>math.log</CODE>.
314−<LI> <CODE>file:write</CODE> returns <CODE>file</CODE>.
315−<LI> closing a pipe returns exit status.
316−<LI> <CODE>os.exit</CODE> may close state.
317−<LI> new option 'isrunning' for <CODE>collectgarbage</CODE> and <CODE>lua_gc</CODE>.
318−<LI> frontier patterns.
319−<LI> <CODE>ipairs</CODE> now goes until #t.
302+<LI> new metamethods <CODE>__pairs</CODE> and <CODE>__ipairs</CODE>
303+<LI> arguments for function called through <CODE>xpcall</CODE>
304+<LI> optional 'mode' argument to load (to control binary x text)
305+<LI> new function <CODE>loadin</CODE>
306+<LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL)
307+<LI> new function <CODE>package.searchpath</CODE>
308+<LI> optional base in <CODE>math.log</CODE>
309+<LI> <CODE>file:write</CODE> returns <CODE>file</CODE>
310+<LI> closing a pipe returns exit status
311+<LI> <CODE>os.exit</CODE> may close state
312+<LI> new option 'isrunning' for <CODE>collectgarbage</CODE> and <CODE>lua_gc</CODE>
313+<LI> frontier patterns
314+<LI> <CODE>\0</CODE> in patterns
315+<LI> new option <CODE>*L</CODE> for <CODE>io.read</CODE>
316+<LI> options for <CODE>io.lines</CODE>
320317 </UL>
321318
322319 <H3>C API</H3>
323320 <UL>
324−<LI> mainthread predefined in the registry.
325−<LI> <CODE>lua_cpcall</CODE> changed to a predefined function in the registry.
326−<LI> new constants <CODE>LUA_OK</CODE> and <CODE>LUA_ERRGCMM</CODE>.
327−<LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE>.
328−<LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE>.
329−<LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string.
330−<LI> new <CODE>luaL_testudata</CODE>.
331−<LI> new <CODE>luaL_tolstring</CODE>.
332−<LI> new <CODE>lua_copy</CODE>.
333−<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>.
334−<LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API.
321+<LI> main thread predefined in the registry
322+<LI> new constants <CODE>LUA_OK</CODE> and <CODE>LUA_ERRGCMM</CODE>
323+<LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE>
324+<LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE>
325+<LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string
326+<LI> new <CODE>luaL_testudata</CODE>
327+<LI> new <CODE>luaL_tolstring</CODE>
328+<LI> new <CODE>lua_copy</CODE>
329+<LI> new <CODE>lua_absindex</CODE>
330+<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>
331+<LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API
335332 </UL>
336333
337334 <H3>Implementation</H3>
338335 <UL>
339−<LI> emergency garbage collector
340− (core forces a full collection when allocation fails).
341−<LI> udata with finalizers are kept in a separated list for the GC.
342−<LI> CallInfo stack now is a linked list.
343−<LI> internal (immutable) version of ctypes.
344−<LI> parser uses much less C-stack space (no more auto arrays).
345−<LI> new hash for floats.
346−<LI> handling of non-string error messages in the standalone interpreter.
336+<LI> max constants per function raised to 2<SUP>26</SUP>
337+<LI> internal (immutable) version of ctypes
338+<LI> simpler implementation for string buffers
339+<LI> udata with finalizers are kept in a separated list for the GC
340+<LI> <CODE>CallInfo</CODE>stack now is a linked list
341+<LI> parser uses much less C-stack space (no more auto arrays)
342+<LI> new hash for floats
343+<LI> handling of non-string error messages in the standalone interpreter
344+<LI> generational mode for garbage collection (experimental)
347345 </UL>
348346
349347 <H2><A NAME="license">License</A></H2>
@@ -352,7 +350,7 @@ lists the · 2 unmodified lines
352350 </A>
353351
354352 <P>
355−Lua is free software licensed under the terms of the
353+Lua is free software distributed under the terms of the
356354 <A HREF="http://www.opensource.org/licenses/mit-license.html">MIT license</A>
357355 reproduced below;
358356 it can be used for any purpose, including commercial purposes,
@@ -392,10 +390,10 @@ THE SOFTWARE. · 33 unmodified lines
392390 <HR>
393391 <SMALL>
394392 Last update:
395−Fri Jul 30 15:12:25 BRT 2010
393+Sat Oct 30 21:36:38 BRST 2010
396394 </SMALL>
397395 <!--
398−Last change: revised for Lua 5.2.0 (work4)
396+Last change: revised for Lua 5.2.0 (work5)
399397 -->
400398
401399 </BODY>
src/Makefile+5−9
@@ -33,7 +33,7 @@ LUA_T= lua · 32 unmodified lines
3333 LUA_O= lua.o
3434
3535 LUAC_T= luac
36−LUAC_O= luac.o print.o
36+LUAC_O= luac.o
3737
3838 ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
3939 ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
@@ -62,7 +62,7 @@ clean: · 22 unmodified lines
6262 $(RM) $(ALL_T) $(ALL_O)
6363
6464 depend:
65− @$(CC) $(CFLAGS) -MM l*.c print.c
65+ @$(CC) $(CFLAGS) -MM l*.c
6666
6767 echo:
6868 @echo "PLAT= $(PLAT)"
@@ -94,8 +94,7 @@ bsd: · 25 unmodified lines
9494 freebsd:
9595 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
9696
97−generic:
98− $(MAKE) $(ALL) MYCFLAGS=
97+generic: $(ALL)
9998
10099 linux:
101100 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline -lncurses"
@@ -170,16 +169,13 @@ ltablib.o: ltablib.c lua.h luaconf.h lauxlib.h lualib.h · 68 unmodified lines
170169 ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
171170 lmem.h lstring.h lgc.h ltable.h
172171 lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
173−luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \
174− lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \
175− lundump.h
172+luac.o: luac.c lua.h luaconf.h lauxlib.h lobject.h llimits.h lstate.h \
173+ ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h
176174 lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
177175 llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
178176 lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
179177 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
180178 lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
181179 lzio.h
182−print.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \
183− ltm.h lzio.h lmem.h lopcodes.h lundump.h
184180
185181 # (end of Makefile)
src/lapi.c+43−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.133 2010/07/25 15:18:19 roberto Exp $
2+** $Id: lapi.c,v 2.139 2010/10/25 20:31:11 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -85,7 +85,7 @@ LUA_API int lua_checkstack (lua_State *L, int size) { · 79 unmodified lines
8585 if (L->stack_last - L->top > size) /* stack large enough? */
8686 res = 1; /* yes; check is OK */
8787 else { /* no; need to grow stack */
88− int inuse = L->top - L->stack + EXTRA_STACK;
88+ int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;
8989 if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */
9090 res = 0; /* no */
9191 else /* try to grow stack */
@@ -347,6 +347,23 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum) { · 255 unmodified lines
347347 }
348348
349349
350+LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) {
351+ TValue n;
352+ const TValue *o = index2addr(L, idx);
353+ if (tonumber(o, &n)) {
354+ lua_Unsigned res;
355+ lua_Number num = nvalue(o);
356+ lua_number2uint(res, num);
357+ if (isnum) *isnum = 1;
358+ return res;
359+ }
360+ else {
361+ if (isnum) *isnum = 0;
362+ return 0;
363+ }
364+}
365+
366+
350367 LUA_API int lua_toboolean (lua_State *L, int idx) {
351368 const TValue *o = index2addr(L, idx);
352369 return !l_isfalse(o);
@@ -452,6 +469,16 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { · 99 unmodified lines
452469 }
453470
454471
472+LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
473+ lua_Number n;
474+ lua_lock(L);
475+ n = lua_uint2number(u);
476+ setnvalue(L->top, n);
477+ api_incr_top(L);
478+ lua_unlock(L);
479+}
480+
481+
455482 LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
456483 TString *ts;
457484 lua_lock(L);
@@ -799,6 +826,7 @@ LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx, · 341 unmodified lines
799826 api_check(L, k == NULL || !isLua(L->ci),
800827 "cannot use continuations inside hooks");
801828 api_checknelems(L, nargs+1);
829+ api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
802830 checkresults(L, nargs, nresults);
803831 func = L->top - (nargs+1);
804832 if (k != NULL && L->nny == 0) { /* need to prepare continuation? */
@@ -839,6 +867,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, · 34 unmodified lines
839867 api_check(L, k == NULL || !isLua(L->ci),
840868 "cannot use continuations inside hooks");
841869 api_checknelems(L, nargs+1);
870+ api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
842871 checkresults(L, nargs, nresults);
843872 if (errfunc == 0)
844873 func = 0;
@@ -889,7 +918,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, · 44 unmodified lines
889918 /* get global table from registry */
890919 Table *reg = hvalue(&G(L)->l_registry);
891920 const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
892− /* set global table as 1st upvalue of 'f' (may be _ENV) */
921+ /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
893922 setobj(L, f->l.upvals[0]->v, gt);
894923 luaC_barrier(L, f->l.upvals[0], gt);
895924 }
@@ -974,6 +1003,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 78 unmodified lines
9741003 g->gcpause = data;
9751004 break;
9761005 }
1006+ case LUA_GCSETMAJORINC: {
1007+ res = g->gcmajorinc;
1008+ g->gcmajorinc = data;
1009+ break;
1010+ }
9771011 case LUA_GCSETSTEPMUL: {
9781012 res = g->gcstepmul;
9791013 g->gcstepmul = data;
@@ -1100,11 +1134,15 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val, · 120 unmodified lines
11001134 return "";
11011135 }
11021136 else {
1137+ const char *name;
11031138 Proto *p = f->l.p;
11041139 if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
11051140 *val = f->l.upvals[n-1]->v;
11061141 if (owner) *owner = obj2gco(f->l.upvals[n - 1]);
1107− return getstr(p->upvalues[n-1].name);
1142+ name = getstr(p->upvalues[n-1].name);
1143+ if (name == NULL) /* no debug information? */
1144+ name = "";
1145+ return name;
11081146 }
11091147 }
11101148
@@ -1144,13 +1182,11 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { · 33 unmodified lines
11441182
11451183 static UpVal **getupvalref (lua_State *L, int fidx, int n, Closure **pf) {
11461184 Closure *f;
1147− Proto *p;
11481185 StkId fi = index2addr(L, fidx);
11491186 api_check(L, ttisclosure(fi), "Lua function expected");
11501187 f = clvalue(fi);
11511188 api_check(L, !f->c.isC, "Lua function expected");
1152− p = f->l.p;
1153− api_check(L, (1 <= n && n <= p->sizeupvalues), "invalid upvalue index");
1189+ api_check(L, (1 <= n && n <= f->l.p->sizeupvalues), "invalid upvalue index");
11541190 if (pf) *pf = f;
11551191 return &f->l.upvals[n - 1]; /* get its upvalue pointer */
11561192 }
src/lauxlib.c+55−20
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.219 2010/07/28 15:51:59 roberto Exp $
2+** $Id: lauxlib.c,v 1.224 2010/10/29 12:52:21 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -330,11 +330,26 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { · 324 unmodified lines
330330 }
331331
332332
333+LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int narg) {
334+ int isnum;
335+ lua_Unsigned d = lua_tounsignedx(L, narg, &isnum);
336+ if (!isnum)
337+ tag_error(L, narg, LUA_TNUMBER);
338+ return d;
339+}
340+
341+
333342 LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
334343 lua_Integer def) {
335344 return luaL_opt(L, luaL_checkinteger, narg, def);
336345 }
337346
347+
348+LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int narg,
349+ lua_Unsigned def) {
350+ return luaL_opt(L, luaL_checkunsigned, narg, def);
351+}
352+
338353 /* }====================================================== */
339354
340355
@@ -434,7 +449,7 @@ LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { · 93 unmodified lines
434449 */
435450
436451 /* index of free-list header */
437−#define freelist "lua-freelist"
452+#define freelist 0
438453
439454
440455 LUALIB_API int luaL_ref (lua_State *L, int t) {
@@ -444,12 +459,12 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { · 3 unmodified lines
444459 lua_pop(L, 1); /* remove from stack */
445460 return LUA_REFNIL; /* `nil' has a unique fixed reference */
446461 }
447− lua_getfield(L, t, freelist); /* get first free element */
448− ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */
462+ lua_rawgeti(L, t, freelist); /* get first free element */
463+ ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
449464 lua_pop(L, 1); /* remove it from stack */
450465 if (ref != 0) { /* any free element? */
451466 lua_rawgeti(L, t, ref); /* remove it from list */
452− lua_setfield(L, t, freelist); /* (t[freelist] = t[ref]) */
467+ lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
453468 }
454469 else /* no free elements */
455470 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
@@ -461,10 +476,10 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { · 5 unmodified lines
461476 LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
462477 if (ref >= 0) {
463478 t = lua_absindex(L, t);
464− lua_getfield(L, t, freelist);
479+ lua_rawgeti(L, t, freelist);
465480 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
466481 lua_pushinteger(L, ref);
467− lua_setfield(L, t, freelist); /* t[freelist] = ref */
482+ lua_rawseti(L, t, freelist); /* t[freelist] = ref */
468483 }
469484 }
470485
@@ -511,17 +526,32 @@ static int errfile (lua_State *L, const char *what, int fnameindex) { · 40 unmodified lines
511526 }
512527
513528
529+static int skipBOM (LoadF *lf) {
530+ const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */
531+ int c;
532+ lf->n = 0;
533+ do {
534+ c = getc(lf->f);
535+ if (c == EOF || c != *(unsigned char *)p++) return c;
536+ lf->buff[lf->n++] = c; /* to be read by the parser */
537+ } while (*p != '\0');
538+ lf->n = 0; /* prefix matched; discard it */
539+ return getc(lf->f); /* return next character */
540+}
541+
542+
514543 /*
515−** reads the first character of file 'f' and skips its first line
516−** if it starts with '#'. Returns true if it skipped the first line.
517−** In any case, '*cp' has the first "valid" character of the file
518−** (after the optional first-line comment).
544+** reads the first character of file 'f' and skips an optional BOM mark
545+** in its beginning plus its first line if it starts with '#'. Returns
546+** true if it skipped the first line. In any case, '*cp' has the
547+** first "valid" character of the file (after the optional BOM and
548+** a first-line comment).
519549 */
520−static int skipcomment (FILE *f, int *cp) {
521− int c = *cp = getc(f);
550+static int skipcomment (LoadF *lf, int *cp) {
551+ int c = *cp = skipBOM(lf);
522552 if (c == '#') { /* first line is a comment (Unix exec. file)? */
523− while ((c = getc(f)) != EOF && c != '\n') ; /* skip first line */
524− *cp = getc(f); /* skip end-of-line */
553+ while ((c = getc(lf->f)) != EOF && c != '\n') ; /* skip first line */
554+ *cp = getc(lf->f); /* skip end-of-line */
525555 return 1; /* there was a comment */
526556 }
527557 else return 0; /* no comment */
@@ -542,14 +572,12 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { · 14 unmodified lines
542572 lf.f = fopen(filename, "r");
543573 if (lf.f == NULL) return errfile(L, "open", fnameindex);
544574 }
545− lf.n = 0;
546− if (skipcomment(lf.f, &c)) /* read initial portion */
575+ if (skipcomment(&lf, &c)) /* read initial portion */
547576 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
548577 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
549578 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
550579 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
551− lf.n = 0;
552− skipcomment(lf.f, &c); /* re-read initial portion */
580+ skipcomment(&lf, &c); /* re-read initial portion */
553581 }
554582 if (c != EOF)
555583 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
@@ -628,7 +656,7 @@ LUALIB_API int luaL_len (lua_State *L, int idx) { · 72 unmodified lines
628656 int l;
629657 int isnum;
630658 lua_len(L, idx);
631− l = lua_tointegerx(L, -1, &isnum);
659+ l = (int)lua_tointegerx(L, -1, &isnum);
632660 if (!isnum)
633661 luaL_error(L, "object length is not a number");
634662 lua_pop(L, 1); /* remove object */
@@ -848,5 +876,12 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) { · 213 unmodified lines
848876 else if (*v != ver)
849877 luaL_error(L, "version mismatch: app. needs %d, Lua core provides %f",
850878 ver, *v);
879+ /* check conversions number -> integer types */
880+ lua_pushnumber(L, -(lua_Number)0x1234);
881+ if (lua_tointeger(L, -1) != -0x1234 ||
882+ lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234)
883+ luaL_error(L, "bad conversion number->int;"
884+ " must recompile Lua with proper settings");
885+ lua_pop(L, 1);
851886 }
852887
src/lauxlib.h+4−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.108 2010/07/02 11:38:13 roberto Exp $
2+** $Id: lauxlib.h,v 1.109 2010/10/25 20:31:11 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -44,6 +44,9 @@ LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); · 38 unmodified lines
4444 LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
4545 LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
4646 lua_Integer def);
47+LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg);
48+LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg,
49+ lua_Unsigned def);
4750
4851 LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
4952 LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
src/lbaselib.c+11−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.246 2010/07/02 11:38:13 roberto Exp $
2+** $Id: lbaselib.c,v 1.251 2010/10/28 15:36:30 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -56,12 +56,15 @@ static int luaB_tonumber (lua_State *L) { · 50 unmodified lines
5656 const char *s1 = luaL_checkstring(L, 1);
5757 char *s2;
5858 unsigned long n;
59+ int neg = 0;
5960 luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
61+ while (isspace((unsigned char)(*s1))) s1++; /* skip initial spaces */
62+ if (*s1 == '-') { s1++; neg = 1; }
6063 n = strtoul(s1, &s2, base);
6164 if (s1 != s2) { /* at least one valid digit? */
6265 while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
6366 if (*s2 == '\0') { /* no invalid trailing characters? */
64− lua_pushnumber(L, (lua_Number)n);
67+ lua_pushnumber(L, (neg) ? -(lua_Number)n : (lua_Number)n);
6568 return 1;
6669 }
6770 }
@@ -142,11 +145,11 @@ static int luaB_rawset (lua_State *L) { · 74 unmodified lines
142145
143146 static int luaB_collectgarbage (lua_State *L) {
144147 static const char *const opts[] = {"stop", "restart", "collect",
145− "count", "step", "setpause", "setstepmul", "isrunning",
146− "gen", "inc", NULL};
148+ "count", "step", "setpause", "setstepmul",
149+ "setmajorinc", "isrunning", "gen", "inc", NULL};
147150 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
148151 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
149− LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
152+ LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
150153 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
151154 int ex = luaL_optint(L, 2, 0);
152155 int res = lua_gc(L, o, ex);
@@ -330,11 +333,12 @@ static int luaB_load (lua_State *L) { · 177 unmodified lines
330333
331334 static int luaB_loadin (lua_State *L) {
332335 int n;
333− luaL_checktype(L, 1, LUA_TTABLE);
336+ luaL_checkany(L, 1);
334337 n = luaB_load_aux(L, 2);
335338 if (n == 1) { /* success? */
336339 lua_pushvalue(L, 1); /* environment for loaded function */
337− lua_setupvalue(L, -2, 1);
340+ if (lua_setupvalue(L, -2, 1) == NULL)
341+ luaL_error(L, "loaded chunk does not have an upvalue");
338342 }
339343 return n;
340344 }
src/lbitlib.c+49−33
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbitlib.c,v 1.6 2010/07/02 12:01:53 roberto Exp $
2+** $Id: lbitlib.c,v 1.10 2010/10/28 15:17:29 roberto Exp $
33 ** Standard library for bitwise operations
44 ** See Copyright Notice in lua.h
55 */
@@ -13,22 +13,19 @@ · 7 unmodified lines
1313 #include "lualib.h"
1414
1515
16−/* number of bits considered when shifting/rotating (must be a power of 2) */
16+/* number of bits to consider in a number */
1717 #define NBITS 32
1818
19+#define ALLONES (~(((~(lua_Unsigned)0) << (NBITS - 1)) << 1))
1920
20−typedef LUA_INT32 b_int;
21−typedef unsigned LUA_INT32 b_uint;
21+/* mask to trim extra bits */
22+#define trim(x) ((x) & ALLONES)
2223
2324
24−static b_uint getuintarg (lua_State *L, int arg) {
25− b_uint r;
26− int isnum;
27− lua_Number x = lua_tonumberx(L, arg, &isnum);
28− if (!isnum) luaL_typeerror(L, arg, "number");
29− lua_number2uint(r, x);
30− return r;
31−}
25+typedef lua_Unsigned b_uint;
26+
27+
28+#define getuintarg(L,arg) luaL_checkunsigned(L,arg)
3229
3330
3431 static b_uint andaux (lua_State *L) {
@@ -36,13 +33,13 @@ static b_uint andaux (lua_State *L) { · 1 unmodified line
3633 b_uint r = ~(b_uint)0;
3734 for (i = 1; i <= n; i++)
3835 r &= getuintarg(L, i);
39− return r;
36+ return trim(r);
4037 }
4138
4239
4340 static int b_and (lua_State *L) {
4441 b_uint r = andaux(L);
45− lua_pushnumber(L, lua_uint2number(r));
42+ lua_pushunsigned(L, r);
4643 return 1;
4744 }
4845
@@ -59,7 +56,7 @@ static int b_or (lua_State *L) { · 10 unmodified lines
5956 b_uint r = 0;
6057 for (i = 1; i <= n; i++)
6158 r |= getuintarg(L, i);
62− lua_pushnumber(L, lua_uint2number(r));
59+ lua_pushunsigned(L, trim(r));
6360 return 1;
6461 }
6562
@@ -69,49 +66,66 @@ static int b_xor (lua_State *L) { · 3 unmodified lines
6966 b_uint r = 0;
7067 for (i = 1; i <= n; i++)
7168 r ^= getuintarg(L, i);
72− lua_pushnumber(L, lua_uint2number(r));
69+ lua_pushunsigned(L, trim(r));
7370 return 1;
7471 }
7572
7673
7774 static int b_not (lua_State *L) {
7875 b_uint r = ~getuintarg(L, 1);
79− lua_pushnumber(L, lua_uint2number(r));
76+ lua_pushunsigned(L, trim(r));
8077 return 1;
8178 }
8279
8380
84−static int b_shift (lua_State *L, int i) {
85− b_uint r = getuintarg(L, 1);
81+static int b_shift (lua_State *L, b_uint r, int i) {
8682 if (i < 0) { /* shift right? */
8783 i = -i;
84+ r = trim(r);
8885 if (i >= NBITS) r = 0;
8986 else r >>= i;
9087 }
9188 else { /* shift left */
9289 if (i >= NBITS) r = 0;
9390 else r <<= i;
91+ r = trim(r);
9492 }
95− lua_pushnumber(L, lua_uint2number(r));
93+ lua_pushunsigned(L, r);
9694 return 1;
9795 }
9896
9997
10098 static int b_lshift (lua_State *L) {
101− return b_shift(L, luaL_checkint(L, 2));
99+ return b_shift(L, getuintarg(L, 1), luaL_checkint(L, 2));
102100 }
103101
104102
105103 static int b_rshift (lua_State *L) {
106− return b_shift(L, -luaL_checkint(L, 2));
104+ return b_shift(L, getuintarg(L, 1), -luaL_checkint(L, 2));
105+}
106+
107+
108+static int b_arshift (lua_State *L) {
109+ b_uint r = getuintarg(L, 1);
110+ int i = luaL_checkint(L, 2);
111+ if (i < 0 || !(r & (1 << (NBITS - 1))))
112+ return b_shift(L, r, -i);
113+ else { /* arithmetic shift for 'negative' number */
114+ if (i >= NBITS) r = ALLONES;
115+ else
116+ r = trim((r >> i) | ~(~(b_uint)0 >> i)); /* add signal bit */
117+ lua_pushunsigned(L, r);
118+ return 1;
119+ }
107120 }
108121
109122
110123 static int b_rot (lua_State *L, int i) {
111124 b_uint r = getuintarg(L, 1);
112125 i &= (NBITS - 1); /* i = i % NBITS */
126+ r = trim(r);
113127 r = (r << i) | (r >> (NBITS - i));
114− lua_pushnumber(L, lua_uint2number(r));
128+ lua_pushunsigned(L, trim(r));
115129 return 1;
116130 }
117131
@@ -127,21 +141,23 @@ static int b_ror (lua_State *L) { · 9 unmodified lines
127141
128142
129143 static const luaL_Reg bitlib[] = {
130− {"band", b_and},
131− {"btest", b_test},
132− {"bor", b_or},
133− {"bxor", b_xor},
134− {"bnot", b_not},
135− {"lshift", b_lshift},
136− {"rshift", b_rshift},
137− {"rol", b_rol},
138− {"ror", b_ror},
144+ {"AND", b_and},
145+ {"TEST", b_test},
146+ {"OR", b_or},
147+ {"XOR", b_xor},
148+ {"NOT", b_not},
149+ {"SHL", b_lshift},
150+ {"SAR", b_arshift},
151+ {"SHR", b_rshift},
152+ {"ROL", b_rol},
153+ {"ROR", b_ror},
139154 {NULL, NULL}
140155 };
141156
142157
143158
144−LUAMOD_API int luaopen_bit (lua_State *L) {
159+LUAMOD_API int luaopen_bit32 (lua_State *L) {
145160 luaL_newlib(L, bitlib);
146161 return 1;
147162 }
163+
src/ldebug.c+12−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldebug.c,v 2.72 2010/06/21 16:30:12 roberto Exp $
2+** $Id: ldebug.c,v 2.74 2010/10/11 20:24:42 roberto Exp $
33 ** Debug Interface
44 ** See Copyright Notice in lua.h
55 */
@@ -160,9 +160,10 @@ static void funcinfo (lua_Debug *ar, Closure *cl) { · 154 unmodified lines
160160 ar->what = "C";
161161 }
162162 else {
163− ar->source = getstr(cl->l.p->source);
164− ar->linedefined = cl->l.p->linedefined;
165− ar->lastlinedefined = cl->l.p->lastlinedefined;
163+ Proto *p = cl->l.p;
164+ ar->source = p->source ? getstr(p->source) : "=?";
165+ ar->linedefined = p->linedefined;
166+ ar->lastlinedefined = p->lastlinedefined;
166167 ar->what = (ar->linedefined == 0) ? "main" : "Lua";
167168 }
168169 luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
@@ -315,7 +316,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, · 146 unmodified lines
315316 ? luaF_getlocalname(p, t + 1, pc)
316317 : getstr(p->upvalues[t].name);
317318 kname(p, k, a, what, name);
318− what = (vn && strcmp(vn, "_ENV") == 0) ? "global" : "field";
319+ what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
319320 }
320321 break;
321322 }
@@ -496,7 +497,12 @@ static void addinfo (lua_State *L, const char *msg) { · 174 unmodified lines
496497 if (isLua(ci)) { /* is Lua code? */
497498 char buff[LUA_IDSIZE]; /* add file:line information */
498499 int line = currentline(ci);
499− luaO_chunkid(buff, getstr(ci_func(ci)->l.p->source), LUA_IDSIZE);
500+ TString *src = ci_func(ci)->l.p->source;
501+ if (src)
502+ luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
503+ else { /* no source available; use "?" instead */
504+ buff[0] = '?'; buff[1] = '\0';
505+ }
500506 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
501507 }
502508 }
src/ldo.c+5−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 2.88 2010/06/04 13:06:15 roberto Exp $
2+** $Id: ldo.c,v 2.90 2010/10/25 19:01:37 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -177,7 +177,7 @@ void luaD_growstack (lua_State *L, int n) { · 171 unmodified lines
177177 if (size > LUAI_MAXSTACK) /* error after extra size? */
178178 luaD_throw(L, LUA_ERRERR);
179179 else {
180− int needed = L->top - L->stack + n + EXTRA_STACK;
180+ int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;
181181 int newsize = 2 * size;
182182 if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;
183183 if (newsize < needed) newsize = needed;
@@ -299,7 +299,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 115 unmodified lines
299299 if (!ttisfunction(func)) /* `func' is not a function? */
300300 func = tryfuncTM(L, func); /* check the `function' tag method */
301301 funcr = savestack(L, func);
302− L->ci->nresults = nresults;
303302 if (ttislcf(func)) { /* light C function? */
304303 f = fvalue(func); /* get it */
305304 goto isCfunc; /* go to call it */
@@ -312,6 +311,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 6 unmodified lines
312311 isCfunc: /* call C function 'f' */
313312 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
314313 ci = next_ci(L); /* now 'enter' new function */
314+ ci->nresults = nresults;
315315 ci->func = restorestack(L, funcr);
316316 ci->top = L->top + LUA_MINSTACK;
317317 lua_assert(ci->top <= L->stack_last);
@@ -341,6 +341,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 23 unmodified lines
341341 else /* vararg function */
342342 base = adjust_varargs(L, p, nargs);
343343 ci = next_ci(L); /* now 'enter' new function */
344+ ci->nresults = nresults;
344345 ci->func = func;
345346 ci->u.l.base = base;
346347 ci->top = base + p->maxstacksize;
@@ -368,8 +369,8 @@ int luaD_poscall (lua_State *L, StkId firstResult) { · 21 unmodified lines
368369 L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */
369370 }
370371 res = ci->func; /* res == final position of 1st result */
371− L->ci = ci = ci->previous; /* back to caller */
372372 wanted = ci->nresults;
373+ L->ci = ci = ci->previous; /* back to caller */
373374 /* move results to correct place */
374375 for (i = wanted; i != 0 && firstResult < L->top; i--)
375376 setobjs2s(L, res++, firstResult++);
src/ldump.c+6−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldump.c,v 2.13 2010/03/12 19:14:06 roberto Exp $
2+** $Id: ldump.c,v 1.17 2010/10/13 21:04:52 lhf Exp $
33 ** save precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -75,7 +75,7 @@ static void DumpString(const TString* s, DumpState* D) · 69 unmodified lines
7575
7676 #define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
7777
78−static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
78+static void DumpFunction(const Proto* f, DumpState* D);
7979
8080 static void DumpConstants(const Proto* f, DumpState* D)
8181 {
@@ -98,14 +98,11 @@ static void DumpConstants(const Proto* f, DumpState* D) · 16 unmodified lines
9898 case LUA_TSTRING:
9999 DumpString(rawtsvalue(o),D);
100100 break;
101− default:
102− lua_assert(0); /* cannot happen */
103− break;
104101 }
105102 }
106103 n=f->sizep;
107104 DumpInt(n,D);
108− for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
105+ for (i=0; i<n; i++) DumpFunction(f->p[i],D);
109106 }
110107
111108 static void DumpUpvalues(const Proto* f, DumpState* D)
@@ -122,6 +119,7 @@ static void DumpUpvalues(const Proto* f, DumpState* D) · 10 unmodified lines
122119 static void DumpDebug(const Proto* f, DumpState* D)
123120 {
124121 int i,n;
122+ DumpString((D->strip) ? NULL : f->source,D);
125123 n= (D->strip) ? 0 : f->sizelineinfo;
126124 DumpVector(f->lineinfo,n,sizeof(int),D);
127125 n= (D->strip) ? 0 : f->sizelocvars;
@@ -137,9 +135,8 @@ static void DumpDebug(const Proto* f, DumpState* D) · 9 unmodified lines
137135 for (i=0; i<n; i++) DumpString(f->upvalues[i].name,D);
138136 }
139137
140−static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
138+static void DumpFunction(const Proto* f, DumpState* D)
141139 {
142− DumpString((f->source==p || D->strip) ? NULL : f->source,D);
143140 DumpInt(f->linedefined,D);
144141 DumpInt(f->lastlinedefined,D);
145142 DumpChar(f->numparams,D);
@@ -170,6 +167,6 @@ int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip · 24 unmodified lines
170167 D.strip=strip;
171168 D.status=0;
172169 DumpHeader(&D);
173− DumpFunction(f,NULL,&D);
170+ DumpFunction(f,&D);
174171 return D.status;
175172 }
src/lgc.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 2.101 2010/06/30 14:11:17 roberto Exp $
2+** $Id: lgc.c,v 2.103 2010/10/25 19:01:37 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -449,7 +449,7 @@ static int traverseproto (global_State *g, Proto *f) { · 443 unmodified lines
449449 }
450450
451451
452−static l_mem traverseclosure (global_State *g, Closure *cl) {
452+static int traverseclosure (global_State *g, Closure *cl) {
453453 if (cl->c.isC) {
454454 int i;
455455 for (i=0; i<cl->c.nupvalues; i++) /* mark its upvalues */
@@ -960,7 +960,7 @@ static void generationalcollection (lua_State *L) { · 504 unmodified lines
960960 else {
961961 luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
962962 luaC_runtilstate(L, bitmask(GCSpause));
963− if (g->totalbytes > g->lastmajormem/100 * g->gcpause)
963+ if (g->totalbytes > g->lastmajormem/100 * g->gcmajorinc)
964964 g->lastmajormem = 0; /* signal for a major collection */
965965 }
966966 g->GCdebt = stddebt(g);
src/linit.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: linit.c,v 1.28 2010/07/02 11:38:13 roberto Exp $
2+** $Id: linit.c,v 1.29 2010/10/25 14:32:36 roberto Exp $
33 ** Initialization of libraries for lua.c and other clients
44 ** See Copyright Notice in lua.h
55 */
@@ -34,7 +34,7 @@ static const luaL_Reg loadedlibs[] = { · 28 unmodified lines
3434 {LUA_IOLIBNAME, luaopen_io},
3535 {LUA_OSLIBNAME, luaopen_os},
3636 {LUA_STRLIBNAME, luaopen_string},
37− {LUA_BITLIBNAME, luaopen_bit},
37+ {LUA_BITLIBNAME, luaopen_bit32},
3838 {LUA_MATHLIBNAME, luaopen_math},
3939 #if defined(LUA_COMPAT_DEBUGLIB)
4040 {LUA_DBLIBNAME, luaopen_debug},
src/liolib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.91 2010/07/28 15:51:59 roberto Exp $
2+** $Id: liolib.c,v 2.92 2010/10/25 19:01:37 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -453,7 +453,7 @@ static int f_read (lua_State *L) { · 447 unmodified lines
453453 static int io_readline (lua_State *L) {
454454 FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
455455 int i;
456− int n = lua_tointeger(L, lua_upvalueindex(2));
456+ int n = (int)lua_tointeger(L, lua_upvalueindex(2));
457457 if (f == NULL) /* file is already closed? */
458458 luaL_error(L, "file is already closed");
459459 lua_settop(L , 1);
src/llex.c+6−8
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llex.c,v 2.37 2010/04/16 12:31:07 roberto Exp $
2+** $Id: llex.c,v 2.40 2010/10/25 12:24:36 roberto Exp $
33 ** Lexical Analyzer
44 ** See Copyright Notice in lua.h
55 */
@@ -161,7 +161,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 155 unmodified lines
161161 ls->linenumber = 1;
162162 ls->lastline = 1;
163163 ls->source = source;
164− ls->envn = luaS_new(L, "_ENV"); /* create env name */
164+ ls->envn = luaS_new(L, LUA_ENV); /* create env name */
165165 luaS_fix(ls->envn); /* never collect this name */
166166 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
167167 next(ls); /* read first char */
@@ -221,11 +221,9 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 53 unmodified lines
221221 lua_assert(lisdigit(ls->current));
222222 do {
223223 save_and_next(ls);
224− } while (lisdigit(ls->current) || ls->current == '.');
225− if (check_next(ls, "Ee")) /* `E'? */
226− check_next(ls, "+-"); /* optional exponent sign */
227− while (lislalnum(ls->current))
228− save_and_next(ls);
224+ if (check_next(ls, "EePp")) /* exponent part? */
225+ check_next(ls, "+-"); /* optional exponent sign */
226+ } while (lislalnum(ls->current) || ls->current == '.');
229227 save(ls, '\0');
230228 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
231229 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */
@@ -234,7 +232,7 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 2 unmodified lines
234232
235233
236234 /*
237−** skip a sequence '[=*=[' or ']=*]' and return its number of '='s or
235+** skip a sequence '[=*[' or ']=*]' and return its number of '='s or
238236 ** -1 if sequence is malformed
239237 */
240238 static int skip_sep (LexState *ls) {
src/lmathlib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmathlib.c,v 1.75 2010/07/02 11:38:13 roberto Exp $
2+** $Id: lmathlib.c,v 1.76 2010/10/25 20:31:11 roberto Exp $
33 ** Standard mathematical library
44 ** See Copyright Notice in lua.h
55 */
@@ -220,7 +220,7 @@ static int math_random (lua_State *L) { · 214 unmodified lines
220220
221221
222222 static int math_randomseed (lua_State *L) {
223− srand(luaL_checkint(L, 1));
223+ srand(luaL_checkunsigned(L, 1));
224224 (void)rand(); /* discard first value to avoid undesirable correlations */
225225 return 0;
226226 }
src/loadlib.c+4−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.89 2010/07/28 15:51:59 roberto Exp $
2+** $Id: loadlib.c,v 1.92 2010/10/29 14:35:09 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -177,7 +177,7 @@ static void ll_unloadlib (void *lib) { · 171 unmodified lines
177177
178178 static void *ll_load (lua_State *L, const char *path, int seeglb) {
179179 HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);
180− (void)(seeglb); /* symbols are 'global' by default? */
180+ (void)(seeglb); /* symbols are 'global' by default */
181181 if (lib == NULL) pusherror(L);
182182 return lib;
183183 }
@@ -212,7 +212,7 @@ static void ll_unloadlib (void *lib) { · 28 unmodified lines
212212
213213
214214 static void *ll_load (lua_State *L, const char *path, int seeglb) {
215− (void)(path); /* to avoid warnings */
215+ (void)(path); (void)(seeglb); /* to avoid warnings */
216216 lua_pushliteral(L, DLMSG);
217217 return NULL;
218218 }
@@ -428,8 +428,6 @@ static int loader_Croot (lua_State *L) { · 209 unmodified lines
428428 static int loader_preload (lua_State *L) {
429429 const char *name = luaL_checkstring(L, 1);
430430 lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
431− if (!lua_istable(L, -1))
432− luaL_error(L, LUA_QL("package.preload") " must be a table");
433431 lua_getfield(L, -1, name);
434432 if (lua_isnil(L, -1)) /* not found? */
435433 lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
@@ -498,7 +496,7 @@ static int ll_require (lua_State *L) { · 62 unmodified lines
498496 #if defined(LUA_COMPAT_MODULE)
499497
500498 /*
501−** changes the _ENV variable of calling function
499+** changes the environment variable of calling function
502500 */
503501 static void set_env (lua_State *L) {
504502 lua_Debug ar;
src/lobject.c+12−7
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lobject.c,v 2.40 2010/04/18 13:22:48 roberto Exp $
2+** $Id: lobject.c,v 2.43 2010/10/29 15:54:55 roberto Exp $
33 ** Some generic functions over Lua objects
44 ** See Copyright Notice in lua.h
55 */
@@ -106,14 +106,19 @@ lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { · 100 unmodified lines
106106 }
107107
108108
109+static int checkend (const char *s, const char *endptr) {
110+ if (endptr == s) return 0; /* no characters converted */
111+ while (lisspace(cast(unsigned char, *endptr))) endptr++;
112+ return (*endptr == '\0'); /* OK if no trailing characters */
113+}
114+
115+
109116 int luaO_str2d (const char *s, lua_Number *result) {
110117 char *endptr;
111118 *result = lua_str2number(s, &endptr);
112− if (endptr == s) return 0; /* conversion failed */
113− if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
114− *result = cast_num(strtoul(s, &endptr, 16));
115− while (lisspace(cast(unsigned char, *endptr))) endptr++;
116− return (*endptr == '\0'); /* OK if no trailing characters */
119+ if (checkend(s, endptr)) return 1; /* conversion OK? */
120+ *result = cast_num(strtoul(s, &endptr, 0)); /* try hexadecimal */
121+ return checkend(s, endptr);
117122 }
118123
119124
@@ -221,7 +226,7 @@ void luaO_chunkid (char *out, const char *source, size_t bufflen) { · 101 unmodified lines
221226 else { /* string; format as [string "source"] */
222227 const char *nl = strchr(source, '\n'); /* find first new line (if any) */
223228 addstr(out, PRE, LL(PRE)); /* add prefix */
224− bufflen -= LL(PRE RETS POS); /* save space for prefix+suffix */
229+ bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
225230 if (l < bufflen && nl == NULL) { /* small one-line source? */
226231 addstr(out, source, l); /* keep it */
227232 }
src/lopcodes.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.c,v 1.43 2010/03/12 19:14:06 roberto Exp $
2+** $Id: lopcodes.c,v 1.44 2010/10/13 16:45:54 roberto Exp $
33 ** See Copyright Notice in lua.h
44 */
55
@@ -48,11 +48,11 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { · 42 unmodified lines
4848 "FORLOOP",
4949 "FORPREP",
5050 "TFORCALL",
51+ "TFORLOOP",
5152 "SETLIST",
5253 "CLOSE",
5354 "CLOSURE",
5455 "VARARG",
55− "TFORLOOP",
5656 "EXTRAARG",
5757 NULL
5858 };
@@ -96,11 +96,11 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { · 37 unmodified lines
9696 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
9797 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
9898 ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */
99+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */
99100 ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
100101 ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
101102 ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
102103 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
103− ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */
104104 ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
105105 };
106106
src/lopcodes.h+5−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lopcodes.h,v 1.135 2010/03/12 19:14:06 roberto Exp $
2+** $Id: lopcodes.h,v 1.137 2010/10/25 12:24:55 roberto Exp $
33 ** Opcodes for Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -17,6 +17,7 @@ · 11 unmodified lines
1717 `A' : 8 bits
1818 `B' : 9 bits
1919 `C' : 9 bits
20+ 'Ax' : 26 bits ('A', 'B', and 'C' together)
2021 `Bx' : 18 bits (`B' and `C' together)
2122 `sBx' : signed Bx
2223
@@ -122,7 +123,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ · 99 unmodified lines
122123 | (cast(Instruction, bc)<<POS_Bx))
123124
124125 #define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
125− | (cast(Instruction, a)<<POS_A))
126+ | (cast(Instruction, a)<<POS_Ax))
126127
127128
128129 /*
@@ -212,6 +213,8 @@ OP_FORLOOP,/* A sBx R(A)+=R(A+2); · 83 unmodified lines
212213 OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
213214
214215 OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
216+OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
217+
215218 OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
216219
217220 OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/
@@ -219,8 +222,6 @@ OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */ · 1 unmodified line
219222
220223 OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
221224
222−OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
223−
224225 OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
225226 } OpCode;
226227
src/loslib.c+6−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loslib.c,v 1.31 2010/07/02 12:01:53 roberto Exp $
2+** $Id: loslib.c,v 1.32 2010/10/05 12:18:03 roberto Exp $
33 ** Standard Operating System library
44 ** See Copyright Notice in lua.h
55 */
@@ -276,7 +276,11 @@ static int os_setlocale (lua_State *L) { · 270 unmodified lines
276276
277277
278278 static int os_exit (lua_State *L) {
279− int status = luaL_optint(L, 1, EXIT_SUCCESS);
279+ int status;
280+ if (lua_isboolean(L, 1))
281+ status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);
282+ else
283+ status = luaL_optint(L, 1, EXIT_SUCCESS);
280284 if (lua_toboolean(L, 2))
281285 lua_close(L);
282286 exit(status);
src/lparser.c+16−11
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 2.90 2010/07/07 16:27:29 roberto Exp $
2+** $Id: lparser.c,v 2.92 2010/09/07 19:21:39 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -289,7 +289,7 @@ static void singlevar (LexState *ls, expdesc *var) { · 283 unmodified lines
289289 FuncState *fs = ls->fs;
290290 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
291291 expdesc key;
292− singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */
292+ singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
293293 lua_assert(var->k == VLOCAL || var->k == VUPVAL);
294294 codestring(ls, &key, varname); /* key is variable name */
295295 luaK_indexed(fs, var, &key); /* env[varname] */
@@ -352,15 +352,20 @@ static void leaveblock (FuncState *fs) { · 56 unmodified lines
352352 }
353353
354354
355−static void pushclosure (LexState *ls, Proto *clp, expdesc *v) {
355+/*
356+** adds prototype being created into its parent list of prototypes
357+** and codes instruction to create new closure
358+*/
359+static void codeclosure (LexState *ls, Proto *clp, expdesc *v) {
356360 FuncState *fs = ls->fs->prev;
357361 Proto *f = fs->f; /* prototype of function creating new closure */
358− int oldsize = f->sizep;
359− luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
360− MAXARG_Bx, "functions");
361− while (oldsize < f->sizep) f->p[oldsize++] = NULL;
362+ if (fs->np >= f->sizep) {
363+ int oldsize = f->sizep;
364+ luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
365+ MAXARG_Bx, "functions");
366+ while (oldsize < f->sizep) f->p[oldsize++] = NULL;
367+ }
362368 f->p[fs->np++] = clp;
363− /* initial environment for new function is current lexical environment */
364369 luaC_objbarrier(ls->L, f, clp);
365370 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
366371 }
@@ -428,14 +433,14 @@ static void close_func (LexState *ls) { · 61 unmodified lines
428433
429434 /*
430435 ** opens the main function, which is a regular vararg function with an
431−** upvalue named '_ENV'
436+** upvalue named LUA_ENV
432437 */
433438 static void open_mainfunc (LexState *ls, FuncState *fs) {
434439 expdesc v;
435440 open_func(ls, fs);
436441 fs->f->is_vararg = 1; /* main function is always vararg */
437442 init_exp(&v, VLOCAL, 0);
438− newupvalue(fs, ls->envn, &v); /* create '_ENV' upvalue */
443+ newupvalue(fs, ls->envn, &v); /* create environment upvalue */
439444 }
440445
441446
@@ -653,7 +658,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { · 211 unmodified lines
653658 chunk(ls);
654659 new_fs.f->lastlinedefined = ls->linenumber;
655660 check_match(ls, TK_END, TK_FUNCTION, line);
656− pushclosure(ls, new_fs.f, e);
661+ codeclosure(ls, new_fs.f, e);
657662 close_func(ls);
658663 }
659664
src/lstate.c+6−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.c,v 2.85 2010/04/30 18:36:22 roberto Exp $
2+** $Id: lstate.c,v 2.86 2010/09/03 14:14:01 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -29,6 +29,10 @@ · 23 unmodified lines
2929 #define LUAI_GCPAUSE 200 /* 200% */
3030 #endif
3131
32+#if !defined(LUAI_GCMAJOR)
33+#define LUAI_GCMAJOR 200 /* 200% */
34+#endif
35+
3236 #if !defined(LUAI_GCMUL)
3337 #define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
3438 #endif
@@ -254,6 +258,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 219 unmodified lines
254258 g->weak = g->ephemeron = g->allweak = NULL;
255259 g->totalbytes = sizeof(LG);
256260 g->gcpause = LUAI_GCPAUSE;
261+ g->gcmajorinc = LUAI_GCMAJOR;
257262 g->gcstepmul = LUAI_GCMUL;
258263 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
259264 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
src/lstate.h+4−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstate.h,v 2.65 2010/05/03 17:39:48 roberto Exp $
2+** $Id: lstate.h,v 2.68 2010/10/29 17:52:46 roberto Exp $
33 ** Global State
44 ** See Copyright Notice in lua.h
55 */
@@ -66,13 +66,13 @@ typedef struct stringtable { · 60 unmodified lines
6666
6767
6868 /*
69−** informations about a call
69+** information about a call
7070 */
7171 typedef struct CallInfo {
7272 StkId func; /* function index in the stack */
7373 StkId top; /* top for this function */
7474 struct CallInfo *previous, *next; /* dynamic call link */
75− short nresults; /* expected number of results from a call */
75+ short nresults; /* expected number of results from this function */
7676 lu_byte callstatus;
7777 union {
7878 struct { /* only for Lua functions */
@@ -136,6 +136,7 @@ typedef struct global_State { · 57 unmodified lines
136136 UpVal uvhead; /* head of double-linked list of all open upvalues */
137137 Mbuffer buff; /* temporary buffer for string concatenation */
138138 int gcpause; /* size of pause between successive GCs */
139+ int gcmajorinc; /* how much to wait for a major GC (only in gen. mode) */
139140 int gcstepmul; /* GC `granularity' */
140141 lua_CFunction panic; /* to be called in unprotected errors */
141142 struct lua_State *mainthread;
src/lstrlib.c+4−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.154 2010/07/02 11:38:13 roberto Exp $
2+** $Id: lstrlib.c,v 1.156 2010/10/29 17:52:46 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -424,7 +424,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 418 unmodified lines
424424 default: goto dflt;
425425 }
426426 }
427− default: dflt: { /* pattern class plus optional sufix */
427+ default: dflt: { /* pattern class plus optional suffix */
428428 const char *ep = classend(ms, p); /* points to what is next */
429429 int m = s < ms->src_end && singlematch(uchar(*s), p, ep);
430430 switch (*ep) {
@@ -758,9 +758,9 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 327 unmodified lines
758758 else if (*s == '\0' || iscntrl(uchar(*s))) {
759759 char buff[10];
760760 if (!isdigit(uchar(*(s+1))))
761− sprintf(buff, "\\%d", uchar(*s));
761+ sprintf(buff, "\\%d", (int)uchar(*s));
762762 else
763− sprintf(buff, "\\%03d", uchar(*s));
763+ sprintf(buff, "\\%03d", (int)uchar(*s));
764764 luaL_addstring(b, buff);
765765 }
766766 else
src/ltablib.c+3−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltablib.c,v 1.56 2010/07/02 11:38:13 roberto Exp $
2+** $Id: ltablib.c,v 1.57 2010/10/25 19:01:37 roberto Exp $
33 ** Library for Table Manipulation
44 ** See Copyright Notice in lua.h
55 */
@@ -16,7 +16,8 @@ · 10 unmodified lines
1616 #include "lualib.h"
1717
1818
19−#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), lua_rawlen(L, n))
19+#define aux_getn(L,n) \
20+ (luaL_checktype(L, n, LUA_TTABLE), (int)lua_rawlen(L, n))
2021
2122
2223 static int foreachi (lua_State *L) {
src/lua.c+7−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.192 2010/07/25 15:03:37 roberto Exp $
2+** $Id: lua.c,v 1.194 2010/10/25 19:01:37 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -369,10 +369,11 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 363 unmodified lines
369369 break;
370370 case 'e':
371371 *pe = 1; /* go through */
372− case 'l':
373− if (argv[i][2] == '\0') {
374− i++;
375− if (argv[i] == NULL) return -(i - 1);
372+ case 'l': /* both options need an argument */
373+ if (argv[i][2] == '\0') { /* no concatenated argument? */
374+ i++; /* try next 'argv' */
375+ if (argv[i] == NULL || argv[i][0] == '-')
376+ return -(i - 1); /* no next argument or it is another option */
376377 }
377378 break;
378379 default: /* invalid option; return its index... */
@@ -427,7 +428,7 @@ static int handle_luainit (lua_State *L) { · 48 unmodified lines
427428
428429
429430 static int pmain (lua_State *L) {
430− int argc = lua_tointeger(L, 1);
431+ int argc = (int)lua_tointeger(L, 1);
431432 char **argv = (char **)lua_touserdata(L, 2);
432433 int script;
433434 int has_i = 0, has_v = 0, has_e = 0;
src/lua.h+12−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.h,v 1.273 2010/07/25 15:18:19 roberto Exp $
2+** $Id: lua.h,v 1.276 2010/10/26 19:32:19 roberto Exp $
33 ** Lua - A Scripting Language
44 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
55 ** See Copyright Notice at the end of this file
@@ -18,7 +18,7 @@ · 12 unmodified lines
1818
1919 #define LUA_VERSION_MAJOR "5"
2020 #define LUA_VERSION_MINOR "2"
21−#define LUA_VERSION_RELEASE "0" " (work4)"
21+#define LUA_VERSION_RELEASE "0" " (work5)"
2222
2323 #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
2424 #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
@@ -106,6 +106,9 @@ typedef LUA_NUMBER lua_Number; · 81 unmodified lines
106106 /* type for integer functions */
107107 typedef LUA_INTEGER lua_Integer;
108108
109+/* unsigned integer type */
110+typedef LUA_UNSIGNED lua_Unsigned;
111+
109112
110113
111114 /*
@@ -159,6 +162,7 @@ LUA_API const char *(lua_typename) (lua_State *L, int tp); · 47 unmodified lines
159162
160163 LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
161164 LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
165+LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
162166 LUA_API int (lua_toboolean) (lua_State *L, int idx);
163167 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
164168 LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
@@ -196,6 +200,7 @@ LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op); · 31 unmodified lines
196200 LUA_API void (lua_pushnil) (lua_State *L);
197201 LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
198202 LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
203+LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
199204 LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
200205 LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
201206 LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
@@ -271,9 +276,10 @@ LUA_API int (lua_status) (lua_State *L); · 69 unmodified lines
271276 #define LUA_GCSTEP 5
272277 #define LUA_GCSETPAUSE 6
273278 #define LUA_GCSETSTEPMUL 7
274−#define LUA_GCISRUNNING 8
275−#define LUA_GCGEN 9
276−#define LUA_GCINC 10
279+#define LUA_GCSETMAJORINC 8
280+#define LUA_GCISRUNNING 9
281+#define LUA_GCGEN 10
282+#define LUA_GCINC 11
277283
278284 LUA_API int (lua_gc) (lua_State *L, int what, int data);
279285
@@ -302,6 +308,7 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); · 22 unmodified lines
302308
303309 #define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
304310 #define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
311+#define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
305312
306313 #define lua_pop(L,n) lua_settop(L, -(n)-1)
307314
src/luac.c+273−39
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luac.c,v 1.61 2010/05/14 11:40:22 lhf Exp $
2+** $Id: luac.c,v 1.65 2010/10/26 09:07:52 lhf Exp $
33 ** Lua compiler (saves bytecodes to files; also list bytecodes)
44 ** See Copyright Notice in lua.h
55 */
@@ -15,14 +15,13 @@ · 9 unmodified lines
1515 #include "lua.h"
1616 #include "lauxlib.h"
1717
18−#include "ldo.h"
19−#include "lfunc.h"
20−#include "lmem.h"
2118 #include "lobject.h"
22−#include "lopcodes.h"
23−#include "lstring.h"
19+#include "lstate.h"
2420 #include "lundump.h"
2521
22+static void PrintFunction(const Proto* f, int full);
23+#define luaU_print PrintFunction
24+
2625 #define PROGNAME "luac" /* default program name */
2726 #define OUTPUT PROGNAME ".out" /* default output file */
2827
@@ -52,16 +51,16 @@ static void usage(const char* message) · 23 unmodified lines
5251 else
5352 fprintf(stderr,"%s: %s\n",progname,message);
5453 fprintf(stderr,
55− "usage: %s [options] [filenames]\n"
56− "Available options are:\n"
57− " -l list\n"
58− " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
59− " -p parse only\n"
60− " -s strip debug information\n"
61− " -v show version information\n"
62− " -- stop handling options\n"
63− " - stop handling options and process stdin\n"
64− ,progname,Output);
54+ "usage: %s [options] [filenames]\n"
55+ "Available options are:\n"
56+ " -l list\n"
57+ " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
58+ " -p parse only\n"
59+ " -s strip debug information\n"
60+ " -v show version information\n"
61+ " -- stop handling options\n"
62+ " - stop handling options and process stdin\n"
63+ ,progname,Output);
6564 exit(EXIT_FAILURE);
6665 }
6766
@@ -89,7 +88,8 @@ static int doargs(int argc, char* argv[]) · 21 unmodified lines
8988 else if (IS("-o")) /* output file */
9089 {
9190 output=argv[++i];
92− if (output==NULL || *output==0 || *output=='-') usage(LUA_QL("-o") " needs argument");
91+ if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))
92+ usage(LUA_QL("-o") " needs argument");
9393 if (IS("-")) output=NULL;
9494 }
9595 else if (IS("-p")) /* parse only */
@@ -114,7 +114,24 @@ static int doargs(int argc, char* argv[]) · 18 unmodified lines
114114 return i;
115115 }
116116
117−#define toproto(L,i) (clvalue(L->top+(i))->l.p)
117+#define FUNCTION "(function()end)();"
118+
119+static const char* reader(lua_State *L, void *ud, size_t *size)
120+{
121+ UNUSED(L);
122+ if ((*(int*)ud)--)
123+ {
124+ *size=sizeof(FUNCTION)-1;
125+ return FUNCTION;
126+ }
127+ else
128+ {
129+ *size=0;
130+ return NULL;
131+ }
132+}
133+
134+#define toproto(L,i) getproto(L->top+(i))
118135
119136 static const Proto* combine(lua_State* L, int n)
120137 {
@@ -122,24 +139,13 @@ static const Proto* combine(lua_State* L, int n) · 1 unmodified line
122139 return toproto(L,-1);
123140 else
124141 {
125− int i,pc;
126− Proto* f=luaF_newproto(L);
127− setptvalue2s(L,L->top,f); incr_top(L);
128− f->source=luaS_newliteral(L,"=(" PROGNAME ")");
129− f->maxstacksize=1;
130− pc=2*n+1;
131− f->code=luaM_newvector(L,pc,Instruction);
132− f->sizecode=pc;
133− f->p=luaM_newvector(L,n,Proto*);
134− f->sizep=n;
135− pc=0;
136− for (i=0; i<n; i++)
137− {
138− f->p[i]=toproto(L,i-n-1);
139− f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i);
140− f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1);
141− }
142− f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0);
142+ Proto* f;
143+ int i=n;
144+ if (lua_load(L,reader,&i,"=(" PROGNAME ")")!=LUA_OK) fatal(lua_tostring(L,-1));
145+ f=toproto(L,-1);
146+ for (i=0; i<n; i++) f->p[i]=toproto(L,i-n-1);
147+ f->sizelineinfo=0;
148+ f->sizeupvalues=0;
143149 return f;
144150 }
145151 }
@@ -152,7 +158,7 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 6 unmodified lines
152158
153159 static int pmain(lua_State* L)
154160 {
155− int argc=lua_tointeger(L,1);
161+ int argc=(int)lua_tointeger(L,1);
156162 char** argv=lua_touserdata(L,2);
157163 const Proto* f;
158164 int i;
@@ -160,7 +166,7 @@ static int pmain(lua_State* L) · 1 unmodified line
160166 for (i=0; i<argc; i++)
161167 {
162168 const char* filename=IS("-") ? NULL : argv[i];
163− if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1));
169+ if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));
164170 }
165171 f=combine(L,argc);
166172 if (listing) luaU_print(f,listing>1);
@@ -188,7 +194,235 @@ int main(int argc, char* argv[]) · 21 unmodified lines
188194 lua_pushcfunction(L,&pmain);
189195 lua_pushinteger(L,argc);
190196 lua_pushlightuserdata(L,argv);
191− if (lua_pcall(L,2,0,0)!=0) fatal(lua_tostring(L,-1));
197+ if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
192198 lua_close(L);
193199 return EXIT_SUCCESS;
194200 }
201+
202+/*
203+** $Id: print.c,v 1.66 2010/10/26 09:07:52 lhf Exp $
204+** print bytecodes
205+** See Copyright Notice in lua.h
206+*/
207+
208+#include <ctype.h>
209+#include <stdio.h>
210+
211+#define luac_c
212+#define LUA_CORE
213+
214+#include "ldebug.h"
215+#include "lobject.h"
216+#include "lopcodes.h"
217+
218+#define Sizeof(x) ((int)sizeof(x))
219+#define VOID(p) ((const void*)(p))
220+
221+static void PrintString(const TString* ts)
222+{
223+ const char* s=getstr(ts);
224+ size_t i,n=ts->tsv.len;
225+ printf("%c",'"');
226+ for (i=0; i<n; i++)
227+ {
228+ int c=(int)(unsigned char)s[i];
229+ switch (c)
230+ {
231+ case '"': printf("\\\""); break;
232+ case '\\': printf("\\\\"); break;
233+ case '\a': printf("\\a"); break;
234+ case '\b': printf("\\b"); break;
235+ case '\f': printf("\\f"); break;
236+ case '\n': printf("\\n"); break;
237+ case '\r': printf("\\r"); break;
238+ case '\t': printf("\\t"); break;
239+ case '\v': printf("\\v"); break;
240+ default: if (isprint(c))
241+ printf("%c",c);
242+ else
243+ printf("\\%03d",c);
244+ }
245+ }
246+ printf("%c",'"');
247+}
248+
249+static void PrintConstant(const Proto* f, int i)
250+{
251+ const TValue* o=&f->k[i];
252+ switch (ttype(o))
253+ {
254+ case LUA_TNIL:
255+ printf("nil");
256+ break;
257+ case LUA_TBOOLEAN:
258+ printf(bvalue(o) ? "true" : "false");
259+ break;
260+ case LUA_TNUMBER:
261+ printf(LUA_NUMBER_FMT,nvalue(o));
262+ break;
263+ case LUA_TSTRING:
264+ PrintString(rawtsvalue(o));
265+ break;
266+ default: /* cannot happen */
267+ printf("? type=%d",ttype(o));
268+ break;
269+ }
270+}
271+
272+#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
273+
274+static void PrintCode(const Proto* f)
275+{
276+ const Instruction* code=f->code;
277+ int pc,n=f->sizecode;
278+ for (pc=0; pc<n; pc++)
279+ {
280+ Instruction i=code[pc];
281+ OpCode o=GET_OPCODE(i);
282+ int a=GETARG_A(i);
283+ int b=GETARG_B(i);
284+ int c=GETARG_C(i);
285+ int ax=GETARG_Ax(i);
286+ int bx=GETARG_Bx(i);
287+ int sbx=GETARG_sBx(i);
288+ int line=getfuncline(f,pc);
289+ printf("\t%d\t",pc+1);
290+ if (line>0) printf("[%d]\t",line); else printf("[-]\t");
291+ printf("%-9s\t",luaP_opnames[o]);
292+ switch (getOpMode(o))
293+ {
294+ case iABC:
295+ printf("%d",a);
296+ if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
297+ if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
298+ break;
299+ case iABx:
300+ if (getBMode(o)==OpArgK) printf("%d %d",a,-bx); else printf("%d %d",a,bx);
301+ break;
302+ case iAsBx:
303+ if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
304+ break;
305+ case iAx:
306+ printf("%d",-1-ax);
307+ break;
308+ }
309+ switch (o)
310+ {
311+ case OP_LOADK:
312+ if (bx>0) { printf("\t; "); PrintConstant(f,bx-1); }
313+ break;
314+ case OP_GETUPVAL:
315+ case OP_SETUPVAL:
316+ printf("\t; %s",UPVALNAME(b));
317+ break;
318+ case OP_GETTABUP:
319+ printf("\t; %s",UPVALNAME(b));
320+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
321+ break;
322+ case OP_SETTABUP:
323+ printf("\t; %s",UPVALNAME(a));
324+ if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
325+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
326+ break;
327+ case OP_GETTABLE:
328+ case OP_SELF:
329+ if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
330+ break;
331+ case OP_SETTABLE:
332+ case OP_ADD:
333+ case OP_SUB:
334+ case OP_MUL:
335+ case OP_DIV:
336+ case OP_POW:
337+ case OP_EQ:
338+ case OP_LT:
339+ case OP_LE:
340+ if (ISK(b) || ISK(c))
341+ {
342+ printf("\t; ");
343+ if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
344+ printf(" ");
345+ if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
346+ }
347+ break;
348+ case OP_JMP:
349+ case OP_FORLOOP:
350+ case OP_FORPREP:
351+ case OP_TFORLOOP:
352+ printf("\t; to %d",sbx+pc+2);
353+ break;
354+ case OP_CLOSURE:
355+ printf("\t; %p",VOID(f->p[bx]));
356+ break;
357+ case OP_SETLIST:
358+ if (c==0) printf("\t; %d",(int)code[++pc]);
359+ else printf("\t; %d",c);
360+ break;
361+ case OP_EXTRAARG:
362+ printf("\t; "); PrintConstant(f,ax);
363+ break;
364+ default:
365+ break;
366+ }
367+ printf("\n");
368+ }
369+}
370+
371+#define SS(x) ((x==1)?"":"s")
372+#define S(x) (int)(x),SS(x)
373+
374+static void PrintHeader(const Proto* f)
375+{
376+ const char* s=f->source ? getstr(f->source) : "=?";
377+ if (*s=='@' || *s=='=')
378+ s++;
379+ else if (*s==LUA_SIGNATURE[0])
380+ s="(bstring)";
381+ else
382+ s="(string)";
383+ printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
384+ (f->linedefined==0)?"main":"function",s,
385+ f->linedefined,f->lastlinedefined,
386+ S(f->sizecode),VOID(f));
387+ printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
388+ (int)(f->numparams),f->is_vararg?"+":"",SS(f->numparams),
389+ S(f->maxstacksize),S(f->sizeupvalues));
390+ printf("%d local%s, %d constant%s, %d function%s\n",
391+ S(f->sizelocvars),S(f->sizek),S(f->sizep));
392+}
393+
394+static void PrintDebug(const Proto* f)
395+{
396+ int i,n;
397+ n=f->sizek;
398+ printf("constants (%d) for %p:\n",n,VOID(f));
399+ for (i=0; i<n; i++)
400+ {
401+ printf("\t%d\t",i+1);
402+ PrintConstant(f,i);
403+ printf("\n");
404+ }
405+ n=f->sizelocvars;
406+ printf("locals (%d) for %p:\n",n,VOID(f));
407+ for (i=0; i<n; i++)
408+ {
409+ printf("\t%d\t%s\t%d\t%d\n",
410+ i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
411+ }
412+ n=f->sizeupvalues;
413+ printf("upvalues (%d) for %p:\n",n,VOID(f));
414+ for (i=0; i<n; i++)
415+ {
416+ printf("\t%d\t%s\t%d\t%d\n",
417+ i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);
418+ }
419+}
420+
421+static void PrintFunction(const Proto* f, int full)
422+{
423+ int i,n=f->sizep;
424+ PrintHeader(f);
425+ PrintCode(f);
426+ if (full) PrintDebug(f);
427+ for (i=0; i<n; i++) PrintFunction(f->p[i],full);
428+}
src/luaconf.h+85−30
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.142 2010/07/28 15:51:59 roberto Exp $
2+** $Id: luaconf.h,v 1.148 2010/10/29 17:52:46 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -47,8 +47,8 @@ · 41 unmodified lines
4747
4848 #if defined(LUA_USE_MACOSX)
4949 #define LUA_USE_POSIX
50−#define LUA_USE_DLOPEN
51−#define LUA_USE_READLINE /* needs some extra libraries */
50+#define LUA_USE_DLOPEN /* does not need -ldl */
51+#define LUA_USE_READLINE /* needs an extra library: -lreadline */
5252 #endif
5353
5454
@@ -115,6 +115,14 @@ · 60 unmodified lines
115115 #endif
116116
117117
118+/*
119+@@ LUA_ENV is the name of the variable that holds the current
120+@@ environment, used to access global names.
121+** CHANGE it if you do not like this name.
122+*/
123+#define LUA_ENV "_ENV"
124+
125+
118126 /*
119127 @@ LUA_API is a mark for all core API functions.
120128 @@ LUALIB_API is a mark for all auxiliary library functions.
@@ -430,26 +438,28 @@ · 309 unmodified lines
430438 */
431439 #define LUA_INTEGER ptrdiff_t
432440
441+/*
442+@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.
443+** It must have at least 32 bits.
444+*/
445+#define LUA_UNSIGNED unsigned LUA_INT32
446+
433447
434448 /*
435449 @@ lua_number2int is a macro to convert lua_Number to int.
436450 @@ lua_number2integer is a macro to convert lua_Number to LUA_INTEGER.
437−@@ lua_number2uint is a macro to convert a lua_Number to an unsigned
438−@* LUA_INT32.
439−@@ lua_uint2number is a macro to convert an unsigned LUA_INT32
440−@* to a lua_Number.
441−** CHANGE them if you know a faster way to convert a lua_Number to
442−** int (with any rounding method and without throwing errors) in your
443−** system. In Pentium machines, a naive typecast from double to int
444−** in C is extremely slow, so any alternative is worth trying.
451+@@ lua_number2uint is a macro to convert a lua_Number to a LUA_UNSIGNED.
452+@@ lua_uint2number is a macro to convert a LUA_UNSIGNED to a lua_Number.
445453 */
446454
447−/* On a Pentium, resort to a trick */
448−#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
449− (defined(__i386) || defined (_M_IX86) || defined(__i386__)) /* { */
455+#if defined(LUA_CORE) /* { */
456+
457+#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && \
458+ !defined(LUA_NOIEEE754TRICK) /* { */
450459
451−/* On a Microsoft compiler, use assembler */
452−#if defined(_MSC_VER) /* { */
460+/* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
461+ with a DirectX idiosyncrasy */
462+#if defined(_MSC_VER) && defined(M_IX86) /* { */
453463
454464 #define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
455465 #define lua_number2integer(i,n) lua_number2int(i, n)
@@ -457,31 +467,76 @@ · 1 unmodified line
457467 {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
458468
459469 #else /* }{ */
460−/* the next trick should work on any Pentium, but sometimes clashes
461− with a DirectX idiosyncrasy */
470+/* the next trick should work on any machine using IEEE754 with
471+ a 32-bit integer type */
462472
463−union luai_Cast { double l_d; long l_l; };
464−#define lua_number2int(i,n) \
465− { volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; (i) = u.l_l; }
466−#define lua_number2integer(i,n) lua_number2int(i, n)
467−#define lua_number2uint(i,n) lua_number2int(i, n)
473+union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
474+
475+/*
476+@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
477+@@ (0 for little endian, 1 for big endian); if not defined, Lua will
478+@@ check it dynamically.
479+*/
480+/* check for known architectures */
481+#if defined(__i386__) || defined(__i386) || defined(i386) || \
482+ defined (__x86_64)
483+#define LUA_IEEEENDIAN 0
484+#elif defined(__POWERPC__) || defined(__ppc__)
485+#define LUA_IEEEENDIAN 1
486+#endif
487+
488+#if !defined(LUA_IEEEENDIAN) /* { */
489+#define LUAI_EXTRAIEEE \
490+ static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
491+#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
492+#else
493+#define LUAI_EXTRAIEEE /* empty */
494+#endif /* } */
495+
496+#define lua_number2int32(i,n,t) \
497+ { LUAI_EXTRAIEEE \
498+ volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
499+ (i) = (t)u.l_p[LUA_IEEEENDIAN]; }
500+
501+#define lua_number2int(i,n) lua_number2int32(i, n, int)
502+#define lua_number2integer(i,n) lua_number2int32(i, n, LUA_INTEGER)
503+#define lua_number2uint(i,n) lua_number2int32(i, n, LUA_UNSIGNED)
468504
469505 #endif /* } */
470506
471507
472−#else /* }{ */
473−/* this option always works, but may be slow */
508+#endif /* } */
509+
510+
511+/* the following definitions always work, but may be slow */
512+
513+#if !defined(lua_number2int)
474514 #define lua_number2int(i,n) ((i)=(int)(n))
475−#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))
476−#define lua_number2uint(i,n) ((i)=(unsigned LUA_INT32)(n))
515+#endif
477516
478−#endif /* } */
517+#if !defined(lua_number2integer)
518+#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))
519+#endif
479520
521+#if !defined(lua_number2uint) && (defined(lapi_c) || defined(luaall_c)) /* { */
522+/* the following definition assures proper modulo behavior */
523+#if defined(LUA_NUMBER_DOUBLE)
524+#include <math.h>
525+#define lua_number2uint(i,n) \
526+ ((i)=(LUA_UNSIGNED)((n) - floor((n)/4294967296.0)*4294967296.0))
527+#else
528+#define lua_number2uint(i,n) ((i)=(LUA_UNSIGNED)(n))
529+#endif
530+#endif /* } */
480531
481−/* on several machines, coercion from unsigned to double is too slow,
482− so avoid that if possible */
532+#if !defined(lua_uint2number)
533+/* on several machines, coercion from unsigned to double is slow,
534+ so it may be worth to avoid */
483535 #define lua_uint2number(u) \
484536 ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u))
537+#endif
538+
539+#endif /* } */
485540
486541
487542 /*
src/lualib.h+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lualib.h,v 1.40 2010/06/10 21:29:47 roberto Exp $
2+** $Id: lualib.h,v 1.41 2010/10/25 14:32:36 roberto Exp $
33 ** Lua standard libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -32,8 +32,8 @@ LUAMOD_API int (luaopen_os) (lua_State *L); · 26 unmodified lines
3232 #define LUA_STRLIBNAME "string"
3333 LUAMOD_API int (luaopen_string) (lua_State *L);
3434
35−#define LUA_BITLIBNAME "bit"
36−LUAMOD_API int (luaopen_bit) (lua_State *L);
35+#define LUA_BITLIBNAME "bit32"
36+LUAMOD_API int (luaopen_bit32) (lua_State *L);
3737
3838 #define LUA_MATHLIBNAME "math"
3939 LUAMOD_API int (luaopen_math) (lua_State *L);
src/lundump.c+30−29
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.c,v 2.13 2010/03/12 19:14:06 roberto Exp $
2+** $Id: lundump.c,v 1.68 2010/10/26 00:23:46 lhf Exp $
33 ** load precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -27,27 +27,20 @@ typedef struct { · 21 unmodified lines
2727 const char* name;
2828 } LoadState;
2929
30−#ifdef LUAC_TRUST_BINARIES
31−#define IF(c,s)
32−#else
33−#define IF(c,s) if (c) error(S,s)
34−
3530 static void error(LoadState* S, const char* why)
3631 {
37− luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
32+ luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
3833 luaD_throw(S->L,LUA_ERRSYNTAX);
3934 }
40−#endif
4135
4236 #define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
43−#define LoadByte(S) (lu_byte)LoadChar(S)
37+#define LoadByte(S) (lu_byte)LoadChar(S)
4438 #define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
4539 #define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
4640
4741 static void LoadBlock(LoadState* S, void* b, size_t size)
4842 {
49− size_t r=luaZ_read(S->Z,b,size);
50− IF (r!=0, "unexpected end");
43+ if (luaZ_read(S->Z,b,size)!=0) error(S,"corrupted");
5144 }
5245
5346 static int LoadChar(LoadState* S)
@@ -61,7 +54,6 @@ static int LoadInt(LoadState* S) · 7 unmodified lines
6154 {
6255 int x;
6356 LoadVar(S,x);
64− IF (x<0, "bad integer");
6557 return x;
6658 }
6759
@@ -94,7 +86,7 @@ static void LoadCode(LoadState* S, Proto* f) · 26 unmodified lines
9486 LoadVector(S,f->code,n,sizeof(Instruction));
9587 }
9688
97−static Proto* LoadFunction(LoadState* S, TString* p);
89+static Proto* LoadFunction(LoadState* S);
9890
9991 static void LoadConstants(LoadState* S, Proto* f)
10092 {
@@ -113,7 +105,7 @@ static void LoadConstants(LoadState* S, Proto* f) · 12 unmodified lines
113105 setnilvalue(o);
114106 break;
115107 case LUA_TBOOLEAN:
116− setbvalue(o,LoadChar(S)!=0);
108+ setbvalue(o,LoadChar(S));
117109 break;
118110 case LUA_TNUMBER:
119111 setnvalue(o,LoadNumber(S));
@@ -121,16 +113,13 @@ static void LoadConstants(LoadState* S, Proto* f) · 1 unmodified line
121113 case LUA_TSTRING:
122114 setsvalue2n(S->L,o,LoadString(S));
123115 break;
124− default:
125− IF (1, "bad constant");
126− break;
127116 }
128117 }
129118 n=LoadInt(S);
130119 f->p=luaM_newvector(S->L,n,Proto*);
131120 f->sizep=n;
132121 for (i=0; i<n; i++) f->p[i]=NULL;
133− for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
122+ for (i=0; i<n; i++) f->p[i]=LoadFunction(S);
134123 }
135124
136125 static void LoadUpvalues(LoadState* S, Proto* f)
@@ -150,6 +139,7 @@ static void LoadUpvalues(LoadState* S, Proto* f) · 13 unmodified lines
150139 static void LoadDebug(LoadState* S, Proto* f)
151140 {
152141 int i,n;
142+ f->source=LoadString(S);
153143 n=LoadInt(S);
154144 f->lineinfo=luaM_newvector(S->L,n,int);
155145 f->sizelineinfo=n;
@@ -168,13 +158,10 @@ static void LoadDebug(LoadState* S, Proto* f) · 12 unmodified lines
168158 for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
169159 }
170160
171−static Proto* LoadFunction(LoadState* S, TString* p)
161+static Proto* LoadFunction(LoadState* S)
172162 {
173− Proto* f;
174− if (++G(S->L)->nCcalls > LUAI_MAXCCALLS) error(S, "function nest too deep");
175− f=luaF_newproto(S->L);
163+ Proto* f=luaF_newproto(S->L);
176164 setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
177− f->source=LoadString(S); if (f->source==NULL) f->source=p;
178165 f->linedefined=LoadInt(S);
179166 f->lastlinedefined=LoadInt(S);
180167 f->numparams=LoadByte(S);
@@ -185,17 +172,25 @@ static Proto* LoadFunction(LoadState* S, TString* p) · 4 unmodified lines
185172 LoadUpvalues(S,f);
186173 LoadDebug(S,f);
187174 S->L->top--;
188− G(S->L)->nCcalls--;
189175 return f;
190176 }
191177
178+/* the code below must be consistent with the code in luaU_header */
179+#define N0 LUAC_HEADERSIZE
180+#define N1 (sizeof(LUA_SIGNATURE)-1)
181+#define N2 N1+2
182+#define N3 N2+6
183+
192184 static void LoadHeader(LoadState* S)
193185 {
194186 char h[LUAC_HEADERSIZE];
195187 char s[LUAC_HEADERSIZE];
196188 luaU_header(h);
197189 LoadBlock(S,s,LUAC_HEADERSIZE);
198− IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
190+ if (memcmp(h,s,N0)==0) return;
191+ if (memcmp(h,s,N1)!=0) error(S,"not a");
192+ if (memcmp(h,s,N2)!=0) error(S,"version mismatch in");
193+ if (memcmp(h,s,N3)!=0) error(S,"incompatible"); else error(S,"corrupted");
199194 }
200195
201196 /*
@@ -214,23 +209,29 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) · 12 unmodified lines
214209 S.Z=Z;
215210 S.b=buff;
216211 LoadHeader(&S);
217− return LoadFunction(&S,luaS_newliteral(L,"=?"));
212+ return LoadFunction(&S);
218213 }
219214
215+/* data to catch conversion errors */
216+#define TAIL "\x19\x93\r\n\x1a\n"
217+
220218 /*
221−* make header
219+* make header for precompiled chunks
220+* if you make any changes in the code below or in LUA_SIGNATURE in lua.h,
221+* be sure to update LoadHeader above and LUAC_HEADERSIZE in lundump.h
222222 */
223223 void luaU_header (char* h)
224224 {
225225 int x=1;
226226 memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
227227 h+=sizeof(LUA_SIGNATURE)-1;
228− *h++=(char)LUAC_VERSION;
229− *h++=(char)LUAC_FORMAT;
228+ *h++=(char)0x52; /* Lua 5.2 */
229+ *h++=(char)0; /* the official format */
230230 *h++=(char)*(char*)&x; /* endianness */
231231 *h++=(char)sizeof(int);
232232 *h++=(char)sizeof(size_t);
233233 *h++=(char)sizeof(Instruction);
234234 *h++=(char)sizeof(lua_Number);
235235 *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
236+ memcpy(h,TAIL,sizeof(TAIL)-1);
236237 }
src/lundump.h+2−13
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lundump.h,v 1.37 2005/11/16 11:55:07 roberto Exp $
2+** $Id: lundump.h,v 1.43 2010/10/26 00:23:46 lhf Exp $
33 ** load precompiled Lua chunks
44 ** See Copyright Notice in lua.h
55 */
@@ -19,18 +19,7 @@ LUAI_FUNC void luaU_header (char* h); · 13 unmodified lines
1919 /* dump one chunk; from ldump.c */
2020 LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
2121
22−#ifdef luac_c
23−/* print one chunk; from print.c */
24−LUAI_FUNC void luaU_print (const Proto* f, int full);
25−#endif
26−
27−/* for header of binary files -- this is Lua 5.1 */
28−#define LUAC_VERSION 0x51
29−
30−/* for header of binary files -- this is the official format */
31−#define LUAC_FORMAT 0
32−
3322 /* size of header of binary files */
34−#define LUAC_HEADERSIZE 12
23+#define LUAC_HEADERSIZE 18
3524
3625 #endif
src/lvm.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 2.123 2010/06/30 14:11:17 roberto Exp $
2+** $Id: lvm.c,v 2.125 2010/10/29 17:52:46 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -301,7 +301,7 @@ void luaV_concat (lua_State *L, int total) { · 295 unmodified lines
301301 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
302302 }
303303 total -= n-1; /* got 'n' strings to create 1 new */
304− L->top -= n-1; /* poped 'n' strings and pushed one */
304+ L->top -= n-1; /* popped 'n' strings and pushed one */
305305 } while (total > 1); /* repeat until only 1 result left */
306306 }
307307
@@ -421,7 +421,7 @@ void luaV_finishOp (lua_State *L) { · 113 unmodified lines
421421 case OP_CONCAT: {
422422 StkId top = L->top - 1; /* top when 'call_binTM' was called */
423423 int b = GETARG_B(inst); /* first element to concatenate */
424− int total = top - 1 - (base + b); /* elements yet to concatenate */
424+ int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */
425425 setobj2s(L, top - 2, top); /* put TM result in proper position */
426426 if (total > 1) { /* are there elements to concat? */
427427 L->top = top - 1; /* top is one after last element (at top-2) */
src/print.c+0−229
@@ -1,229 +0,0 @@
1−/*
2−** $Id: print.c,v 1.61 2010/07/31 11:34:07 lhf Exp $
3−** print bytecodes
4−** See Copyright Notice in lua.h
5−*/
6−
7−#include <ctype.h>
8−#include <stdio.h>
9−
10−#define luac_c
11−#define LUA_CORE
12−
13−#include "ldebug.h"
14−#include "lobject.h"
15−#include "lopcodes.h"
16−#include "lundump.h"
17−
18−#define PrintFunction luaU_print
19−
20−#define Sizeof(x) ((int)sizeof(x))
21−#define VOID(p) ((const void*)(p))
22−
23−static void PrintString(const TString* ts)
24−{
25− const char* s=getstr(ts);
26− size_t i,n=ts->tsv.len;
27− putchar('"');
28− for (i=0; i<n; i++)
29− {
30− int c=s[i];
31− switch (c)
32− {
33− case '"': printf("\\\""); break;
34− case '\\': printf("\\\\"); break;
35− case '\a': printf("\\a"); break;
36− case '\b': printf("\\b"); break;
37− case '\f': printf("\\f"); break;
38− case '\n': printf("\\n"); break;
39− case '\r': printf("\\r"); break;
40− case '\t': printf("\\t"); break;
41− case '\v': printf("\\v"); break;
42− default: if (isprint((unsigned char)c))
43− putchar(c);
44− else
45− printf("\\%03u",(unsigned char)c);
46− }
47− }
48− putchar('"');
49−}
50−
51−static void PrintConstant(const Proto* f, int i)
52−{
53− const TValue* o=&f->k[i];
54− switch (ttype(o))
55− {
56− case LUA_TNIL:
57− printf("nil");
58− break;
59− case LUA_TBOOLEAN:
60− printf(bvalue(o) ? "true" : "false");
61− break;
62− case LUA_TNUMBER:
63− printf(LUA_NUMBER_FMT,nvalue(o));
64− break;
65− case LUA_TSTRING:
66− PrintString(rawtsvalue(o));
67− break;
68− default: /* cannot happen */
69− printf("? type=%d",ttype(o));
70− break;
71− }
72−}
73−
74−#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
75−
76−static void PrintCode(const Proto* f)
77−{
78− const Instruction* code=f->code;
79− int pc,n=f->sizecode;
80− for (pc=0; pc<n; pc++)
81− {
82− Instruction i=code[pc];
83− OpCode o=GET_OPCODE(i);
84− int a=GETARG_A(i);
85− int b=GETARG_B(i);
86− int c=GETARG_C(i);
87− int ax=GETARG_Ax(i);
88− int bx=GETARG_Bx(i);
89− int sbx=GETARG_sBx(i);
90− int line=getfuncline(f,pc);
91−#ifdef LUAC_DUMP_INSTRUCTIONS
92− printf("%0*X",2*sizeof(i),i);
93−#endif
94− printf("\t%d\t",pc+1);
95− if (line>0) printf("[%d]\t",line); else printf("[-]\t");
96− printf("%-9s\t",luaP_opnames[o]);
97− switch (getOpMode(o))
98− {
99− case iABC:
100− printf("%d",a);
101− if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
102− if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
103− break;
104− case iABx:
105− if (getBMode(o)==OpArgK) printf("%d %d",a,-bx); else printf("%d %d",a,bx);
106− break;
107− case iAsBx:
108− if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
109− break;
110− case iAx:
111− printf("%d",ax);
112− break;
113− }
114− switch (o)
115− {
116− case OP_LOADK:
117− printf("\t; "); PrintConstant(f,bx-1);
118− break;
119− case OP_GETUPVAL:
120− case OP_SETUPVAL:
121− printf("\t; %s", UPVALNAME(b));
122− break;
123− case OP_GETTABUP:
124− printf("\t; %s", UPVALNAME(b));
125− if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
126− break;
127− case OP_SETTABUP:
128− printf("\t; %s", UPVALNAME(a));
129− if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
130− if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
131− break;
132− case OP_GETTABLE:
133− case OP_SELF:
134− if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
135− break;
136− case OP_SETTABLE:
137− case OP_ADD:
138− case OP_SUB:
139− case OP_MUL:
140− case OP_DIV:
141− case OP_POW:
142− case OP_EQ:
143− case OP_LT:
144− case OP_LE:
145− if (ISK(b) || ISK(c))
146− {
147− printf("\t; ");
148− if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
149− printf(" ");
150− if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
151− }
152− break;
153− case OP_JMP:
154− case OP_FORLOOP:
155− case OP_FORPREP:
156− printf("\t; to %d",sbx+pc+2);
157− break;
158− case OP_CLOSURE:
159− printf("\t; %p",VOID(f->p[bx]));
160− break;
161− case OP_SETLIST:
162− if (c==0) printf("\t; %d",(int)code[++pc]);
163− else printf("\t; %d",c);
164− break;
165− default:
166− break;
167− }
168− printf("\n");
169− }
170−}
171−
172−#define SS(x) ((x==1)?"":"s")
173−#define S(x) x,SS(x)
174−
175−static void PrintHeader(const Proto* f)
176−{
177− const char* s=getstr(f->source);
178− if (*s=='@' || *s=='=')
179− s++;
180− else if (*s==LUA_SIGNATURE[0])
181− s="(bstring)";
182− else
183− s="(string)";
184− printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
185− (f->linedefined==0)?"main":"function",s,
186− f->linedefined,f->lastlinedefined,
187− S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
188− printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
189− f->numparams,f->is_vararg?"+":"",SS(f->numparams),
190− S(f->maxstacksize),S(f->sizeupvalues));
191− printf("%d local%s, %d constant%s, %d function%s\n",
192− S(f->sizelocvars),S(f->sizek),S(f->sizep));
193−}
194−
195−static void PrintDebug(const Proto* f)
196−{
197− int i,n;
198− n=f->sizek;
199− printf("constants (%d) for %p:\n",n,VOID(f));
200− for (i=0; i<n; i++)
201− {
202− printf("\t%d\t",i+1);
203− PrintConstant(f,i);
204− printf("\n");
205− }
206− n=f->sizelocvars;
207− printf("locals (%d) for %p:\n",n,VOID(f));
208− for (i=0; i<n; i++)
209− {
210− printf("\t%d\t%s\t%d\t%d\n",
211− i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
212− }
213− n=f->sizeupvalues;
214− printf("upvalues (%d) for %p:\n",n,VOID(f));
215− if (f->upvalues==NULL) return;
216− for (i=0; i<n; i++)
217− {
218− printf("\t%d\t%s\n",i,getstr(f->upvalues[i].name));
219− }
220−}
221−
222−void PrintFunction(const Proto* f, int full)
223−{
224− int i,n=f->sizep;
225− PrintHeader(f);
226− PrintCode(f);
227− if (full) PrintDebug(f);
228− for (i=0; i<n; i++) PrintFunction(f->p[i],full);
229−}
test/hello.lua+0−3
@@ -1,3 +0,0 @@
1−-- the first program in every language
2−
3−io.write("Hello world, from ",_VERSION,"!\n")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t