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
55 cd src && $(MAKE) $@55 cd src && $(MAKE) $@
56 56
57test: dummy57test: dummy
58 src/lua test/hello.lua58 src/lua -v
59 59
60install: dummy60install: dummy
61 cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)61 cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
README+3−3
@@ -1,6 +1,6 @@
1 1
2This is Lua 5.2 (work4), released on 30 July 2010.2This is Lua 5.2 (work5), released on 30 Oct 2010.
3 3
4For information about Lua, including installation instructions and4For installation instructions, license details, and
5license details, see doc/readme.html.5further information about Lua, see doc/readme.html.
6 6
doc/Makefile+0−9
@@ -1,9 +0,0 @@
1R= readme
2T= $R.txt
3H= $R.html
4
5$T: $H
6 lynx -dump $? >$@
7
8clean:
9 -rm -f $T
doc/contents.html+18−12
@@ -126,7 +126,7 @@ Freely available under the terms of the · 125 unmodified lines
126<LI><A HREF="manual.html#6.10">6.10 &ndash; The Debug Library</A>126<LI><A HREF="manual.html#6.10">6.10 &ndash; The Debug Library</A>
127</UL>127</UL>
128<P>128<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>
130<P>130<P>
131<LI><A HREF="manual.html#8">8 &ndash; Incompatibilities with the Previous Version</A>131<LI><A HREF="manual.html#8">8 &ndash; Incompatibilities with the Previous Version</A>
132<UL>132<UL>
@@ -172,15 +172,16 @@ Freely available under the terms of the · 39 unmodified lines
172<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>172<A HREF="manual.html#pdf-xpcall">xpcall</A><BR>
173 173
174<P>174<P>
175<A HREF="manual.html#pdf-bit.band">bit.band</A><BR>175<A HREF="manual.html#pdf-bit32.AND">bit32.AND</A><BR>
176<A HREF="manual.html#pdf-bit.bnot">bit.bnot</A><BR>176<A HREF="manual.html#pdf-bit32.NOT">bit32.NOT</A><BR>
177<A HREF="manual.html#pdf-bit.bor">bit.bor</A><BR>177<A HREF="manual.html#pdf-bit32.OR">bit32.OR</A><BR>
178<A HREF="manual.html#pdf-bit.btest">bit.btest</A><BR>178<A HREF="manual.html#pdf-bit32.ROL">bit32.ROL</A><BR>
179<A HREF="manual.html#pdf-bit.bxor">bit.bxor</A><BR>179<A HREF="manual.html#pdf-bit32.ROR">bit32.ROR</A><BR>
180<A HREF="manual.html#pdf-bit.lshift">bit.lshift</A><BR>180<A HREF="manual.html#pdf-bit32.SAR">bit32.SAR</A><BR>
181<A HREF="manual.html#pdf-bit.rol">bit.rol</A><BR>181<A HREF="manual.html#pdf-bit32.SHL">bit32.SHL</A><BR>
182<A HREF="manual.html#pdf-bit.ror">bit.ror</A><BR>182<A HREF="manual.html#pdf-bit32.SHR">bit32.SHR</A><BR>
183<A HREF="manual.html#pdf-bit.rshift">bit.rshift</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>
184 185
185<P>186<P>
186<A HREF="manual.html#pdf-coroutine.create">coroutine.create</A><BR>187<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
326<A HREF="manual.html#lua_Number">lua_Number</A><BR>327<A HREF="manual.html#lua_Number">lua_Number</A><BR>
327<A HREF="manual.html#lua_Reader">lua_Reader</A><BR>328<A HREF="manual.html#lua_Reader">lua_Reader</A><BR>
328<A HREF="manual.html#lua_State">lua_State</A><BR>329<A HREF="manual.html#lua_State">lua_State</A><BR>
330<A HREF="manual.html#lua_Unsigned">lua_Unsigned</A><BR>
329<A HREF="manual.html#lua_Writer">lua_Writer</A><BR>331<A HREF="manual.html#lua_Writer">lua_Writer</A><BR>
330 332
331<P>333<P>
@@ -426,6 +428,8 @@ Freely available under the terms of the · 94 unmodified lines
426<A HREF="manual.html#lua_topointer">lua_topointer</A><BR>428<A HREF="manual.html#lua_topointer">lua_topointer</A><BR>
427<A HREF="manual.html#lua_tostring">lua_tostring</A><BR>429<A HREF="manual.html#lua_tostring">lua_tostring</A><BR>
428<A HREF="manual.html#lua_tothread">lua_tothread</A><BR>430<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>
429<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>433<A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR>
430<A HREF="manual.html#lua_type">lua_type</A><BR>434<A HREF="manual.html#lua_type">lua_type</A><BR>
431<A HREF="manual.html#lua_typename">lua_typename</A><BR>435<A HREF="manual.html#lua_typename">lua_typename</A><BR>
@@ -465,6 +469,7 @@ Freely available under the terms of the · 33 unmodified lines
465<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>469<A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR>
466<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>470<A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR>
467<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>471<A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR>
472<A HREF="manual.html#luaL_checkunsigned">luaL_checkunsigned</A><BR>
468<A HREF="manual.html#luaL_checkversion">luaL_checkversion</A><BR>473<A HREF="manual.html#luaL_checkversion">luaL_checkversion</A><BR>
469<A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR>474<A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR>
470<A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR>475<A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR>
@@ -487,6 +492,7 @@ Freely available under the terms of the · 16 unmodified lines
487<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>492<A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR>
488<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>493<A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR>
489<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>494<A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR>
495<A HREF="manual.html#luaL_optunsigned">luaL_optunsigned</A><BR>
490<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>496<A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR>
491<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>497<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
492<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>498<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
@@ -506,10 +512,10 @@ Freely available under the terms of the · 13 unmodified lines
506<HR>512<HR>
507<SMALL>513<SMALL>
508Last update:514Last update:
509Fri Jul 30 15:13:14 BRT 2010515Sat Oct 30 21:34:44 BRST 2010
510</SMALL>516</SMALL>
511<!--517<!--
512Last change: revised for Lua 5.2.0 (work4)518Last change: revised for Lua 5.2.0 (work5)
513-->519-->
514 520
515</BODY>521</BODY>
doc/manual.html+331−159
@@ -38,12 +38,12 @@ Freely available under the terms of the · 37 unmodified lines
38<!-- ====================================================================== -->38<!-- ====================================================================== -->
39<p>39<p>
40 40
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 $ -->
42 42
43 43
44 44
45 45
46<h1>1 - <a name="1">Introduction</a></h1>46<h1>1 &ndash; <a name="1">Introduction</a></h1>
47 47
48<p>48<p>
49Lua is an extension programming language designed to support49Lua 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
68a wide range of different domains,68a wide range of different domains,
69thus creating customized programming languages sharing a syntactical framework.69thus creating customized programming languages sharing a syntactical framework.
70The Lua distribution includes a sample host program called <code>lua</code>,70The Lua distribution includes a sample host program called <code>lua</code>,
71which uses the Lua library to offer a complete, stand-alone Lua interpreter.71which uses the Lua library to offer a complete, standalone Lua interpreter.
72 72
73 73
74<p>74<p>
@@ -89,14 +89,14 @@ see Roberto's book, <em>Programming in Lua (Second Edition)</em>. · 14 unmodified lines
89 89
90 90
91 91
92<h1>2 - <a name="2">Basic Concepts</a></h1>92<h1>2 &ndash; <a name="2">Basic Concepts</a></h1>
93 93
94<p>94<p>
95This section describes some basic concepts of the language.95This section describes some basic concepts of the language.
96 96
97 97
98 98
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>
100 100
101<p>101<p>
102Lua is a <em>dynamically typed language</em>.102Lua is a <em>dynamically typed language</em>.
@@ -205,14 +205,29 @@ of a given value. · 102 unmodified lines
205 205
206 206
207 207
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>
209 209
210<p>210<p>
211As discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,211As discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
212any reference to a global name <code>var</code> is syntactically translated 212any reference to a global name <code>var</code> is syntactically translated
213to <code>_ENV.var</code>.213to <code>_ENV.var</code>.
214Moreover, any chunk is compiled in the scope of an external214Moreover, any chunk is compiled in the scope of an external
215variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>).215variable called <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>),
216so <code>_ENV</code> itself is never a global name in a chunk.
217
218
219<p>
220Despite the existence of this external <code>_ENV</code> variable and
221the translation of global names,
222<code>_ENV</code> is a completely regular name.
223In particular,
224you can define new variables and parameters with that name.
225Each reference to a global name uses the <code>_ENV</code> that is
226visible at that point in the program,
227following the usual visibility rules of Lua.
228
229
230<p>
216Any table used as the value of <code>_ENV</code> is usually called231Any table used as the value of <code>_ENV</code> is usually called
217an <em>environment</em>.232an <em>environment</em>.
218 233
@@ -250,7 +265,7 @@ is never updated by Lua. · 31 unmodified lines
250 265
251 266
252 267
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>
254 269
255<p>270<p>
256Because Lua is an embedded extension language,271Because 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
272 287
273 288
274 289
275<h2>2.4 - <a name="2.4">Metatables</a></h2>290<h2>2.4 &ndash; <a name="2.4">Metatables</a></h2>
276 291
277<p>292<p>
278Every value in Lua can have a <em>metatable</em>.293Every value in Lua can have a <em>metatable</em>.
@@ -282,7 +297,7 @@ under certain special operations. · 3 unmodified lines
282You can change several aspects of the behavior297You can change several aspects of the behavior
283of operations over a value by setting specific fields in its metatable.298of operations over a value by setting specific fields in its metatable.
284For instance, when a non-numeric value is the operand of an addition,299For instance, when a non-numeric value is the operand of an addition,
285Lua checks for a function in the field <code>"__add"</code> in its metatable.300Lua checks for a function in the field "<code>__add</code>" in its metatable.
286If it finds one,301If it finds one,
287Lua calls this function to perform the addition.302Lua calls this function to perform the addition.
288 303
@@ -337,7 +352,7 @@ Each operation is identified by its corresponding name. · 48 unmodified lines
337The key for each operation is a string with its name prefixed by352The key for each operation is a string with its name prefixed by
338two underscores, '<code>__</code>';353two underscores, '<code>__</code>';
339for instance, the key for operation "add" is the354for instance, the key for operation "add" is the
340string <code>"__add"</code>.355string "<code>__add</code>".
341The semantics of these operations is better explained by a Lua function356The semantics of these operations is better explained by a Lua function
342describing how the interpreter executes the operation.357describing how the interpreter executes the operation.
343 358
@@ -684,7 +699,7 @@ called when Lua calls a value. · 340 unmodified lines
684 699
685 700
686 701
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>
688 703
689<p>704<p>
690Lua performs automatic memory management.705Lua performs automatic memory management.
@@ -748,7 +763,7 @@ the collector directly (e.g., stop and restart it). · 57 unmodified lines
748 763
749 764
750 765
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>
752 767
753<p>768<p>
754Using the C&nbsp;API,769Using the C&nbsp;API,
@@ -761,9 +776,22 @@ or freeing your own memory). · 6 unmodified lines
761 776
762 777
763<p>778<p>
764Garbage userdata with a field <code>__gc</code> in their metatables are not779For a userdata to be finalized when collected,
765collected immediately by the garbage collector.780you must <em>mark</em> it first.
766Instead, Lua puts them in a list.781
782You mark a userdata for finalization when you set its metatable
783and the metatable has a field indexed by the string "<code>__gc</code>".
784Note that if you set a metatable without a <code>__gc</code> field
785and later create that field,
786the userdata will not be marked for finalization.
787However, after a userdata is marked,
788you can freely change the <code>__gc</code> field of its metatable.
789
790
791<p>
792When a marked userdata becomes garbage,
793it is not collected immediately by the garbage collector.
794Instead, Lua puts it in a list.
767After the collection,795After the collection,
768Lua does the equivalent of the following function796Lua does the equivalent of the following function
769for each userdata in that list:797for each userdata in that list:
@@ -771,7 +799,7 @@ for each userdata in that list: · 1 unmodified line
771<pre>799<pre>
772 function gc_event (udata)800 function gc_event (udata)
773 local h = metatable(udata).__gc801 local h = metatable(udata).__gc
774 if h then802 if type(h) == "function" then
775 h(udata)803 h(udata)
776 end804 end
777 end805 end
@@ -779,18 +807,18 @@ for each userdata in that list: · 1 unmodified line
779 807
780<p>808<p>
781At the end of each garbage-collection cycle,809At the end of each garbage-collection cycle,
782the finalizers for userdata are called in <em>reverse</em>810the finalizers for userdata are called in
783order of their creation,811the reverse order that they were marked for collection,
784among those collected in that cycle.812among those collected in that cycle;
785That is, the first finalizer to be called is the one associated813that is, the first finalizer to be called is the one associated
786with the userdata created last in the program.814with the userdata marked last in the program.
787The userdata itself is freed only in the next garbage-collection cycle.815The userdata memory is freed only in the next garbage-collection cycle.
788 816
789 817
790 818
791 819
792 820
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>
794 822
795<p>823<p>
796A <em>weak table</em> is a table whose elements are824A <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
823In an ephemeron table,851In an ephemeron table,
824a value is considered reachable only if its key is reachable.852a value is considered reachable only if its key is reachable.
825In particular,853In particular,
826if the only reference to a key comes from its value,854if the only reference to a key comes through its value,
827the pair is removed.855the pair is removed.
828 856
829 857
@@ -845,8 +873,8 @@ Lua treats strings and light C functions as non-object values. · 15 unmodified lines
845 873
846 874
847<p>875<p>
848Userdata with finalizers has a special behavior in weak tables.876Userdata marked for finalization has a special behavior in weak tables.
849When a userdata is a value in a weak table,877When a marked userdata is a value in a weak table,
850it is removed from the table the first time it is collected,878it is removed from the table the first time it is collected,
851before running its finalizer.879before running its finalizer.
852When it is a key, however,880When it is a key, however,
@@ -861,7 +889,7 @@ associated with the userdata through weak tables. · 8 unmodified lines
861 889
862 890
863 891
864<h2>2.6 - <a name="2.6">Coroutines</a></h2>892<h2>2.6 &ndash; <a name="2.6">Coroutines</a></h2>
865 893
866<p>894<p>
867Lua supports coroutines,895Lua supports coroutines,
@@ -980,7 +1008,7 @@ and <a href="#lua_yield"><code>lua_yield</code></a>. · 112 unmodified lines
980 1008
981 1009
982 1010
983<h1>3 - <a name="3">The Language</a></h1>1011<h1>3 &ndash; <a name="3">The Language</a></h1>
984 1012
985<p>1013<p>
986This section describes the lexis, the syntax, and the semantics of Lua.1014This section describes the lexis, the syntax, and the semantics of Lua.
@@ -1004,7 +1032,7 @@ at the end of this manual. · 17 unmodified lines
1004 1032
1005 1033
1006 1034
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>
1008 1036
1009<p>1037<p>
1010Lua is a free-form language.1038Lua is a free-form language.
@@ -1073,7 +1101,7 @@ results in a newline in the string. · 62 unmodified lines
1073The escape sequence '<code>\*</code>' skips the following span1101The escape sequence '<code>\*</code>' skips the following span
1074of white-space characters,1102of white-space characters,
1075including line breaks;1103including line breaks;
1076it is particularly useful to break and ident a string 1104it is particularly useful to break and indent a long string
1077into multiple lines without adding the newlines and spaces1105into multiple lines without adding the newlines and spaces
1078into the string contents.1106into the string contents.
1079 1107
@@ -1161,7 +1189,7 @@ Long comments are frequently used to disable code temporarily. · 81 unmodified lines
1161 1189
1162 1190
1163 1191
1164<h2>3.2 - <a name="3.2">Variables</a></h2>1192<h2>3.2 &ndash; <a name="3.2">Variables</a></h2>
1165 1193
1166<p>1194<p>
1167Variables are places that store values.1195Variables are places that store values.
@@ -1226,7 +1254,7 @@ Due to the way that chunks are compiled, · 58 unmodified lines
1226 1254
1227 1255
1228 1256
1229<h2>3.3 - <a name="3.3">Statements</a></h2>1257<h2>3.3 &ndash; <a name="3.3">Statements</a></h2>
1230 1258
1231<p>1259<p>
1232Lua supports an almost conventional set of statements,1260Lua supports an almost conventional set of statements,
@@ -1237,7 +1265,7 @@ and variable declarations. · 4 unmodified lines
1237 1265
1238 1266
1239 1267
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>
1241 1269
1242<p>1270<p>
1243A block is a list of statements,1271A 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
1271 1299
1272 1300
1273 1301
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>
1275 1303
1276<p>1304<p>
1277The unit of execution of Lua is called a <em>chunk</em>.1305The 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
1290receive arguments, and return values.1318receive arguments, and return values.
1291Moreover, such anonymous function is compiled as in the1319Moreover, such anonymous function is compiled as in the
1292scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">&sect;2.2</a>).1320scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">&sect;2.2</a>).
1321The resulting function always has <code>_ENV</code> as its only upvalue,
1322even if it does not use that variable.
1293 1323
1294 1324
1295<p>1325<p>
@@ -1311,7 +1341,7 @@ Lua automatically detects the file type and acts accordingly. · 15 unmodified lines
1311 1341
1312 1342
1313 1343
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>
1315 1345
1316<p>1346<p>
1317Lua allows multiple assignments.1347Lua allows multiple assignments.
@@ -1388,7 +1418,7 @@ is equivalent to the assignment · 70 unmodified lines
1388 1418
1389 1419
1390 1420
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>
1392The control structures1422The control structures
1393<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and1423<b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and
1394familiar syntax:1424familiar syntax:
@@ -1458,7 +1488,7 @@ their (inner) blocks. · 63 unmodified lines
1458 1488
1459 1489
1460 1490
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>
1462 1492
1463<p>1493<p>
1464 1494
@@ -1589,7 +1619,7 @@ then assign them to other variables before breaking or exiting the loop. · 124 unmodified lines
1589 1619
1590 1620
1591 1621
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>
1593To allow possible side-effects,1623To allow possible side-effects,
1594function calls can be executed as statements:1624function calls can be executed as statements:
1595 1625
@@ -1603,7 +1633,7 @@ Function calls are explained in <a href="#3.4.9">&sect;3.4.9</a>. · 7 unmodified lines
1603 1633
1604 1634
1605 1635
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>
1607Local variables can be declared anywhere inside a block.1637Local variables can be declared anywhere inside a block.
1608The declaration can include an initial assignment:1638The declaration can include an initial assignment:
1609 1639
@@ -1630,7 +1660,7 @@ The visibility rules for local variables are explained in <a href="#3.5">&sect;3 · 20 unmodified lines
1630 1660
1631 1661
1632 1662
1633<h2>3.4 - <a name="3.4">Expressions</a></h2>1663<h2>3.4 &ndash; <a name="3.4">Expressions</a></h2>
1634 1664
1635<p>1665<p>
1636The basic expressions in Lua are the following:1666The 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
1716 1746
1717 1747
1718 1748
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>
1720Lua supports the usual arithmetic operators:1750Lua supports the usual arithmetic operators:
1721the binary <code>+</code> (addition),1751the binary <code>+</code> (addition),
1722<code>-</code> (subtraction), <code>*</code> (multiplication),1752<code>-</code> (subtraction), <code>*</code> (multiplication),
@@ -1739,7 +1769,7 @@ the quotient towards minus infinity. · 16 unmodified lines
1739 1769
1740 1770
1741 1771
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>
1743 1773
1744<p>1774<p>
1745Lua provides automatic conversion between1775Lua provides automatic conversion between
@@ -1756,7 +1786,7 @@ use the <code>format</code> function from the string library · 10 unmodified lines
1756 1786
1757 1787
1758 1788
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>
1760The relational operators in Lua are1790The relational operators in Lua are
1761 1791
1762<pre>1792<pre>
@@ -1812,7 +1842,7 @@ and <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>. · 49 unmodified lines
1812 1842
1813 1843
1814 1844
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>
1816The logical operators in Lua are1846The logical operators in Lua are
1817<b>and</b>, <b>or</b>, and <b>not</b>.1847<b>and</b>, <b>or</b>, and <b>not</b>.
1818Like the control structures (see <a href="#3.3.4">&sect;3.3.4</a>),1848Like 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
1850 1880
1851 1881
1852 1882
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>
1854The string concatenation operator in Lua is1884The string concatenation operator in Lua is
1855denoted by two dots ('<code>..</code>').1885denoted by two dots ('<code>..</code>').
1856If both operands are strings or numbers, then they are converted to1886If 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
1861 1891
1862 1892
1863 1893
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>
1865 1895
1866<p>1896<p>
1867The length operator is denoted by the unary prefix operator <code>#</code>.1897The 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
1895 1925
1896 1926
1897 1927
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>
1899Operator precedence in Lua follows the table below,1929Operator precedence in Lua follows the table below,
1900from lower to higher priority:1930from lower to higher priority:
1901 1931
@@ -1919,7 +1949,7 @@ All other binary operators are left associative. · 17 unmodified lines
1919 1949
1920 1950
1921 1951
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>
1923Table constructors are expressions that create tables.1953Table constructors are expressions that create tables.
1924Every time a constructor is evaluated, a new table is created.1954Every time a constructor is evaluated, a new table is created.
1925A constructor can be used to create an empty table1955A constructor can be used to create an empty table
@@ -1981,7 +2011,7 @@ as a convenience for machine-generated code. · 55 unmodified lines
1981 2011
1982 2012
1983 2013
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>
1985A function call in Lua has the following syntax:2015A function call in Lua has the following syntax:
1986 2016
1987<pre>2017<pre>
@@ -2056,7 +2086,7 @@ So, none of the following examples are tail calls: · 68 unmodified lines
2056 2086
2057 2087
2058 2088
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>
2060 2090
2061<p>2091<p>
2062The syntax for function definition is2092The syntax for function definition is
@@ -2206,7 +2236,7 @@ is syntactic sugar for · 143 unmodified lines
2206 2236
2207 2237
2208 2238
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>
2210 2240
2211<p>2241<p>
2212 2242
@@ -2268,7 +2298,7 @@ while all of them share the same <code>x</code>. · 55 unmodified lines
2268 2298
2269 2299
2270 2300
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>
2272 2302
2273<p>2303<p>
2274 2304
@@ -2296,7 +2326,7 @@ in file <code>luaconf.h</code>. · 21 unmodified lines
2296 2326
2297 2327
2298 2328
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>
2300 2330
2301<p>2331<p>
2302Lua uses a <em>virtual stack</em> to pass values to and from C.2332Lua 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
2338 2368
2339 2369
2340 2370
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>
2342 2372
2343<p>2373<p>
2344When you interact with Lua API,2374When you interact with the Lua API,
2345you are responsible for ensuring consistency.2375you are responsible for ensuring consistency.
2346In particular,2376In particular,
2347<em>you are responsible for controlling stack overflow</em>.2377<em>you are responsible for controlling stack overflow</em>.
@@ -2384,7 +2414,7 @@ Note that 0 is never an acceptable index. · 36 unmodified lines
2384 2414
2385 2415
2386 2416
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>
2388 2418
2389<p>2419<p>
2390Unless otherwise noted,2420Unless 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
2399 2429
2400 2430
2401 2431
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>
2403 2433
2404<p>2434<p>
2405When a C&nbsp;function is created,2435When a C&nbsp;function is created,
@@ -2426,7 +2456,7 @@ produces an acceptable (but invalid) index. · 20 unmodified lines
2426 2456
2427 2457
2428 2458
2429<h2>4.5 - <a name="4.5">Registry</a></h2>2459<h2>4.5 &ndash; <a name="4.5">Registry</a></h2>
2430 2460
2431<p>2461<p>
2432Lua provides a <em>registry</em>,2462Lua provides a <em>registry</em>,
@@ -2437,8 +2467,12 @@ This table is always located at pseudo-index · 4 unmodified lines
2437Any C&nbsp;library can store data into this table,2467Any C&nbsp;library can store data into this table,
2438but it should take care to choose keys different from those used2468but it should take care to choose keys different from those used
2439by other libraries, to avoid collisions.2469by other libraries, to avoid collisions.
2440Typically, you should use as key a string containing your library name2470Typically, you should use as key a string containing your library name,
2441or a light userdata with the address of a C&nbsp;object in your code.2471or a light userdata with the address of a C&nbsp;object in your code,
2472or any Lua object created by your code.
2473As with global names,
2474string keys starting with an underscore followed by
2475uppercase letters are reserved for Lua.
2442 2476
2443 2477
2444<p>2478<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
2470 2504
2471 2505
2472 2506
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>
2474 2508
2475<p>2509<p>
2476Internally, Lua uses the C <code>longjmp</code> facility to handle errors.2510Internally, 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
2509 2543
2510 2544
2511 2545
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>
2513 2547
2514<p>2548<p>
2515Internally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.2549Internally, 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
2522 2556
2523<p>2557<p>
2524To avoid this kind of problem,2558To avoid this kind of problem,
2525Lua raises an error whenever it tries to yield accross an API call,2559Lua raises an error whenever it tries to yield across an API call,
2526except for three functions:2560except for three functions:
2527<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>.2561<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>.
2528All those functions receive a <em>continuation function</em>2562All 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
2577 2611
2578 2612
2579 2613
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>
2581 2615
2582<p>2616<p>
2583Here we list all functions and types from the C&nbsp;API in2617Here 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
2731<li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>:</b>performs multiplication (<code>*</code>)</li>2765<li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>:</b>performs multiplication (<code>*</code>)</li>
2732<li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>:</b>performs division (<code>/</code>)</li>2766<li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>:</b>performs division (<code>/</code>)</li>
2733<li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>:</b>performs modulo (<code>%</code>)</li>2767<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>
2735<li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>:</b>performs mathematical negation (unary <code>-</code>)</li>2769<li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>:</b>performs mathematical negation (unary <code>-</code>)</li>
2736 2770
2737</ul>2771</ul>
@@ -3264,7 +3298,7 @@ because a pseudo-index is not an actual stack position. · 526 unmodified lines
3264<pre>typedef ptrdiff_t lua_Integer;</pre>3298<pre>typedef ptrdiff_t lua_Integer;</pre>
3265 3299
3266<p>3300<p>
3267The type used by the Lua API to represent integral values.3301The type used by the Lua API to represent signed integral values.
3268 3302
3269 3303
3270<p>3304<p>
@@ -3493,8 +3527,8 @@ which is used for error messages and in debug information (see <a href="#4.9">&s · 222 unmodified lines
3493 3527
3494 3528
3495<p>3529<p>
3496If the resulting function has upvalues,3530If the resulting function has one upvalue,
3497the first upvalue is set to the value of the global environment3531this upvalue is set to the value of the global environment
3498stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">&sect;4.5</a>).3532stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">&sect;4.5</a>).
3499(When loading main chunks,3533(When loading main chunks,
3500this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).)3534this 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
4334You can only call functions in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.4368You can only call functions in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.
4335You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>4369You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>
4336(to start a new coroutine) or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a>4370(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).
4338 4372
4339 4373
4340 4374
@@ -4517,6 +4551,46 @@ otherwise, the function returns <code>NULL</code>. · 176 unmodified lines
4517 4551
4518 4552
4519 4553
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>
4559A 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>
4570Converts the Lua value at the given acceptable index
4571to the unsigned integral type <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
4572The 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>);
4574otherwise, <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> returns&nbsp;0.
4575
4576
4577<p>
4578If the number is not an integer,
4579it is truncated in some non-specified way.
4580If the number is outside the range of representable values,
4581it is normalized to the remainder of its division by
4582one more than the maximum representable value.
4583
4584
4585<p>
4586If <code>isnum</code> is different from <code>NULL</code>,
4587its referent is assigned a boolean value that
4588indicates whether the operation succeeded.
4589
4590
4591
4592
4593
4520<hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>4594<hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>
4521<span class="apii">[-0, +0, <em>-</em>]</span>4595<span class="apii">[-0, +0, <em>-</em>]</span>
4522<pre>void *lua_touserdata (lua_State *L, int index);</pre>4596<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
4569 4643
4570 4644
4571 4645
4646<hr><h3><a name="lua_Unsigned"><code>lua_Unsigned</code></a></h3>
4647<pre>typedef unsigned long lua_Unsigned;</pre>
4648
4649<p>
4650The type used by the Lua API to represent unsigned integral values.
4651It must have at least 32 bits.
4652
4653
4654<p>
4655By default it is an <code>unsigned int</code> or an <code>unsigned long</code>,
4656whichever can hold 32-bit values.
4657
4658
4659
4660
4661
4572<hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p>4662<hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p>
4573<span class="apii">[-0, +0, <em>v</em>]</span>4663<span class="apii">[-0, +0, <em>v</em>]</span>
4574<pre>const lua_Number *lua_version (lua_State *L);</pre>4664<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
4681 4771
4682 4772
4683 4773
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>
4685 4775
4686<p>4776<p>
4687Lua has no built-in debugging facilities.4777Lua has no built-in debugging facilities.
@@ -5165,16 +5255,19 @@ will return identical ids for those upvalue indices. · 477 unmodified lines
5165 5255
5166<hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3>5256<hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3>
5167<pre>void lua_upvaluejoin (lua_State *L, int fidx1, int n1,5257<pre>void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
5168 int fidx2, int n2);</pre><p>5258 int fidx2, int n2);</pre>
5169TO BE DONE!!
5170 5259
5260<p>
5261Make the <code>n1</code>-th upvalue of the Lua closure at index <code>fidx1</code>
5262refer to the <code>n2</code>-th upvalue of the Lua closure at index <code>fidx2</code>.
5171 5263
5172 5264
5173 5265
5174 5266
5175 5267
5176 5268
5177<h1>5 - <a name="5">The Auxiliary Library</a></h1>5269
5270<h1>5 &ndash; <a name="5">The Auxiliary Library</a></h1>
5178 5271
5179<p>5272<p>
5180 5273
@@ -5220,7 +5313,7 @@ always throw an error if the check is not satisfied. · 39 unmodified lines
5220 5313
5221 5314
5222 5315
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>
5224 5317
5225<p>5318<p>
5226Here we list all functions and types from the auxiliary library5319Here 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
5591 5684
5592 5685
5593 5686
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>
5692Checks whether the function argument <code>narg</code> is a number
5693and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
5694
5695
5696
5697
5698
5594<hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>5699<hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
5595<span class="apii">[-0, +0, <em>-</em>]</span>5700<span class="apii">[-0, +0, <em>-</em>]</span>
5596<pre>void *luaL_checkversion (lua_State *L);</pre>5701<pre>void *luaL_checkversion (lua_State *L);</pre>
@@ -5959,7 +6064,7 @@ Otherwise, raises an error. · 362 unmodified lines
5959 6064
5960<p>6065<p>
5961If <code>l</code> is not <code>NULL</code>,6066If <code>l</code> is not <code>NULL</code>,
5962fills the position <code>*l</code> with the results's length.6067fills the position <code>*l</code> with the result's length.
5963 6068
5964 6069
5965 6070
@@ -5997,6 +6102,23 @@ Otherwise, raises an error. · 31 unmodified lines
5997 6102
5998 6103
5999 6104
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>
6112If the function argument <code>narg</code> is a number,
6113returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>.
6114If this argument is absent or is <b>nil</b>,
6115returns <code>u</code>.
6116Otherwise, raises an error.
6117
6118
6119
6120
6121
6000<hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p>6122<hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p>
6001<span class="apii">[-0, +0, <em>-</em>]</span>6123<span class="apii">[-0, +0, <em>-</em>]</span>
6002<pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre>6124<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
6222 6344
6223 6345
6224 6346
6225<h1>6 - <a name="6">Standard Libraries</a></h1>6347<h1>6 &ndash; <a name="6">Standard Libraries</a></h1>
6226 6348
6227<p>6349<p>
6228The standard Lua libraries provide useful functions6350The 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
6291 6413
6292 6414
6293 6415
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>
6295 6417
6296<p>6418<p>
6297The basic library provides some core functions to Lua.6419The basic library provides some core functions to Lua.
@@ -6513,7 +6635,8 @@ The default is "<code>bt</code>". · 215 unmodified lines
6513This function is similar to <a href="#pdf-load"><code>load</code></a>,6635This function is similar to <a href="#pdf-load"><code>load</code></a>,
6514but sets <code>env</code> as the value of the first upvalue6636but sets <code>env</code> as the value of the first upvalue
6515of the created function in case of success.6637of 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,
6639this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).)
6517The parameters after <code>env</code> are similar to those of <a href="#pdf-load"><code>load</code></a>, too.6640The parameters after <code>env</code> are similar to those of <a href="#pdf-load"><code>load</code></a>, too.
6518 6641
6519 6642
@@ -6797,7 +6920,7 @@ except that it sets a new error handler <code>err</code>. · 277 unmodified lines
6797 6920
6798 6921
6799 6922
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>
6801 6924
6802<p>6925<p>
6803The operations related to coroutines comprise a sub-library of6926The 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
6907 7030
6908 7031
6909 7032
6910<h2>6.3 - <a name="6.3">Modules</a></h2>7033<h2>6.3 &ndash; <a name="6.3">Modules</a></h2>
6911 7034
6912<p>7035<p>
6913The package library provides basic7036The 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
6954<p>7077<p>
6955Once a loader is found,7078Once a loader is found,
6956<code>require</code> calls the loader with a single argument, <code>modname</code>.7079<code>require</code> calls the loader with a single argument, <code>modname</code>.
6957If the loader returns any value,7080If the loader returns any non-nil value,
6958<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.7081<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.
6959If the loader returns no value and7082If the loader does not return a non-nil value and
6960has not assigned any value to <code>package.loaded[modname]</code>,7083has not assigned any value to <code>package.loaded[modname]</code>,
6961then <code>require</code> assigns <b>true</b> to this entry.7084then <code>require</code> assigns <b>true</b> to this entry.
6962In any case, <code>require</code> returns the7085In any case, <code>require</code> returns the
@@ -6995,7 +7118,7 @@ Default is '<code>?</code>'.</li> · 32 unmodified lines
6995is replaced by the executable's directory.7118is replaced by the executable's directory.
6996Default is '<code>!</code>'.</li>7119Default is '<code>!</code>'.</li>
6997 7120
6998<li>The fifth line is a mark to ignore all before it when bulding the7121<li>The fifth line is a mark to ignore all before it when building the
6999<code>luaopen_</code> function name.7122<code>luaopen_</code> function name.
7000Default is '<code>-</code>'.</li>7123Default is '<code>-</code>'.</li>
7001 7124
@@ -7227,7 +7350,7 @@ or <b>nil</b> plus an error message if none succeeds. · 225 unmodified lines
7227 7350
7228 7351
7229 7352
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>
7231 7354
7232<p>7355<p>
7233This library provides generic functions for string manipulation,7356This 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
7556 7679
7557 7680
7558 7681
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>
7560 7683
7561 7684
7562<h4>Character Class:</h4><p>7685<h4>Character Class:</h4><p>
@@ -7605,7 +7728,8 @@ when used to represent itself in a pattern. · 42 unmodified lines
7605represents the class which is the union of all7728represents the class which is the union of all
7606characters in <em>set</em>.7729characters in <em>set</em>.
7607A range of characters can be specified by7730A range of characters can be specified by
7608separating the end characters of the range with a '<code>-</code>'.7731separating the end characters of the range,
7732in ascending order, with a '<code>-</code>',
7609All classes <code>%</code><em>x</em> described above can also be used as7733All classes <code>%</code><em>x</em> described above can also be used as
7610components in <em>set</em>.7734components in <em>set</em>.
7611All other characters in <em>set</em> represent themselves.7735All 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
7699the next character belongs to <em>set</em>7823the next character belongs to <em>set</em>
7700and the previous character does not belong to <em>set</em>.7824and the previous character does not belong to <em>set</em>.
7701The set <em>set</em> is interpreted as previously described.7825The set <em>set</em> is interpreted as previously described.
7702The beggining and the end of the subject are handled as if7826The beginning and the end of the subject are handled as if
7703they were the character '<code>\0</code>'.7827they were the character '<code>\0</code>'.
7704</li>7828</li>
7705 7829
@@ -7750,7 +7874,7 @@ string <code>"flaaap"</code>, there will be two captures: 3&nbsp;and&nbsp;5. · 44 unmodified lines
7750 7874
7751 7875
7752 7876
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>
7754This library provides generic functions for table manipulation.7878This library provides generic functions for table manipulation.
7755It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>.7879It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>.
7756 7880
@@ -7858,7 +7982,7 @@ as defined by the length operator (see <a href="#3.4.6">&sect;3.4.6</a>). · 101 unmodified lines
7858 7982
7859 7983
7860 7984
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>
7862 7986
7863<p>7987<p>
7864This library is an interface to the standard C&nbsp;math library.7988This 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
8187 8311
8188 8312
8189 8313
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>
8191 8315
8192<p>8316<p>
8193This library provides bitwise operations.8317This library provides bitwise operations.
8194It provides all its functions inside the table <a name="pdf-bit"><code>bit</code></a>.8318It provides all its functions inside the table <a name="pdf-bit32"><code>bit32</code></a>.
8319It uses upper case for function names to avoid collision with
8320some reserved words (<b>and</b>, <b>or</b>, and <b>not</b>).
8321
8322
8323<p>
8195Unless otherwise stated,8324Unless otherwise stated,
8196all functions accept as arguments and return numbers8325all functions accept numeric arguments in the range
8197in the range <em>[0,2^32 - 1]</em>.8326<em>(-2<sup>51</sup>,+2<sup>51</sup>)</em>;
8198Standard Lua does not use 2-complement representation for numbers,8327each argument is normalized to
8199so in standard Lua (that is, with floating-point numbers) you8328the remainder of its division by <em>2<sup>32</sup></em>
8200cannot use negative numbers with this library.8329and truncated to an integer (in some unspecified way),
8201In particular, -1 is not the same as 0xffffffff.8330so that its final value falls in the range <em>[0,2<sup>32</sup> - 1]</em>.
8331Similarly, all results are in the range <em>[0,2<sup>32</sup> - 1]</em>.
8332Note that <code>bit32.NOT(0)</code> is <code>0xFFFFFFFF</code>,
8333which is different from <code>-1</code>.
8202 8334
8203 8335
8204<p>8336<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>
8206 8338
8207 8339
8208<p>8340<p>
@@ -8212,22 +8344,22 @@ Returns the bitwise and of its operands. · 3 unmodified lines
8212 8344
8213 8345
8214<p>8346<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>
8216 8348
8217 8349
8218<p>8350<p>
8219Returns the bitwise negation of <code>x</code>.8351Returns the bitwise negation of <code>x</code>.
8220For any valid <code>x</code>,8352For any integer <code>x</code>,
8221the following identity holds:8353the following identity holds:
8222 8354
8223<pre>8355<pre>
8224 assert(bit.bnot(x) == 2^32 - 1 - x)8356 assert(bit32.NOT(x) == (-1 - x) % 2^32)
8225</pre>8357</pre>
8226 8358
8227 8359
8228 8360
8229<p>8361<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>
8231 8363
8232 8364
8233<p>8365<p>
@@ -8237,7 +8369,7 @@ Returns the bitwise or of its operands. · 3 unmodified lines
8237 8369
8238 8370
8239<p>8371<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>
8241 8373
8242 8374
8243<p>8375<p>
@@ -8248,7 +8380,7 @@ whether the bitwise and of its operands is different from zero. · 4 unmodified lines
8248 8380
8249 8381
8250<p>8382<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>
8252 8384
8253 8385
8254<p>8386<p>
@@ -8258,36 +8390,33 @@ Returns the bitwise exclusive or of its operands. · 3 unmodified lines
8258 8390
8259 8391
8260<p>8392<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>
8262 8394
8263 8395
8264<p>8396<p>
8265Returns the number <code>x</code> shifted <code>disp</code> bits to the left.8397Returns the number <code>x</code> rotated <code>disp</code> bits to the left.
8266The number <code>disp</code> may be any representable integer.8398The number <code>disp</code> may be any representable integer.
8267Negative displacements shift to the right.
8268In any direction, vacant bits are filled with zeros.
8269In particular,
8270displacements with absolute values higher than
8271the total number of bits in the representation of <code>x</code>
8272result in zero (all bits are shifted out).
8273 8399
8274 8400
8275<p>8401<p>
8276For positive displacements,8402For any valid displacement,
8277the following equality holds:8403the following identity holds:
8278 8404
8279<pre>8405<pre>
8280 assert(bit.lshift(b, disp) == (b * 2^disp) % 2^32)8406 assert(bit32.ROL(x, disp) == bit32.ROL(x, disp % 32))
8281</pre>8407</pre><p>
8408In particular,
8409negative displacements rotate to the right.
8410
8282 8411
8283 8412
8284 8413
8285<p>8414<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>
8287 8416
8288 8417
8289<p>8418<p>
8290Returns the number <code>x</code> rotated <code>disp</code> bits to the left.8419Returns the number <code>x</code> rotated <code>disp</code> bits to the right.
8291The number <code>disp</code> may be any representable integer.8420The number <code>disp</code> may be any representable integer.
8292 8421
8293 8422
@@ -8296,38 +8425,62 @@ For any valid displacement, · 2 unmodified lines
8296the following identity holds:8425the following identity holds:
8297 8426
8298<pre>8427<pre>
8299 assert(bit.rol(x, disp) == bit.rol(x, disp % 32))8428 assert(bit32.ROR(x, disp) == bit32.ROR(x, disp % 32))
8300</pre><p>8429</pre><p>
8301In particular,8430In particular,
8302negative displacements rotate to the right.8431negative displacements rotate to the left.
8303 8432
8304 8433
8305 8434
8306 8435
8307<p>8436<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>
8309 8438
8310 8439
8311<p>8440<p>
8312Returns the number <code>x</code> rotated <code>disp</code> bits to the right.8441Returns the number <code>x</code> shifted <code>disp</code> bits to the right.
8313The number <code>disp</code> may be any representable integer.8442The number <code>disp</code> may be any representable integer.
8443Negative displacements shift to the left.
8314 8444
8315 8445
8316<p>8446<p>
8317For any valid displacement,8447This shift operation is what is called arithmetic shift.
8318the following identity holds:8448Vacant bits on the left are filled
8449with copies of the higher bit of <code>x</code>;
8450vacant bits on the right are filled with zeros.
8451In particular,
8452displacements with absolute values higher than 31
8453result in zero or <code>0xFFFFFFFF</code> (all bits are shifted out).
8319 8454
8320<pre>8455
8321 assert(bit.ror(x, disp) == bit.ror(x, disp % 32))8456
8322</pre><p>8457
8458<p>
8459<hr><h3><a name="pdf-bit32.SHL"><code>bit32.SHL (x, disp)</code></a></h3>
8460
8461
8462<p>
8463Returns the number <code>x</code> shifted <code>disp</code> bits to the left.
8464The number <code>disp</code> may be any representable integer.
8465Negative displacements shift to the right.
8466In any direction, vacant bits are filled with zeros.
8323In particular,8467In particular,
8324negative displacements rotate to the left.8468displacements with absolute values higher than 31
8469result in zero (all bits are shifted out).
8325 8470
8326 8471
8472<p>
8473For positive displacements,
8474the following equality holds:
8475
8476<pre>
8477 assert(bit32.SHL(b, disp) == (b * 2^disp) % 2^32)
8478</pre>
8479
8327 8480
8328 8481
8329<p>8482<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>
8331 8484
8332 8485
8333<p>8486<p>
@@ -8336,8 +8489,7 @@ The number <code>disp</code> may be any representable integer. · 2 unmodified lines
8336Negative displacements shift to the left.8489Negative displacements shift to the left.
8337In any direction, vacant bits are filled with zeros.8490In any direction, vacant bits are filled with zeros.
8338In particular,8491In particular,
8339displacements with absolute values higher than8492displacements with absolute values higher than 31
8340the total number of bits in the representation of <code>x</code>
8341result in zero (all bits are shifted out).8493result in zero (all bits are shifted out).
8342 8494
8343 8495
@@ -8346,13 +8498,11 @@ For positive displacements, · 2 unmodified lines
8346the following equality holds:8498the following equality holds:
8347 8499
8348<pre>8500<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))
8350</pre>8502</pre>
8351 8503
8352<p>8504<p>
8353This shift operation is what is called logical shift.8505This shift operation is what is called logical shift.
8354For an arithmetic shift,
8355you should use the arithmetic operators.
8356 8506
8357 8507
8358 8508
@@ -8360,7 +8510,7 @@ you should use the arithmetic operators. · 1 unmodified line
8360 8510
8361 8511
8362 8512
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>
8364 8514
8365<p>8515<p>
8366The I/O library provides two different styles for file manipulation.8516The 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
8584 8734
8585<p>8735<p>
8586If <code>file</code> was created with <a href="#pdf-io.popen"><code>io.popen</code></a>,8736If <code>file</code> was created with <a href="#pdf-io.popen"><code>io.popen</code></a>,
8587a sucessful close returns the exit status of the process.8737a successful close returns the exit status of the process.
8588 8738
8589 8739
8590 8740
@@ -8768,7 +8918,7 @@ Otherwise it returns <b>nil</b> plus a string describing the error. · 177 unmodified lines
8768 8918
8769 8919
8770 8920
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>
8772 8922
8773<p>8923<p>
8774This library is implemented through table <a name="pdf-os"><code>os</code></a>.8924This library is implemented through table <a name="pdf-os"><code>os</code></a>.
@@ -8860,9 +9010,13 @@ and zero otherwise. · 85 unmodified lines
8860 9010
8861 9011
8862<p>9012<p>
8863Calls the C&nbsp;function <code>exit</code>,9013Calls the C&nbsp;function <code>exit</code> to terminate the host program.
8864with an optional <code>code</code>,9014If <code>code</code> is <b>true</b>,
8865to terminate the host program.9015the returned status is <code>EXIT_SUCCESS</code>;
9016if <code>code</code> is <b>false</b>,
9017the returned status is <code>EXIT_FAILURE</code>.
9018if <code>code</code> is a number,
9019the returned status is this number.
8866The default value for <code>code</code> is the success code.9020The default value for <code>code</code> is the success code.
8867 9021
8868 9022
@@ -8994,7 +9148,7 @@ which automatically removes the file when the program ends. · 125 unmodified lines
8994 9148
8995 9149
8996 9150
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>
8998 9152
8999<p>9153<p>
9000This library provides9154This library provides
@@ -9305,11 +9459,12 @@ will return identical ids for those upvalue indices. · 304 unmodified lines
9305 9459
9306 9460
9307<p>9461<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>
9309 9463
9310 9464
9311<p>9465<p>
9312TO BE DONE!!9466Make the <code>n1</code>-th upvalue of the Lua closure <code>func1</code>
9467refer to the <code>n2</code>-th upvalue of the Lua closure <code>func2</code>.
9313 9468
9314 9469
9315 9470
@@ -9317,16 +9472,16 @@ TO BE DONE!! · 1 unmodified line
9317 9472
9318 9473
9319 9474
9320<h1>7 - <a name="7">Lua Stand-alone</a></h1>9475<h1>7 &ndash; <a name="7">Lua Standalone</a></h1>
9321 9476
9322<p>9477<p>
9323Although Lua has been designed as an extension language,9478Although Lua has been designed as an extension language,
9324to be embedded in a host C&nbsp;program,9479to be embedded in a host C&nbsp;program,
9325it is also frequently used as a stand-alone language.9480it is also frequently used as a standalone language.
9326An interpreter for Lua as a stand-alone language,9481An interpreter for Lua as a standalone language,
9327called simply <code>lua</code>,9482called simply <code>lua</code>,
9328is provided with the standard distribution.9483is provided with the standard distribution.
9329The stand-alone interpreter includes9484The standalone interpreter includes
9330all standard libraries, including the debug library.9485all standard libraries, including the debug library.
9331Its usage is:9486Its usage is:
9332 9487
@@ -9443,7 +9598,7 @@ right after the assignment to <code>_PROMPT</code>. · 110 unmodified lines
9443<p>9598<p>
9444To allow the use of Lua as a9599To allow the use of Lua as a
9445script interpreter in Unix systems,9600script interpreter in Unix systems,
9446the stand-alone interpreter skips9601the standalone interpreter skips
9447the first line of a chunk if it starts with <code>#</code>.9602the first line of a chunk if it starts with <code>#</code>.
9448Therefore, Lua scripts can be made into executable programs9603Therefore, Lua scripts can be made into executable programs
9449by using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,9604by using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,
@@ -9464,7 +9619,7 @@ is a more portable solution.) · 14 unmodified lines
9464 9619
9465 9620
9466 9621
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>
9468 9623
9469<p>9624<p>
9470Here we list the incompatibilities that you can find when moving a program9625Here 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
9476 9631
9477 9632
9478 9633
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>
9480<ul>9635<ul>
9481 9636
9482<li>9637<li>
@@ -9500,7 +9655,7 @@ All threads share a single fixed environment. · 17 unmodified lines
9500<li>9655<li>
9501The event <em>tail return</em> in debug hooks was removed.9656The event <em>tail return</em> in debug hooks was removed.
9502Instead, tail calls generate a special new event,9657Instead, tail calls generate a special new event,
9503<em>tail call</em>, so that the debuger can know there will9658<em>tail call</em>, so that the debugger can know there will
9504not be a corresponding return event.9659not be a corresponding return event.
9505</li>9660</li>
9506 9661
@@ -9509,7 +9664,7 @@ not be a corresponding return event. · 2 unmodified lines
9509 9664
9510 9665
9511 9666
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>
9513<ul>9668<ul>
9514 9669
9515<li>9670<li>
@@ -9566,7 +9721,7 @@ to restrict it to loading textual chunks. · 50 unmodified lines
9566 9721
9567 9722
9568 9723
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>
9570<ul>9725<ul>
9571 9726
9572<li>9727<li>
@@ -9593,6 +9748,24 @@ use the new functions · 20 unmodified lines
9593<a href="#lua_getuservalue"><code>lua_getuservalue</code></a> and <a href="#lua_setuservalue"><code>lua_setuservalue</code></a>.9748<a href="#lua_getuservalue"><code>lua_getuservalue</code></a> and <a href="#lua_setuservalue"><code>lua_setuservalue</code></a>.
9594</li>9749</li>
9595 9750
9751<li>
9752Function <code>luaL_register</code> is deprecated.
9753Use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> so that your module does not
9754create globals anymore.
9755(Modules are not expected to set global variables anymore.)
9756</li>
9757
9758<li>
9759Finalizers ("<code>__gc</code>" metamethods) for userdata are called in the
9760reverse order that they were marked,
9761not 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.)
9763Moreover,
9764if the metatable does not have a "<code>__gc</code>" field when set,
9765the finalizer will not be called,
9766even if it is set later.
9767</li>
9768
9596<li>9769<li>
9597<code>luaL_typerror</code> was renamed <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>,9770<code>luaL_typerror</code> was renamed <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>,
9598to have a correct spelling.9771to 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
9618 9791
9619 9792
9620 9793
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>
9622 9795
9623<p>9796<p>
9624Here is the complete syntax of Lua in extended BNF.9797Here 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
9644 <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> | 9817 <b>for</b> namelist <b>in</b> explist <b>do</b> block <b>end</b> |
9645 <b>function</b> funcname funcbody | 9818 <b>function</b> funcname funcbody |
9646 <b>local</b> <b>function</b> Name funcbody | 9819 <b>local</b> <b>function</b> Name funcbody |
9647 <b>local</b> namelist [&lsquo<b>=</b>&rsquo; explist] | 9820 <b>local</b> namelist [&lsquo<b>=</b>&rsquo; explist]
9648 <b>in</b> exp <b>do</b> block <b>end</b>
9649 9821
9650 laststat ::= <b>return</b> [explist] | <b>break</b>9822 laststat ::= <b>return</b> [explist] | <b>break</b>
9651 9823
@@ -9701,10 +9873,10 @@ Here is the complete syntax of Lua in extended BNF. · 49 unmodified lines
9701<HR>9873<HR>
9702<SMALL>9874<SMALL>
9703Last update:9875Last update:
9704Fri Jul 30 16:41:34 BRT 20109876Sat Oct 30 21:36:20 BRST 2010
9705</SMALL>9877</SMALL>
9706<!--9878<!--
9707Last change: revised for Lua 5.2.0 (work4)9879Last change: revised for Lua 5.2.0 (work5)
9708-->9880-->
9709 9881
9710</body></html>9882</body></html>
doc/readme.html+63−65
@@ -27,7 +27,7 @@ tt, kbd, code { · 26 unmodified lines
27<HR>27<HR>
28<H1>28<H1>
29<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>29<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
30Welcome to Lua 5.2 (work4)30Welcome to Lua 5.2 (work5)
31</H1>31</H1>
32 32
33<P>33<P>
@@ -89,12 +89,10 @@ because · 55 unmodified lines
89Lua is implemented in pure ANSI C, and compiles unmodified in all known89Lua is implemented in pure ANSI C, and compiles unmodified in all known
90platforms that have an ANSI C compiler.90platforms that have an ANSI C compiler.
91Lua also compiles unmodified as C++.91Lua also compiles unmodified as C++.
92 92The instructions given below for building Lua are for Unix-like platforms.
93<P>93See also
94The instructions below are for Unix-like platforms.94<A HREF="#other">instructions for other systems</A>
95There are also95and
96<A HREF="#other">instructions for other systems</A>.
97See below for
98<A HREF="#customization">customization options</A>.96<A HREF="#customization">customization options</A>.
99 97
100<P>98<P>
@@ -250,7 +248,7 @@ interpreter: · 149 unmodified lines
250<DT>248<DT>
251compiler:249compiler:
252<DD>250<DD>
253 library, luac.c print.c251 library, luac.c
254</DL>252</DL>
255 253
256<P>254<P>
@@ -258,7 +256,7 @@ compiler: · 1 unmodified line
258 create and use libraries with your compiler. Moreover, to dynamically load256 create and use libraries with your compiler. Moreover, to dynamically load
259 C libraries for Lua you'll need to know how to create dynamic libraries257 C libraries for Lua you'll need to know how to create dynamic libraries
260 and you'll need to make sure that the Lua API functions are accessible to258 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 library259 those dynamic libraries &mdash; but <EM>don't</EM> link the Lua library
262 into each dynamic library. For Unix, we recommend that the Lua library260 into each dynamic library. For Unix, we recommend that the Lua library
263 be linked statically into the host program and its symbols exported for261 be linked statically into the host program and its symbols exported for
264 dynamic linking; src/Makefile does this for the Lua interpreter.262 dynamic linking; src/Makefile does this for the Lua interpreter.
@@ -268,18 +266,6 @@ compiler: · 3 unmodified lines
268 As mentioned above, you may edit src/luaconf.h to customize266 As mentioned above, you may edit src/luaconf.h to customize
269 some features before building Lua.267 some features before building Lua.
270 268
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
283<H2><A NAME="changes">Changes since Lua 5.1</A></H2>269<H2><A NAME="changes">Changes since Lua 5.1</A></H2>
284 270
285<P>271<P>
@@ -289,61 +275,73 @@ The · 3 unmodified lines
289lists the275lists the
290<A HREF="manual.html#8">incompatibilities</A> that had to be introduced.276<A HREF="manual.html#8">incompatibilities</A> that had to be introduced.
291 277
292<H3>Language</H3>278<H3>Main changes</H3>
293<UL>279<UL>
294<LI> new lexical environments.280<LI> yieldable pcall and metamethods
295<LI> no more fenv for threads.281<LI> new <CODE>_ENV</CODE> scheme
296<LI> ephemeron tables282<LI> ephemeron tables
297 (tables with weak keys only visit value when key is accessible).283<LI> new library for bitwise operations
298<LI> yieldable pcall and metamethods.284<LI> light C functions
299<LI> tables honor the <CODE>__len</CODE> metamethod.285<LI> emergency garbage collector
300<LI> max constants per function raised to 2^26.286</UL>
301<LI> hex escapes in strings.287
302<LI> no more verification of opcode consistency.288Here 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
303</UL>298</UL>
304 299
305<H3>Libraries</H3>300<H3>Libraries</H3>
306<UL>301<UL>
307<LI> new library for bitwise operations.302<LI> new metamethods <CODE>__pairs</CODE> and <CODE>__ipairs</CODE>
308<LI> new metamethods <CODE>__pairs</CODE> and <CODE>__ipairs</CODE>.303<LI> arguments for function called through <CODE>xpcall</CODE>
309<LI> arguments for function called through <CODE>xpcall</CODE>.304<LI> optional 'mode' argument to load (to control binary x text)
310<LI> optional argument to load (to control binary x text).305<LI> new function <CODE>loadin</CODE>
311<LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL).306<LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL)
312<LI> new function <CODE>package.searchpath</CODE>.307<LI> new function <CODE>package.searchpath</CODE>
313<LI> optional base in <CODE>math.log</CODE>.308<LI> optional base in <CODE>math.log</CODE>
314<LI> <CODE>file:write</CODE> returns <CODE>file</CODE>.309<LI> <CODE>file:write</CODE> returns <CODE>file</CODE>
315<LI> closing a pipe returns exit status.310<LI> closing a pipe returns exit status
316<LI> <CODE>os.exit</CODE> may close state.311<LI> <CODE>os.exit</CODE> may close state
317<LI> new option 'isrunning' for <CODE>collectgarbage</CODE> and <CODE>lua_gc</CODE>.312<LI> new option 'isrunning' for <CODE>collectgarbage</CODE> and <CODE>lua_gc</CODE>
318<LI> frontier patterns.313<LI> frontier patterns
319<LI> <CODE>ipairs</CODE> now goes until #t.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>
320</UL>317</UL>
321 318
322<H3>C API</H3>319<H3>C API</H3>
323<UL>320<UL>
324<LI> mainthread predefined in the registry.321<LI> main thread predefined in the registry
325<LI> <CODE>lua_cpcall</CODE> changed to a predefined function in the registry.322<LI> new constants <CODE>LUA_OK</CODE> and <CODE>LUA_ERRGCMM</CODE>
326<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>
327<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>
328<LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE>.325<LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string
329<LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string.326<LI> new <CODE>luaL_testudata</CODE>
330<LI> new <CODE>luaL_testudata</CODE>.327<LI> new <CODE>luaL_tolstring</CODE>
331<LI> new <CODE>luaL_tolstring</CODE>.328<LI> new <CODE>lua_copy</CODE>
332<LI> new <CODE>lua_copy</CODE>.329<LI> new <CODE>lua_absindex</CODE>
333<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>.330<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>
334<LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API.331<LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API
335</UL>332</UL>
336 333
337<H3>Implementation</H3>334<H3>Implementation</H3>
338<UL>335<UL>
339<LI> emergency garbage collector336<LI> max constants per function raised to 2<SUP>26</SUP>
340 (core forces a full collection when allocation fails).337<LI> internal (immutable) version of ctypes
341<LI> udata with finalizers are kept in a separated list for the GC.338<LI> simpler implementation for string buffers
342<LI> CallInfo stack now is a linked list.339<LI> udata with finalizers are kept in a separated list for the GC
343<LI> internal (immutable) version of ctypes.340<LI> <CODE>CallInfo</CODE>stack now is a linked list
344<LI> parser uses much less C-stack space (no more auto arrays).341<LI> parser uses much less C-stack space (no more auto arrays)
345<LI> new hash for floats.342<LI> new hash for floats
346<LI> handling of non-string error messages in the standalone interpreter.343<LI> handling of non-string error messages in the standalone interpreter
344<LI> generational mode for garbage collection (experimental)
347</UL>345</UL>
348 346
349<H2><A NAME="license">License</A></H2>347<H2><A NAME="license">License</A></H2>
@@ -352,7 +350,7 @@ lists the · 2 unmodified lines
352</A>350</A>
353 351
354<P>352<P>
355Lua is free software licensed under the terms of the353Lua is free software distributed under the terms of the
356<A HREF="http://www.opensource.org/licenses/mit-license.html">MIT license</A>354<A HREF="http://www.opensource.org/licenses/mit-license.html">MIT license</A>
357reproduced below;355reproduced below;
358it can be used for any purpose, including commercial purposes,356it can be used for any purpose, including commercial purposes,
@@ -392,10 +390,10 @@ THE SOFTWARE. · 33 unmodified lines
392<HR>390<HR>
393<SMALL>391<SMALL>
394Last update:392Last update:
395Fri Jul 30 15:12:25 BRT 2010393Sat Oct 30 21:36:38 BRST 2010
396</SMALL>394</SMALL>
397<!--395<!--
398Last change: revised for Lua 5.2.0 (work4)396Last change: revised for Lua 5.2.0 (work5)
399-->397-->
400 398
401</BODY>399</BODY>
src/Makefile+5−9
@@ -33,7 +33,7 @@ LUA_T= lua · 32 unmodified lines
33LUA_O= lua.o33LUA_O= lua.o
34 34
35LUAC_T= luac35LUAC_T= luac
36LUAC_O= luac.o print.o36LUAC_O= luac.o
37 37
38ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)38ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
39ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)39ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
@@ -62,7 +62,7 @@ clean: · 22 unmodified lines
62 $(RM) $(ALL_T) $(ALL_O)62 $(RM) $(ALL_T) $(ALL_O)
63 63
64depend:64depend:
65 @$(CC) $(CFLAGS) -MM l*.c print.c65 @$(CC) $(CFLAGS) -MM l*.c
66 66
67echo:67echo:
68 @echo "PLAT= $(PLAT)"68 @echo "PLAT= $(PLAT)"
@@ -94,8 +94,7 @@ bsd: · 25 unmodified lines
94freebsd:94freebsd:
95 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"95 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
96 96
97generic:97generic: $(ALL)
98 $(MAKE) $(ALL) MYCFLAGS=
99 98
100linux:99linux:
101 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline -lncurses"100 $(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
170ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \169ltm.o: ltm.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h lzio.h \
171 lmem.h lstring.h lgc.h ltable.h170 lmem.h lstring.h lgc.h ltable.h
172lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h171lua.o: lua.c lua.h luaconf.h lauxlib.h lualib.h
173luac.o: luac.c lua.h luaconf.h lauxlib.h ldo.h lobject.h llimits.h \172luac.o: luac.c lua.h luaconf.h lauxlib.h lobject.h llimits.h lstate.h \
174 lstate.h ltm.h lzio.h lmem.h lfunc.h lopcodes.h lstring.h lgc.h \173 ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h
175 lundump.h
176lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \174lundump.o: lundump.c lua.h luaconf.h ldebug.h lstate.h lobject.h \
177 llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h175 llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
178lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \176lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
179 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h177 lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
180lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \178lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
181 lzio.h179 lzio.h
182print.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
184 180
185# (end of Makefile)181# (end of Makefile)
src/lapi.c+43−7
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua API3** Lua API
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -85,7 +85,7 @@ LUA_API int lua_checkstack (lua_State *L, int size) { · 79 unmodified lines
85 if (L->stack_last - L->top > size) /* stack large enough? */85 if (L->stack_last - L->top > size) /* stack large enough? */
86 res = 1; /* yes; check is OK */86 res = 1; /* yes; check is OK */
87 else { /* no; need to grow stack */87 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;
89 if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */89 if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */
90 res = 0; /* no */90 res = 0; /* no */
91 else /* try to grow stack */91 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
347}347}
348 348
349 349
350LUA_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
350LUA_API int lua_toboolean (lua_State *L, int idx) {367LUA_API int lua_toboolean (lua_State *L, int idx) {
351 const TValue *o = index2addr(L, idx);368 const TValue *o = index2addr(L, idx);
352 return !l_isfalse(o);369 return !l_isfalse(o);
@@ -452,6 +469,16 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { · 99 unmodified lines
452}469}
453 470
454 471
472LUA_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
455LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {482LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
456 TString *ts;483 TString *ts;
457 lua_lock(L);484 lua_lock(L);
@@ -799,6 +826,7 @@ LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx, · 341 unmodified lines
799 api_check(L, k == NULL || !isLua(L->ci),826 api_check(L, k == NULL || !isLua(L->ci),
800 "cannot use continuations inside hooks");827 "cannot use continuations inside hooks");
801 api_checknelems(L, nargs+1);828 api_checknelems(L, nargs+1);
829 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
802 checkresults(L, nargs, nresults);830 checkresults(L, nargs, nresults);
803 func = L->top - (nargs+1);831 func = L->top - (nargs+1);
804 if (k != NULL && L->nny == 0) { /* need to prepare continuation? */832 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
839 api_check(L, k == NULL || !isLua(L->ci),867 api_check(L, k == NULL || !isLua(L->ci),
840 "cannot use continuations inside hooks");868 "cannot use continuations inside hooks");
841 api_checknelems(L, nargs+1);869 api_checknelems(L, nargs+1);
870 api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
842 checkresults(L, nargs, nresults);871 checkresults(L, nargs, nresults);
843 if (errfunc == 0)872 if (errfunc == 0)
844 func = 0;873 func = 0;
@@ -889,7 +918,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, · 44 unmodified lines
889 /* get global table from registry */918 /* get global table from registry */
890 Table *reg = hvalue(&G(L)->l_registry);919 Table *reg = hvalue(&G(L)->l_registry);
891 const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);920 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) */
893 setobj(L, f->l.upvals[0]->v, gt);922 setobj(L, f->l.upvals[0]->v, gt);
894 luaC_barrier(L, f->l.upvals[0], gt);923 luaC_barrier(L, f->l.upvals[0], gt);
895 }924 }
@@ -974,6 +1003,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 78 unmodified lines
974 g->gcpause = data;1003 g->gcpause = data;
975 break;1004 break;
976 }1005 }
1006 case LUA_GCSETMAJORINC: {
1007 res = g->gcmajorinc;
1008 g->gcmajorinc = data;
1009 break;
1010 }
977 case LUA_GCSETSTEPMUL: {1011 case LUA_GCSETSTEPMUL: {
978 res = g->gcstepmul;1012 res = g->gcstepmul;
979 g->gcstepmul = data;1013 g->gcstepmul = data;
@@ -1100,11 +1134,15 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val, · 120 unmodified lines
1100 return "";1134 return "";
1101 }1135 }
1102 else {1136 else {
1137 const char *name;
1103 Proto *p = f->l.p;1138 Proto *p = f->l.p;
1104 if (!(1 <= n && n <= p->sizeupvalues)) return NULL;1139 if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
1105 *val = f->l.upvals[n-1]->v;1140 *val = f->l.upvals[n-1]->v;
1106 if (owner) *owner = obj2gco(f->l.upvals[n - 1]);1141 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;
1108 }1146 }
1109}1147}
1110 1148
@@ -1144,13 +1182,11 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { · 33 unmodified lines
1144 1182
1145static UpVal **getupvalref (lua_State *L, int fidx, int n, Closure **pf) {1183static UpVal **getupvalref (lua_State *L, int fidx, int n, Closure **pf) {
1146 Closure *f;1184 Closure *f;
1147 Proto *p;
1148 StkId fi = index2addr(L, fidx);1185 StkId fi = index2addr(L, fidx);
1149 api_check(L, ttisclosure(fi), "Lua function expected");1186 api_check(L, ttisclosure(fi), "Lua function expected");
1150 f = clvalue(fi);1187 f = clvalue(fi);
1151 api_check(L, !f->c.isC, "Lua function expected");1188 api_check(L, !f->c.isC, "Lua function expected");
1152 p = f->l.p;1189 api_check(L, (1 <= n && n <= f->l.p->sizeupvalues), "invalid upvalue index");
1153 api_check(L, (1 <= n && n <= p->sizeupvalues), "invalid upvalue index");
1154 if (pf) *pf = f;1190 if (pf) *pf = f;
1155 return &f->l.upvals[n - 1]; /* get its upvalue pointer */1191 return &f->l.upvals[n - 1]; /* get its upvalue pointer */
1156}1192}
src/lauxlib.c+55−20
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Auxiliary functions for building Lua libraries3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -330,11 +330,26 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { · 324 unmodified lines
330}330}
331 331
332 332
333LUALIB_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
333LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,342LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
334 lua_Integer def) {343 lua_Integer def) {
335 return luaL_opt(L, luaL_checkinteger, narg, def);344 return luaL_opt(L, luaL_checkinteger, narg, def);
336}345}
337 346
347
348LUALIB_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
338/* }====================================================== */353/* }====================================================== */
339 354
340 355
@@ -434,7 +449,7 @@ LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { · 93 unmodified lines
434*/449*/
435 450
436/* index of free-list header */451/* index of free-list header */
437#define freelist "lua-freelist"452#define freelist 0
438 453
439 454
440LUALIB_API int luaL_ref (lua_State *L, int t) {455LUALIB_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
444 lua_pop(L, 1); /* remove from stack */459 lua_pop(L, 1); /* remove from stack */
445 return LUA_REFNIL; /* `nil' has a unique fixed reference */460 return LUA_REFNIL; /* `nil' has a unique fixed reference */
446 }461 }
447 lua_getfield(L, t, freelist); /* get first free element */462 lua_rawgeti(L, t, freelist); /* get first free element */
448 ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */463 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
449 lua_pop(L, 1); /* remove it from stack */464 lua_pop(L, 1); /* remove it from stack */
450 if (ref != 0) { /* any free element? */465 if (ref != 0) { /* any free element? */
451 lua_rawgeti(L, t, ref); /* remove it from list */466 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]) */
453 }468 }
454 else /* no free elements */469 else /* no free elements */
455 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */470 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
461LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {476LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
462 if (ref >= 0) {477 if (ref >= 0) {
463 t = lua_absindex(L, t);478 t = lua_absindex(L, t);
464 lua_getfield(L, t, freelist);479 lua_rawgeti(L, t, freelist);
465 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */480 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */
466 lua_pushinteger(L, ref);481 lua_pushinteger(L, ref);
467 lua_setfield(L, t, freelist); /* t[freelist] = ref */482 lua_rawseti(L, t, freelist); /* t[freelist] = ref */
468 }483 }
469}484}
470 485
@@ -511,17 +526,32 @@ static int errfile (lua_State *L, const char *what, int fnameindex) { · 40 unmodified lines
511}526}
512 527
513 528
529static 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
514/*543/*
515** reads the first character of file 'f' and skips its first line544** reads the first character of file 'f' and skips an optional BOM mark
516** if it starts with '#'. Returns true if it skipped the first line.545** in its beginning plus its first line if it starts with '#'. Returns
517** In any case, '*cp' has the first "valid" character of the file546** true if it skipped the first line. In any case, '*cp' has the
518** (after the optional first-line comment).547** first "valid" character of the file (after the optional BOM and
548** a first-line comment).
519*/549*/
520static int skipcomment (FILE *f, int *cp) {550static int skipcomment (LoadF *lf, int *cp) {
521 int c = *cp = getc(f);551 int c = *cp = skipBOM(lf);
522 if (c == '#') { /* first line is a comment (Unix exec. file)? */552 if (c == '#') { /* first line is a comment (Unix exec. file)? */
523 while ((c = getc(f)) != EOF && c != '\n') ; /* skip first line */553 while ((c = getc(lf->f)) != EOF && c != '\n') ; /* skip first line */
524 *cp = getc(f); /* skip end-of-line */554 *cp = getc(lf->f); /* skip end-of-line */
525 return 1; /* there was a comment */555 return 1; /* there was a comment */
526 }556 }
527 else return 0; /* no comment */557 else return 0; /* no comment */
@@ -542,14 +572,12 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { · 14 unmodified lines
542 lf.f = fopen(filename, "r");572 lf.f = fopen(filename, "r");
543 if (lf.f == NULL) return errfile(L, "open", fnameindex);573 if (lf.f == NULL) return errfile(L, "open", fnameindex);
544 }574 }
545 lf.n = 0;575 if (skipcomment(&lf, &c)) /* read initial portion */
546 if (skipcomment(lf.f, &c)) /* read initial portion */
547 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */576 lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
548 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */577 if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
549 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */578 lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
550 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);579 if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
551 lf.n = 0;580 skipcomment(&lf, &c); /* re-read initial portion */
552 skipcomment(lf.f, &c); /* re-read initial portion */
553 }581 }
554 if (c != EOF)582 if (c != EOF)
555 lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */583 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
628 int l;656 int l;
629 int isnum;657 int isnum;
630 lua_len(L, idx);658 lua_len(L, idx);
631 l = lua_tointegerx(L, -1, &isnum);659 l = (int)lua_tointegerx(L, -1, &isnum);
632 if (!isnum)660 if (!isnum)
633 luaL_error(L, "object length is not a number");661 luaL_error(L, "object length is not a number");
634 lua_pop(L, 1); /* remove object */662 lua_pop(L, 1); /* remove object */
@@ -848,5 +876,12 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) { · 213 unmodified lines
848 else if (*v != ver)876 else if (*v != ver)
849 luaL_error(L, "version mismatch: app. needs %d, Lua core provides %f",877 luaL_error(L, "version mismatch: app. needs %d, Lua core provides %f",
850 ver, *v);878 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);
851}886}
852 887
src/lauxlib.h+4−1
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Auxiliary functions for building Lua libraries3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -44,6 +44,9 @@ LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); · 38 unmodified lines
44LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);44LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
45LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,45LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
46 lua_Integer def);46 lua_Integer def);
47LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg);
48LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg,
49 lua_Unsigned def);
47 50
48LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);51LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
49LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);52LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
src/lbaselib.c+11−7
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Basic library3** Basic library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -56,12 +56,15 @@ static int luaB_tonumber (lua_State *L) { · 50 unmodified lines
56 const char *s1 = luaL_checkstring(L, 1);56 const char *s1 = luaL_checkstring(L, 1);
57 char *s2;57 char *s2;
58 unsigned long n;58 unsigned long n;
59 int neg = 0;
59 luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");60 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; }
60 n = strtoul(s1, &s2, base);63 n = strtoul(s1, &s2, base);
61 if (s1 != s2) { /* at least one valid digit? */64 if (s1 != s2) { /* at least one valid digit? */
62 while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */65 while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
63 if (*s2 == '\0') { /* no invalid trailing characters? */66 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);
65 return 1;68 return 1;
66 }69 }
67 }70 }
@@ -142,11 +145,11 @@ static int luaB_rawset (lua_State *L) { · 74 unmodified lines
142 145
143static int luaB_collectgarbage (lua_State *L) {146static int luaB_collectgarbage (lua_State *L) {
144 static const char *const opts[] = {"stop", "restart", "collect",147 static const char *const opts[] = {"stop", "restart", "collect",
145 "count", "step", "setpause", "setstepmul", "isrunning",148 "count", "step", "setpause", "setstepmul",
146 "gen", "inc", NULL};149 "setmajorinc", "isrunning", "gen", "inc", NULL};
147 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,150 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
148 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,151 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
149 LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};152 LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
150 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];153 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
151 int ex = luaL_optint(L, 2, 0);154 int ex = luaL_optint(L, 2, 0);
152 int res = lua_gc(L, o, ex);155 int res = lua_gc(L, o, ex);
@@ -330,11 +333,12 @@ static int luaB_load (lua_State *L) { · 177 unmodified lines
330 333
331static int luaB_loadin (lua_State *L) {334static int luaB_loadin (lua_State *L) {
332 int n;335 int n;
333 luaL_checktype(L, 1, LUA_TTABLE);336 luaL_checkany(L, 1);
334 n = luaB_load_aux(L, 2);337 n = luaB_load_aux(L, 2);
335 if (n == 1) { /* success? */338 if (n == 1) { /* success? */
336 lua_pushvalue(L, 1); /* environment for loaded function */339 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");
338 }342 }
339 return n;343 return n;
340}344}
src/lbitlib.c+49−33
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard library for bitwise operations3** Standard library for bitwise operations
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -13,22 +13,19 @@ · 7 unmodified lines
13#include "lualib.h"13#include "lualib.h"
14 14
15 15
16/* number of bits considered when shifting/rotating (must be a power of 2) */16/* number of bits to consider in a number */
17#define NBITS 3217#define NBITS 32
18 18
19#define ALLONES (~(((~(lua_Unsigned)0) << (NBITS - 1)) << 1))
19 20
20typedef LUA_INT32 b_int;21/* mask to trim extra bits */
21typedef unsigned LUA_INT32 b_uint;22#define trim(x) ((x) & ALLONES)
22 23
23 24
24static b_uint getuintarg (lua_State *L, int arg) {25typedef lua_Unsigned b_uint;
25 b_uint r;26
26 int isnum;27
27 lua_Number x = lua_tonumberx(L, arg, &isnum);28#define getuintarg(L,arg) luaL_checkunsigned(L,arg)
28 if (!isnum) luaL_typeerror(L, arg, "number");
29 lua_number2uint(r, x);
30 return r;
31}
32 29
33 30
34static b_uint andaux (lua_State *L) {31static b_uint andaux (lua_State *L) {
@@ -36,13 +33,13 @@ static b_uint andaux (lua_State *L) { · 1 unmodified line
36 b_uint r = ~(b_uint)0;33 b_uint r = ~(b_uint)0;
37 for (i = 1; i <= n; i++)34 for (i = 1; i <= n; i++)
38 r &= getuintarg(L, i);35 r &= getuintarg(L, i);
39 return r;36 return trim(r);
40}37}
41 38
42 39
43static int b_and (lua_State *L) {40static int b_and (lua_State *L) {
44 b_uint r = andaux(L);41 b_uint r = andaux(L);
45 lua_pushnumber(L, lua_uint2number(r));42 lua_pushunsigned(L, r);
46 return 1;43 return 1;
47}44}
48 45
@@ -59,7 +56,7 @@ static int b_or (lua_State *L) { · 10 unmodified lines
59 b_uint r = 0;56 b_uint r = 0;
60 for (i = 1; i <= n; i++)57 for (i = 1; i <= n; i++)
61 r |= getuintarg(L, i);58 r |= getuintarg(L, i);
62 lua_pushnumber(L, lua_uint2number(r));59 lua_pushunsigned(L, trim(r));
63 return 1;60 return 1;
64}61}
65 62
@@ -69,49 +66,66 @@ static int b_xor (lua_State *L) { · 3 unmodified lines
69 b_uint r = 0;66 b_uint r = 0;
70 for (i = 1; i <= n; i++)67 for (i = 1; i <= n; i++)
71 r ^= getuintarg(L, i);68 r ^= getuintarg(L, i);
72 lua_pushnumber(L, lua_uint2number(r));69 lua_pushunsigned(L, trim(r));
73 return 1;70 return 1;
74}71}
75 72
76 73
77static int b_not (lua_State *L) {74static int b_not (lua_State *L) {
78 b_uint r = ~getuintarg(L, 1);75 b_uint r = ~getuintarg(L, 1);
79 lua_pushnumber(L, lua_uint2number(r));76 lua_pushunsigned(L, trim(r));
80 return 1;77 return 1;
81}78}
82 79
83 80
84static int b_shift (lua_State *L, int i) {81static int b_shift (lua_State *L, b_uint r, int i) {
85 b_uint r = getuintarg(L, 1);
86 if (i < 0) { /* shift right? */82 if (i < 0) { /* shift right? */
87 i = -i;83 i = -i;
84 r = trim(r);
88 if (i >= NBITS) r = 0;85 if (i >= NBITS) r = 0;
89 else r >>= i;86 else r >>= i;
90 }87 }
91 else { /* shift left */88 else { /* shift left */
92 if (i >= NBITS) r = 0;89 if (i >= NBITS) r = 0;
93 else r <<= i;90 else r <<= i;
91 r = trim(r);
94 }92 }
95 lua_pushnumber(L, lua_uint2number(r));93 lua_pushunsigned(L, r);
96 return 1;94 return 1;
97}95}
98 96
99 97
100static int b_lshift (lua_State *L) {98static 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));
102}100}
103 101
104 102
105static int b_rshift (lua_State *L) {103static 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
108static 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 }
107}120}
108 121
109 122
110static int b_rot (lua_State *L, int i) {123static int b_rot (lua_State *L, int i) {
111 b_uint r = getuintarg(L, 1);124 b_uint r = getuintarg(L, 1);
112 i &= (NBITS - 1); /* i = i % NBITS */125 i &= (NBITS - 1); /* i = i % NBITS */
126 r = trim(r);
113 r = (r << i) | (r >> (NBITS - i));127 r = (r << i) | (r >> (NBITS - i));
114 lua_pushnumber(L, lua_uint2number(r));128 lua_pushunsigned(L, trim(r));
115 return 1;129 return 1;
116}130}
117 131
@@ -127,21 +141,23 @@ static int b_ror (lua_State *L) { · 9 unmodified lines
127 141
128 142
129static const luaL_Reg bitlib[] = {143static const luaL_Reg bitlib[] = {
130 {"band", b_and},144 {"AND", b_and},
131 {"btest", b_test},145 {"TEST", b_test},
132 {"bor", b_or},146 {"OR", b_or},
133 {"bxor", b_xor},147 {"XOR", b_xor},
134 {"bnot", b_not},148 {"NOT", b_not},
135 {"lshift", b_lshift},149 {"SHL", b_lshift},
136 {"rshift", b_rshift},150 {"SAR", b_arshift},
137 {"rol", b_rol},151 {"SHR", b_rshift},
138 {"ror", b_ror},152 {"ROL", b_rol},
153 {"ROR", b_ror},
139 {NULL, NULL}154 {NULL, NULL}
140};155};
141 156
142 157
143 158
144LUAMOD_API int luaopen_bit (lua_State *L) {159LUAMOD_API int luaopen_bit32 (lua_State *L) {
145 luaL_newlib(L, bitlib);160 luaL_newlib(L, bitlib);
146 return 1;161 return 1;
147}162}
163
src/ldebug.c+12−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Debug Interface3** Debug Interface
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -160,9 +160,10 @@ static void funcinfo (lua_Debug *ar, Closure *cl) { · 154 unmodified lines
160 ar->what = "C";160 ar->what = "C";
161 }161 }
162 else {162 else {
163 ar->source = getstr(cl->l.p->source);163 Proto *p = cl->l.p;
164 ar->linedefined = cl->l.p->linedefined;164 ar->source = p->source ? getstr(p->source) : "=?";
165 ar->lastlinedefined = cl->l.p->lastlinedefined;165 ar->linedefined = p->linedefined;
166 ar->lastlinedefined = p->lastlinedefined;
166 ar->what = (ar->linedefined == 0) ? "main" : "Lua";167 ar->what = (ar->linedefined == 0) ? "main" : "Lua";
167 }168 }
168 luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);169 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
315 ? luaF_getlocalname(p, t + 1, pc)316 ? luaF_getlocalname(p, t + 1, pc)
316 : getstr(p->upvalues[t].name);317 : getstr(p->upvalues[t].name);
317 kname(p, k, a, what, name);318 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";
319 }320 }
320 break;321 break;
321 }322 }
@@ -496,7 +497,12 @@ static void addinfo (lua_State *L, const char *msg) { · 174 unmodified lines
496 if (isLua(ci)) { /* is Lua code? */497 if (isLua(ci)) { /* is Lua code? */
497 char buff[LUA_IDSIZE]; /* add file:line information */498 char buff[LUA_IDSIZE]; /* add file:line information */
498 int line = currentline(ci);499 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 }
500 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);506 luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
501 }507 }
502}508}
src/ldo.c+5−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Stack and Call structure of Lua3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -177,7 +177,7 @@ void luaD_growstack (lua_State *L, int n) { · 171 unmodified lines
177 if (size > LUAI_MAXSTACK) /* error after extra size? */177 if (size > LUAI_MAXSTACK) /* error after extra size? */
178 luaD_throw(L, LUA_ERRERR);178 luaD_throw(L, LUA_ERRERR);
179 else {179 else {
180 int needed = L->top - L->stack + n + EXTRA_STACK;180 int needed = cast_int(L->top - L->stack) + n + EXTRA_STACK;
181 int newsize = 2 * size;181 int newsize = 2 * size;
182 if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;182 if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;
183 if (newsize < needed) newsize = needed;183 if (newsize < needed) newsize = needed;
@@ -299,7 +299,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 115 unmodified lines
299 if (!ttisfunction(func)) /* `func' is not a function? */299 if (!ttisfunction(func)) /* `func' is not a function? */
300 func = tryfuncTM(L, func); /* check the `function' tag method */300 func = tryfuncTM(L, func); /* check the `function' tag method */
301 funcr = savestack(L, func);301 funcr = savestack(L, func);
302 L->ci->nresults = nresults;
303 if (ttislcf(func)) { /* light C function? */302 if (ttislcf(func)) { /* light C function? */
304 f = fvalue(func); /* get it */303 f = fvalue(func); /* get it */
305 goto isCfunc; /* go to call it */304 goto isCfunc; /* go to call it */
@@ -312,6 +311,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 6 unmodified lines
312 isCfunc: /* call C function 'f' */311 isCfunc: /* call C function 'f' */
313 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */312 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
314 ci = next_ci(L); /* now 'enter' new function */313 ci = next_ci(L); /* now 'enter' new function */
314 ci->nresults = nresults;
315 ci->func = restorestack(L, funcr);315 ci->func = restorestack(L, funcr);
316 ci->top = L->top + LUA_MINSTACK;316 ci->top = L->top + LUA_MINSTACK;
317 lua_assert(ci->top <= L->stack_last);317 lua_assert(ci->top <= L->stack_last);
@@ -341,6 +341,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 23 unmodified lines
341 else /* vararg function */341 else /* vararg function */
342 base = adjust_varargs(L, p, nargs);342 base = adjust_varargs(L, p, nargs);
343 ci = next_ci(L); /* now 'enter' new function */343 ci = next_ci(L); /* now 'enter' new function */
344 ci->nresults = nresults;
344 ci->func = func;345 ci->func = func;
345 ci->u.l.base = base;346 ci->u.l.base = base;
346 ci->top = base + p->maxstacksize;347 ci->top = base + p->maxstacksize;
@@ -368,8 +369,8 @@ int luaD_poscall (lua_State *L, StkId firstResult) { · 21 unmodified lines
368 L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */369 L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */
369 }370 }
370 res = ci->func; /* res == final position of 1st result */371 res = ci->func; /* res == final position of 1st result */
371 L->ci = ci = ci->previous; /* back to caller */
372 wanted = ci->nresults;372 wanted = ci->nresults;
373 L->ci = ci = ci->previous; /* back to caller */
373 /* move results to correct place */374 /* move results to correct place */
374 for (i = wanted; i != 0 && firstResult < L->top; i--)375 for (i = wanted; i != 0 && firstResult < L->top; i--)
375 setobjs2s(L, res++, firstResult++);376 setobjs2s(L, res++, firstResult++);
src/ldump.c+6−9
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** save precompiled Lua chunks3** save precompiled Lua chunks
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -75,7 +75,7 @@ static void DumpString(const TString* s, DumpState* D) · 69 unmodified lines
75 75
76#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)76#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
77 77
78static void DumpFunction(const Proto* f, const TString* p, DumpState* D);78static void DumpFunction(const Proto* f, DumpState* D);
79 79
80static void DumpConstants(const Proto* f, DumpState* D)80static void DumpConstants(const Proto* f, DumpState* D)
81{81{
@@ -98,14 +98,11 @@ static void DumpConstants(const Proto* f, DumpState* D) · 16 unmodified lines
98 case LUA_TSTRING:98 case LUA_TSTRING:
99 DumpString(rawtsvalue(o),D);99 DumpString(rawtsvalue(o),D);
100 break;100 break;
101 default:
102 lua_assert(0); /* cannot happen */
103 break;
104 }101 }
105 }102 }
106 n=f->sizep;103 n=f->sizep;
107 DumpInt(n,D);104 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);
109}106}
110 107
111static void DumpUpvalues(const Proto* f, DumpState* D)108static void DumpUpvalues(const Proto* f, DumpState* D)
@@ -122,6 +119,7 @@ static void DumpUpvalues(const Proto* f, DumpState* D) · 10 unmodified lines
122static void DumpDebug(const Proto* f, DumpState* D)119static void DumpDebug(const Proto* f, DumpState* D)
123{120{
124 int i,n;121 int i,n;
122 DumpString((D->strip) ? NULL : f->source,D);
125 n= (D->strip) ? 0 : f->sizelineinfo;123 n= (D->strip) ? 0 : f->sizelineinfo;
126 DumpVector(f->lineinfo,n,sizeof(int),D);124 DumpVector(f->lineinfo,n,sizeof(int),D);
127 n= (D->strip) ? 0 : f->sizelocvars;125 n= (D->strip) ? 0 : f->sizelocvars;
@@ -137,9 +135,8 @@ static void DumpDebug(const Proto* f, DumpState* D) · 9 unmodified lines
137 for (i=0; i<n; i++) DumpString(f->upvalues[i].name,D);135 for (i=0; i<n; i++) DumpString(f->upvalues[i].name,D);
138}136}
139 137
140static void DumpFunction(const Proto* f, const TString* p, DumpState* D)138static void DumpFunction(const Proto* f, DumpState* D)
141{139{
142 DumpString((f->source==p || D->strip) ? NULL : f->source,D);
143 DumpInt(f->linedefined,D);140 DumpInt(f->linedefined,D);
144 DumpInt(f->lastlinedefined,D);141 DumpInt(f->lastlinedefined,D);
145 DumpChar(f->numparams,D);142 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
170 D.strip=strip;167 D.strip=strip;
171 D.status=0;168 D.status=0;
172 DumpHeader(&D);169 DumpHeader(&D);
173 DumpFunction(f,NULL,&D);170 DumpFunction(f,&D);
174 return D.status;171 return D.status;
175}172}
src/lgc.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Garbage Collector3** Garbage Collector
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -449,7 +449,7 @@ static int traverseproto (global_State *g, Proto *f) { · 443 unmodified lines
449}449}
450 450
451 451
452static l_mem traverseclosure (global_State *g, Closure *cl) {452static int traverseclosure (global_State *g, Closure *cl) {
453 if (cl->c.isC) {453 if (cl->c.isC) {
454 int i;454 int i;
455 for (i=0; i<cl->c.nupvalues; i++) /* mark its upvalues */455 for (i=0; i<cl->c.nupvalues; i++) /* mark its upvalues */
@@ -960,7 +960,7 @@ static void generationalcollection (lua_State *L) { · 504 unmodified lines
960 else {960 else {
961 luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */961 luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
962 luaC_runtilstate(L, bitmask(GCSpause));962 luaC_runtilstate(L, bitmask(GCSpause));
963 if (g->totalbytes > g->lastmajormem/100 * g->gcpause)963 if (g->totalbytes > g->lastmajormem/100 * g->gcmajorinc)
964 g->lastmajormem = 0; /* signal for a major collection */964 g->lastmajormem = 0; /* signal for a major collection */
965 }965 }
966 g->GCdebt = stddebt(g);966 g->GCdebt = stddebt(g);
src/linit.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Initialization of libraries for lua.c and other clients 3** Initialization of libraries for lua.c and other clients
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -34,7 +34,7 @@ static const luaL_Reg loadedlibs[] = { · 28 unmodified lines
34 {LUA_IOLIBNAME, luaopen_io},34 {LUA_IOLIBNAME, luaopen_io},
35 {LUA_OSLIBNAME, luaopen_os},35 {LUA_OSLIBNAME, luaopen_os},
36 {LUA_STRLIBNAME, luaopen_string},36 {LUA_STRLIBNAME, luaopen_string},
37 {LUA_BITLIBNAME, luaopen_bit},37 {LUA_BITLIBNAME, luaopen_bit32},
38 {LUA_MATHLIBNAME, luaopen_math},38 {LUA_MATHLIBNAME, luaopen_math},
39#if defined(LUA_COMPAT_DEBUGLIB)39#if defined(LUA_COMPAT_DEBUGLIB)
40 {LUA_DBLIBNAME, luaopen_debug},40 {LUA_DBLIBNAME, luaopen_debug},
src/liolib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard I/O (and system) library3** Standard I/O (and system) library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -453,7 +453,7 @@ static int f_read (lua_State *L) { · 447 unmodified lines
453static int io_readline (lua_State *L) {453static int io_readline (lua_State *L) {
454 FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));454 FILE *f = *(FILE **)lua_touserdata(L, lua_upvalueindex(1));
455 int i;455 int i;
456 int n = lua_tointeger(L, lua_upvalueindex(2));456 int n = (int)lua_tointeger(L, lua_upvalueindex(2));
457 if (f == NULL) /* file is already closed? */457 if (f == NULL) /* file is already closed? */
458 luaL_error(L, "file is already closed");458 luaL_error(L, "file is already closed");
459 lua_settop(L , 1);459 lua_settop(L , 1);
src/llex.c+6−8
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lexical Analyzer3** Lexical Analyzer
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -161,7 +161,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { · 155 unmodified lines
161 ls->linenumber = 1;161 ls->linenumber = 1;
162 ls->lastline = 1;162 ls->lastline = 1;
163 ls->source = source;163 ls->source = source;
164 ls->envn = luaS_new(L, "_ENV"); /* create env name */164 ls->envn = luaS_new(L, LUA_ENV); /* create env name */
165 luaS_fix(ls->envn); /* never collect this name */165 luaS_fix(ls->envn); /* never collect this name */
166 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */166 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
167 next(ls); /* read first char */167 next(ls); /* read first char */
@@ -221,11 +221,9 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { · 53 unmodified lines
221 lua_assert(lisdigit(ls->current));221 lua_assert(lisdigit(ls->current));
222 do {222 do {
223 save_and_next(ls);223 save_and_next(ls);
224 } while (lisdigit(ls->current) || ls->current == '.');224 if (check_next(ls, "EePp")) /* exponent part? */
225 if (check_next(ls, "Ee")) /* `E'? */225 check_next(ls, "+-"); /* optional exponent sign */
226 check_next(ls, "+-"); /* optional exponent sign */226 } while (lislalnum(ls->current) || ls->current == '.');
227 while (lislalnum(ls->current))
228 save_and_next(ls);
229 save(ls, '\0');227 save(ls, '\0');
230 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */228 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
231 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */229 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
234 232
235 233
236/*234/*
237** skip a sequence '[=*=[' or ']=*]' and return its number of '='s or235** skip a sequence '[=*[' or ']=*]' and return its number of '='s or
238** -1 if sequence is malformed236** -1 if sequence is malformed
239*/237*/
240static int skip_sep (LexState *ls) {238static int skip_sep (LexState *ls) {
src/lmathlib.c+2−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard mathematical library3** Standard mathematical library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -220,7 +220,7 @@ static int math_random (lua_State *L) { · 214 unmodified lines
220 220
221 221
222static int math_randomseed (lua_State *L) {222static int math_randomseed (lua_State *L) {
223 srand(luaL_checkint(L, 1));223 srand(luaL_checkunsigned(L, 1));
224 (void)rand(); /* discard first value to avoid undesirable correlations */224 (void)rand(); /* discard first value to avoid undesirable correlations */
225 return 0;225 return 0;
226}226}
src/loadlib.c+4−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Dynamic library loader for Lua3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5**5**
@@ -177,7 +177,7 @@ static void ll_unloadlib (void *lib) { · 171 unmodified lines
177 177
178static void *ll_load (lua_State *L, const char *path, int seeglb) {178static void *ll_load (lua_State *L, const char *path, int seeglb) {
179 HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);179 HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS);
180 (void)(seeglb); /* symbols are 'global' by default? */180 (void)(seeglb); /* symbols are 'global' by default */
181 if (lib == NULL) pusherror(L);181 if (lib == NULL) pusherror(L);
182 return lib;182 return lib;
183}183}
@@ -212,7 +212,7 @@ static void ll_unloadlib (void *lib) { · 28 unmodified lines
212 212
213 213
214static void *ll_load (lua_State *L, const char *path, int seeglb) {214static 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 */
216 lua_pushliteral(L, DLMSG);216 lua_pushliteral(L, DLMSG);
217 return NULL;217 return NULL;
218}218}
@@ -428,8 +428,6 @@ static int loader_Croot (lua_State *L) { · 209 unmodified lines
428static int loader_preload (lua_State *L) {428static int loader_preload (lua_State *L) {
429 const char *name = luaL_checkstring(L, 1);429 const char *name = luaL_checkstring(L, 1);
430 lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");430 lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD");
431 if (!lua_istable(L, -1))
432 luaL_error(L, LUA_QL("package.preload") " must be a table");
433 lua_getfield(L, -1, name);431 lua_getfield(L, -1, name);
434 if (lua_isnil(L, -1)) /* not found? */432 if (lua_isnil(L, -1)) /* not found? */
435 lua_pushfstring(L, "\n\tno field package.preload['%s']", name);433 lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
@@ -498,7 +496,7 @@ static int ll_require (lua_State *L) { · 62 unmodified lines
498#if defined(LUA_COMPAT_MODULE)496#if defined(LUA_COMPAT_MODULE)
499 497
500/*498/*
501** changes the _ENV variable of calling function499** changes the environment variable of calling function
502*/500*/
503static void set_env (lua_State *L) {501static void set_env (lua_State *L) {
504 lua_Debug ar;502 lua_Debug ar;
src/lobject.c+12−7
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Some generic functions over Lua objects3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -106,14 +106,19 @@ lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { · 100 unmodified lines
106}106}
107 107
108 108
109static 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
109int luaO_str2d (const char *s, lua_Number *result) {116int luaO_str2d (const char *s, lua_Number *result) {
110 char *endptr;117 char *endptr;
111 *result = lua_str2number(s, &endptr);118 *result = lua_str2number(s, &endptr);
112 if (endptr == s) return 0; /* conversion failed */119 if (checkend(s, endptr)) return 1; /* conversion OK? */
113 if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */120 *result = cast_num(strtoul(s, &endptr, 0)); /* try hexadecimal */
114 *result = cast_num(strtoul(s, &endptr, 16));121 return checkend(s, endptr);
115 while (lisspace(cast(unsigned char, *endptr))) endptr++;
116 return (*endptr == '\0'); /* OK if no trailing characters */
117}122}
118 123
119 124
@@ -221,7 +226,7 @@ void luaO_chunkid (char *out, const char *source, size_t bufflen) { · 101 unmodified lines
221 else { /* string; format as [string "source"] */226 else { /* string; format as [string "source"] */
222 const char *nl = strchr(source, '\n'); /* find first new line (if any) */227 const char *nl = strchr(source, '\n'); /* find first new line (if any) */
223 addstr(out, PRE, LL(PRE)); /* add prefix */228 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' */
225 if (l < bufflen && nl == NULL) { /* small one-line source? */230 if (l < bufflen && nl == NULL) { /* small one-line source? */
226 addstr(out, source, l); /* keep it */231 addstr(out, source, l); /* keep it */
227 }232 }
src/lopcodes.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** See Copyright Notice in lua.h3** See Copyright Notice in lua.h
4*/4*/
5 5
@@ -48,11 +48,11 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { · 42 unmodified lines
48 "FORLOOP",48 "FORLOOP",
49 "FORPREP",49 "FORPREP",
50 "TFORCALL",50 "TFORCALL",
51 "TFORLOOP",
51 "SETLIST",52 "SETLIST",
52 "CLOSE",53 "CLOSE",
53 "CLOSURE",54 "CLOSURE",
54 "VARARG",55 "VARARG",
55 "TFORLOOP",
56 "EXTRAARG",56 "EXTRAARG",
57 NULL57 NULL
58};58};
@@ -96,11 +96,11 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { · 37 unmodified lines
96 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */96 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
97 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */97 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
98 ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */98 ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */
99 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */
99 ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */100 ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
100 ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */101 ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */
101 ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */102 ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
102 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */103 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
103 ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */
104 ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */104 ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
105};105};
106 106
src/lopcodes.h+5−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Opcodes for Lua virtual machine3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -17,6 +17,7 @@ · 11 unmodified lines
17 `A' : 8 bits17 `A' : 8 bits
18 `B' : 9 bits18 `B' : 9 bits
19 `C' : 9 bits19 `C' : 9 bits
20 'Ax' : 26 bits ('A', 'B', and 'C' together)
20 `Bx' : 18 bits (`B' and `C' together)21 `Bx' : 18 bits (`B' and `C' together)
21 `sBx' : signed Bx22 `sBx' : signed Bx
22 23
@@ -122,7 +123,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ · 99 unmodified lines
122 | (cast(Instruction, bc)<<POS_Bx))123 | (cast(Instruction, bc)<<POS_Bx))
123 124
124#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \125#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
125 | (cast(Instruction, a)<<POS_A))126 | (cast(Instruction, a)<<POS_Ax))
126 127
127 128
128/*129/*
@@ -212,6 +213,8 @@ OP_FORLOOP,/* A sBx R(A)+=R(A+2); · 83 unmodified lines
212OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */213OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
213 214
214OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */215OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
216OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
217
215OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */218OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
216 219
217OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/220OP_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
219 222
220OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */223OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
221 224
222OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
223
224OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */225OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
225} OpCode;226} OpCode;
226 227
src/loslib.c+6−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard Operating System library3** Standard Operating System library
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -276,7 +276,11 @@ static int os_setlocale (lua_State *L) { · 270 unmodified lines
276 276
277 277
278static int os_exit (lua_State *L) {278static 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);
280 if (lua_toboolean(L, 2))284 if (lua_toboolean(L, 2))
281 lua_close(L);285 lua_close(L);
282 exit(status);286 exit(status);
src/lparser.c+16−11
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua Parser3** Lua Parser
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -289,7 +289,7 @@ static void singlevar (LexState *ls, expdesc *var) { · 283 unmodified lines
289 FuncState *fs = ls->fs;289 FuncState *fs = ls->fs;
290 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */290 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
291 expdesc key;291 expdesc key;
292 singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */292 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
293 lua_assert(var->k == VLOCAL || var->k == VUPVAL);293 lua_assert(var->k == VLOCAL || var->k == VUPVAL);
294 codestring(ls, &key, varname); /* key is variable name */294 codestring(ls, &key, varname); /* key is variable name */
295 luaK_indexed(fs, var, &key); /* env[varname] */295 luaK_indexed(fs, var, &key); /* env[varname] */
@@ -352,15 +352,20 @@ static void leaveblock (FuncState *fs) { · 56 unmodified lines
352}352}
353 353
354 354
355static 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*/
359static void codeclosure (LexState *ls, Proto *clp, expdesc *v) {
356 FuncState *fs = ls->fs->prev;360 FuncState *fs = ls->fs->prev;
357 Proto *f = fs->f; /* prototype of function creating new closure */361 Proto *f = fs->f; /* prototype of function creating new closure */
358 int oldsize = f->sizep;362 if (fs->np >= f->sizep) {
359 luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,363 int oldsize = f->sizep;
360 MAXARG_Bx, "functions");364 luaM_growvector(ls->L, f->p, fs->np, f->sizep, Proto *,
361 while (oldsize < f->sizep) f->p[oldsize++] = NULL;365 MAXARG_Bx, "functions");
366 while (oldsize < f->sizep) f->p[oldsize++] = NULL;
367 }
362 f->p[fs->np++] = clp;368 f->p[fs->np++] = clp;
363 /* initial environment for new function is current lexical environment */
364 luaC_objbarrier(ls->L, f, clp);369 luaC_objbarrier(ls->L, f, clp);
365 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));370 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
366}371}
@@ -428,14 +433,14 @@ static void close_func (LexState *ls) { · 61 unmodified lines
428 433
429/*434/*
430** opens the main function, which is a regular vararg function with an435** opens the main function, which is a regular vararg function with an
431** upvalue named '_ENV'436** upvalue named LUA_ENV
432*/437*/
433static void open_mainfunc (LexState *ls, FuncState *fs) {438static void open_mainfunc (LexState *ls, FuncState *fs) {
434 expdesc v;439 expdesc v;
435 open_func(ls, fs);440 open_func(ls, fs);
436 fs->f->is_vararg = 1; /* main function is always vararg */441 fs->f->is_vararg = 1; /* main function is always vararg */
437 init_exp(&v, VLOCAL, 0);442 init_exp(&v, VLOCAL, 0);
438 newupvalue(fs, ls->envn, &v); /* create '_ENV' upvalue */443 newupvalue(fs, ls->envn, &v); /* create environment upvalue */
439}444}
440 445
441 446
@@ -653,7 +658,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { · 211 unmodified lines
653 chunk(ls);658 chunk(ls);
654 new_fs.f->lastlinedefined = ls->linenumber;659 new_fs.f->lastlinedefined = ls->linenumber;
655 check_match(ls, TK_END, TK_FUNCTION, line);660 check_match(ls, TK_END, TK_FUNCTION, line);
656 pushclosure(ls, new_fs.f, e);661 codeclosure(ls, new_fs.f, e);
657 close_func(ls);662 close_func(ls);
658}663}
659 664
src/lstate.c+6−1
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Global State3** Global State
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -29,6 +29,10 @@ · 23 unmodified lines
29#define LUAI_GCPAUSE 200 /* 200% */29#define LUAI_GCPAUSE 200 /* 200% */
30#endif30#endif
31 31
32#if !defined(LUAI_GCMAJOR)
33#define LUAI_GCMAJOR 200 /* 200% */
34#endif
35
32#if !defined(LUAI_GCMUL)36#if !defined(LUAI_GCMUL)
33#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */37#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
34#endif38#endif
@@ -254,6 +258,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 219 unmodified lines
254 g->weak = g->ephemeron = g->allweak = NULL;258 g->weak = g->ephemeron = g->allweak = NULL;
255 g->totalbytes = sizeof(LG);259 g->totalbytes = sizeof(LG);
256 g->gcpause = LUAI_GCPAUSE;260 g->gcpause = LUAI_GCPAUSE;
261 g->gcmajorinc = LUAI_GCMAJOR;
257 g->gcstepmul = LUAI_GCMUL;262 g->gcstepmul = LUAI_GCMUL;
258 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;263 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
259 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {264 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
src/lstate.h+4−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Global State3** Global State
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -66,13 +66,13 @@ typedef struct stringtable { · 60 unmodified lines
66 66
67 67
68/*68/*
69** informations about a call69** information about a call
70*/70*/
71typedef struct CallInfo {71typedef struct CallInfo {
72 StkId func; /* function index in the stack */72 StkId func; /* function index in the stack */
73 StkId top; /* top for this function */73 StkId top; /* top for this function */
74 struct CallInfo *previous, *next; /* dynamic call link */74 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 */
76 lu_byte callstatus;76 lu_byte callstatus;
77 union {77 union {
78 struct { /* only for Lua functions */78 struct { /* only for Lua functions */
@@ -136,6 +136,7 @@ typedef struct global_State { · 57 unmodified lines
136 UpVal uvhead; /* head of double-linked list of all open upvalues */136 UpVal uvhead; /* head of double-linked list of all open upvalues */
137 Mbuffer buff; /* temporary buffer for string concatenation */137 Mbuffer buff; /* temporary buffer for string concatenation */
138 int gcpause; /* size of pause between successive GCs */138 int gcpause; /* size of pause between successive GCs */
139 int gcmajorinc; /* how much to wait for a major GC (only in gen. mode) */
139 int gcstepmul; /* GC `granularity' */140 int gcstepmul; /* GC `granularity' */
140 lua_CFunction panic; /* to be called in unprotected errors */141 lua_CFunction panic; /* to be called in unprotected errors */
141 struct lua_State *mainthread;142 struct lua_State *mainthread;
src/lstrlib.c+4−4
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Standard library for string operations and pattern-matching3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -424,7 +424,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { · 418 unmodified lines
424 default: goto dflt;424 default: goto dflt;
425 }425 }
426 }426 }
427 default: dflt: { /* pattern class plus optional sufix */427 default: dflt: { /* pattern class plus optional suffix */
428 const char *ep = classend(ms, p); /* points to what is next */428 const char *ep = classend(ms, p); /* points to what is next */
429 int m = s < ms->src_end && singlematch(uchar(*s), p, ep);429 int m = s < ms->src_end && singlematch(uchar(*s), p, ep);
430 switch (*ep) {430 switch (*ep) {
@@ -758,9 +758,9 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { · 327 unmodified lines
758 else if (*s == '\0' || iscntrl(uchar(*s))) {758 else if (*s == '\0' || iscntrl(uchar(*s))) {
759 char buff[10];759 char buff[10];
760 if (!isdigit(uchar(*(s+1))))760 if (!isdigit(uchar(*(s+1))))
761 sprintf(buff, "\\%d", uchar(*s));761 sprintf(buff, "\\%d", (int)uchar(*s));
762 else762 else
763 sprintf(buff, "\\%03d", uchar(*s));763 sprintf(buff, "\\%03d", (int)uchar(*s));
764 luaL_addstring(b, buff);764 luaL_addstring(b, buff);
765 }765 }
766 else766 else
src/ltablib.c+3−2
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Library for Table Manipulation3** Library for Table Manipulation
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -16,7 +16,8 @@ · 10 unmodified lines
16#include "lualib.h"16#include "lualib.h"
17 17
18 18
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))
20 21
21 22
22static int foreachi (lua_State *L) {23static int foreachi (lua_State *L) {
src/lua.c+7−6
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua stand-alone interpreter3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -369,10 +369,11 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 363 unmodified lines
369 break;369 break;
370 case 'e':370 case 'e':
371 *pe = 1; /* go through */371 *pe = 1; /* go through */
372 case 'l':372 case 'l': /* both options need an argument */
373 if (argv[i][2] == '\0') {373 if (argv[i][2] == '\0') { /* no concatenated argument? */
374 i++;374 i++; /* try next 'argv' */
375 if (argv[i] == NULL) return -(i - 1);375 if (argv[i] == NULL || argv[i][0] == '-')
376 return -(i - 1); /* no next argument or it is another option */
376 }377 }
377 break;378 break;
378 default: /* invalid option; return its index... */379 default: /* invalid option; return its index... */
@@ -427,7 +428,7 @@ static int handle_luainit (lua_State *L) { · 48 unmodified lines
427 428
428 429
429static int pmain (lua_State *L) {430static int pmain (lua_State *L) {
430 int argc = lua_tointeger(L, 1);431 int argc = (int)lua_tointeger(L, 1);
431 char **argv = (char **)lua_touserdata(L, 2);432 char **argv = (char **)lua_touserdata(L, 2);
432 int script;433 int script;
433 int has_i = 0, has_v = 0, has_e = 0;434 int has_i = 0, has_v = 0, has_e = 0;
src/lua.h+12−5
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua - A Scripting Language3** Lua - A Scripting Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file5** See Copyright Notice at the end of this file
@@ -18,7 +18,7 @@ · 12 unmodified lines
18 18
19#define LUA_VERSION_MAJOR "5"19#define LUA_VERSION_MAJOR "5"
20#define LUA_VERSION_MINOR "2"20#define LUA_VERSION_MINOR "2"
21#define LUA_VERSION_RELEASE "0" " (work4)"21#define LUA_VERSION_RELEASE "0" " (work5)"
22 22
23#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR23#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
24#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE24#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
@@ -106,6 +106,9 @@ typedef LUA_NUMBER lua_Number; · 81 unmodified lines
106/* type for integer functions */106/* type for integer functions */
107typedef LUA_INTEGER lua_Integer;107typedef LUA_INTEGER lua_Integer;
108 108
109/* unsigned integer type */
110typedef LUA_UNSIGNED lua_Unsigned;
111
109 112
110 113
111/*114/*
@@ -159,6 +162,7 @@ LUA_API const char *(lua_typename) (lua_State *L, int tp); · 47 unmodified lines
159 162
160LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);163LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
161LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);164LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
165LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
162LUA_API int (lua_toboolean) (lua_State *L, int idx);166LUA_API int (lua_toboolean) (lua_State *L, int idx);
163LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);167LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
164LUA_API size_t (lua_rawlen) (lua_State *L, int idx);168LUA_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
196LUA_API void (lua_pushnil) (lua_State *L);200LUA_API void (lua_pushnil) (lua_State *L);
197LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);201LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
198LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);202LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
203LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
199LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);204LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
200LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);205LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
201LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,206LUA_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
271#define LUA_GCSTEP 5276#define LUA_GCSTEP 5
272#define LUA_GCSETPAUSE 6277#define LUA_GCSETPAUSE 6
273#define LUA_GCSETSTEPMUL 7278#define LUA_GCSETSTEPMUL 7
274#define LUA_GCISRUNNING 8279#define LUA_GCSETMAJORINC 8
275#define LUA_GCGEN 9280#define LUA_GCISRUNNING 9
276#define LUA_GCINC 10281#define LUA_GCGEN 10
282#define LUA_GCINC 11
277 283
278LUA_API int (lua_gc) (lua_State *L, int what, int data);284LUA_API int (lua_gc) (lua_State *L, int what, int data);
279 285
@@ -302,6 +308,7 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); · 22 unmodified lines
302 308
303#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)309#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
304#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)310#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
311#define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
305 312
306#define lua_pop(L,n) lua_settop(L, -(n)-1)313#define lua_pop(L,n) lua_settop(L, -(n)-1)
307 314
src/luac.c+273−39
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua compiler (saves bytecodes to files; also list bytecodes)3** Lua compiler (saves bytecodes to files; also list bytecodes)
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -15,14 +15,13 @@ · 9 unmodified lines
15#include "lua.h"15#include "lua.h"
16#include "lauxlib.h"16#include "lauxlib.h"
17 17
18#include "ldo.h"
19#include "lfunc.h"
20#include "lmem.h"
21#include "lobject.h"18#include "lobject.h"
22#include "lopcodes.h"19#include "lstate.h"
23#include "lstring.h"
24#include "lundump.h"20#include "lundump.h"
25 21
22static void PrintFunction(const Proto* f, int full);
23#define luaU_print PrintFunction
24
26#define PROGNAME "luac" /* default program name */25#define PROGNAME "luac" /* default program name */
27#define OUTPUT PROGNAME ".out" /* default output file */26#define OUTPUT PROGNAME ".out" /* default output file */
28 27
@@ -52,16 +51,16 @@ static void usage(const char* message) · 23 unmodified lines
52 else51 else
53 fprintf(stderr,"%s: %s\n",progname,message);52 fprintf(stderr,"%s: %s\n",progname,message);
54 fprintf(stderr,53 fprintf(stderr,
55 "usage: %s [options] [filenames]\n"54 "usage: %s [options] [filenames]\n"
56 "Available options are:\n"55 "Available options are:\n"
57 " -l list\n"56 " -l list\n"
58 " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"57 " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
59 " -p parse only\n"58 " -p parse only\n"
60 " -s strip debug information\n"59 " -s strip debug information\n"
61 " -v show version information\n"60 " -v show version information\n"
62 " -- stop handling options\n"61 " -- stop handling options\n"
63 " - stop handling options and process stdin\n"62 " - stop handling options and process stdin\n"
64 ,progname,Output);63 ,progname,Output);
65 exit(EXIT_FAILURE);64 exit(EXIT_FAILURE);
66}65}
67 66
@@ -89,7 +88,8 @@ static int doargs(int argc, char* argv[]) · 21 unmodified lines
89 else if (IS("-o")) /* output file */88 else if (IS("-o")) /* output file */
90 {89 {
91 output=argv[++i];90 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");
93 if (IS("-")) output=NULL;93 if (IS("-")) output=NULL;
94 }94 }
95 else if (IS("-p")) /* parse only */95 else if (IS("-p")) /* parse only */
@@ -114,7 +114,24 @@ static int doargs(int argc, char* argv[]) · 18 unmodified lines
114 return i;114 return i;
115}115}
116 116
117#define toproto(L,i) (clvalue(L->top+(i))->l.p)117#define FUNCTION "(function()end)();"
118
119static 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))
118 135
119static const Proto* combine(lua_State* L, int n)136static const Proto* combine(lua_State* L, int n)
120{137{
@@ -122,24 +139,13 @@ static const Proto* combine(lua_State* L, int n) · 1 unmodified line
122 return toproto(L,-1);139 return toproto(L,-1);
123 else140 else
124 {141 {
125 int i,pc;142 Proto* f;
126 Proto* f=luaF_newproto(L);143 int i=n;
127 setptvalue2s(L,L->top,f); incr_top(L);144 if (lua_load(L,reader,&i,"=(" PROGNAME ")")!=LUA_OK) fatal(lua_tostring(L,-1));
128 f->source=luaS_newliteral(L,"=(" PROGNAME ")");145 f=toproto(L,-1);
129 f->maxstacksize=1;146 for (i=0; i<n; i++) f->p[i]=toproto(L,i-n-1);
130 pc=2*n+1;147 f->sizelineinfo=0;
131 f->code=luaM_newvector(L,pc,Instruction);148 f->sizeupvalues=0;
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);
143 return f;149 return f;
144 }150 }
145}151}
@@ -152,7 +158,7 @@ static int writer(lua_State* L, const void* p, size_t size, void* u) · 6 unmodified lines
152 158
153static int pmain(lua_State* L)159static int pmain(lua_State* L)
154{160{
155 int argc=lua_tointeger(L,1);161 int argc=(int)lua_tointeger(L,1);
156 char** argv=lua_touserdata(L,2);162 char** argv=lua_touserdata(L,2);
157 const Proto* f;163 const Proto* f;
158 int i;164 int i;
@@ -160,7 +166,7 @@ static int pmain(lua_State* L) · 1 unmodified line
160 for (i=0; i<argc; i++)166 for (i=0; i<argc; i++)
161 {167 {
162 const char* filename=IS("-") ? NULL : argv[i];168 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));
164 }170 }
165 f=combine(L,argc);171 f=combine(L,argc);
166 if (listing) luaU_print(f,listing>1);172 if (listing) luaU_print(f,listing>1);
@@ -188,7 +194,235 @@ int main(int argc, char* argv[]) · 21 unmodified lines
188 lua_pushcfunction(L,&pmain);194 lua_pushcfunction(L,&pmain);
189 lua_pushinteger(L,argc);195 lua_pushinteger(L,argc);
190 lua_pushlightuserdata(L,argv);196 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));
192 lua_close(L);198 lua_close(L);
193 return EXIT_SUCCESS;199 return EXIT_SUCCESS;
194}200}
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
221static 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
249static 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
274static 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
374static 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
394static 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
421static 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 @@
1/*1/*
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 $
3** Configuration file for Lua3** Configuration file for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -47,8 +47,8 @@ · 41 unmodified lines
47 47
48#if defined(LUA_USE_MACOSX)48#if defined(LUA_USE_MACOSX)
49#define LUA_USE_POSIX49#define LUA_USE_POSIX
50#define LUA_USE_DLOPEN50#define LUA_USE_DLOPEN /* does not need -ldl */
51#define LUA_USE_READLINE /* needs some extra libraries */51#define LUA_USE_READLINE /* needs an extra library: -lreadline */
52#endif52#endif
53 53
54 54
@@ -115,6 +115,14 @@ · 60 unmodified lines
115#endif115#endif
116 116
117 117
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
118/*126/*
119@@ LUA_API is a mark for all core API functions.127@@ LUA_API is a mark for all core API functions.
120@@ LUALIB_API is a mark for all auxiliary library functions.128@@ LUALIB_API is a mark for all auxiliary library functions.
@@ -430,26 +438,28 @@ · 309 unmodified lines
430*/438*/
431#define LUA_INTEGER ptrdiff_t439#define LUA_INTEGER ptrdiff_t
432 440
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
433 447
434/*448/*
435@@ lua_number2int is a macro to convert lua_Number to int.449@@ lua_number2int is a macro to convert lua_Number to int.
436@@ lua_number2integer is a macro to convert lua_Number to LUA_INTEGER.450@@ 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 unsigned451@@ lua_number2uint is a macro to convert a lua_Number to a LUA_UNSIGNED.
438@* LUA_INT32.452@@ lua_uint2number is a macro to convert a LUA_UNSIGNED to a lua_Number.
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.
445*/453*/
446 454
447/* On a Pentium, resort to a trick */455#if defined(LUA_CORE) /* { */
448#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \456
449 (defined(__i386) || defined (_M_IX86) || defined(__i386__)) /* { */457#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && \
458 !defined(LUA_NOIEEE754TRICK) /* { */
450 459
451/* On a Microsoft compiler, use assembler */460/* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
452#if defined(_MSC_VER) /* { */461 with a DirectX idiosyncrasy */
462#if defined(_MSC_VER) && defined(M_IX86) /* { */
453 463
454#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}464#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
455#define lua_number2integer(i,n) lua_number2int(i, n)465#define lua_number2integer(i,n) lua_number2int(i, n)
@@ -457,31 +467,76 @@ · 1 unmodified line
457 {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}467 {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
458 468
459#else /* }{ */469#else /* }{ */
460/* the next trick should work on any Pentium, but sometimes clashes470/* the next trick should work on any machine using IEEE754 with
461 with a DirectX idiosyncrasy */471 a 32-bit integer type */
462 472
463union luai_Cast { double l_d; long l_l; };473union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
464#define lua_number2int(i,n) \474
465 { volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; (i) = u.l_l; }475/*
466#define lua_number2integer(i,n) lua_number2int(i, n)476@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
467#define lua_number2uint(i,n) lua_number2int(i, n)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)
468 504
469#endif /* } */505#endif /* } */
470 506
471 507
472#else /* }{ */508#endif /* } */
473/* this option always works, but may be slow */509
510
511/* the following definitions always work, but may be slow */
512
513#if !defined(lua_number2int)
474#define lua_number2int(i,n) ((i)=(int)(n))514#define lua_number2int(i,n) ((i)=(int)(n))
475#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))515#endif
476#define lua_number2uint(i,n) ((i)=(unsigned LUA_INT32)(n))
477 516
478#endif /* } */517#if !defined(lua_number2integer)
518#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))
519#endif
479 520
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 /* } */
480 531
481/* on several machines, coercion from unsigned to double is too slow,532#if !defined(lua_uint2number)
482 so avoid that if possible */533/* on several machines, coercion from unsigned to double is slow,
534 so it may be worth to avoid */
483#define lua_uint2number(u) \535#define lua_uint2number(u) \
484 ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u))536 ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u))
537#endif
538
539#endif /* } */
485 540
486 541
487/*542/*
src/lualib.h+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua standard libraries3** Lua standard libraries
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -32,8 +32,8 @@ LUAMOD_API int (luaopen_os) (lua_State *L); · 26 unmodified lines
32#define LUA_STRLIBNAME "string"32#define LUA_STRLIBNAME "string"
33LUAMOD_API int (luaopen_string) (lua_State *L);33LUAMOD_API int (luaopen_string) (lua_State *L);
34 34
35#define LUA_BITLIBNAME "bit"35#define LUA_BITLIBNAME "bit32"
36LUAMOD_API int (luaopen_bit) (lua_State *L);36LUAMOD_API int (luaopen_bit32) (lua_State *L);
37 37
38#define LUA_MATHLIBNAME "math"38#define LUA_MATHLIBNAME "math"
39LUAMOD_API int (luaopen_math) (lua_State *L);39LUAMOD_API int (luaopen_math) (lua_State *L);
src/lundump.c+30−29
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** load precompiled Lua chunks3** load precompiled Lua chunks
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -27,27 +27,20 @@ typedef struct { · 21 unmodified lines
27 const char* name;27 const char* name;
28} LoadState;28} LoadState;
29 29
30#ifdef LUAC_TRUST_BINARIES
31#define IF(c,s)
32#else
33#define IF(c,s) if (c) error(S,s)
34
35static void error(LoadState* S, const char* why)30static void error(LoadState* S, const char* why)
36{31{
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);
38 luaD_throw(S->L,LUA_ERRSYNTAX);33 luaD_throw(S->L,LUA_ERRSYNTAX);
39}34}
40#endif
41 35
42#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))36#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)
44#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))38#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
45#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)39#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
46 40
47static void LoadBlock(LoadState* S, void* b, size_t size)41static void LoadBlock(LoadState* S, void* b, size_t size)
48{42{
49 size_t r=luaZ_read(S->Z,b,size);43 if (luaZ_read(S->Z,b,size)!=0) error(S,"corrupted");
50 IF (r!=0, "unexpected end");
51}44}
52 45
53static int LoadChar(LoadState* S)46static int LoadChar(LoadState* S)
@@ -61,7 +54,6 @@ static int LoadInt(LoadState* S) · 7 unmodified lines
61{54{
62 int x;55 int x;
63 LoadVar(S,x);56 LoadVar(S,x);
64 IF (x<0, "bad integer");
65 return x;57 return x;
66}58}
67 59
@@ -94,7 +86,7 @@ static void LoadCode(LoadState* S, Proto* f) · 26 unmodified lines
94 LoadVector(S,f->code,n,sizeof(Instruction));86 LoadVector(S,f->code,n,sizeof(Instruction));
95}87}
96 88
97static Proto* LoadFunction(LoadState* S, TString* p);89static Proto* LoadFunction(LoadState* S);
98 90
99static void LoadConstants(LoadState* S, Proto* f)91static void LoadConstants(LoadState* S, Proto* f)
100{92{
@@ -113,7 +105,7 @@ static void LoadConstants(LoadState* S, Proto* f) · 12 unmodified lines
113 setnilvalue(o);105 setnilvalue(o);
114 break;106 break;
115 case LUA_TBOOLEAN:107 case LUA_TBOOLEAN:
116 setbvalue(o,LoadChar(S)!=0);108 setbvalue(o,LoadChar(S));
117 break;109 break;
118 case LUA_TNUMBER:110 case LUA_TNUMBER:
119 setnvalue(o,LoadNumber(S));111 setnvalue(o,LoadNumber(S));
@@ -121,16 +113,13 @@ static void LoadConstants(LoadState* S, Proto* f) · 1 unmodified line
121 case LUA_TSTRING:113 case LUA_TSTRING:
122 setsvalue2n(S->L,o,LoadString(S));114 setsvalue2n(S->L,o,LoadString(S));
123 break;115 break;
124 default:
125 IF (1, "bad constant");
126 break;
127 }116 }
128 }117 }
129 n=LoadInt(S);118 n=LoadInt(S);
130 f->p=luaM_newvector(S->L,n,Proto*);119 f->p=luaM_newvector(S->L,n,Proto*);
131 f->sizep=n;120 f->sizep=n;
132 for (i=0; i<n; i++) f->p[i]=NULL;121 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);
134}123}
135 124
136static void LoadUpvalues(LoadState* S, Proto* f)125static void LoadUpvalues(LoadState* S, Proto* f)
@@ -150,6 +139,7 @@ static void LoadUpvalues(LoadState* S, Proto* f) · 13 unmodified lines
150static void LoadDebug(LoadState* S, Proto* f)139static void LoadDebug(LoadState* S, Proto* f)
151{140{
152 int i,n;141 int i,n;
142 f->source=LoadString(S);
153 n=LoadInt(S);143 n=LoadInt(S);
154 f->lineinfo=luaM_newvector(S->L,n,int);144 f->lineinfo=luaM_newvector(S->L,n,int);
155 f->sizelineinfo=n;145 f->sizelineinfo=n;
@@ -168,13 +158,10 @@ static void LoadDebug(LoadState* S, Proto* f) · 12 unmodified lines
168 for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);158 for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
169}159}
170 160
171static Proto* LoadFunction(LoadState* S, TString* p)161static Proto* LoadFunction(LoadState* S)
172{162{
173 Proto* f;163 Proto* f=luaF_newproto(S->L);
174 if (++G(S->L)->nCcalls > LUAI_MAXCCALLS) error(S, "function nest too deep");
175 f=luaF_newproto(S->L);
176 setptvalue2s(S->L,S->L->top,f); incr_top(S->L);164 setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
177 f->source=LoadString(S); if (f->source==NULL) f->source=p;
178 f->linedefined=LoadInt(S);165 f->linedefined=LoadInt(S);
179 f->lastlinedefined=LoadInt(S);166 f->lastlinedefined=LoadInt(S);
180 f->numparams=LoadByte(S);167 f->numparams=LoadByte(S);
@@ -185,17 +172,25 @@ static Proto* LoadFunction(LoadState* S, TString* p) · 4 unmodified lines
185 LoadUpvalues(S,f);172 LoadUpvalues(S,f);
186 LoadDebug(S,f);173 LoadDebug(S,f);
187 S->L->top--;174 S->L->top--;
188 G(S->L)->nCcalls--;
189 return f;175 return f;
190}176}
191 177
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
192static void LoadHeader(LoadState* S)184static void LoadHeader(LoadState* S)
193{185{
194 char h[LUAC_HEADERSIZE];186 char h[LUAC_HEADERSIZE];
195 char s[LUAC_HEADERSIZE];187 char s[LUAC_HEADERSIZE];
196 luaU_header(h);188 luaU_header(h);
197 LoadBlock(S,s,LUAC_HEADERSIZE);189 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");
199}194}
200 195
201/*196/*
@@ -214,23 +209,29 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) · 12 unmodified lines
214 S.Z=Z;209 S.Z=Z;
215 S.b=buff;210 S.b=buff;
216 LoadHeader(&S);211 LoadHeader(&S);
217 return LoadFunction(&S,luaS_newliteral(L,"=?"));212 return LoadFunction(&S);
218}213}
219 214
215/* data to catch conversion errors */
216#define TAIL "\x19\x93\r\n\x1a\n"
217
220/*218/*
221* make header219* 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
222*/222*/
223void luaU_header (char* h)223void luaU_header (char* h)
224{224{
225 int x=1;225 int x=1;
226 memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);226 memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
227 h+=sizeof(LUA_SIGNATURE)-1;227 h+=sizeof(LUA_SIGNATURE)-1;
228 *h++=(char)LUAC_VERSION;228 *h++=(char)0x52; /* Lua 5.2 */
229 *h++=(char)LUAC_FORMAT;229 *h++=(char)0; /* the official format */
230 *h++=(char)*(char*)&x; /* endianness */230 *h++=(char)*(char*)&x; /* endianness */
231 *h++=(char)sizeof(int);231 *h++=(char)sizeof(int);
232 *h++=(char)sizeof(size_t);232 *h++=(char)sizeof(size_t);
233 *h++=(char)sizeof(Instruction);233 *h++=(char)sizeof(Instruction);
234 *h++=(char)sizeof(lua_Number);234 *h++=(char)sizeof(lua_Number);
235 *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */235 *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
236 memcpy(h,TAIL,sizeof(TAIL)-1);
236}237}
src/lundump.h+2−13
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** load precompiled Lua chunks3** load precompiled Lua chunks
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -19,18 +19,7 @@ LUAI_FUNC void luaU_header (char* h); · 13 unmodified lines
19/* dump one chunk; from ldump.c */19/* dump one chunk; from ldump.c */
20LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);20LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
21 21
22#ifdef luac_c
23/* print one chunk; from print.c */
24LUAI_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
33/* size of header of binary files */22/* size of header of binary files */
34#define LUAC_HEADERSIZE 1223#define LUAC_HEADERSIZE 18
35 24
36#endif25#endif
src/lvm.c+3−3
@@ -1,5 +1,5 @@
1/*1/*
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 $
3** Lua virtual machine3** Lua virtual machine
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -301,7 +301,7 @@ void luaV_concat (lua_State *L, int total) { · 295 unmodified lines
301 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));301 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
302 }302 }
303 total -= n-1; /* got 'n' strings to create 1 new */303 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 */
305 } while (total > 1); /* repeat until only 1 result left */305 } while (total > 1); /* repeat until only 1 result left */
306}306}
307 307
@@ -421,7 +421,7 @@ void luaV_finishOp (lua_State *L) { · 113 unmodified lines
421 case OP_CONCAT: {421 case OP_CONCAT: {
422 StkId top = L->top - 1; /* top when 'call_binTM' was called */422 StkId top = L->top - 1; /* top when 'call_binTM' was called */
423 int b = GETARG_B(inst); /* first element to concatenate */423 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 */
425 setobj2s(L, top - 2, top); /* put TM result in proper position */425 setobj2s(L, top - 2, top); /* put TM result in proper position */
426 if (total > 1) { /* are there elements to concat? */426 if (total > 1) { /* are there elements to concat? */
427 L->top = top - 1; /* top is one after last element (at top-2) */427 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
23static 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
51static 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
76static 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
175static 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
195static 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
222void 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
3io.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