Unified · Split
| @@ -62,13 +62,13 @@ install: dummy · 61 unmodified lines | ||
| 62 | 62 | cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) |
| 63 | 63 | cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) |
| 64 | 64 | cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) |
| 65 | − #cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) | |
| 65 | + cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) | |
| 66 | 66 | |
| 67 | 67 | uninstall: |
| 68 | 68 | cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN) |
| 69 | 69 | cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC) |
| 70 | 70 | cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB) |
| 71 | − #cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN) | |
| 71 | + cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN) | |
| 72 | 72 | |
| 73 | 73 | local: |
| 74 | 74 | $(MAKE) install INSTALL_TOP=../install |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | |
| 2 | −This is Lua 5.2 (beta), released on 05 Jul 2011. | |
| 2 | +This is Lua 5.2, released on 24 Nov 2011. | |
| 3 | 3 | |
| 4 | 4 | For installation instructions, license details, and |
| 5 | 5 | further information about Lua, see doc/readme.html. |
Binary file not shown.
| @@ -20,11 +20,6 @@ ul { · 19 unmodified lines | ||
| 20 | 20 | Lua 5.2 Reference Manual |
| 21 | 21 | </H1> |
| 22 | 22 | |
| 23 | −<P> | |
| 24 | −<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> | |
| 25 | −<EM>This is a beta version of Lua 5.2. | |
| 26 | −Some details may change in the final version.</EM> | |
| 27 | − | |
| 28 | 23 | <P> |
| 29 | 24 | The reference manual is the official definition of the Lua language. |
| 30 | 25 | For a complete introduction to Lua programming, see the book |
| @@ -95,7 +90,7 @@ Freely available under the terms of the · 64 unmodified lines | ||
| 95 | 90 | <UL> |
| 96 | 91 | <LI><A HREF="manual.html#4.1">4.1 – The Stack</A> |
| 97 | 92 | <LI><A HREF="manual.html#4.2">4.2 – Stack Size</A> |
| 98 | −<LI><A HREF="manual.html#4.3">4.3 – Pseudo-Indices</A> | |
| 93 | +<LI><A HREF="manual.html#4.3">4.3 – Valid and Acceptable Indices</A> | |
| 99 | 94 | <LI><A HREF="manual.html#4.4">4.4 – C Closures</A> |
| 100 | 95 | <LI><A HREF="manual.html#4.5">4.5 – Registry</A> |
| 101 | 96 | <LI><A HREF="manual.html#4.6">4.6 – Error Handling in C</A> |
| @@ -154,8 +149,8 @@ Freely available under the terms of the · 52 unmodified lines | ||
| 154 | 149 | <A HREF="manual.html#pdf-error">error</A><BR> |
| 155 | 150 | <A HREF="manual.html#pdf-getmetatable">getmetatable</A><BR> |
| 156 | 151 | <A HREF="manual.html#pdf-ipairs">ipairs</A><BR> |
| 157 | −<A HREF="manual.html#pdf-load">load</A><BR> | |
| 158 | 152 | <A HREF="manual.html#pdf-loadfile">loadfile</A><BR> |
| 153 | +<A HREF="manual.html#pdf-load">load</A><BR> | |
| 159 | 154 | <A HREF="manual.html#pdf-next">next</A><BR> |
| 160 | 155 | <A HREF="manual.html#pdf-pairs">pairs</A><BR> |
| 161 | 156 | <A HREF="manual.html#pdf-pcall">pcall</A><BR> |
| @@ -406,6 +401,8 @@ Freely available under the terms of the · 244 unmodified lines | ||
| 406 | 401 | <A HREF="manual.html#lua_rawlen">lua_rawlen</A><BR> |
| 407 | 402 | <A HREF="manual.html#lua_rawset">lua_rawset</A><BR> |
| 408 | 403 | <A HREF="manual.html#lua_rawseti">lua_rawseti</A><BR> |
| 404 | +<A HREF="manual.html#lua_rawgetp">lua_rawgetp</A><BR> | |
| 405 | +<A HREF="manual.html#lua_rawsetp">lua_rawsetp</A><BR> | |
| 409 | 406 | <A HREF="manual.html#lua_register">lua_register</A><BR> |
| 410 | 407 | <A HREF="manual.html#lua_remove">lua_remove</A><BR> |
| 411 | 408 | <A HREF="manual.html#lua_replace">lua_replace</A><BR> |
| @@ -463,8 +460,8 @@ Freely available under the terms of the · 51 unmodified lines | ||
| 463 | 460 | <A HREF="manual.html#luaL_buffinitsize">luaL_buffinitsize</A><BR> |
| 464 | 461 | <A HREF="manual.html#luaL_callmeta">luaL_callmeta</A><BR> |
| 465 | 462 | <A HREF="manual.html#luaL_checkany">luaL_checkany</A><BR> |
| 466 | −<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR> | |
| 467 | 463 | <A HREF="manual.html#luaL_checkinteger">luaL_checkinteger</A><BR> |
| 464 | +<A HREF="manual.html#luaL_checkint">luaL_checkint</A><BR> | |
| 468 | 465 | <A HREF="manual.html#luaL_checklong">luaL_checklong</A><BR> |
| 469 | 466 | <A HREF="manual.html#luaL_checklstring">luaL_checklstring</A><BR> |
| 470 | 467 | <A HREF="manual.html#luaL_checknumber">luaL_checknumber</A><BR> |
| @@ -487,14 +484,15 @@ Freely available under the terms of the · 16 unmodified lines | ||
| 487 | 484 | <A HREF="manual.html#luaL_len">luaL_len</A><BR> |
| 488 | 485 | <A HREF="manual.html#luaL_loadbuffer">luaL_loadbuffer</A><BR> |
| 489 | 486 | <A HREF="manual.html#luaL_loadfile">luaL_loadfile</A><BR> |
| 487 | +<A HREF="manual.html#luaL_loadfilex">luaL_loadfilex</A><BR> | |
| 490 | 488 | <A HREF="manual.html#luaL_loadstring">luaL_loadstring</A><BR> |
| 491 | 489 | <A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR> |
| 492 | 490 | <A HREF="manual.html#luaL_newlibtable">luaL_newlibtable</A><BR> |
| 493 | 491 | <A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR> |
| 494 | 492 | <A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR> |
| 495 | 493 | <A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR> |
| 496 | −<A HREF="manual.html#luaL_optint">luaL_optint</A><BR> | |
| 497 | 494 | <A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR> |
| 495 | +<A HREF="manual.html#luaL_optint">luaL_optint</A><BR> | |
| 498 | 496 | <A HREF="manual.html#luaL_optlong">luaL_optlong</A><BR> |
| 499 | 497 | <A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR> |
| 500 | 498 | <A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR> |
| @@ -522,10 +520,10 @@ Freely available under the terms of the · 21 unmodified lines | ||
| 522 | 520 | <HR> |
| 523 | 521 | <SMALL CLASS="footer"> |
| 524 | 522 | Last update: |
| 525 | −Tue Jun 28 14:53:13 BRT 2011 | |
| 523 | +Wed Nov 23 16:14:28 BRST 2011 | |
| 526 | 524 | </SMALL> |
| 527 | 525 | <!-- |
| 528 | −Last change: revised for Lua 5.2.0 (beta) | |
| 526 | +Last change: revised for Lua 5.2.0 | |
| 529 | 527 | --> |
| 530 | 528 | |
| 531 | 529 | </BODY> |
| @@ -0,0 +1,116 @@ | ||
| 1 | +.\" $Id: lua.man,v 1.13 2011/11/16 17:16:53 lhf Exp $ | |
| 2 | +.TH LUA 1 "$Date: 2011/11/16 17:16:53 $" | |
| 3 | +.SH NAME | |
| 4 | +lua \- Lua interpreter | |
| 5 | +.SH SYNOPSIS | |
| 6 | +.B lua | |
| 7 | +[ | |
| 8 | +.I options | |
| 9 | +] | |
| 10 | +[ | |
| 11 | +.I script | |
| 12 | +[ | |
| 13 | +.I args | |
| 14 | +] | |
| 15 | +] | |
| 16 | +.SH DESCRIPTION | |
| 17 | +.B lua | |
| 18 | +is the standalone Lua interpreter. | |
| 19 | +It loads and executes Lua programs, | |
| 20 | +either in textual source form or | |
| 21 | +in precompiled binary form. | |
| 22 | +(Precompiled binaries are output by | |
| 23 | +.BR luac , | |
| 24 | +the Lua compiler.) | |
| 25 | +.B lua | |
| 26 | +can be used as a batch interpreter and also interactively. | |
| 27 | +.LP | |
| 28 | +The given | |
| 29 | +.I options | |
| 30 | +are handled in order and then | |
| 31 | +the Lua program in file | |
| 32 | +.I script | |
| 33 | +is loaded and executed. | |
| 34 | +The given | |
| 35 | +.I args | |
| 36 | +are available to | |
| 37 | +.I script | |
| 38 | +as strings in a global table named | |
| 39 | +.BR arg . | |
| 40 | +If no options or arguments are given, | |
| 41 | +then | |
| 42 | +.B "\-v \-i" | |
| 43 | +is assumed when the standard input is a terminal; | |
| 44 | +otherwise, | |
| 45 | +.B "\-" | |
| 46 | +is assumed. | |
| 47 | +.LP | |
| 48 | +In interactive mode, | |
| 49 | +.B lua | |
| 50 | +prompts the user, | |
| 51 | +reads lines from the standard input, | |
| 52 | +and executes them as they are read. | |
| 53 | +If a line does not contain a complete statement, | |
| 54 | +then a secondary prompt is displayed and | |
| 55 | +lines are read until a complete statement is formed or | |
| 56 | +a syntax error is found. | |
| 57 | +If a line starts with | |
| 58 | +.BR '=' , | |
| 59 | +then | |
| 60 | +.B lua | |
| 61 | +evaluates and displays | |
| 62 | +the values of the expressions in the remainder of the line. | |
| 63 | +.LP | |
| 64 | +At the very start, | |
| 65 | +before even handling the command line, | |
| 66 | +.B lua | |
| 67 | +checks the contents of the environment variables | |
| 68 | +.B LUA_INIT_5_2 | |
| 69 | +or | |
| 70 | +.BR LUA_INIT , | |
| 71 | +in that order. | |
| 72 | +If the contents is of the form | |
| 73 | +.RI '@ filename ', | |
| 74 | +then | |
| 75 | +.I filename | |
| 76 | +is executed. | |
| 77 | +Otherwise, the string is assumed to be a Lua statement and is executed. | |
| 78 | +.SH OPTIONS | |
| 79 | +.TP | |
| 80 | +.BI \-e " stat" | |
| 81 | +execute statement | |
| 82 | +.IR stat . | |
| 83 | +.TP | |
| 84 | +.B \-i | |
| 85 | +enter interactive mode after executing | |
| 86 | +.IR script . | |
| 87 | +.TP | |
| 88 | +.BI \-l " name" | |
| 89 | +execute the equivalent of | |
| 90 | +.IB name =require(' name ') | |
| 91 | +before executing | |
| 92 | +.IR script . | |
| 93 | +.TP | |
| 94 | +.B \-v | |
| 95 | +show version information. | |
| 96 | +.TP | |
| 97 | +.B \-E | |
| 98 | +ignore environment variables. | |
| 99 | +.TP | |
| 100 | +.B \-\- | |
| 101 | +stop handling options. | |
| 102 | +.TP | |
| 103 | +.B \- | |
| 104 | +stop handling options and execute the standard input as a file. | |
| 105 | +.SH "SEE ALSO" | |
| 106 | +.BR luac (1) | |
| 107 | +.br | |
| 108 | +The documentation at lua.org, | |
| 109 | +especially section 7 of the reference manual. | |
| 110 | +.SH DIAGNOSTICS | |
| 111 | +Error messages should be self explanatory. | |
| 112 | +.SH AUTHORS | |
| 113 | +R. Ierusalimschy, | |
| 114 | +L. H. de Figueiredo, | |
| 115 | +W. Celes | |
| 116 | +.\" EOF | |
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | body { |
| 2 | 2 | color: #000000 ; |
| 3 | 3 | background-color: #FFFFFF ; |
| 4 | − font-family: sans-serif ; | |
| 5 | 4 | font-family: Helvetica, Arial, sans-serif ; |
| 6 | 5 | text-align: justify ; |
| 7 | 6 | margin-right: 20px ; |
| @@ -18,12 +17,13 @@ h2 { · 10 unmodified lines | ||
| 18 | 17 | padding-top: 0.4em ; |
| 19 | 18 | padding-bottom: 0.4em ; |
| 20 | 19 | padding-left: 20px ; |
| 20 | + padding-right: 20px ; | |
| 21 | 21 | margin-left: -20px ; |
| 22 | 22 | background-color: #E0E0FF ; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | h3 { |
| 26 | − padding-left: 8px ; | |
| 26 | + padding-left: 0.5em ; | |
| 27 | 27 | border-left: solid #E0E0FF 1em ; |
| 28 | 28 | } |
| 29 | 29 | |
| @@ -76,7 +76,6 @@ input[type=text] { · 46 unmodified lines | ||
| 76 | 76 | -moz-border-radius: 2em ; |
| 77 | 77 | background-image: url('images/search.png') ; |
| 78 | 78 | background-repeat: no-repeat; |
| 79 | − background-position: left center ; | |
| 80 | 79 | background-position: 4px center ; |
| 81 | 80 | padding-left: 20px ; |
| 82 | 81 | height: 2em ; |
| @@ -0,0 +1,118 @@ | ||
| 1 | +.\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $ | |
| 2 | +.TH LUAC 1 "$Date: 2011/11/16 13:53:40 $" | |
| 3 | +.SH NAME | |
| 4 | +luac \- Lua compiler | |
| 5 | +.SH SYNOPSIS | |
| 6 | +.B luac | |
| 7 | +[ | |
| 8 | +.I options | |
| 9 | +] [ | |
| 10 | +.I filenames | |
| 11 | +] | |
| 12 | +.SH DESCRIPTION | |
| 13 | +.B luac | |
| 14 | +is the Lua compiler. | |
| 15 | +It translates programs written in the Lua programming language | |
| 16 | +into binary files containing precompiled chunks | |
| 17 | +that can be later loaded and executed. | |
| 18 | +.LP | |
| 19 | +The main advantages of precompiling chunks are: | |
| 20 | +faster loading, | |
| 21 | +protecting source code from accidental user changes, | |
| 22 | +and | |
| 23 | +off-line syntax checking. | |
| 24 | +Precompiling does not imply faster execution | |
| 25 | +because in Lua chunks are always compiled into bytecodes before being executed. | |
| 26 | +.B luac | |
| 27 | +simply allows those bytecodes to be saved in a file for later execution. | |
| 28 | +Precompiled chunks are not necessarily smaller than the corresponding source. | |
| 29 | +The main goal in precompiling is faster loading. | |
| 30 | +.LP | |
| 31 | +In the command line, | |
| 32 | +you can mix | |
| 33 | +text files containing Lua source and | |
| 34 | +binary files containing precompiled chunks. | |
| 35 | +.B luac | |
| 36 | +produces a single output file containing the combined bytecodes | |
| 37 | +for all files given. | |
| 38 | +Executing the combined file is equivalent to executing the given files. | |
| 39 | +By default, | |
| 40 | +the output file is named | |
| 41 | +.BR luac.out , | |
| 42 | +but you can change this with the | |
| 43 | +.B \-o | |
| 44 | +option. | |
| 45 | +.LP | |
| 46 | +Precompiled chunks are | |
| 47 | +.I not | |
| 48 | +portable across different architectures. | |
| 49 | +Moreover, | |
| 50 | +the internal format of precompiled chunks | |
| 51 | +is likely to change when a new version of Lua is released. | |
| 52 | +Make sure you save the source files of all Lua programs that you precompile. | |
| 53 | +.LP | |
| 54 | +.SH OPTIONS | |
| 55 | +.TP | |
| 56 | +.B \-l | |
| 57 | +produce a listing of the compiled bytecode for Lua's virtual machine. | |
| 58 | +Listing bytecodes is useful to learn about Lua's virtual machine. | |
| 59 | +If no files are given, then | |
| 60 | +.B luac | |
| 61 | +loads | |
| 62 | +.B luac.out | |
| 63 | +and lists its contents. | |
| 64 | +Use | |
| 65 | +.B \-l \-l | |
| 66 | +for a full listing. | |
| 67 | +.TP | |
| 68 | +.BI \-o " file" | |
| 69 | +output to | |
| 70 | +.IR file , | |
| 71 | +instead of the default | |
| 72 | +.BR luac.out . | |
| 73 | +(You can use | |
| 74 | +.B "'\-'" | |
| 75 | +for standard output, | |
| 76 | +but not on platforms that open standard output in text mode.) | |
| 77 | +The output file may be one of the given files because | |
| 78 | +all files are loaded before the output file is written. | |
| 79 | +Be careful not to overwrite precious files. | |
| 80 | +.TP | |
| 81 | +.B \-p | |
| 82 | +load files but do not generate any output file. | |
| 83 | +Used mainly for syntax checking and for testing precompiled chunks: | |
| 84 | +corrupted files will probably generate errors when loaded. | |
| 85 | +If no files are given, then | |
| 86 | +.B luac | |
| 87 | +loads | |
| 88 | +.B luac.out | |
| 89 | +and tests its contents. | |
| 90 | +No messages are displayed if the file loads without errors. | |
| 91 | +.TP | |
| 92 | +.B \-s | |
| 93 | +strip debug information before writing the output file. | |
| 94 | +This saves some space in very large chunks, | |
| 95 | +but if errors occur when running a stripped chunk, | |
| 96 | +then the error messages may not contain the full information they usually do. | |
| 97 | +In particular, | |
| 98 | +line numbers and names of local variables are lost. | |
| 99 | +.TP | |
| 100 | +.B \-v | |
| 101 | +show version information. | |
| 102 | +.TP | |
| 103 | +.B \-\- | |
| 104 | +stop handling options. | |
| 105 | +.TP | |
| 106 | +.B \- | |
| 107 | +stop handling options and process standard input. | |
| 108 | +.SH "SEE ALSO" | |
| 109 | +.BR lua (1) | |
| 110 | +.br | |
| 111 | +The documentation at lua.org. | |
| 112 | +.SH DIAGNOSTICS | |
| 113 | +Error messages should be self explanatory. | |
| 114 | +.SH AUTHORS | |
| 115 | +R. Ierusalimschy, | |
| 116 | +L. H. de Figueiredo, | |
| 117 | +W. Celes | |
| 118 | +.\" EOF | |
| @@ -2,13 +2,16 @@ h3 code { · 1 unmodified line | ||
| 2 | 2 | font-family: inherit ; |
| 3 | 3 | } |
| 4 | 4 | |
| 5 | −pre { | |
| 6 | − font-size: 105% ; | |
| 5 | +pre, code { | |
| 6 | + font-size: 12pt ; | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | span.apii { |
| 10 | 10 | float: right ; |
| 11 | 11 | font-family: inherit ; |
| 12 | + font-style: normal ; | |
| 13 | + font-size: small ; | |
| 14 | + color: gray ; | |
| 12 | 15 | } |
| 13 | 16 | |
| 14 | 17 | p+h1, ul+h1 { |
| @@ -16,11 +16,6 @@ · 15 unmodified lines | ||
| 16 | 16 | Lua 5.2 Reference Manual |
| 17 | 17 | </h1> |
| 18 | 18 | |
| 19 | −<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> | |
| 20 | −<EM>This is a beta version of Lua 5.2. | |
| 21 | −Some details may change in the final version.</EM> | |
| 22 | −<P> | |
| 23 | − | |
| 24 | 19 | by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes |
| 25 | 20 | <p> |
| 26 | 21 | <small> |
| @@ -38,7 +33,7 @@ Freely available under the terms of the · 11 unmodified lines | ||
| 38 | 33 | <!-- ====================================================================== --> |
| 39 | 34 | <p> |
| 40 | 35 | |
| 41 | −<!-- $Id: manual.of,v 1.86 2011/07/08 20:00:45 roberto Exp $ --> | |
| 36 | +<!-- $Id: manual.of,v 1.88 2011/11/24 13:23:53 roberto Exp $ --> | |
| 42 | 37 | |
| 43 | 38 | |
| 44 | 39 | |
| @@ -51,8 +46,8 @@ general procedural programming with data description · 6 unmodified lines | ||
| 51 | 46 | facilities. |
| 52 | 47 | It also offers good support for object-oriented programming, |
| 53 | 48 | functional programming, and data-driven programming. |
| 54 | −Lua is intended to be used as a powerful, light-weight | |
| 55 | −scripting language for any program that needs one. | |
| 49 | +Lua is intended to be used as a powerful, lightweight, | |
| 50 | +embeddable scripting language for any program that needs one. | |
| 56 | 51 | Lua is implemented as a library, written in <em>clean C</em>, |
| 57 | 52 | the common subset of Standard C and C++. |
| 58 | 53 | |
| @@ -86,14 +81,14 @@ this document is dry in places. · 27 unmodified lines | ||
| 86 | 81 | For a discussion of the decisions behind the design of Lua, |
| 87 | 82 | see the technical papers available at Lua's web site. |
| 88 | 83 | For a detailed introduction to programming in Lua, |
| 89 | −see Roberto's book, <em>Programming in Lua</em> (second edition). | |
| 84 | +see Roberto's book, <em>Programming in Lua</em>. | |
| 90 | 85 | |
| 91 | 86 | |
| 92 | 87 | |
| 93 | 88 | <h1>2 – <a name="2">Basic Concepts</a></h1> |
| 94 | 89 | |
| 95 | 90 | <p> |
| 96 | −This section describes some basic concepts of the language. | |
| 91 | +This section describes the basic concepts of the language. | |
| 97 | 92 | |
| 98 | 93 | |
| 99 | 94 | |
| @@ -148,11 +143,14 @@ functions written in C · 48 unmodified lines | ||
| 148 | 143 | <p> |
| 149 | 144 | The type <em>userdata</em> is provided to allow arbitrary C data to |
| 150 | 145 | be stored in Lua variables. |
| 151 | −This type corresponds to a block of raw memory | |
| 152 | −and has no pre-defined operations in Lua, | |
| 146 | +A userdata value is a pointer to a block of raw memory. | |
| 147 | +There are two kinds of userdata: | |
| 148 | +full userdata, where the block of memory is managed by Lua, | |
| 149 | +and light userdata, where the block of memory is managed by the host. | |
| 150 | +Userdata has no predefined operations in Lua, | |
| 153 | 151 | except assignment and identity test. |
| 154 | −However, by using <em>metatables</em>, | |
| 155 | −the programmer can define operations for userdata values | |
| 152 | +By using <em>metatables</em>, | |
| 153 | +the programmer can define operations for full userdata values | |
| 156 | 154 | (see <a href="#2.4">§2.4</a>). |
| 157 | 155 | Userdata values cannot be created or modified in Lua, |
| 158 | 156 | only through the C API. |
| @@ -200,7 +198,7 @@ which is called the length of the sequence (see <a href="#3.4.6">§3.4.6</a> · 41 unmodified lines | ||
| 200 | 198 | |
| 201 | 199 | <p> |
| 202 | 200 | Like indices, |
| 203 | −the value of a table field can be of any type. | |
| 201 | +the values of table fields can be of any type. | |
| 204 | 202 | In particular, |
| 205 | 203 | because functions are first-class values, |
| 206 | 204 | table fields can contain functions. |
| @@ -227,7 +225,7 @@ these operations do not imply any kind of copy. · 20 unmodified lines | ||
| 227 | 225 | |
| 228 | 226 | <p> |
| 229 | 227 | The library function <a href="#pdf-type"><code>type</code></a> returns a string describing the type |
| 230 | −of a given value. | |
| 228 | +of a given value (see <a href="#6.1">§6.1</a>). | |
| 231 | 229 | |
| 232 | 230 | |
| 233 | 231 | |
| @@ -239,8 +237,8 @@ of a given value. · 5 unmodified lines | ||
| 239 | 237 | As will be discussed in <a href="#3.2">§3.2</a> and <a href="#3.3.3">§3.3.3</a>, |
| 240 | 238 | any reference to a global name <code>var</code> is syntactically translated |
| 241 | 239 | to <code>_ENV.var</code>. |
| 242 | −Moreover, every chunk is compiled in the scope of an external | |
| 243 | −variable called <code>_ENV</code> (see <a href="#3.3.2">§3.3.2</a>), | |
| 240 | +Moreover, every chunk is compiled in the scope of | |
| 241 | +an external local variable called <code>_ENV</code> (see <a href="#3.3.2">§3.3.2</a>), | |
| 244 | 242 | so <code>_ENV</code> itself is never a global name in a chunk. |
| 245 | 243 | |
| 246 | 244 | |
| @@ -252,12 +250,11 @@ In particular, · 5 unmodified lines | ||
| 252 | 250 | you can define new variables and parameters with that name. |
| 253 | 251 | Each reference to a global name uses the <code>_ENV</code> that is |
| 254 | 252 | visible at that point in the program, |
| 255 | −following the usual visibility rules of Lua. | |
| 253 | +following the usual visibility rules of Lua (see <a href="#3.5">§3.5</a>). | |
| 256 | 254 | |
| 257 | 255 | |
| 258 | 256 | <p> |
| 259 | −Any table used as the value of <code>_ENV</code> is usually called | |
| 260 | −an <em>environment</em>. | |
| 257 | +Any table used as the value of <code>_ENV</code> is called an <em>environment</em>. | |
| 261 | 258 | |
| 262 | 259 | |
| 263 | 260 | <p> |
| @@ -268,13 +265,14 @@ In Lua, the variable <a href="#pdf-_G"><code>_G</code></a> is initialized with t · 4 unmodified lines | ||
| 268 | 265 | |
| 269 | 266 | <p> |
| 270 | 267 | When Lua compiles a chunk, |
| 271 | −it initializes the value of its <code>_ENV</code> variable | |
| 268 | +it initializes the value of its <code>_ENV</code> upvalue | |
| 272 | 269 | with the global environment (see <a href="#pdf-load"><code>load</code></a>). |
| 273 | 270 | Therefore, by default, |
| 274 | 271 | global variables in Lua code refer to entries in the global environment. |
| 275 | −Moreover, all standard libraries are loaded in the global environment, | |
| 272 | +Moreover, all standard libraries are loaded in the global environment | |
| 276 | 273 | and several functions there operate on that environment. |
| 277 | −You can use <a href="#pdf-load"><code>load</code></a> to load a chunk with a different environment. | |
| 274 | +You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>loadfile</code></a>) | |
| 275 | +to load a chunk with a different environment. | |
| 278 | 276 | (In C, you have to load the chunk and then change the value |
| 279 | 277 | of its first upvalue.) |
| 280 | 278 | |
| @@ -325,7 +323,7 @@ any value for the error object. · 44 unmodified lines | ||
| 325 | 323 | |
| 326 | 324 | <p> |
| 327 | 325 | When you use <a href="#pdf-xpcall"><code>xpcall</code></a> or <a href="#lua_pcall"><code>lua_pcall</code></a>, |
| 328 | −you may give an <em>message handler</em> | |
| 326 | +you may give a <em>message handler</em> | |
| 329 | 327 | to be called in case of errors. |
| 330 | 328 | This function is called with the original error message |
| 331 | 329 | and returns a new error message. |
| @@ -389,8 +387,8 @@ but the string library sets a metatable for the string type (see <a href="#6.4"> · 57 unmodified lines | ||
| 389 | 387 | <p> |
| 390 | 388 | A metatable controls how an object behaves in arithmetic operations, |
| 391 | 389 | order comparisons, concatenation, length operation, and indexing. |
| 392 | −A metatable also can define a function to be called when a userdata | |
| 393 | −is garbage collected. | |
| 390 | +A metatable also can define a function to be called | |
| 391 | +when a userdata or a table is garbage collected. | |
| 394 | 392 | When Lua performs one of these operations over a value, |
| 395 | 393 | it checks whether this value has a metatable with the corresponding event. |
| 396 | 394 | If so, the value associated with that key (the metamethod) |
| @@ -427,8 +425,8 @@ This should be read as · 30 unmodified lines | ||
| 427 | 425 | rawget(getmetatable(obj) or {}, event) |
| 428 | 426 | </pre><p> |
| 429 | 427 | |
| 430 | −That is, the access to a metamethod does not invoke other metamethods, | |
| 431 | −and the access to objects with no metatables does not fail | |
| 428 | +This means that the access to a metamethod does not invoke other metamethods, | |
| 429 | +and access to objects with no metatables does not fail | |
| 432 | 430 | (it simply results in <b>nil</b>). |
| 433 | 431 | |
| 434 | 432 | |
| @@ -590,13 +588,17 @@ The function <code>getequalhandler</code> defines how Lua chooses a metamethod · 155 unmodified lines | ||
| 590 | 588 | for equality. |
| 591 | 589 | A metamethod is selected only when both values |
| 592 | 590 | being compared have the same type |
| 593 | −and the same metamethod for the selected operation. | |
| 591 | +and the same metamethod for the selected operation, | |
| 592 | +and the values are either tables or full userdata. | |
| 594 | 593 | |
| 595 | 594 | <pre> |
| 596 | − function getequalhandler (op1, op2, event) | |
| 597 | − if type(op1) ~= type(op2) then return nil end | |
| 598 | − local mm1 = metatable(op1)[event] | |
| 599 | − local mm2 = metatable(op2)[event] | |
| 595 | + function getequalhandler (op1, op2) | |
| 596 | + if type(op1) ~= type(op2) or | |
| 597 | + (type(op1) ~= "table" and type(op1) ~= "userdata") then | |
| 598 | + return nil -- different values | |
| 599 | + end | |
| 600 | + local mm1 = metatable(op1).__eq | |
| 601 | + local mm2 = metatable(op2).__eq | |
| 600 | 602 | if mm1 == mm2 then return mm1 else return nil end |
| 601 | 603 | end |
| 602 | 604 | </pre><p> |
| @@ -604,21 +606,19 @@ The "eq" event is defined as follows: · 1 unmodified line | ||
| 604 | 606 | |
| 605 | 607 | <pre> |
| 606 | 608 | function eq_event (op1, op2) |
| 607 | − if type(op1) ~= type(op2) then -- different types? | |
| 608 | − return false -- different values | |
| 609 | − end | |
| 610 | 609 | if op1 == op2 then -- primitive equal? |
| 611 | 610 | return true -- values are equal |
| 612 | 611 | end |
| 613 | 612 | -- try metamethod |
| 614 | − local h = getequalhandler(op1, op2, "__eq") | |
| 613 | + local h = getequalhandler(op1, op2) | |
| 615 | 614 | if h then |
| 616 | − return (h(op1, op2)) | |
| 615 | + return not not h(op1, op2) | |
| 617 | 616 | else |
| 618 | 617 | return false |
| 619 | 618 | end |
| 620 | 619 | end |
| 621 | 620 | </pre><p> |
| 621 | +Note that the result is always a boolean. | |
| 622 | 622 | </li> |
| 623 | 623 | |
| 624 | 624 | <li><b>"lt": </b> |
| @@ -634,13 +634,14 @@ the <code><</code> operation. · 9 unmodified lines | ||
| 634 | 634 | else |
| 635 | 635 | local h = getbinhandler(op1, op2, "__lt") |
| 636 | 636 | if h then |
| 637 | − return (h(op1, op2)) | |
| 637 | + return not not h(op1, op2) | |
| 638 | 638 | else |
| 639 | 639 | error(···) |
| 640 | 640 | end |
| 641 | 641 | end |
| 642 | 642 | end |
| 643 | 643 | </pre><p> |
| 644 | +Note that the result is always a boolean. | |
| 644 | 645 | </li> |
| 645 | 646 | |
| 646 | 647 | <li><b>"le": </b> |
| @@ -656,7 +657,7 @@ the <code><=</code> operation. · 9 unmodified lines | ||
| 656 | 657 | else |
| 657 | 658 | local h = getbinhandler(op1, op2, "__le") |
| 658 | 659 | if h then |
| 659 | − return (h(op1, op2)) | |
| 660 | + return not not h(op1, op2) | |
| 660 | 661 | else |
| 661 | 662 | h = getbinhandler(op1, op2, "__lt") |
| 662 | 663 | if h then |
| @@ -671,6 +672,11 @@ the <code><=</code> operation. · 8 unmodified lines | ||
| 671 | 672 | Note that, in the absence of a "le" metamethod, |
| 672 | 673 | Lua tries the "lt", assuming that <code>a <= b</code> is |
| 673 | 674 | equivalent to <code>not (b < a)</code>. |
| 675 | + | |
| 676 | + | |
| 677 | +<p> | |
| 678 | +As with the other comparison operators, | |
| 679 | +the result is always a boolean. | |
| 674 | 680 | </li> |
| 675 | 681 | |
| 676 | 682 | <li><b>"index": </b> |
| @@ -770,7 +776,7 @@ Lua manages memory automatically by running · 93 unmodified lines | ||
| 770 | 776 | a <em>garbage collector</em> to collect all <em>dead objects</em> |
| 771 | 777 | (that is, objects that are no longer accessible from Lua). |
| 772 | 778 | All memory used by Lua is subject to automatic management: |
| 773 | −tables, userdata, functions, threads, strings, etc. | |
| 779 | +strings, tables, userdata, functions, threads, internal structures, etc. | |
| 774 | 780 | |
| 775 | 781 | |
| 776 | 782 | <p> |
| @@ -819,10 +825,25 @@ memory usage. · 42 unmodified lines | ||
| 819 | 825 | <p> |
| 820 | 826 | You can change these numbers by calling <a href="#lua_gc"><code>lua_gc</code></a> in C |
| 821 | 827 | or <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> in Lua. |
| 822 | −With these functions you can also control | |
| 828 | +You can also use these functions to control | |
| 823 | 829 | the collector directly (e.g., stop and restart it). |
| 824 | 830 | |
| 825 | 831 | |
| 832 | +<p> | |
| 833 | +As an experimental feature in Lua 5.2, | |
| 834 | +you can change the collector's operation mode | |
| 835 | +from incremental to <em>generational</em>. | |
| 836 | +A <em>generational collector</em> assumes that most objects die young, | |
| 837 | +and therefore it traverses only young (recently created) objects. | |
| 838 | +This behavior can reduce the time used by the collector, | |
| 839 | +but also increases memory usage (as old dead objects may accumulate). | |
| 840 | +To mitigate this second problem, | |
| 841 | +from time to time the generational collector performs a full collection. | |
| 842 | +Remember that this is an experimental feature; | |
| 843 | +you are welcome to try it, | |
| 844 | +but check your gains. | |
| 845 | + | |
| 846 | + | |
| 826 | 847 | |
| 827 | 848 | <h3>2.5.1 – <a name="2.5.1">Garbage-Collection Metamethods</a></h3> |
| 828 | 849 | |
| @@ -879,11 +900,17 @@ the execution of the regular code. · 50 unmodified lines | ||
| 879 | 900 | |
| 880 | 901 | |
| 881 | 902 | <p> |
| 882 | −Because the object being collected must still be used by the finalizer | |
| 883 | −and even <em>resurrected</em> | |
| 884 | −(e.g., stored by the finalizer in a global variable), | |
| 885 | −the object memory is freed only when it becomes completely inaccessible | |
| 886 | −(that is, in the next garbage-collection cycle unless it was resurrected). | |
| 903 | +Because the object being collected must still be used by the finalizer, | |
| 904 | +it (and other objects accessible only through it) | |
| 905 | +must be <em>resurrected</em> by Lua. | |
| 906 | +Usually, this resurrection is transient, | |
| 907 | +and the object memory is freed in the next garbage-collection cycle. | |
| 908 | +However, if the finalizer stores the object in some global place | |
| 909 | +(e.g., a global variable), | |
| 910 | +then there is a permanent resurrection. | |
| 911 | +In any case, | |
| 912 | +the object memory is freed only when it becomes completely inaccessible; | |
| 913 | +its finalizer will never be called twice. | |
| 887 | 914 | |
| 888 | 915 | |
| 889 | 916 | |
| @@ -927,32 +954,42 @@ the pair is removed. · 37 unmodified lines | ||
| 927 | 954 | |
| 928 | 955 | |
| 929 | 956 | <p> |
| 930 | −After you use a table as a metatable, | |
| 931 | −you should not change the value of its <code>__mode</code> field. | |
| 932 | −Otherwise, the weak behavior of the tables controlled by this | |
| 933 | −metatable is undefined. | |
| 957 | +Any change in the weakness of a table may take effect only | |
| 958 | +at the next collect cycle. | |
| 959 | +In particular, if you change the weakness to a stronger mode, | |
| 960 | +Lua may still collect some items from that table | |
| 961 | +before the change takes effect. | |
| 934 | 962 | |
| 935 | 963 | |
| 936 | 964 | <p> |
| 937 | 965 | Only objects that have an explicit construction |
| 938 | −can be removed from weak tables. | |
| 939 | −Values, such as numbers and booleans, | |
| 966 | +are removed from weak tables. | |
| 967 | +Values, such as numbers and light C functions, | |
| 940 | 968 | are not subject to garbage collection, |
| 941 | 969 | and therefore are not removed from weak tables |
| 942 | 970 | (unless its associated value is collected). |
| 943 | −Lua treats strings and light C functions as non-object values. | |
| 971 | +Although strings are subject to garbage collection, | |
| 972 | +they do not have an explicit construction, | |
| 973 | +and therefore are not removed from weak tables. | |
| 944 | 974 | |
| 945 | 975 | |
| 946 | 976 | <p> |
| 947 | −Objects marked for finalization have a special behavior in weak tables. | |
| 948 | −When a marked object is a value in a weak table, | |
| 949 | −it is removed from the table before running its finalizer. | |
| 950 | −However, when it is a key, | |
| 951 | −it is removed from the table only after running its finalizer. | |
| 977 | +Resurrected objects | |
| 978 | +(that is, objects being finalized | |
| 979 | +and objects accessible only through objects being finalized) | |
| 980 | +have a special behavior in weak tables. | |
| 981 | +They are removed from weak values before running their finalizers, | |
| 982 | +but are removed from weak keys only in the next collection | |
| 983 | +after running their finalizers, when such objects are actually freed. | |
| 952 | 984 | This behavior allows the finalizer to access properties |
| 953 | 985 | associated with the object through weak tables. |
| 954 | 986 | |
| 955 | 987 | |
| 988 | +<p> | |
| 989 | +If a weak table is among the resurrected objects in a collection cycle, | |
| 990 | +it may not be properly cleared until the next cycle. | |
| 991 | + | |
| 992 | + | |
| 956 | 993 | |
| 957 | 994 | |
| 958 | 995 | |
| @@ -1060,7 +1097,6 @@ When you run it, it produces the following output: · 101 unmodified lines | ||
| 1060 | 1097 | <pre> |
| 1061 | 1098 | co-body 1 10 |
| 1062 | 1099 | foo 2 |
| 1063 | − | |
| 1064 | 1100 | main true 4 |
| 1065 | 1101 | co-body r |
| 1066 | 1102 | main true 11 -9 |
| @@ -1090,7 +1126,7 @@ and what their combinations mean. · 23 unmodified lines | ||
| 1090 | 1126 | |
| 1091 | 1127 | |
| 1092 | 1128 | <p> |
| 1093 | −The language constructs will be explained using the usual extended BNF notation, | |
| 1129 | +Language constructs will be explained using the usual extended BNF notation, | |
| 1094 | 1130 | in which |
| 1095 | 1131 | {<em>a</em>} means 0 or more <em>a</em>'s, and |
| 1096 | 1132 | [<em>a</em>] means an optional <em>a</em>. |
| @@ -1176,7 +1212,7 @@ into the string contents. · 79 unmodified lines | ||
| 1176 | 1212 | |
| 1177 | 1213 | |
| 1178 | 1214 | <p> |
| 1179 | −A character in a literal string can also be specified by its numerical value. | |
| 1215 | +A byte in a literal string can also be specified by its numerical value. | |
| 1180 | 1216 | This can be done with the escape sequence <code>\x<em>XX</em></code>, |
| 1181 | 1217 | where <em>XX</em> is a sequence of exactly two hexadecimal digits, |
| 1182 | 1218 | or with the escape sequence <code>\<em>ddd</em></code>, |
| @@ -1407,13 +1443,13 @@ even if it does not use that variable. · 224 unmodified lines | ||
| 1407 | 1443 | <p> |
| 1408 | 1444 | A chunk can be stored in a file or in a string inside the host program. |
| 1409 | 1445 | To execute a chunk, |
| 1410 | −Lua first pre-compiles the chunk into instructions for a virtual machine, | |
| 1446 | +Lua first precompiles the chunk into instructions for a virtual machine, | |
| 1411 | 1447 | and then it executes the compiled code |
| 1412 | 1448 | with an interpreter for the virtual machine. |
| 1413 | 1449 | |
| 1414 | 1450 | |
| 1415 | 1451 | <p> |
| 1416 | −Chunks can also be pre-compiled into binary form; | |
| 1452 | +Chunks can also be precompiled into binary form; | |
| 1417 | 1453 | see program <code>luac</code> for details. |
| 1418 | 1454 | Programs in source and compiled forms are interchangeable; |
| 1419 | 1455 | Lua automatically detects the file type and acts accordingly. |
| @@ -1555,7 +1591,7 @@ enter into the scope of a local variable. · 135 unmodified lines | ||
| 1555 | 1591 | |
| 1556 | 1592 | |
| 1557 | 1593 | <p> |
| 1558 | −Both labels and empty statements are called <em>void statements</em>, | |
| 1594 | +Labels and empty statements are called <em>void statements</em>, | |
| 1559 | 1595 | as they perform no actions. |
| 1560 | 1596 | |
| 1561 | 1597 | |
| @@ -1806,14 +1842,13 @@ and the unary <em>length operator</em> (see <a href="#3.4.6">§3.4.6</a>). · 244 unmodified lines | ||
| 1806 | 1842 | |
| 1807 | 1843 | <p> |
| 1808 | 1844 | Both function calls and vararg expressions can result in multiple values. |
| 1809 | −If an expression is used as a statement | |
| 1810 | −(only possible for function calls (see <a href="#3.3.6">§3.3.6</a>)), | |
| 1845 | +If a function call is used as a statement (see <a href="#3.3.6">§3.3.6</a>), | |
| 1811 | 1846 | then its return list is adjusted to zero elements, |
| 1812 | 1847 | thus discarding all returned values. |
| 1813 | 1848 | If an expression is used as the last (or the only) element |
| 1814 | 1849 | of a list of expressions, |
| 1815 | 1850 | then no adjustment is made |
| 1816 | −(unless the call is enclosed in parentheses). | |
| 1851 | +(unless the expression is enclosed in parentheses). | |
| 1817 | 1852 | In all other contexts, |
| 1818 | 1853 | Lua adjusts the result list to one element, |
| 1819 | 1854 | discarding all values except the first one. |
| @@ -1881,8 +1916,7 @@ Lua provides automatic conversion between · 61 unmodified lines | ||
| 1881 | 1916 | string and number values at run time. |
| 1882 | 1917 | Any arithmetic operation applied to a string tries to convert |
| 1883 | 1918 | this string to a number, following the rules of the Lua lexer. |
| 1884 | −(The string may have leading and trailing spaces, | |
| 1885 | −plus an optional sign.) | |
| 1919 | +(The string may have leading and trailing spaces and a sign.) | |
| 1886 | 1920 | Conversely, whenever a number is used where a string is expected, |
| 1887 | 1921 | the number is converted to a string, in a reasonable format. |
| 1888 | 1922 | For complete control over how numbers are converted to strings, |
| @@ -2254,8 +2288,8 @@ contains references to <code>f</code>.) · 365 unmodified lines | ||
| 2254 | 2288 | <p> |
| 2255 | 2289 | A function definition is an executable expression, |
| 2256 | 2290 | whose value has type <em>function</em>. |
| 2257 | −When Lua pre-compiles a chunk, | |
| 2258 | −all its function bodies are pre-compiled too. | |
| 2291 | +When Lua precompiles a chunk, | |
| 2292 | +all its function bodies are precompiled too. | |
| 2259 | 2293 | Then, whenever Lua executes the function definition, |
| 2260 | 2294 | the function is <em>instantiated</em> (or <em>closed</em>). |
| 2261 | 2295 | This function instance (or <em>closure</em>) |
| @@ -2272,9 +2306,9 @@ initialized with the argument values: · 10 unmodified lines | ||
| 2272 | 2306 | When a function is called, |
| 2273 | 2307 | the list of arguments is adjusted to |
| 2274 | 2308 | the length of the list of parameters, |
| 2275 | −unless the function is a variadic or <em>vararg function</em>, | |
| 2276 | −which is | |
| 2277 | −indicated by three dots ('<code>...</code>') at the end of its parameter list. | |
| 2309 | +unless the function is a <em>vararg function</em>, | |
| 2310 | +which is indicated by three dots ('<code>...</code>') | |
| 2311 | +at the end of its parameter list. | |
| 2278 | 2312 | A vararg function does not adjust its argument list; |
| 2279 | 2313 | instead, it collects all extra arguments and supplies them |
| 2280 | 2314 | to the function through a <em>vararg expression</em>, |
| @@ -2425,7 +2459,8 @@ are declared in the header file <a name="pdf-lua.h"><code>lua.h</code></a>. · 144 unmodified lines | ||
| 2425 | 2459 | <p> |
| 2426 | 2460 | Even when we use the term "function", |
| 2427 | 2461 | any facility in the API may be provided as a macro instead. |
| 2428 | −All such macros use each of their arguments exactly once | |
| 2462 | +Except where stated otherwise, | |
| 2463 | +all such macros use each of their arguments exactly once | |
| 2429 | 2464 | (except for the first argument, which is always a Lua state), |
| 2430 | 2465 | and so do not generate any hidden side-effects. |
| 2431 | 2466 | |
| @@ -2434,8 +2469,7 @@ and so do not generate any hidden side-effects. · 2 unmodified lines | ||
| 2434 | 2469 | As in most C libraries, |
| 2435 | 2470 | the Lua API functions do not check their arguments for validity or consistency. |
| 2436 | 2471 | However, you can change this behavior by compiling Lua |
| 2437 | −with a proper definition for the macro <a name="pdf-luai_apicheck"><code>luai_apicheck</code></a>, | |
| 2438 | −in file <code>luaconf.h</code>. | |
| 2472 | +with the macro <a name="pdf-LUA_USE_APICHECK"><code>LUA_USE_APICHECK</code></a> defined. | |
| 2439 | 2473 | |
| 2440 | 2474 | |
| 2441 | 2475 | |
| @@ -2472,10 +2506,6 @@ index <em>n</em> represents the last element; · 30 unmodified lines | ||
| 2472 | 2506 | index -1 also represents the last element |
| 2473 | 2507 | (that is, the element at the top) |
| 2474 | 2508 | and index <em>-n</em> represents the first element. |
| 2475 | −We say that an index is <em>valid</em> | |
| 2476 | −if it lies between 1 and the stack top | |
| 2477 | −(that is, if <code>1 ≤ abs(index) ≤ top</code>). | |
| 2478 | − | |
| 2479 | 2509 | |
| 2480 | 2510 | |
| 2481 | 2511 | |
| @@ -2494,7 +2524,7 @@ to ensure that the stack has extra slots when pushing new elements. · 12 unmodified lines | ||
| 2494 | 2524 | |
| 2495 | 2525 | <p> |
| 2496 | 2526 | Whenever Lua calls C, |
| 2497 | −it ensures that at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> stack positions are available. | |
| 2527 | +it ensures that the stack has at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> extra slots. | |
| 2498 | 2528 | <code>LUA_MINSTACK</code> is defined as 20, |
| 2499 | 2529 | so that usually you do not have to worry about stack space |
| 2500 | 2530 | unless your code has loops pushing elements onto the stack. |
| @@ -2509,33 +2539,66 @@ So, before pushing anything in the stack after such a call · 8 unmodified lines | ||
| 2509 | 2539 | you should use <a href="#lua_checkstack"><code>lua_checkstack</code></a>. |
| 2510 | 2540 | |
| 2511 | 2541 | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | +<h2>4.3 – <a name="4.3">Valid and Acceptable Indices</a></h2> | |
| 2546 | + | |
| 2512 | 2547 | <p> |
| 2513 | −Most query functions accept as indices any value inside the | |
| 2514 | −available stack space, that is, indices up to the maximum stack size | |
| 2515 | −that you have set through <a href="#lua_checkstack"><code>lua_checkstack</code></a>. | |
| 2516 | −Such indices are called <em>acceptable indices</em>. | |
| 2517 | −More formally, we define an <em>acceptable index</em> | |
| 2548 | +Any function in the API that receives stack indices | |
| 2549 | +works only with <em>valid indices</em> or <em>acceptable indices</em>. | |
| 2550 | + | |
| 2551 | + | |
| 2552 | +<p> | |
| 2553 | +A <em>valid index</em> is an index that refers to a | |
| 2554 | +valid position within the stack, that is, | |
| 2555 | +it lies between 1 and the stack top | |
| 2556 | +(<code>1 ≤ abs(index) ≤ top</code>). | |
| 2557 | + | |
| 2558 | +Usually, functions that need a specific stack position | |
| 2559 | +(e.g., <a href="#lua_remove"><code>lua_remove</code></a>) require valid indices. | |
| 2560 | + | |
| 2561 | + | |
| 2562 | +<p> | |
| 2563 | +Functions that do not need a specific stack position, | |
| 2564 | +but only a value in the stack (e.g., query functions), | |
| 2565 | +can be called with acceptable indices. | |
| 2566 | +An <em>acceptable index</em> refers to a position within | |
| 2567 | +the space allocated for the stack, | |
| 2568 | +that is, indices up to the stack size. | |
| 2569 | +More formally, we define an acceptable index | |
| 2518 | 2570 | as follows: |
| 2519 | 2571 | |
| 2520 | 2572 | <pre> |
| 2521 | 2573 | (index < 0 && abs(index) <= top) || |
| 2522 | − (index > 0 && index <= stackspace) | |
| 2574 | + (index > 0 && index <= stack size) | |
| 2523 | 2575 | </pre><p> |
| 2524 | −Note that 0 is never an acceptable index. | |
| 2576 | +(Note that 0 is never an acceptable index.) | |
| 2577 | +When a function is called, | |
| 2578 | +its stack size is <code>top + LUA_MINSTACK</code>. | |
| 2579 | +You can change its stack size through function <a href="#lua_checkstack"><code>lua_checkstack</code></a>. | |
| 2525 | 2580 | |
| 2526 | 2581 | |
| 2582 | +<p> | |
| 2583 | +Acceptable indices serve to avoid extra tests | |
| 2584 | +against the stack top when querying the stack. | |
| 2585 | +For instance, a C function can query its third argument | |
| 2586 | +without the need to first check whether there is a third argument, | |
| 2587 | +that is, without the need to check whether 3 is a valid index. | |
| 2527 | 2588 | |
| 2528 | 2589 | |
| 2590 | +<p> | |
| 2591 | +For functions that can be called with acceptable indices, | |
| 2592 | +any non-valid index is treated as if it | |
| 2593 | +contains a value of a virtual type <a name="pdf-LUA_TNONE"><code>LUA_TNONE</code></a>. | |
| 2529 | 2594 | |
| 2530 | −<h2>4.3 – <a name="4.3">Pseudo-Indices</a></h2> | |
| 2531 | 2595 | |
| 2532 | 2596 | <p> |
| 2533 | 2597 | Unless otherwise noted, |
| 2534 | 2598 | any function that accepts valid indices also accepts <em>pseudo-indices</em>, |
| 2535 | 2599 | which represent some Lua values that are accessible to C code |
| 2536 | 2600 | but which are not in the stack. |
| 2537 | −Pseudo-indices are used to access | |
| 2538 | −the registry | |
| 2601 | +Pseudo-indices are used to access the registry | |
| 2539 | 2602 | and the upvalues of a C function (see <a href="#4.4">§4.4</a>). |
| 2540 | 2603 | |
| 2541 | 2604 | |
| @@ -2547,10 +2610,10 @@ and the upvalues of a C function (see <a href="#4.4">§4.4</a>). · 5 unmodified lines | ||
| 2547 | 2610 | <p> |
| 2548 | 2611 | When a C function is created, |
| 2549 | 2612 | it is possible to associate some values with it, |
| 2550 | −thus creating a <em>C closure</em>; | |
| 2613 | +thus creating a <em>C closure</em> | |
| 2614 | +(see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>); | |
| 2551 | 2615 | these values are called <em>upvalues</em> and are |
| 2552 | −accessible to the function whenever it is called | |
| 2553 | −(see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>). | |
| 2616 | +accessible to the function whenever it is called. | |
| 2554 | 2617 | |
| 2555 | 2618 | |
| 2556 | 2619 | <p> |
| @@ -2573,12 +2636,13 @@ produces an acceptable (but invalid) index. · 16 unmodified lines | ||
| 2573 | 2636 | |
| 2574 | 2637 | <p> |
| 2575 | 2638 | Lua provides a <em>registry</em>, |
| 2576 | −a pre-defined table that can be used by any C code to | |
| 2577 | −store whatever Lua value it needs to store. | |
| 2578 | −This table is always located at pseudo-index | |
| 2639 | +a predefined table that can be used by any C code to | |
| 2640 | +store whatever Lua values it needs to store. | |
| 2641 | +The registry table is always located at pseudo-index | |
| 2579 | 2642 | <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>. |
| 2580 | 2643 | Any C library can store data into this table, |
| 2581 | −but it should take care to choose keys different from those used | |
| 2644 | +but it should take care to choose keys | |
| 2645 | +that are different from those used | |
| 2582 | 2646 | by other libraries, to avoid collisions. |
| 2583 | 2647 | Typically, you should use as key a string containing your library name, |
| 2584 | 2648 | or a light userdata with the address of a C object in your code, |
| @@ -2610,7 +2674,6 @@ the main thread of the state. · 25 unmodified lines | ||
| 2610 | 2674 | |
| 2611 | 2675 | <li><b><a name="pdf-LUA_RIDX_GLOBALS"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the registry has |
| 2612 | 2676 | the global environment. |
| 2613 | −This is the C equivalent to the <a href="#pdf-_G"><code>_G</code></a> global variable. | |
| 2614 | 2677 | </li> |
| 2615 | 2678 | </ul> |
| 2616 | 2679 | |
| @@ -2629,8 +2692,8 @@ and runtime errors) · 12 unmodified lines | ||
| 2629 | 2692 | it <em>raises</em> an error; |
| 2630 | 2693 | that is, it does a long jump. |
| 2631 | 2694 | A <em>protected environment</em> uses <code>setjmp</code> |
| 2632 | −to set a recover point; | |
| 2633 | −any error jumps to the most recent active recover point. | |
| 2695 | +to set a recovery point; | |
| 2696 | +any error jumps to the most recent active recovery point. | |
| 2634 | 2697 | |
| 2635 | 2698 | |
| 2636 | 2699 | <p> |
| @@ -2639,7 +2702,8 @@ Lua calls a <em>panic function</em> (see <a href="#lua_atpanic"><code>lua_atpani · 2 unmodified lines | ||
| 2639 | 2702 | and then calls <code>abort</code>, |
| 2640 | 2703 | thus exiting the host application. |
| 2641 | 2704 | Your panic function can avoid this exit by |
| 2642 | −never returning (e.g., doing a long jump). | |
| 2705 | +never returning | |
| 2706 | +(e.g., doing a long jump to your own recovery point outside Lua). | |
| 2643 | 2707 | |
| 2644 | 2708 | |
| 2645 | 2709 | <p> |
| @@ -2677,8 +2741,7 @@ All those functions receive a <em>continuation function</em> · 31 unmodified lines | ||
| 2677 | 2741 | |
| 2678 | 2742 | |
| 2679 | 2743 | <p> |
| 2680 | −To explain continuations, | |
| 2681 | −let us set some terminology. | |
| 2744 | +We need to set some terminology to explain continuations. | |
| 2682 | 2745 | We have a C function called from Lua which we will call |
| 2683 | 2746 | the <em>original function</em>. |
| 2684 | 2747 | This original function then calls one of those three functions in the C API, |
| @@ -2704,7 +2767,7 @@ of the original function. · 19 unmodified lines | ||
| 2704 | 2767 | |
| 2705 | 2768 | |
| 2706 | 2769 | <p> |
| 2707 | −Lua treats the continuation function as if it was the original function. | |
| 2770 | +Lua treats the continuation function as if it were the original function. | |
| 2708 | 2771 | The continuation function receives the same Lua stack |
| 2709 | 2772 | from the original function, |
| 2710 | 2773 | in the same state it would be if the callee function had returned. |
| @@ -2712,7 +2775,7 @@ in the same state it would be if the callee function had returned. · 1 unmodified line | ||
| 2712 | 2775 | after a <a href="#lua_callk"><code>lua_callk</code></a> the function and its arguments are |
| 2713 | 2776 | removed from the stack and replaced by the results from the call.) |
| 2714 | 2777 | It also has the same upvalues. |
| 2715 | −Whatever it returns is handled by Lua as if it was the return | |
| 2778 | +Whatever it returns is handled by Lua as if it were the return | |
| 2716 | 2779 | of the original function. |
| 2717 | 2780 | |
| 2718 | 2781 | |
| @@ -2749,15 +2812,14 @@ by looking only at its arguments · 30 unmodified lines | ||
| 2749 | 2812 | The third field, <code>x</code>, |
| 2750 | 2813 | tells whether the function may throw errors: |
| 2751 | 2814 | '<code>-</code>' means the function never throws any error; |
| 2752 | −'<code>m</code>' means the function may throw an error | |
| 2753 | −only due to not enough memory; | |
| 2815 | +'<code>m</code>' means the function may throw only memory allocation errors; | |
| 2754 | 2816 | '<code>e</code>' means the function may throw other kinds of errors; |
| 2755 | 2817 | '<code>v</code>' means the function may throw an error on purpose. |
| 2756 | 2818 | |
| 2757 | 2819 | |
| 2758 | 2820 | |
| 2759 | 2821 | <hr><h3><a name="lua_absindex"><code>lua_absindex</code></a></h3><p> |
| 2760 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 2822 | +<span class="apii">[-0, +0, –]</span> | |
| 2761 | 2823 | <pre>int lua_absindex (lua_State *L, int idx);</pre> |
| 2762 | 2824 | |
| 2763 | 2825 | <p> |
| @@ -2795,7 +2857,7 @@ that is, the size given when it was allocated or reallocated. · 31 unmodified lines | ||
| 2795 | 2857 | |
| 2796 | 2858 | <p> |
| 2797 | 2859 | When <code>ptr</code> is <code>NULL</code>, |
| 2798 | −<code>osize</code> codes the kind of object that Lua is allocating. | |
| 2860 | +<code>osize</code> encodes the kind of object that Lua is allocating. | |
| 2799 | 2861 | <code>osize</code> is any of |
| 2800 | 2862 | <a href="#pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>, <a href="#pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>, <a href="#pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>, |
| 2801 | 2863 | <a href="#pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>, or <a href="#pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a> when (and only when) |
| @@ -2818,7 +2880,7 @@ and return <code>NULL</code>. · 16 unmodified lines | ||
| 2818 | 2880 | When <code>nsize</code> is not zero, |
| 2819 | 2881 | the allocator should behave like <code>realloc</code>. |
| 2820 | 2882 | The allocator returns <code>NULL</code> |
| 2821 | −if and only if it cannot fill the request. | |
| 2883 | +if and only if it cannot fulfill the request. | |
| 2822 | 2884 | Lua assumes that the allocator never fails when |
| 2823 | 2885 | <code>osize >= nsize</code>. |
| 2824 | 2886 | |
| @@ -2843,8 +2905,8 @@ Note that Standard C ensures · 18 unmodified lines | ||
| 2843 | 2905 | that <code>free(NULL)</code> has no effect and that |
| 2844 | 2906 | <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>. |
| 2845 | 2907 | This code assumes that <code>realloc</code> does not fail when shrinking a block. |
| 2846 | −Standard C does not ensure this behavior, | |
| 2847 | −but it seems a safe assumption. | |
| 2908 | +(Although Standard C does not ensure this behavior, | |
| 2909 | +it seems to be a safe assumption.) | |
| 2848 | 2910 | |
| 2849 | 2911 | |
| 2850 | 2912 | |
| @@ -2883,7 +2945,7 @@ The value of <code>op</code> must be one of the following constants: · 32 unmodified lines | ||
| 2883 | 2945 | |
| 2884 | 2946 | |
| 2885 | 2947 | <hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3><p> |
| 2886 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 2948 | +<span class="apii">[-0, +0, –]</span> | |
| 2887 | 2949 | <pre>lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);</pre> |
| 2888 | 2950 | |
| 2889 | 2951 | <p> |
| @@ -2901,7 +2963,7 @@ In particular, the error message is at the top of the stack. · 11 unmodified lines | ||
| 2901 | 2963 | |
| 2902 | 2964 | |
| 2903 | 2965 | <hr><h3><a name="lua_call"><code>lua_call</code></a></h3><p> |
| 2904 | −<span class="apii">[-(nargs + 1), +nresults, <em>e</em>]</span> | |
| 2966 | +<span class="apii">[-(nargs+1), +nresults, <em>e</em>]</span> | |
| 2905 | 2967 | <pre>void lua_call (lua_State *L, int nargs, int nresults);</pre> |
| 2906 | 2968 | |
| 2907 | 2969 | <p> |
| @@ -3025,12 +3087,12 @@ of numerical arguments and returns their average and sum: · 117 unmodified lines | ||
| 3025 | 3087 | |
| 3026 | 3088 | |
| 3027 | 3089 | <hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3><p> |
| 3028 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3090 | +<span class="apii">[-0, +0, –]</span> | |
| 3029 | 3091 | <pre>int lua_checkstack (lua_State *L, int extra);</pre> |
| 3030 | 3092 | |
| 3031 | 3093 | <p> |
| 3032 | 3094 | Ensures that there are at least <code>extra</code> free stack slots in the stack. |
| 3033 | −It returns false if it cannot grant the request, | |
| 3095 | +It returns false if it cannot fulfill the request, | |
| 3034 | 3096 | because it would cause the stack to be larger than a fixed maximum size |
| 3035 | 3097 | (typically at least a few thousand elements) or |
| 3036 | 3098 | because it cannot allocate memory for the new stack size. |
| @@ -3043,7 +3105,7 @@ it is left unchanged. · 6 unmodified lines | ||
| 3043 | 3105 | |
| 3044 | 3106 | |
| 3045 | 3107 | <hr><h3><a name="lua_close"><code>lua_close</code></a></h3><p> |
| 3046 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3108 | +<span class="apii">[-0, +0, –]</span> | |
| 3047 | 3109 | <pre>void lua_close (lua_State *L);</pre> |
| 3048 | 3110 | |
| 3049 | 3111 | <p> |
| @@ -3052,10 +3114,9 @@ Destroys all objects in the given Lua state · 2 unmodified lines | ||
| 3052 | 3114 | and frees all dynamic memory used by this state. |
| 3053 | 3115 | On several platforms, you may not need to call this function, |
| 3054 | 3116 | because all resources are naturally released when the host program ends. |
| 3055 | −On the other hand, long-running programs, | |
| 3056 | −such as a daemon or a web server, | |
| 3057 | −might need to release states as soon as they are not needed, | |
| 3058 | −to avoid growing too large. | |
| 3117 | +On the other hand, long-running programs that create multiple states, | |
| 3118 | +such as daemons or web servers, | |
| 3119 | +might need to close states as soon as they are not needed. | |
| 3059 | 3120 | |
| 3060 | 3121 | |
| 3061 | 3122 | |
| @@ -3066,6 +3127,7 @@ to avoid growing too large. · 4 unmodified lines | ||
| 3066 | 3127 | <pre>int lua_compare (lua_State *L, int index1, int index2, int op);</pre> |
| 3067 | 3128 | |
| 3068 | 3129 | <p> |
| 3130 | +Compares two Lua values. | |
| 3069 | 3131 | Returns 1 if the value at acceptable index <code>index1</code> satisfies <code>op</code> |
| 3070 | 3132 | when compared with the value at acceptable index <code>index2</code>, |
| 3071 | 3133 | following the semantics of the corresponding Lua operator |
| @@ -3106,7 +3168,7 @@ Concatenation is performed following the usual semantics of Lua · 34 unmodified lines | ||
| 3106 | 3168 | |
| 3107 | 3169 | |
| 3108 | 3170 | <hr><h3><a name="lua_copy"><code>lua_copy</code></a></h3><p> |
| 3109 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3171 | +<span class="apii">[-0, +0, –]</span> | |
| 3110 | 3172 | <pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre> |
| 3111 | 3173 | |
| 3112 | 3174 | <p> |
| @@ -3176,7 +3238,7 @@ Generates a Lua error. · 63 unmodified lines | ||
| 3176 | 3238 | The error message (which can actually be a Lua value of any type) |
| 3177 | 3239 | must be on the stack top. |
| 3178 | 3240 | This function does a long jump, |
| 3179 | −and therefore never returns. | |
| 3241 | +and therefore never returns | |
| 3180 | 3242 | (see <a href="#luaL_error"><code>luaL_error</code></a>). |
| 3181 | 3243 | |
| 3182 | 3244 | |
| @@ -3245,10 +3307,20 @@ returns a boolean that tells whether the collector is running · 62 unmodified lines | ||
| 3245 | 3307 | (i.e., not stopped). |
| 3246 | 3308 | </li> |
| 3247 | 3309 | |
| 3310 | +<li><b><code>LUA_GCGEN</code>: </b> | |
| 3311 | +changes the collector to generational mode | |
| 3312 | +(see <a href="#2.5">§2.5</a>). | |
| 3313 | +</li> | |
| 3314 | + | |
| 3315 | +<li><b><code>LUA_GCINC</code>: </b> | |
| 3316 | +changes the collector to incremental mode. | |
| 3317 | +This is the default mode. | |
| 3318 | +</li> | |
| 3319 | + | |
| 3248 | 3320 | </ul> |
| 3249 | 3321 | |
| 3250 | 3322 | <p> |
| 3251 | −For more details about some options, | |
| 3323 | +For more details about these options, | |
| 3252 | 3324 | see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>. |
| 3253 | 3325 | |
| 3254 | 3326 | |
| @@ -3256,7 +3328,7 @@ see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>. · 1 unmodified line | ||
| 3256 | 3328 | |
| 3257 | 3329 | |
| 3258 | 3330 | <hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3><p> |
| 3259 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3331 | +<span class="apii">[-0, +0, –]</span> | |
| 3260 | 3332 | <pre>lua_Alloc lua_getallocf (lua_State *L, void **ud);</pre> |
| 3261 | 3333 | |
| 3262 | 3334 | <p> |
| @@ -3269,7 +3341,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. · 6 unmodified lines | ||
| 3269 | 3341 | |
| 3270 | 3342 | |
| 3271 | 3343 | <hr><h3><a name="lua_getctx"><code>lua_getctx</code></a></h3><p> |
| 3272 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3344 | +<span class="apii">[-0, +0, –]</span> | |
| 3273 | 3345 | <pre>int lua_getctx (lua_State *L, int *ctx);</pre> |
| 3274 | 3346 | |
| 3275 | 3347 | <p> |
| @@ -3293,7 +3365,7 @@ When the callee is <a href="#lua_pcallk"><code>lua_pcallk</code></a>, · 17 unmodified lines | ||
| 3293 | 3365 | Lua may also call its continuation function |
| 3294 | 3366 | to handle errors during the call. |
| 3295 | 3367 | That is, upon an error in the function called by <a href="#lua_pcallk"><code>lua_pcallk</code></a>, |
| 3296 | −Lua may not return <a href="#lua_pcallk"><code>lua_pcallk</code></a> | |
| 3368 | +Lua may not return to the original function | |
| 3297 | 3369 | but instead may call the continuation function. |
| 3298 | 3370 | In that case, a call to <a href="#lua_getctx"><code>lua_getctx</code></a> will return the error code |
| 3299 | 3371 | (the value that would be returned by <a href="#lua_pcallk"><code>lua_pcallk</code></a>); |
| @@ -3324,21 +3396,19 @@ for the "index" event (see <a href="#2.4">§2.4</a>). · 24 unmodified lines | ||
| 3324 | 3396 | |
| 3325 | 3397 | <p> |
| 3326 | 3398 | Pushes onto the stack the value of the global <code>name</code>. |
| 3327 | −It is defined as a macro. | |
| 3328 | 3399 | |
| 3329 | 3400 | |
| 3330 | 3401 | |
| 3331 | 3402 | |
| 3332 | 3403 | |
| 3333 | 3404 | <hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3><p> |
| 3334 | −<span class="apii">[-0, +(0|1), <em>-</em>]</span> | |
| 3405 | +<span class="apii">[-0, +(0|1), –]</span> | |
| 3335 | 3406 | <pre>int lua_getmetatable (lua_State *L, int index);</pre> |
| 3336 | 3407 | |
| 3337 | 3408 | <p> |
| 3338 | 3409 | Pushes onto the stack the metatable of the value at the given |
| 3339 | 3410 | acceptable index. |
| 3340 | −If the index is not valid, | |
| 3341 | −or if the value does not have a metatable, | |
| 3411 | +If the value does not have a metatable, | |
| 3342 | 3412 | the function returns 0 and pushes nothing on the stack. |
| 3343 | 3413 | |
| 3344 | 3414 | |
| @@ -3366,7 +3436,7 @@ for the "index" event (see <a href="#2.4">§2.4</a>). · 21 unmodified lines | ||
| 3366 | 3436 | |
| 3367 | 3437 | |
| 3368 | 3438 | <hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3><p> |
| 3369 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3439 | +<span class="apii">[-0, +0, –]</span> | |
| 3370 | 3440 | <pre>int lua_gettop (lua_State *L);</pre> |
| 3371 | 3441 | |
| 3372 | 3442 | <p> |
| @@ -3380,7 +3450,7 @@ this result is equal to the number of elements in the stack · 7 unmodified lines | ||
| 3380 | 3450 | |
| 3381 | 3451 | |
| 3382 | 3452 | <hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p> |
| 3383 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 3453 | +<span class="apii">[-0, +1, –]</span> | |
| 3384 | 3454 | <pre>void lua_getuservalue (lua_State *L, int index);</pre> |
| 3385 | 3455 | |
| 3386 | 3456 | <p> |
| @@ -3393,7 +3463,7 @@ This Lua value must be a table or <b>nil</b>. · 6 unmodified lines | ||
| 3393 | 3463 | |
| 3394 | 3464 | |
| 3395 | 3465 | <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p> |
| 3396 | −<span class="apii">[-1, +1, <em>-</em>]</span> | |
| 3466 | +<span class="apii">[-1, +1, –]</span> | |
| 3397 | 3467 | <pre>void lua_insert (lua_State *L, int index);</pre> |
| 3398 | 3468 | |
| 3399 | 3469 | <p> |
| @@ -3423,11 +3493,11 @@ which is usually the largest signed integral type the machine handles · 23 unmodified lines | ||
| 3423 | 3493 | |
| 3424 | 3494 | |
| 3425 | 3495 | <hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3><p> |
| 3426 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3496 | +<span class="apii">[-0, +0, –]</span> | |
| 3427 | 3497 | <pre>int lua_isboolean (lua_State *L, int index);</pre> |
| 3428 | 3498 | |
| 3429 | 3499 | <p> |
| 3430 | −Returns 1 if the value at the given acceptable index has type boolean, | |
| 3500 | +Returns 1 if the value at the given acceptable index is a boolean, | |
| 3431 | 3501 | and 0 otherwise. |
| 3432 | 3502 | |
| 3433 | 3503 | |
| @@ -3435,7 +3505,7 @@ and 0 otherwise. · 1 unmodified line | ||
| 3435 | 3505 | |
| 3436 | 3506 | |
| 3437 | 3507 | <hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3><p> |
| 3438 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3508 | +<span class="apii">[-0, +0, –]</span> | |
| 3439 | 3509 | <pre>int lua_iscfunction (lua_State *L, int index);</pre> |
| 3440 | 3510 | |
| 3441 | 3511 | <p> |
| @@ -3447,7 +3517,7 @@ and 0 otherwise. · 5 unmodified lines | ||
| 3447 | 3517 | |
| 3448 | 3518 | |
| 3449 | 3519 | <hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3><p> |
| 3450 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3520 | +<span class="apii">[-0, +0, –]</span> | |
| 3451 | 3521 | <pre>int lua_isfunction (lua_State *L, int index);</pre> |
| 3452 | 3522 | |
| 3453 | 3523 | <p> |
| @@ -3459,7 +3529,7 @@ Returns 1 if the value at the given acceptable index is a function · 5 unmodified lines | ||
| 3459 | 3529 | |
| 3460 | 3530 | |
| 3461 | 3531 | <hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3><p> |
| 3462 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3532 | +<span class="apii">[-0, +0, –]</span> | |
| 3463 | 3533 | <pre>int lua_islightuserdata (lua_State *L, int index);</pre> |
| 3464 | 3534 | |
| 3465 | 3535 | <p> |
| @@ -3471,7 +3541,7 @@ and 0 otherwise. · 5 unmodified lines | ||
| 3471 | 3541 | |
| 3472 | 3542 | |
| 3473 | 3543 | <hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3><p> |
| 3474 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3544 | +<span class="apii">[-0, +0, –]</span> | |
| 3475 | 3545 | <pre>int lua_isnil (lua_State *L, int index);</pre> |
| 3476 | 3546 | |
| 3477 | 3547 | <p> |
| @@ -3483,7 +3553,7 @@ and 0 otherwise. · 5 unmodified lines | ||
| 3483 | 3553 | |
| 3484 | 3554 | |
| 3485 | 3555 | <hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3><p> |
| 3486 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3556 | +<span class="apii">[-0, +0, –]</span> | |
| 3487 | 3557 | <pre>int lua_isnone (lua_State *L, int index);</pre> |
| 3488 | 3558 | |
| 3489 | 3559 | <p> |
| @@ -3496,7 +3566,7 @@ and 0 otherwise. · 6 unmodified lines | ||
| 3496 | 3566 | |
| 3497 | 3567 | |
| 3498 | 3568 | <hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3><p> |
| 3499 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3569 | +<span class="apii">[-0, +0, –]</span> | |
| 3500 | 3570 | <pre>int lua_isnoneornil (lua_State *L, int index);</pre> |
| 3501 | 3571 | |
| 3502 | 3572 | <p> |
| @@ -3510,7 +3580,7 @@ and 0 otherwise. · 7 unmodified lines | ||
| 3510 | 3580 | |
| 3511 | 3581 | |
| 3512 | 3582 | <hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3><p> |
| 3513 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3583 | +<span class="apii">[-0, +0, –]</span> | |
| 3514 | 3584 | <pre>int lua_isnumber (lua_State *L, int index);</pre> |
| 3515 | 3585 | |
| 3516 | 3586 | <p> |
| @@ -3523,7 +3593,7 @@ and 0 otherwise. · 6 unmodified lines | ||
| 3523 | 3593 | |
| 3524 | 3594 | |
| 3525 | 3595 | <hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3><p> |
| 3526 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3596 | +<span class="apii">[-0, +0, –]</span> | |
| 3527 | 3597 | <pre>int lua_isstring (lua_State *L, int index);</pre> |
| 3528 | 3598 | |
| 3529 | 3599 | <p> |
| @@ -3536,7 +3606,7 @@ and 0 otherwise. · 6 unmodified lines | ||
| 3536 | 3606 | |
| 3537 | 3607 | |
| 3538 | 3608 | <hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3><p> |
| 3539 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3609 | +<span class="apii">[-0, +0, –]</span> | |
| 3540 | 3610 | <pre>int lua_istable (lua_State *L, int index);</pre> |
| 3541 | 3611 | |
| 3542 | 3612 | <p> |
| @@ -3548,7 +3618,7 @@ and 0 otherwise. · 5 unmodified lines | ||
| 3548 | 3618 | |
| 3549 | 3619 | |
| 3550 | 3620 | <hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3><p> |
| 3551 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3621 | +<span class="apii">[-0, +0, –]</span> | |
| 3552 | 3622 | <pre>int lua_isthread (lua_State *L, int index);</pre> |
| 3553 | 3623 | |
| 3554 | 3624 | <p> |
| @@ -3560,7 +3630,7 @@ and 0 otherwise. · 5 unmodified lines | ||
| 3560 | 3630 | |
| 3561 | 3631 | |
| 3562 | 3632 | <hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3><p> |
| 3563 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3633 | +<span class="apii">[-0, +0, –]</span> | |
| 3564 | 3634 | <pre>int lua_isuserdata (lua_State *L, int index);</pre> |
| 3565 | 3635 | |
| 3566 | 3636 | <p> |
| @@ -3585,7 +3655,7 @@ The result is pushed on the stack. · 18 unmodified lines | ||
| 3585 | 3655 | |
| 3586 | 3656 | |
| 3587 | 3657 | <hr><h3><a name="lua_load"><code>lua_load</code></a></h3><p> |
| 3588 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 3658 | +<span class="apii">[-0, +1, –]</span> | |
| 3589 | 3659 | <pre>int lua_load (lua_State *L, |
| 3590 | 3660 | lua_Reader reader, |
| 3591 | 3661 | void *data, |
| @@ -3601,13 +3671,13 @@ The return values of <a href="#lua_load"><code>lua_load</code></a> are: · 9 unmodified lines | ||
| 3601 | 3671 | |
| 3602 | 3672 | <ul> |
| 3603 | 3673 | |
| 3604 | −<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> no errors;</li> | |
| 3674 | +<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a>: </b> no errors;</li> | |
| 3605 | 3675 | |
| 3606 | 3676 | <li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b> |
| 3607 | −syntax error during pre-compilation;</li> | |
| 3677 | +syntax error during precompilation;</li> | |
| 3608 | 3678 | |
| 3609 | 3679 | <li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b> |
| 3610 | −memory allocation error.</li> | |
| 3680 | +memory allocation error;</li> | |
| 3611 | 3681 | |
| 3612 | 3682 | <li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b> |
| 3613 | 3683 | error while running a <code>__gc</code> metamethod. |
| @@ -3623,7 +3693,7 @@ it does not run it. · 9 unmodified lines | ||
| 3623 | 3693 | |
| 3624 | 3694 | |
| 3625 | 3695 | <p> |
| 3626 | −<a href="#lua_load"><code>lua_load</code></a> automatically detects whether the chunk is text or binary, | |
| 3696 | +<a href="#lua_load"><code>lua_load</code></a> automatically detects whether the chunk is text or binary | |
| 3627 | 3697 | and loads it accordingly (see program <code>luac</code>). |
| 3628 | 3698 | |
| 3629 | 3699 | |
| @@ -3642,25 +3712,25 @@ which is used for error messages and in debug information (see <a href="#4.9">&s · 12 unmodified lines | ||
| 3642 | 3712 | If the resulting function has one upvalue, |
| 3643 | 3713 | this upvalue is set to the value of the global environment |
| 3644 | 3714 | stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.5">§4.5</a>). |
| 3645 | −(When loading main chunks, | |
| 3646 | −this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>).) | |
| 3715 | +When loading main chunks, | |
| 3716 | +this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>). | |
| 3647 | 3717 | |
| 3648 | 3718 | |
| 3649 | 3719 | |
| 3650 | 3720 | |
| 3651 | 3721 | |
| 3652 | 3722 | <hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3><p> |
| 3653 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 3723 | +<span class="apii">[-0, +0, –]</span> | |
| 3654 | 3724 | <pre>lua_State *lua_newstate (lua_Alloc f, void *ud);</pre> |
| 3655 | 3725 | |
| 3656 | 3726 | <p> |
| 3657 | 3727 | Creates a new thread running in a new, independent state. |
| 3658 | −Returns <code>NULL</code> if cannot create the thread/state | |
| 3728 | +Returns <code>NULL</code> if cannot create the thread or the state | |
| 3659 | 3729 | (due to lack of memory). |
| 3660 | 3730 | The argument <code>f</code> is the allocator function; |
| 3661 | 3731 | Lua does all memory allocation for this state through this function. |
| 3662 | 3732 | The second argument, <code>ud</code>, is an opaque pointer that Lua |
| 3663 | −simply passes to the allocator in every call. | |
| 3733 | +passes to the allocator in every call. | |
| 3664 | 3734 | |
| 3665 | 3735 | |
| 3666 | 3736 | |
| @@ -3686,7 +3756,7 @@ It is equivalent to <code>lua_createtable(L, 0, 0)</code>. · 19 unmodified lines | ||
| 3686 | 3756 | Creates a new thread, pushes it on the stack, |
| 3687 | 3757 | and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new thread. |
| 3688 | 3758 | The new thread returned by this function shares with the original thread |
| 3689 | −all global objects (such as tables), | |
| 3759 | +its global environment, | |
| 3690 | 3760 | but has an independent execution stack. |
| 3691 | 3761 | |
| 3692 | 3762 | |
| @@ -3707,15 +3777,7 @@ like any Lua object. · 14 unmodified lines | ||
| 3707 | 3777 | This function allocates a new block of memory with the given size, |
| 3708 | 3778 | pushes onto the stack a new full userdata with the block address, |
| 3709 | 3779 | and returns this address. |
| 3710 | − | |
| 3711 | − | |
| 3712 | −<p> | |
| 3713 | −Userdata represent C values in Lua. | |
| 3714 | −A <em>full userdata</em> represents a block of memory. | |
| 3715 | −It is an object (like a table): | |
| 3716 | −you must create it, it can have its own metatable, | |
| 3717 | −and you can detect when it is being collected. | |
| 3718 | −A full userdata is only equal to itself (under raw equality). | |
| 3780 | +The host program can freely use this memory. | |
| 3719 | 3781 | |
| 3720 | 3782 | |
| 3721 | 3783 | |
| @@ -3780,7 +3842,7 @@ Lua to operate with another type for numbers (e.g., float or long). · 58 unmodified lines | ||
| 3780 | 3842 | |
| 3781 | 3843 | |
| 3782 | 3844 | <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3><p> |
| 3783 | −<span class="apii">[-(nargs + 1), +(nresults|1), <em>-</em>]</span> | |
| 3845 | +<span class="apii">[-(nargs + 1), +(nresults|1), –]</span> | |
| 3784 | 3846 | <pre>int lua_pcall (lua_State *L, int nargs, int nresults, int msgh);</pre> |
| 3785 | 3847 | |
| 3786 | 3848 | <p> |
| @@ -3855,9 +3917,13 @@ It is generated by the garbage collector.) · 68 unmodified lines | ||
| 3855 | 3917 | |
| 3856 | 3918 | |
| 3857 | 3919 | <hr><h3><a name="lua_pcallk"><code>lua_pcallk</code></a></h3><p> |
| 3858 | −<span class="apii">[-(nargs + 1), +(nresults|1), <em>-</em>]</span> | |
| 3859 | −<pre>int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | |
| 3860 | − int ctx, lua_CFunction k);</pre> | |
| 3920 | +<span class="apii">[-(nargs + 1), +(nresults|1), –]</span> | |
| 3921 | +<pre>int lua_pcallk (lua_State *L, | |
| 3922 | + int nargs, | |
| 3923 | + int nresults, | |
| 3924 | + int errfunc, | |
| 3925 | + int ctx, | |
| 3926 | + lua_CFunction k);</pre> | |
| 3861 | 3927 | |
| 3862 | 3928 | <p> |
| 3863 | 3929 | This function behaves exactly like <a href="#lua_pcall"><code>lua_pcall</code></a>, |
| @@ -3868,7 +3934,7 @@ but allows the called function to yield (see <a href="#4.7">§4.7</a>). · 4 unmodified lines | ||
| 3868 | 3934 | |
| 3869 | 3935 | |
| 3870 | 3936 | <hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3><p> |
| 3871 | −<span class="apii">[-n, +0, <em>-</em>]</span> | |
| 3937 | +<span class="apii">[-n, +0, –]</span> | |
| 3872 | 3938 | <pre>void lua_pop (lua_State *L, int n);</pre> |
| 3873 | 3939 | |
| 3874 | 3940 | <p> |
| @@ -3879,7 +3945,7 @@ Pops <code>n</code> elements from the stack. · 4 unmodified lines | ||
| 3879 | 3945 | |
| 3880 | 3946 | |
| 3881 | 3947 | <hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3><p> |
| 3882 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 3948 | +<span class="apii">[-0, +1, –]</span> | |
| 3883 | 3949 | <pre>void lua_pushboolean (lua_State *L, int b);</pre> |
| 3884 | 3950 | |
| 3885 | 3951 | <p> |
| @@ -3920,14 +3986,14 @@ The maximum value for <code>n</code> is 255. · 34 unmodified lines | ||
| 3920 | 3986 | When <code>n</code> is zero, |
| 3921 | 3987 | this function creates a <em>light C function</em>, |
| 3922 | 3988 | which is just a pointer to the C function. |
| 3923 | −In that case, it cannot throw a memory error. | |
| 3989 | +In that case, it never throws a memory error. | |
| 3924 | 3990 | |
| 3925 | 3991 | |
| 3926 | 3992 | |
| 3927 | 3993 | |
| 3928 | 3994 | |
| 3929 | 3995 | <hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3><p> |
| 3930 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 3996 | +<span class="apii">[-0, +1, –]</span> | |
| 3931 | 3997 | <pre>void lua_pushcfunction (lua_State *L, lua_CFunction f);</pre> |
| 3932 | 3998 | |
| 3933 | 3999 | <p> |
| @@ -3948,7 +4014,9 @@ and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code>< · 14 unmodified lines | ||
| 3948 | 4014 | |
| 3949 | 4015 | <pre> |
| 3950 | 4016 | #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0) |
| 3951 | −</pre> | |
| 4017 | +</pre><p> | |
| 4018 | +Note that <code>f</code> is used twice. | |
| 4019 | + | |
| 3952 | 4020 | |
| 3953 | 4021 | |
| 3954 | 4022 | |
| @@ -3980,7 +4048,7 @@ The conversion specifiers can only be · 25 unmodified lines | ||
| 3980 | 4048 | '<code>%f</code>' (inserts a <a href="#lua_Number"><code>lua_Number</code></a>), |
| 3981 | 4049 | '<code>%p</code>' (inserts a pointer as a hexadecimal numeral), |
| 3982 | 4050 | '<code>%d</code>' (inserts an <code>int</code>), and |
| 3983 | −'<code>%c</code>' (inserts an <code>int</code> as a character). | |
| 4051 | +'<code>%c</code>' (inserts an <code>int</code> as a byte). | |
| 3984 | 4052 | </li> |
| 3985 | 4053 | |
| 3986 | 4054 | </ul> |
| @@ -3989,7 +4057,7 @@ The conversion specifiers can only be · 2 unmodified lines | ||
| 3989 | 4057 | |
| 3990 | 4058 | |
| 3991 | 4059 | <hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3><p> |
| 3992 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 4060 | +<span class="apii">[-0, +1, –]</span> | |
| 3993 | 4061 | <pre>void lua_pushinteger (lua_State *L, lua_Integer n);</pre> |
| 3994 | 4062 | |
| 3995 | 4063 | <p> |
| @@ -4000,7 +4068,7 @@ Pushes a number with value <code>n</code> onto the stack. · 4 unmodified lines | ||
| 4000 | 4068 | |
| 4001 | 4069 | |
| 4002 | 4070 | <hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3><p> |
| 4003 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 4071 | +<span class="apii">[-0, +1, –]</span> | |
| 4004 | 4072 | <pre>void lua_pushlightuserdata (lua_State *L, void *p);</pre> |
| 4005 | 4073 | |
| 4006 | 4074 | <p> |
| @@ -4027,7 +4095,7 @@ light userdata with the same C address. · 20 unmodified lines | ||
| 4027 | 4095 | <p> |
| 4028 | 4096 | This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>, |
| 4029 | 4097 | but can be used only when <code>s</code> is a literal string. |
| 4030 | −In these cases, it automatically provides the string length. | |
| 4098 | +It automatically provides the string length. | |
| 4031 | 4099 | |
| 4032 | 4100 | |
| 4033 | 4101 | |
| @@ -4055,7 +4123,7 @@ Returns a pointer to the internal copy of the string. · 21 unmodified lines | ||
| 4055 | 4123 | |
| 4056 | 4124 | |
| 4057 | 4125 | <hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3><p> |
| 4058 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 4126 | +<span class="apii">[-0, +1, –]</span> | |
| 4059 | 4127 | <pre>void lua_pushnil (lua_State *L);</pre> |
| 4060 | 4128 | |
| 4061 | 4129 | <p> |
| @@ -4066,7 +4134,7 @@ Pushes a nil value onto the stack. · 4 unmodified lines | ||
| 4066 | 4134 | |
| 4067 | 4135 | |
| 4068 | 4136 | <hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3><p> |
| 4069 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 4137 | +<span class="apii">[-0, +1, –]</span> | |
| 4070 | 4138 | <pre>void lua_pushnumber (lua_State *L, lua_Number n);</pre> |
| 4071 | 4139 | |
| 4072 | 4140 | <p> |
| @@ -4100,7 +4168,7 @@ If <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL · 27 unmodified lines | ||
| 4100 | 4168 | |
| 4101 | 4169 | |
| 4102 | 4170 | <hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3><p> |
| 4103 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 4171 | +<span class="apii">[-0, +1, –]</span> | |
| 4104 | 4172 | <pre>int lua_pushthread (lua_State *L);</pre> |
| 4105 | 4173 | |
| 4106 | 4174 | <p> |
| @@ -4112,7 +4180,7 @@ Returns 1 if this thread is the main thread of its state. · 5 unmodified lines | ||
| 4112 | 4180 | |
| 4113 | 4181 | |
| 4114 | 4182 | <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p> |
| 4115 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 4183 | +<span class="apii">[-0, +1, –]</span> | |
| 4116 | 4184 | <pre>void lua_pushvalue (lua_State *L, int index);</pre> |
| 4117 | 4185 | |
| 4118 | 4186 | <p> |
| @@ -4138,7 +4206,7 @@ instead of a variable number of arguments. · 19 unmodified lines | ||
| 4138 | 4206 | |
| 4139 | 4207 | |
| 4140 | 4208 | <hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3><p> |
| 4141 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4209 | +<span class="apii">[-0, +0, –]</span> | |
| 4142 | 4210 | <pre>int lua_rawequal (lua_State *L, int index1, int index2);</pre> |
| 4143 | 4211 | |
| 4144 | 4212 | <p> |
| @@ -4153,7 +4221,7 @@ Also returns 0 if any of the indices are non valid. · 8 unmodified lines | ||
| 4153 | 4221 | |
| 4154 | 4222 | |
| 4155 | 4223 | <hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3><p> |
| 4156 | −<span class="apii">[-1, +1, <em>-</em>]</span> | |
| 4224 | +<span class="apii">[-1, +1, –]</span> | |
| 4157 | 4225 | <pre>void lua_rawget (lua_State *L, int index);</pre> |
| 4158 | 4226 | |
| 4159 | 4227 | <p> |
| @@ -4165,7 +4233,7 @@ Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw · 5 unmodified lines | ||
| 4165 | 4233 | |
| 4166 | 4234 | |
| 4167 | 4235 | <hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3><p> |
| 4168 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 4236 | +<span class="apii">[-0, +1, –]</span> | |
| 4169 | 4237 | <pre>void lua_rawgeti (lua_State *L, int index, int n);</pre> |
| 4170 | 4238 | |
| 4171 | 4239 | <p> |
| @@ -4178,8 +4246,23 @@ that is, it does not invoke metamethods. · 6 unmodified lines | ||
| 4178 | 4246 | |
| 4179 | 4247 | |
| 4180 | 4248 | |
| 4249 | +<hr><h3><a name="lua_rawgetp"><code>lua_rawgetp</code></a></h3><p> | |
| 4250 | +<span class="apii">[-0, +1, –]</span> | |
| 4251 | +<pre>void lua_rawgetp (lua_State *L, int index, const void *p);</pre> | |
| 4252 | + | |
| 4253 | +<p> | |
| 4254 | +Pushes onto the stack the value <code>t[k]</code>, | |
| 4255 | +where <code>t</code> is the table at the given valid index and | |
| 4256 | +<code>k</code> is the pointer <code>p</code> represented as a light userdata. | |
| 4257 | +The access is raw; | |
| 4258 | +that is, it does not invoke metamethods. | |
| 4259 | + | |
| 4260 | + | |
| 4261 | + | |
| 4262 | + | |
| 4263 | + | |
| 4181 | 4264 | <hr><h3><a name="lua_rawlen"><code>lua_rawlen</code></a></h3><p> |
| 4182 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4265 | +<span class="apii">[-0, +0, –]</span> | |
| 4183 | 4266 | <pre>size_t lua_rawlen (lua_State *L, int index);</pre> |
| 4184 | 4267 | |
| 4185 | 4268 | <p> |
| @@ -4226,6 +4309,26 @@ that is, it does not invoke metamethods. · 40 unmodified lines | ||
| 4226 | 4309 | |
| 4227 | 4310 | |
| 4228 | 4311 | |
| 4312 | +<hr><h3><a name="lua_rawsetp"><code>lua_rawsetp</code></a></h3><p> | |
| 4313 | +<span class="apii">[-1, +0, <em>m</em>]</span> | |
| 4314 | +<pre>void lua_rawsetp (lua_State *L, int index, const void *p);</pre> | |
| 4315 | + | |
| 4316 | +<p> | |
| 4317 | +Does the equivalent of <code>t[k] = v</code>, | |
| 4318 | +where <code>t</code> is the table at the given valid index, | |
| 4319 | +<code>k</code> is the pointer <code>p</code> represented as a light userdata, | |
| 4320 | +and <code>v</code> is the value at the top of the stack. | |
| 4321 | + | |
| 4322 | + | |
| 4323 | +<p> | |
| 4324 | +This function pops the value from the stack. | |
| 4325 | +The assignment is raw; | |
| 4326 | +that is, it does not invoke metamethods. | |
| 4327 | + | |
| 4328 | + | |
| 4329 | + | |
| 4330 | + | |
| 4331 | + | |
| 4229 | 4332 | <hr><h3><a name="lua_Reader"><code>lua_Reader</code></a></h3> |
| 4230 | 4333 | <pre>typedef const char * (*lua_Reader) (lua_State *L, |
| 4231 | 4334 | void *data, |
| @@ -4250,9 +4353,7 @@ The reader function may return pieces of any size greater than zero. · 18 unmodified lines | ||
| 4250 | 4353 | |
| 4251 | 4354 | <hr><h3><a name="lua_register"><code>lua_register</code></a></h3><p> |
| 4252 | 4355 | <span class="apii">[-0, +0, <em>e</em>]</span> |
| 4253 | −<pre>void lua_register (lua_State *L, | |
| 4254 | − const char *name, | |
| 4255 | − lua_CFunction f);</pre> | |
| 4356 | +<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre> | |
| 4256 | 4357 | |
| 4257 | 4358 | <p> |
| 4258 | 4359 | Sets the C function <code>f</code> as the new value of global <code>name</code>. |
| @@ -4267,7 +4368,7 @@ It is defined as a macro: · 8 unmodified lines | ||
| 4267 | 4368 | |
| 4268 | 4369 | |
| 4269 | 4370 | <hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3><p> |
| 4270 | −<span class="apii">[-1, +0, <em>-</em>]</span> | |
| 4371 | +<span class="apii">[-1, +0, –]</span> | |
| 4271 | 4372 | <pre>void lua_remove (lua_State *L, int index);</pre> |
| 4272 | 4373 | |
| 4273 | 4374 | <p> |
| @@ -4281,7 +4382,7 @@ because a pseudo-index is not an actual stack position. · 7 unmodified lines | ||
| 4281 | 4382 | |
| 4282 | 4383 | |
| 4283 | 4384 | <hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3><p> |
| 4284 | −<span class="apii">[-1, +0, <em>-</em>]</span> | |
| 4385 | +<span class="apii">[-1, +0, –]</span> | |
| 4285 | 4386 | <pre>void lua_replace (lua_State *L, int index);</pre> |
| 4286 | 4387 | |
| 4287 | 4388 | <p> |
| @@ -4295,8 +4396,8 @@ and then pops the top element. · 7 unmodified lines | ||
| 4295 | 4396 | |
| 4296 | 4397 | |
| 4297 | 4398 | <hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3><p> |
| 4298 | −<span class="apii">[-?, +?, <em>-</em>]</span> | |
| 4299 | −<pre>int lua_resume (lua_State *L, int narg);</pre> | |
| 4399 | +<span class="apii">[-?, +?, –]</span> | |
| 4400 | +<pre>int lua_resume (lua_State *L, lua_State *from, int narg);</pre> | |
| 4300 | 4401 | |
| 4301 | 4402 | <p> |
| 4302 | 4403 | Starts and resumes a coroutine in a given thread. |
| @@ -4330,11 +4431,17 @@ be passed as results from <code>yield</code>, · 27 unmodified lines | ||
| 4330 | 4431 | and then call <a href="#lua_resume"><code>lua_resume</code></a>. |
| 4331 | 4432 | |
| 4332 | 4433 | |
| 4434 | +<p> | |
| 4435 | +The parameter <code>from</code> represents the coroutine that is resuming <code>L</code>. | |
| 4436 | +If there is no such coroutine, | |
| 4437 | +this parameter can be <code>NULL</code>. | |
| 4438 | + | |
| 4439 | + | |
| 4333 | 4440 | |
| 4334 | 4441 | |
| 4335 | 4442 | |
| 4336 | 4443 | <hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3><p> |
| 4337 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4444 | +<span class="apii">[-0, +0, –]</span> | |
| 4338 | 4445 | <pre>void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);</pre> |
| 4339 | 4446 | |
| 4340 | 4447 | <p> |
| @@ -4371,14 +4478,13 @@ for the "newindex" event (see <a href="#2.4">§2.4</a>). · 30 unmodified lines | ||
| 4371 | 4478 | <p> |
| 4372 | 4479 | Pops a value from the stack and |
| 4373 | 4480 | sets it as the new value of global <code>name</code>. |
| 4374 | −It is defined as a macro. | |
| 4375 | 4481 | |
| 4376 | 4482 | |
| 4377 | 4483 | |
| 4378 | 4484 | |
| 4379 | 4485 | |
| 4380 | 4486 | <hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3><p> |
| 4381 | −<span class="apii">[-1, +0, <em>-</em>]</span> | |
| 4487 | +<span class="apii">[-1, +0, –]</span> | |
| 4382 | 4488 | <pre>void lua_setmetatable (lua_State *L, int index);</pre> |
| 4383 | 4489 | |
| 4384 | 4490 | <p> |
| @@ -4411,7 +4517,7 @@ for the "newindex" event (see <a href="#2.4">§2.4</a>). · 26 unmodified lines | ||
| 4411 | 4517 | |
| 4412 | 4518 | |
| 4413 | 4519 | <hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3><p> |
| 4414 | −<span class="apii">[-?, +?, <em>-</em>]</span> | |
| 4520 | +<span class="apii">[-?, +?, –]</span> | |
| 4415 | 4521 | <pre>void lua_settop (lua_State *L, int index);</pre> |
| 4416 | 4522 | |
| 4417 | 4523 | <p> |
| @@ -4426,7 +4532,7 @@ If <code>index</code> is 0, then all stack elements are removed. · 8 unmodified lines | ||
| 4426 | 4532 | |
| 4427 | 4533 | |
| 4428 | 4534 | <hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p> |
| 4429 | −<span class="apii">[-1, +0, <em>-</em>]</span> | |
| 4535 | +<span class="apii">[-1, +0, –]</span> | |
| 4430 | 4536 | <pre>void lua_setuservalue (lua_State *L, int index);</pre> |
| 4431 | 4537 | |
| 4432 | 4538 | <p> |
| @@ -4457,7 +4563,7 @@ which creates a Lua state from scratch. · 24 unmodified lines | ||
| 4457 | 4563 | |
| 4458 | 4564 | |
| 4459 | 4565 | <hr><h3><a name="lua_status"><code>lua_status</code></a></h3><p> |
| 4460 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4566 | +<span class="apii">[-0, +0, –]</span> | |
| 4461 | 4567 | <pre>int lua_status (lua_State *L);</pre> |
| 4462 | 4568 | |
| 4463 | 4569 | <p> |
| @@ -4482,7 +4588,7 @@ You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> · 18 unmodified lines | ||
| 4482 | 4588 | |
| 4483 | 4589 | |
| 4484 | 4590 | <hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3><p> |
| 4485 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4591 | +<span class="apii">[-0, +0, –]</span> | |
| 4486 | 4592 | <pre>int lua_toboolean (lua_State *L, int index);</pre> |
| 4487 | 4593 | |
| 4488 | 4594 | <p> |
| @@ -4501,7 +4607,7 @@ use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's · 12 unmodified lines | ||
| 4501 | 4607 | |
| 4502 | 4608 | |
| 4503 | 4609 | <hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3><p> |
| 4504 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4610 | +<span class="apii">[-0, +0, –]</span> | |
| 4505 | 4611 | <pre>lua_CFunction lua_tocfunction (lua_State *L, int index);</pre> |
| 4506 | 4612 | |
| 4507 | 4613 | <p> |
| @@ -4514,18 +4620,18 @@ otherwise, returns <code>NULL</code>. · 6 unmodified lines | ||
| 4514 | 4620 | |
| 4515 | 4621 | |
| 4516 | 4622 | <hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p> |
| 4517 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4623 | +<span class="apii">[-0, +0, –]</span> | |
| 4518 | 4624 | <pre>lua_Integer lua_tointeger (lua_State *L, int index);</pre> |
| 4519 | 4625 | |
| 4520 | 4626 | <p> |
| 4521 | −A macro equivalent to <code>lua_tointegerx(L, index, NULL)</code>. | |
| 4627 | +Equivalent to <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> with <code>isnum</code> equal to <code>NULL</code>. | |
| 4522 | 4628 | |
| 4523 | 4629 | |
| 4524 | 4630 | |
| 4525 | 4631 | |
| 4526 | 4632 | |
| 4527 | 4633 | <hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p> |
| 4528 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4634 | +<span class="apii">[-0, +0, –]</span> | |
| 4529 | 4635 | <pre>lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum);</pre> |
| 4530 | 4636 | |
| 4531 | 4637 | <p> |
| @@ -4533,7 +4639,7 @@ Converts the Lua value at the given acceptable index · 1 unmodified line | ||
| 4533 | 4639 | to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>. |
| 4534 | 4640 | The Lua value must be a number or a string convertible to a number |
| 4535 | 4641 | (see <a href="#3.4.2">§3.4.2</a>); |
| 4536 | −otherwise, <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> returns 0. | |
| 4642 | +otherwise, <code>lua_tointegerx</code> returns 0. | |
| 4537 | 4643 | |
| 4538 | 4644 | |
| 4539 | 4645 | <p> |
| @@ -4542,7 +4648,7 @@ it is truncated in some non-specified way. · 2 unmodified lines | ||
| 4542 | 4648 | |
| 4543 | 4649 | |
| 4544 | 4650 | <p> |
| 4545 | −If <code>isnum</code> is different from <code>NULL</code>, | |
| 4651 | +If <code>isnum</code> is not <code>NULL</code>, | |
| 4546 | 4652 | its referent is assigned a boolean value that |
| 4547 | 4653 | indicates whether the operation succeeded. |
| 4548 | 4654 | |
| @@ -4561,20 +4667,20 @@ it also sets <code>*len</code> with the string length. · 12 unmodified lines | ||
| 4561 | 4667 | The Lua value must be a string or a number; |
| 4562 | 4668 | otherwise, the function returns <code>NULL</code>. |
| 4563 | 4669 | If the value is a number, |
| 4564 | −then <a href="#lua_tolstring"><code>lua_tolstring</code></a> also | |
| 4670 | +then <code>lua_tolstring</code> also | |
| 4565 | 4671 | <em>changes the actual value in the stack to a string</em>. |
| 4566 | 4672 | (This change confuses <a href="#lua_next"><code>lua_next</code></a> |
| 4567 | −when <a href="#lua_tolstring"><code>lua_tolstring</code></a> is applied to keys during a table traversal.) | |
| 4673 | +when <code>lua_tolstring</code> is applied to keys during a table traversal.) | |
| 4568 | 4674 | |
| 4569 | 4675 | |
| 4570 | 4676 | <p> |
| 4571 | −<a href="#lua_tolstring"><code>lua_tolstring</code></a> returns a fully aligned pointer | |
| 4677 | +<code>lua_tolstring</code> returns a fully aligned pointer | |
| 4572 | 4678 | to a string inside the Lua state. |
| 4573 | 4679 | This string always has a zero ('<code>\0</code>') |
| 4574 | 4680 | after its last character (as in C), |
| 4575 | 4681 | but can contain other zeros in its body. |
| 4576 | 4682 | Because Lua has garbage collection, |
| 4577 | −there is no guarantee that the pointer returned by <a href="#lua_tolstring"><code>lua_tolstring</code></a> | |
| 4683 | +there is no guarantee that the pointer returned by <code>lua_tolstring</code> | |
| 4578 | 4684 | will be valid after the corresponding value is removed from the stack. |
| 4579 | 4685 | |
| 4580 | 4686 | |
| @@ -4582,18 +4688,18 @@ will be valid after the corresponding value is removed from the stack. · 1 unmodified line | ||
| 4582 | 4688 | |
| 4583 | 4689 | |
| 4584 | 4690 | <hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p> |
| 4585 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4691 | +<span class="apii">[-0, +0, –]</span> | |
| 4586 | 4692 | <pre>lua_Number lua_tonumber (lua_State *L, int index);</pre> |
| 4587 | 4693 | |
| 4588 | 4694 | <p> |
| 4589 | −A macro equivalent to <code>lua_tonumberx(L, index, NULL)</code>. | |
| 4695 | +Equivalent to <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> with <code>isnum</code> equal to <code>NULL</code>. | |
| 4590 | 4696 | |
| 4591 | 4697 | |
| 4592 | 4698 | |
| 4593 | 4699 | |
| 4594 | 4700 | |
| 4595 | 4701 | <hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p> |
| 4596 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4702 | +<span class="apii">[-0, +0, –]</span> | |
| 4597 | 4703 | <pre>lua_Number lua_tonumberx (lua_State *L, int index, int *isnum);</pre> |
| 4598 | 4704 | |
| 4599 | 4705 | <p> |
| @@ -4605,7 +4711,7 @@ otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns · 5 unmodified lines | ||
| 4605 | 4711 | |
| 4606 | 4712 | |
| 4607 | 4713 | <p> |
| 4608 | −If <code>isnum</code> is different from <code>NULL</code>, | |
| 4714 | +If <code>isnum</code> is not <code>NULL</code>, | |
| 4609 | 4715 | its referent is assigned a boolean value that |
| 4610 | 4716 | indicates whether the operation succeeded. |
| 4611 | 4717 | |
| @@ -4614,14 +4720,14 @@ indicates whether the operation succeeded. · 2 unmodified lines | ||
| 4614 | 4720 | |
| 4615 | 4721 | |
| 4616 | 4722 | <hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p> |
| 4617 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4723 | +<span class="apii">[-0, +0, –]</span> | |
| 4618 | 4724 | <pre>const void *lua_topointer (lua_State *L, int index);</pre> |
| 4619 | 4725 | |
| 4620 | 4726 | <p> |
| 4621 | 4727 | Converts the value at the given acceptable index to a generic |
| 4622 | 4728 | C pointer (<code>void*</code>). |
| 4623 | 4729 | The value can be a userdata, a table, a thread, or a function; |
| 4624 | −otherwise, <a href="#lua_topointer"><code>lua_topointer</code></a> returns <code>NULL</code>. | |
| 4730 | +otherwise, <code>lua_topointer</code> returns <code>NULL</code>. | |
| 4625 | 4731 | Different objects will give different pointers. |
| 4626 | 4732 | There is no way to convert the pointer back to its original value. |
| 4627 | 4733 | |
| @@ -4645,7 +4751,7 @@ Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code · 17 unmodified lines | ||
| 4645 | 4751 | |
| 4646 | 4752 | |
| 4647 | 4753 | <hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p> |
| 4648 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4754 | +<span class="apii">[-0, +0, –]</span> | |
| 4649 | 4755 | <pre>lua_State *lua_tothread (lua_State *L, int index);</pre> |
| 4650 | 4756 | |
| 4651 | 4757 | <p> |
| @@ -4659,18 +4765,18 @@ otherwise, the function returns <code>NULL</code>. · 7 unmodified lines | ||
| 4659 | 4765 | |
| 4660 | 4766 | |
| 4661 | 4767 | <hr><h3><a name="lua_tounsigned"><code>lua_tounsigned</code></a></h3><p> |
| 4662 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4768 | +<span class="apii">[-0, +0, –]</span> | |
| 4663 | 4769 | <pre>lua_Unsigned lua_tounsigned (lua_State *L, int index);</pre> |
| 4664 | 4770 | |
| 4665 | 4771 | <p> |
| 4666 | −A macro equivalent to <code>lua_tounsignedx(L, index, NULL)</code>. | |
| 4772 | +Equivalent to <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> with <code>isnum</code> equal to <code>NULL</code>. | |
| 4667 | 4773 | |
| 4668 | 4774 | |
| 4669 | 4775 | |
| 4670 | 4776 | |
| 4671 | 4777 | |
| 4672 | 4778 | <hr><h3><a name="lua_tounsignedx"><code>lua_tounsignedx</code></a></h3><p> |
| 4673 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4779 | +<span class="apii">[-0, +0, –]</span> | |
| 4674 | 4780 | <pre>lua_Unsigned lua_tounsignedx (lua_State *L, int index, int *isnum);</pre> |
| 4675 | 4781 | |
| 4676 | 4782 | <p> |
| @@ -4678,7 +4784,7 @@ Converts the Lua value at the given acceptable index · 1 unmodified line | ||
| 4678 | 4784 | to the unsigned integral type <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>. |
| 4679 | 4785 | The Lua value must be a number or a string convertible to a number |
| 4680 | 4786 | (see <a href="#3.4.2">§3.4.2</a>); |
| 4681 | −otherwise, <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> returns 0. | |
| 4787 | +otherwise, <code>lua_tounsignedx</code> returns 0. | |
| 4682 | 4788 | |
| 4683 | 4789 | |
| 4684 | 4790 | <p> |
| @@ -4690,7 +4796,7 @@ one more than the maximum representable value. · 5 unmodified lines | ||
| 4690 | 4796 | |
| 4691 | 4797 | |
| 4692 | 4798 | <p> |
| 4693 | −If <code>isnum</code> is different from <code>NULL</code>, | |
| 4799 | +If <code>isnum</code> is not <code>NULL</code>, | |
| 4694 | 4800 | its referent is assigned a boolean value that |
| 4695 | 4801 | indicates whether the operation succeeded. |
| 4696 | 4802 | |
| @@ -4699,7 +4805,7 @@ indicates whether the operation succeeded. · 2 unmodified lines | ||
| 4699 | 4805 | |
| 4700 | 4806 | |
| 4701 | 4807 | <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p> |
| 4702 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4808 | +<span class="apii">[-0, +0, –]</span> | |
| 4703 | 4809 | <pre>void *lua_touserdata (lua_State *L, int index);</pre> |
| 4704 | 4810 | |
| 4705 | 4811 | <p> |
| @@ -4714,13 +4820,12 @@ Otherwise, returns <code>NULL</code>. · 8 unmodified lines | ||
| 4714 | 4820 | |
| 4715 | 4821 | |
| 4716 | 4822 | <hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p> |
| 4717 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4823 | +<span class="apii">[-0, +0, –]</span> | |
| 4718 | 4824 | <pre>int lua_type (lua_State *L, int index);</pre> |
| 4719 | 4825 | |
| 4720 | 4826 | <p> |
| 4721 | 4827 | Returns the type of the value in the given acceptable index, |
| 4722 | −or <code>LUA_TNONE</code> for a non-valid index | |
| 4723 | −(that is, an index to an "empty" stack position). | |
| 4828 | +or <code>LUA_TNONE</code> for a non-valid index. | |
| 4724 | 4829 | The types returned by <a href="#lua_type"><code>lua_type</code></a> are coded by the following constants |
| 4725 | 4830 | defined in <code>lua.h</code>: |
| 4726 | 4831 | <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>, |
| @@ -4739,7 +4844,7 @@ and · 12 unmodified lines | ||
| 4739 | 4844 | |
| 4740 | 4845 | |
| 4741 | 4846 | <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p> |
| 4742 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 4847 | +<span class="apii">[-0, +0, –]</span> | |
| 4743 | 4848 | <pre>const char *lua_typename (lua_State *L, int tp);</pre> |
| 4744 | 4849 | |
| 4745 | 4850 | <p> |
| @@ -4807,11 +4912,11 @@ calling the writer again. · 61 unmodified lines | ||
| 4807 | 4912 | |
| 4808 | 4913 | |
| 4809 | 4914 | <hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p> |
| 4810 | −<span class="apii">[-?, +?, <em>-</em>]</span> | |
| 4915 | +<span class="apii">[-?, +?, –]</span> | |
| 4811 | 4916 | <pre>void lua_xmove (lua_State *from, lua_State *to, int n);</pre> |
| 4812 | 4917 | |
| 4813 | 4918 | <p> |
| 4814 | −Exchange values between different threads of the same global state. | |
| 4919 | +Exchange values between different threads of the same state. | |
| 4815 | 4920 | |
| 4816 | 4921 | |
| 4817 | 4922 | <p> |
| @@ -4823,7 +4928,7 @@ and pushes them onto the stack <code>to</code>. · 5 unmodified lines | ||
| 4823 | 4928 | |
| 4824 | 4929 | |
| 4825 | 4930 | <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p> |
| 4826 | −<span class="apii">[-?, +?, <em>-</em>]</span> | |
| 4931 | +<span class="apii">[-?, +?, –]</span> | |
| 4827 | 4932 | <pre>int lua_yield (lua_State *L, int nresults);</pre> |
| 4828 | 4933 | |
| 4829 | 4934 | <p> |
| @@ -4838,7 +4943,7 @@ the function calling <code>lua_yield</code>. · 8 unmodified lines | ||
| 4838 | 4943 | |
| 4839 | 4944 | |
| 4840 | 4945 | <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p> |
| 4841 | −<span class="apii">[-?, +?, <em>-</em>]</span> | |
| 4946 | +<span class="apii">[-?, +?, –]</span> | |
| 4842 | 4947 | <pre>int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k);</pre> |
| 4843 | 4948 | |
| 4844 | 4949 | <p> |
| @@ -4850,7 +4955,7 @@ This function should only be called as the · 5 unmodified lines | ||
| 4850 | 4955 | return expression of a C function, as follows: |
| 4851 | 4956 | |
| 4852 | 4957 | <pre> |
| 4853 | − return lua_yield (L, nresults, i, k); | |
| 4958 | + return lua_yieldk (L, n, i, k); | |
| 4854 | 4959 | </pre><p> |
| 4855 | 4960 | When a C function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a> in that way, |
| 4856 | 4961 | the running coroutine suspends its execution, |
| @@ -4928,7 +5033,7 @@ If <code>source</code> starts with a '<code>@</code>', · 71 unmodified lines | ||
| 4928 | 5033 | it means that the function was defined in a file where |
| 4929 | 5034 | the file name follows the '<code>@</code>'. |
| 4930 | 5035 | If <code>source</code> starts with a '<code>=</code>', |
| 4931 | −the rest of it should describe the source in a user-dependent manner. | |
| 5036 | +the remainder of its contents describe the source in a user-dependent manner. | |
| 4932 | 5037 | Otherwise, |
| 4933 | 5038 | the function was defined in a string where |
| 4934 | 5039 | <code>source</code> is that string. |
| @@ -4994,7 +5099,7 @@ the number of fixed parameters of the function · 59 unmodified lines | ||
| 4994 | 5099 | </li> |
| 4995 | 5100 | |
| 4996 | 5101 | <li><b><code>isvararg</code>: </b> |
| 4997 | −whether the function is a vararg function | |
| 5102 | +true if the function is a vararg function | |
| 4998 | 5103 | (always true for C functions). |
| 4999 | 5104 | </li> |
| 5000 | 5105 | |
| @@ -5004,7 +5109,7 @@ whether the function is a vararg function · 3 unmodified lines | ||
| 5004 | 5109 | |
| 5005 | 5110 | |
| 5006 | 5111 | <hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p> |
| 5007 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5112 | +<span class="apii">[-0, +0, –]</span> | |
| 5008 | 5113 | <pre>lua_Hook lua_gethook (lua_State *L);</pre> |
| 5009 | 5114 | |
| 5010 | 5115 | <p> |
| @@ -5015,7 +5120,7 @@ Returns the current hook function. · 4 unmodified lines | ||
| 5015 | 5120 | |
| 5016 | 5121 | |
| 5017 | 5122 | <hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p> |
| 5018 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5123 | +<span class="apii">[-0, +0, –]</span> | |
| 5019 | 5124 | <pre>int lua_gethookcount (lua_State *L);</pre> |
| 5020 | 5125 | |
| 5021 | 5126 | <p> |
| @@ -5026,7 +5131,7 @@ Returns the current hook count. · 4 unmodified lines | ||
| 5026 | 5131 | |
| 5027 | 5132 | |
| 5028 | 5133 | <hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p> |
| 5029 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5134 | +<span class="apii">[-0, +0, –]</span> | |
| 5030 | 5135 | <pre>int lua_gethookmask (lua_State *L);</pre> |
| 5031 | 5136 | |
| 5032 | 5137 | <p> |
| @@ -5115,7 +5220,7 @@ This function returns 0 on error · 82 unmodified lines | ||
| 5115 | 5220 | |
| 5116 | 5221 | |
| 5117 | 5222 | <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p> |
| 5118 | −<span class="apii">[-0, +(0|1), <em>-</em>]</span> | |
| 5223 | +<span class="apii">[-0, +(0|1), –]</span> | |
| 5119 | 5224 | <pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre> |
| 5120 | 5225 | |
| 5121 | 5226 | <p> |
| @@ -5156,7 +5261,7 @@ the number of active local variables. · 34 unmodified lines | ||
| 5156 | 5261 | |
| 5157 | 5262 | |
| 5158 | 5263 | <hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p> |
| 5159 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5264 | +<span class="apii">[-0, +0, –]</span> | |
| 5160 | 5265 | <pre>int lua_getstack (lua_State *L, int level, lua_Debug *ar);</pre> |
| 5161 | 5266 | |
| 5162 | 5267 | <p> |
| @@ -5179,7 +5284,7 @@ it returns 0. · 16 unmodified lines | ||
| 5179 | 5284 | |
| 5180 | 5285 | |
| 5181 | 5286 | <hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p> |
| 5182 | −<span class="apii">[-0, +(0|1), <em>-</em>]</span> | |
| 5287 | +<span class="apii">[-0, +(0|1), –]</span> | |
| 5183 | 5288 | <pre>const char *lua_getupvalue (lua_State *L, int funcindex, int n);</pre> |
| 5184 | 5289 | |
| 5185 | 5290 | <p> |
| @@ -5241,7 +5346,7 @@ this execution occurs without any calls to hooks. · 55 unmodified lines | ||
| 5241 | 5346 | |
| 5242 | 5347 | |
| 5243 | 5348 | <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p> |
| 5244 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5349 | +<span class="apii">[-0, +0, –]</span> | |
| 5245 | 5350 | <pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre> |
| 5246 | 5351 | |
| 5247 | 5352 | <p> |
| @@ -5294,7 +5399,7 @@ A hook is disabled by setting <code>mask</code> to zero. · 46 unmodified lines | ||
| 5294 | 5399 | |
| 5295 | 5400 | |
| 5296 | 5401 | <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p> |
| 5297 | −<span class="apii">[-(0|1), +0, <em>-</em>]</span> | |
| 5402 | +<span class="apii">[-(0|1), +0, –]</span> | |
| 5298 | 5403 | <pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre> |
| 5299 | 5404 | |
| 5300 | 5405 | <p> |
| @@ -5316,7 +5421,7 @@ the number of active local variables. · 15 unmodified lines | ||
| 5316 | 5421 | |
| 5317 | 5422 | |
| 5318 | 5423 | <hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p> |
| 5319 | −<span class="apii">[-(0|1), +0, <em>-</em>]</span> | |
| 5424 | +<span class="apii">[-(0|1), +0, –]</span> | |
| 5320 | 5425 | <pre>const char *lua_setupvalue (lua_State *L, int funcindex, int n);</pre> |
| 5321 | 5426 | |
| 5322 | 5427 | <p> |
| @@ -5337,7 +5442,7 @@ when the index is greater than the number of upvalues. · 14 unmodified lines | ||
| 5337 | 5442 | |
| 5338 | 5443 | |
| 5339 | 5444 | <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p> |
| 5340 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5445 | +<span class="apii">[-0, +0, –]</span> | |
| 5341 | 5446 | <pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre> |
| 5342 | 5447 | |
| 5343 | 5448 | <p> |
| @@ -5386,7 +5491,7 @@ common tasks. · 42 unmodified lines | ||
| 5386 | 5491 | |
| 5387 | 5492 | |
| 5388 | 5493 | <p> |
| 5389 | −All functions from the auxiliary library | |
| 5494 | +All functions and types from the auxiliary library | |
| 5390 | 5495 | are defined in header file <code>lauxlib.h</code> and |
| 5391 | 5496 | have a prefix <code>luaL_</code>. |
| 5392 | 5497 | |
| @@ -5395,6 +5500,8 @@ have a prefix <code>luaL_</code>. · 2 unmodified lines | ||
| 5395 | 5500 | All functions in the auxiliary library are built on |
| 5396 | 5501 | top of the basic API, |
| 5397 | 5502 | and so they provide nothing that cannot be done with that API. |
| 5503 | +Nevertheless, the use of the auxiliary library ensures | |
| 5504 | +more consistency to your code. | |
| 5398 | 5505 | |
| 5399 | 5506 | |
| 5400 | 5507 | <p> |
| @@ -5432,7 +5539,7 @@ in alphabetical order. · 31 unmodified lines | ||
| 5432 | 5539 | <pre>void luaL_addchar (luaL_Buffer *B, char c);</pre> |
| 5433 | 5540 | |
| 5434 | 5541 | <p> |
| 5435 | −Adds the character <code>c</code> to the buffer <code>B</code> | |
| 5542 | +Adds the byte <code>c</code> to the buffer <code>B</code> | |
| 5436 | 5543 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 5437 | 5544 | |
| 5438 | 5545 | |
| @@ -5474,7 +5581,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>). · 35 unmodified lines | ||
| 5474 | 5581 | Adds the zero-terminated string pointed to by <code>s</code> |
| 5475 | 5582 | to the buffer <code>B</code> |
| 5476 | 5583 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 5477 | −The string should not contain embedded zeros. | |
| 5584 | +The string cannot contain embedded zeros. | |
| 5478 | 5585 | |
| 5479 | 5586 | |
| 5480 | 5587 | |
| @@ -5509,12 +5616,8 @@ which is the value to be added to the buffer. · 28 unmodified lines | ||
| 5509 | 5616 | |
| 5510 | 5617 | <p> |
| 5511 | 5618 | Checks whether <code>cond</code> is true. |
| 5512 | −If not, raises an error with the following message, | |
| 5513 | −where <code>func</code> is retrieved from the call stack: | |
| 5619 | +If not, raises an error with a standard message. | |
| 5514 | 5620 | |
| 5515 | −<pre> | |
| 5516 | − bad argument #<narg> to <func> (<extramsg>) | |
| 5517 | −</pre> | |
| 5518 | 5621 | |
| 5519 | 5622 | |
| 5520 | 5623 | |
| @@ -5524,12 +5627,9 @@ where <code>func</code> is retrieved from the call stack: · 3 unmodified lines | ||
| 5524 | 5627 | <pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre> |
| 5525 | 5628 | |
| 5526 | 5629 | <p> |
| 5527 | −Raises an error with the following message, | |
| 5528 | −where <code>func</code> is retrieved from the call stack: | |
| 5630 | +Raises an error with a standard message | |
| 5631 | +that includes <code>extramsg</code> as a comment. | |
| 5529 | 5632 | |
| 5530 | −<pre> | |
| 5531 | − bad argument #<narg> to <func> (<extramsg>) | |
| 5532 | −</pre> | |
| 5533 | 5633 | |
| 5534 | 5634 | <p> |
| 5535 | 5635 | This function never returns, |
| @@ -5553,17 +5653,17 @@ Its pattern of use is as follows: · 17 unmodified lines | ||
| 5553 | 5653 | |
| 5554 | 5654 | <ul> |
| 5555 | 5655 | |
| 5556 | −<li>First you declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li> | |
| 5656 | +<li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li> | |
| 5557 | 5657 | |
| 5558 | −<li>Then you initialize it with a call <code>luaL_buffinit(L, &b)</code>.</li> | |
| 5658 | +<li>Then initialize it with a call <code>luaL_buffinit(L, &b)</code>.</li> | |
| 5559 | 5659 | |
| 5560 | 5660 | <li> |
| 5561 | −Then you add string pieces to the buffer calling any of | |
| 5661 | +Then add string pieces to the buffer calling any of | |
| 5562 | 5662 | the <code>luaL_add*</code> functions. |
| 5563 | 5663 | </li> |
| 5564 | 5664 | |
| 5565 | 5665 | <li> |
| 5566 | −You finish by calling <code>luaL_pushresult(&b)</code>. | |
| 5666 | +Finish by calling <code>luaL_pushresult(&b)</code>. | |
| 5567 | 5667 | This call leaves the final string on the top of the stack. |
| 5568 | 5668 | </li> |
| 5569 | 5669 | |
| @@ -5575,15 +5675,15 @@ you can use the buffer like this: · 5 unmodified lines | ||
| 5575 | 5675 | |
| 5576 | 5676 | <ul> |
| 5577 | 5677 | |
| 5578 | −<li>First you declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li> | |
| 5678 | +<li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>.</li> | |
| 5579 | 5679 | |
| 5580 | −<li>Then you initialize it and preallocate a space of | |
| 5680 | +<li>Then initialize it and preallocate a space of | |
| 5581 | 5681 | size <code>sz</code> with a call <code>luaL_buffinitsize(L, &b, sz)</code>.</li> |
| 5582 | 5682 | |
| 5583 | −<li>Then you copy the string into that space.</li> | |
| 5683 | +<li>Then copy the string into that space.</li> | |
| 5584 | 5684 | |
| 5585 | 5685 | <li> |
| 5586 | −You finish by calling <code>luaL_pushresult(&b, sz)</code>, | |
| 5686 | +Finish by calling <code>luaL_pushresult(&b, sz)</code>, | |
| 5587 | 5687 | where <code>sz</code> is the total size of the resulting string |
| 5588 | 5688 | copied into that space. |
| 5589 | 5689 | </li> |
| @@ -5611,7 +5711,7 @@ plus the final string on its top. · 21 unmodified lines | ||
| 5611 | 5711 | |
| 5612 | 5712 | |
| 5613 | 5713 | <hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p> |
| 5614 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5714 | +<span class="apii">[-0, +0, –]</span> | |
| 5615 | 5715 | <pre>void luaL_buffinit (lua_State *L, luaL_Buffer *B);</pre> |
| 5616 | 5716 | |
| 5617 | 5717 | <p> |
| @@ -5647,7 +5747,7 @@ Calls a metamethod. · 29 unmodified lines | ||
| 5647 | 5747 | <p> |
| 5648 | 5748 | If the object at index <code>obj</code> has a metatable and this |
| 5649 | 5749 | metatable has a field <code>e</code>, |
| 5650 | −this function calls this field and passes the object as its only argument. | |
| 5750 | +this function calls this field passing the object as its only argument. | |
| 5651 | 5751 | In this case this function returns true and pushes onto the |
| 5652 | 5752 | stack the value returned by the call. |
| 5653 | 5753 | If there is no metatable or no metamethod, |
| @@ -5755,7 +5855,7 @@ if the string cannot be found. · 101 unmodified lines | ||
| 5755 | 5855 | <p> |
| 5756 | 5856 | If <code>def</code> is not <code>NULL</code>, |
| 5757 | 5857 | the function uses <code>def</code> as a default value when |
| 5758 | −there is no argument <code>narg</code> or if this argument is <b>nil</b>. | |
| 5858 | +there is no argument <code>narg</code> or when this argument is <b>nil</b>. | |
| 5759 | 5859 | |
| 5760 | 5860 | |
| 5761 | 5861 | <p> |
| @@ -5836,7 +5936,7 @@ and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</co · 74 unmodified lines | ||
| 5836 | 5936 | |
| 5837 | 5937 | |
| 5838 | 5938 | <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p> |
| 5839 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 5939 | +<span class="apii">[-0, +0, –]</span> | |
| 5840 | 5940 | <pre>void luaL_checkversion (lua_State *L);</pre> |
| 5841 | 5941 | |
| 5842 | 5942 | <p> |
| @@ -5870,7 +5970,7 @@ or true in case of errors. · 27 unmodified lines | ||
| 5870 | 5970 | |
| 5871 | 5971 | |
| 5872 | 5972 | <hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p> |
| 5873 | −<span class="apii">[-0, +?, <em>-</em>]</span> | |
| 5973 | +<span class="apii">[-0, +?, –]</span> | |
| 5874 | 5974 | <pre>int luaL_dostring (lua_State *L, const char *str);</pre> |
| 5875 | 5975 | |
| 5876 | 5976 | <p> |
| @@ -5952,7 +6052,7 @@ returns false and pushes nothing. · 75 unmodified lines | ||
| 5952 | 6052 | |
| 5953 | 6053 | |
| 5954 | 6054 | <hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p> |
| 5955 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 6055 | +<span class="apii">[-0, +1, –]</span> | |
| 5956 | 6056 | <pre>void luaL_getmetatable (lua_State *L, const char *tname);</pre> |
| 5957 | 6057 | |
| 5958 | 6058 | <p> |
| @@ -6012,7 +6112,7 @@ Raises an error if the result of the operation is not a number. · 53 unmodified lines | ||
| 6012 | 6112 | |
| 6013 | 6113 | |
| 6014 | 6114 | <hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p> |
| 6015 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 6115 | +<span class="apii">[-0, +1, –]</span> | |
| 6016 | 6116 | <pre>int luaL_loadbuffer (lua_State *L, |
| 6017 | 6117 | const char *buff, |
| 6018 | 6118 | size_t sz, |
| @@ -6035,7 +6135,16 @@ used for debug information and error messages. · 16 unmodified lines | ||
| 6035 | 6135 | |
| 6036 | 6136 | <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p> |
| 6037 | 6137 | <span class="apii">[-0, +1, <em>m</em>]</span> |
| 6038 | −<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre> | |
| 6138 | +<pre>int luaL_loadfile (lua_State *L, const char *filename);</pre><p> | |
| 6139 | +Equivalent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal to <code>NULL</code>. | |
| 6140 | + | |
| 6141 | + | |
| 6142 | + | |
| 6143 | + | |
| 6144 | +<hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p> | |
| 6145 | +<span class="apii">[-0, +1, <em>m</em>]</span> | |
| 6146 | +<pre>int luaL_loadfilex (lua_State *L, const char *filename, | |
| 6147 | + const char *mode);</pre> | |
| 6039 | 6148 | |
| 6040 | 6149 | <p> |
| 6041 | 6150 | Loads a file as a Lua chunk. |
| @@ -6046,10 +6155,16 @@ then it loads from the standard input. · 4 unmodified lines | ||
| 6046 | 6155 | The first line in the file is ignored if it starts with a <code>#</code>. |
| 6047 | 6156 | |
| 6048 | 6157 | |
| 6158 | +<p> | |
| 6159 | +The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>, | |
| 6160 | +with the addition that | |
| 6161 | +a <code>NULL</code> value is equivalent to the string "<code>bt</code>". | |
| 6162 | + | |
| 6163 | + | |
| 6049 | 6164 | <p> |
| 6050 | 6165 | This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>, |
| 6051 | 6166 | but it has an extra error code <a name="pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a> |
| 6052 | −if it cannot open/read the file. | |
| 6167 | +if it cannot open/read the file or the file has a wrong mode. | |
| 6053 | 6168 | |
| 6054 | 6169 | |
| 6055 | 6170 | <p> |
| @@ -6061,7 +6176,7 @@ it does not run it. · 5 unmodified lines | ||
| 6061 | 6176 | |
| 6062 | 6177 | |
| 6063 | 6178 | <hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p> |
| 6064 | −<span class="apii">[-0, +1, <em>-</em>]</span> | |
| 6179 | +<span class="apii">[-0, +1, –]</span> | |
| 6065 | 6180 | <pre>int luaL_loadstring (lua_State *L, const char *s);</pre> |
| 6066 | 6181 | |
| 6067 | 6182 | <p> |
| @@ -6141,7 +6256,7 @@ with <code>tname</code> in the registry. · 73 unmodified lines | ||
| 6141 | 6256 | |
| 6142 | 6257 | |
| 6143 | 6258 | <hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p> |
| 6144 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 6259 | +<span class="apii">[-0, +0, –]</span> | |
| 6145 | 6260 | <pre>lua_State *luaL_newstate (void);</pre> |
| 6146 | 6261 | |
| 6147 | 6262 | <p> |
| @@ -6434,7 +6549,7 @@ These values are popped from the stack after the registration. · 286 unmodified lines | ||
| 6434 | 6549 | |
| 6435 | 6550 | |
| 6436 | 6551 | <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p> |
| 6437 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 6552 | +<span class="apii">[-0, +0, –]</span> | |
| 6438 | 6553 | <pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre> |
| 6439 | 6554 | |
| 6440 | 6555 | <p> |
| @@ -6499,7 +6614,7 @@ to start the traceback. · 58 unmodified lines | ||
| 6499 | 6614 | |
| 6500 | 6615 | |
| 6501 | 6616 | <hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p> |
| 6502 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 6617 | +<span class="apii">[-0, +0, –]</span> | |
| 6503 | 6618 | <pre>const char *luaL_typename (lua_State *L, int index);</pre> |
| 6504 | 6619 | |
| 6505 | 6620 | <p> |
| @@ -6510,7 +6625,7 @@ Returns the name of the type of the value at the given index. · 4 unmodified lines | ||
| 6510 | 6625 | |
| 6511 | 6626 | |
| 6512 | 6627 | <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p> |
| 6513 | −<span class="apii">[-0, +0, <em>-</em>]</span> | |
| 6628 | +<span class="apii">[-0, +0, –]</span> | |
| 6514 | 6629 | <pre>void luaL_unref (lua_State *L, int t, int ref);</pre> |
| 6515 | 6630 | |
| 6516 | 6631 | <p> |
| @@ -6575,28 +6690,28 @@ Currently, Lua has the following standard libraries: · 58 unmodified lines | ||
| 6575 | 6690 | |
| 6576 | 6691 | <ul> |
| 6577 | 6692 | |
| 6578 | −<li>basic library;</li> | |
| 6693 | +<li>basic library (<a href="#6.1">§6.1</a>);</li> | |
| 6579 | 6694 | |
| 6580 | −<li>package library;</li> | |
| 6695 | +<li>coroutine library (<a href="#6.2">§6.2</a>);</li> | |
| 6581 | 6696 | |
| 6582 | −<li>coroutine library;</li> | |
| 6697 | +<li>package library (<a href="#6.3">§6.3</a>);</li> | |
| 6583 | 6698 | |
| 6584 | −<li>string manipulation;</li> | |
| 6699 | +<li>string manipulation (<a href="#6.4">§6.4</a>);</li> | |
| 6585 | 6700 | |
| 6586 | −<li>table manipulation;</li> | |
| 6701 | +<li>table manipulation (<a href="#6.5">§6.5</a>);</li> | |
| 6587 | 6702 | |
| 6588 | −<li>mathematical functions (sin, log, etc.);</li> | |
| 6703 | +<li>mathematical functions (<a href="#6.6">§6.6</a>) (sin, log, etc.);</li> | |
| 6589 | 6704 | |
| 6590 | −<li>bitwise operations;</li> | |
| 6705 | +<li>bitwise operations (<a href="#6.7">§6.7</a>);</li> | |
| 6591 | 6706 | |
| 6592 | −<li>input and output;</li> | |
| 6707 | +<li>input and output (<a href="#6.8">§6.8</a>);</li> | |
| 6593 | 6708 | |
| 6594 | −<li>operating system facilities;</li> | |
| 6709 | +<li>operating system facilities (<a href="#6.9">§6.9</a>);</li> | |
| 6595 | 6710 | |
| 6596 | −<li>debug facilities.</li> | |
| 6711 | +<li>debug facilities (<a href="#6.10">§6.10</a>).</li> | |
| 6597 | 6712 | |
| 6598 | 6713 | </ul><p> |
| 6599 | −Except for the basic and package libraries, | |
| 6714 | +Except for the basic and the package libraries, | |
| 6600 | 6715 | each library provides all its functions as fields of a global table |
| 6601 | 6716 | or as methods of its objects. |
| 6602 | 6717 | |
| @@ -6627,7 +6742,7 @@ e.g., by using <a href="#lua_call"><code>lua_call</code></a>. · 24 unmodified lines | ||
| 6627 | 6742 | <h2>6.1 – <a name="6.1">Basic Functions</a></h2> |
| 6628 | 6743 | |
| 6629 | 6744 | <p> |
| 6630 | −The basic library provides some core functions to Lua. | |
| 6745 | +The basic library provides core functions to Lua. | |
| 6631 | 6746 | If you do not include this library in your application, |
| 6632 | 6747 | you should check carefully whether you need to provide |
| 6633 | 6748 | implementations for some of its facilities. |
| @@ -6660,13 +6775,13 @@ This is the default option. · 26 unmodified lines | ||
| 6660 | 6775 | </li> |
| 6661 | 6776 | |
| 6662 | 6777 | <li><b>"<code>stop</code>": </b> |
| 6663 | −stops automatic invocation of the garbage collector. | |
| 6664 | −The collector will run only when explcitly invoked, | |
| 6778 | +stops automatic execution of the garbage collector. | |
| 6779 | +The collector will run only when explicitly invoked, | |
| 6665 | 6780 | until a call to restart it. |
| 6666 | 6781 | </li> |
| 6667 | 6782 | |
| 6668 | 6783 | <li><b>"<code>restart</code>": </b> |
| 6669 | −restarts automatic invocation the garbage collector. | |
| 6784 | +restarts automatic execution of the garbage collector. | |
| 6670 | 6785 | </li> |
| 6671 | 6786 | |
| 6672 | 6787 | <li><b>"<code>count</code>": </b> |
| @@ -6709,6 +6824,16 @@ returns a boolean that tells whether the collector is running · 36 unmodified lines | ||
| 6709 | 6824 | (i.e., not stopped). |
| 6710 | 6825 | </li> |
| 6711 | 6826 | |
| 6827 | +<li><b>"<code>generational</code>": </b> | |
| 6828 | +changes the collector to generational mode. | |
| 6829 | +This is an experimental feature (see <a href="#2.5">§2.5</a>). | |
| 6830 | +</li> | |
| 6831 | + | |
| 6832 | +<li><b>"<code>incremental</code>": </b> | |
| 6833 | +changes the collector to incremental mode. | |
| 6834 | +This is the default mode. | |
| 6835 | +</li> | |
| 6836 | + | |
| 6712 | 6837 | </ul> |
| 6713 | 6838 | |
| 6714 | 6839 | |
| @@ -6789,7 +6914,7 @@ so that the construction · 74 unmodified lines | ||
| 6789 | 6914 | <pre> |
| 6790 | 6915 | for i,v in ipairs(t) do <em>body</em> end |
| 6791 | 6916 | </pre><p> |
| 6792 | −will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ···, | |
| 6917 | +will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ..., | |
| 6793 | 6918 | up to the first integer key absent from the table. |
| 6794 | 6919 | |
| 6795 | 6920 | |
| @@ -6823,8 +6948,8 @@ If the resulting function has upvalues, · 27 unmodified lines | ||
| 6823 | 6948 | the first upvalue is set to the value of the |
| 6824 | 6949 | global environment or to <code>env</code>, |
| 6825 | 6950 | if that parameter is given. |
| 6826 | −(When loading main chunks, | |
| 6827 | −the first upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>).) | |
| 6951 | +When loading main chunks, | |
| 6952 | +the first upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>). | |
| 6828 | 6953 | |
| 6829 | 6954 | |
| 6830 | 6955 | <p> |
| @@ -6832,21 +6957,22 @@ the first upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&se · 1 unmodified line | ||
| 6832 | 6957 | and debug information (see <a href="#4.9">§4.9</a>). |
| 6833 | 6958 | When absent, |
| 6834 | 6959 | it defaults to <code>ld</code>, if <code>ld</code> is a string, |
| 6835 | −or to "<code>=(load)</code>". | |
| 6960 | +or to "<code>=(load)</code>" otherwise. | |
| 6836 | 6961 | |
| 6837 | 6962 | |
| 6838 | 6963 | <p> |
| 6839 | 6964 | The string <code>mode</code> controls whether the chunk can be text or binary |
| 6840 | 6965 | (that is, a precompiled chunk). |
| 6841 | −A letter '<code>t</code>' in <code>mode</code> allows a text chunk; | |
| 6842 | −a letter '<code>b</code>' allows a binary chunk. | |
| 6966 | +It may be the string "<code>b</code>" (only binary chunks), | |
| 6967 | +"<code>t</code>" (only text chunks), | |
| 6968 | +or "<code>bt</code>" (both binary and text). | |
| 6843 | 6969 | The default is "<code>bt</code>". |
| 6844 | 6970 | |
| 6845 | 6971 | |
| 6846 | 6972 | |
| 6847 | 6973 | |
| 6848 | 6974 | <p> |
| 6849 | −<hr><h3><a name="pdf-loadfile"><code>loadfile ([filename])</code></a></h3> | |
| 6975 | +<hr><h3><a name="pdf-loadfile"><code>loadfile ([filename [, mode [, env]]])</code></a></h3> | |
| 6850 | 6976 | |
| 6851 | 6977 | |
| 6852 | 6978 | <p> |
| @@ -6945,13 +7071,14 @@ In case of any error, <code>pcall</code> returns <b>false</b> plus the error mes · 92 unmodified lines | ||
| 6945 | 7071 | |
| 6946 | 7072 | <p> |
| 6947 | 7073 | <hr><h3><a name="pdf-print"><code>print (···)</code></a></h3> |
| 6948 | −Receives any number of arguments, | |
| 7074 | +Receives any number of arguments | |
| 6949 | 7075 | and prints their values to <code>stdout</code>, |
| 6950 | −using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings. | |
| 7076 | +using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert each argument to a string. | |
| 6951 | 7077 | <code>print</code> is not intended for formatted output, |
| 6952 | 7078 | but only as a quick way to show a value, |
| 6953 | −typically for debugging. | |
| 6954 | −For formatted output, use <a href="#pdf-string.format"><code>string.format</code></a>. | |
| 7079 | +for instance for debugging. | |
| 7080 | +For complete control over the output, | |
| 7081 | +use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>io.write</code></a>. | |
| 6955 | 7082 | |
| 6956 | 7083 | |
| 6957 | 7084 | |
| @@ -6990,7 +7117,7 @@ Returns an integer number. · 32 unmodified lines | ||
| 6990 | 7117 | Sets the real value of <code>table[index]</code> to <code>value</code>, |
| 6991 | 7118 | without invoking any metamethod. |
| 6992 | 7119 | <code>table</code> must be a table, |
| 6993 | −<code>index</code> any value different from <b>nil</b>, | |
| 7120 | +<code>index</code> any value different from <b>nil</b> and NaN, | |
| 6994 | 7121 | and <code>value</code> any Lua value. |
| 6995 | 7122 | |
| 6996 | 7123 | |
| @@ -7035,37 +7162,43 @@ This function returns <code>table</code>. · 38 unmodified lines | ||
| 7035 | 7162 | |
| 7036 | 7163 | <p> |
| 7037 | 7164 | <hr><h3><a name="pdf-tonumber"><code>tonumber (e [, base])</code></a></h3> |
| 7038 | −Tries to convert its argument to a number. | |
| 7039 | −If the argument is already a number or a string convertible | |
| 7040 | −to a number, then <code>tonumber</code> returns this number; | |
| 7165 | + | |
| 7166 | + | |
| 7167 | +<p> | |
| 7168 | +When called with no <code>base</code>, | |
| 7169 | +<code>tonumber</code> tries to convert its argument to a number. | |
| 7170 | +If the argument is already a number or | |
| 7171 | +a string convertible to a number (see <a href="#3.4.2">§3.4.2</a>), | |
| 7172 | +then <code>tonumber</code> returns this number; | |
| 7041 | 7173 | otherwise, it returns <b>nil</b>. |
| 7042 | 7174 | |
| 7043 | 7175 | |
| 7044 | 7176 | <p> |
| 7045 | −An optional argument specifies the base to interpret the numeral. | |
| 7177 | +When called with <code>base</code>, | |
| 7178 | +then <code>e</code> should be a string to be interpreted as | |
| 7179 | +an integer numeral in that base. | |
| 7046 | 7180 | The base may be any integer between 2 and 36, inclusive. |
| 7047 | 7181 | In bases above 10, the letter '<code>A</code>' (in either upper or lower case) |
| 7048 | 7182 | represents 10, '<code>B</code>' represents 11, and so forth, |
| 7049 | 7183 | with '<code>Z</code>' representing 35. |
| 7050 | −In base 10 (the default), | |
| 7051 | −the numeral is converted following the coercion rules (see <a href="#3.4.2">§3.4.2</a>). | |
| 7052 | −In other bases, only integers are accepted. | |
| 7184 | +If the string <code>e</code> is not a valid numeral in the given base, | |
| 7185 | +the function returns <b>nil</b>. | |
| 7053 | 7186 | |
| 7054 | 7187 | |
| 7055 | 7188 | |
| 7056 | 7189 | |
| 7057 | 7190 | <p> |
| 7058 | −<hr><h3><a name="pdf-tostring"><code>tostring (e)</code></a></h3> | |
| 7059 | −Receives an argument of any type and | |
| 7191 | +<hr><h3><a name="pdf-tostring"><code>tostring (v)</code></a></h3> | |
| 7192 | +Receives a value of any type and | |
| 7060 | 7193 | converts it to a string in a reasonable format. |
| 7061 | −For complete control of how numbers are converted, | |
| 7062 | −use <a href="#pdf-string.format"><code>string.format</code></a>. | |
| 7194 | +(For complete control of how numbers are converted, | |
| 7195 | +use <a href="#pdf-string.format"><code>string.format</code></a>.) | |
| 7063 | 7196 | |
| 7064 | 7197 | |
| 7065 | 7198 | <p> |
| 7066 | −If the metatable of <code>e</code> has a <code>"__tostring"</code> field, | |
| 7199 | +If the metatable of <code>v</code> has a <code>"__tostring"</code> field, | |
| 7067 | 7200 | then <code>tostring</code> calls the corresponding value |
| 7068 | −with <code>e</code> as argument, | |
| 7201 | +with <code>v</code> as argument, | |
| 7069 | 7202 | and uses the result of the call as its result. |
| 7070 | 7203 | |
| 7071 | 7204 | |
| @@ -7139,11 +7272,11 @@ an object with type <code>"thread"</code>. · 67 unmodified lines | ||
| 7139 | 7272 | Starts or continues the execution of coroutine <code>co</code>. |
| 7140 | 7273 | The first time you resume a coroutine, |
| 7141 | 7274 | it starts running its body. |
| 7142 | −The values <code>val1</code>, ··· are passed | |
| 7275 | +The values <code>val1</code>, ... are passed | |
| 7143 | 7276 | as the arguments to the body function. |
| 7144 | 7277 | If the coroutine has yielded, |
| 7145 | 7278 | <code>resume</code> restarts it; |
| 7146 | −the values <code>val1</code>, ··· are passed | |
| 7279 | +the values <code>val1</code>, ... are passed | |
| 7147 | 7280 | as the results from the yield. |
| 7148 | 7281 | |
| 7149 | 7282 | |
| @@ -7280,7 +7413,7 @@ final value of <code>package.loaded[modname]</code>. · 130 unmodified lines | ||
| 7280 | 7413 | <p> |
| 7281 | 7414 | If there is any error loading or running the module, |
| 7282 | 7415 | or if it cannot find any loader for the module, |
| 7283 | −then <code>require</code> signals an error. | |
| 7416 | +then <code>require</code> raises an error. | |
| 7284 | 7417 | |
| 7285 | 7418 | |
| 7286 | 7419 | |
| @@ -7309,8 +7442,8 @@ Default is '<code>?</code>'.</li> · 22 unmodified lines | ||
| 7309 | 7442 | is replaced by the executable's directory. |
| 7310 | 7443 | Default is '<code>!</code>'.</li> |
| 7311 | 7444 | |
| 7312 | −<li>The fifth line is a mark to ignore all before it when building the | |
| 7313 | −<code>luaopen_</code> function name. | |
| 7445 | +<li>The fifth line is a mark to ignore all text before it | |
| 7446 | +when building the <code>luaopen_</code> function name. | |
| 7314 | 7447 | Default is '<code>-</code>'.</li> |
| 7315 | 7448 | |
| 7316 | 7449 | </ul> |
| @@ -7372,7 +7505,7 @@ available to other dynamically linked libraries. · 55 unmodified lines | ||
| 7372 | 7505 | Otherwise, |
| 7373 | 7506 | it looks for a function <code>funcname</code> inside the library |
| 7374 | 7507 | and returns this function as a C function. |
| 7375 | −(So, <code>funcname</code> must follow the protocol (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>)). | |
| 7508 | +(So, <code>funcname</code> must follow the prototype <a href="#lua_CFunction"><code>lua_CFunction</code></a>). | |
| 7376 | 7509 | |
| 7377 | 7510 | |
| 7378 | 7511 | <p> |
| @@ -7409,7 +7542,7 @@ At start-up, Lua initializes this variable with · 30 unmodified lines | ||
| 7409 | 7542 | the value of the environment variable <a name="pdf-LUA_PATH_5_2"><code>LUA_PATH_5_2</code></a> or |
| 7410 | 7543 | the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or |
| 7411 | 7544 | with a default path defined in <code>luaconf.h</code>, |
| 7412 | −if the environment variable is not defined. | |
| 7545 | +if those environment variables are not defined. | |
| 7413 | 7546 | Any "<code>;;</code>" in the value of the environment variable |
| 7414 | 7547 | is replaced by the default path. |
| 7415 | 7548 | |
| @@ -7511,7 +7644,7 @@ with each submodule keeping its original open function. · 95 unmodified lines | ||
| 7511 | 7644 | |
| 7512 | 7645 | |
| 7513 | 7646 | <p> |
| 7514 | −All searchers except the first (preload) return as the extra value | |
| 7647 | +All searchers except the first one (preload) return as the extra value | |
| 7515 | 7648 | the file name where the module was found, |
| 7516 | 7649 | as returned by <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>. |
| 7517 | 7650 | The first searcher returns no extra value. |
| @@ -7520,7 +7653,7 @@ The first searcher returns no extra value. · 2 unmodified lines | ||
| 7520 | 7653 | |
| 7521 | 7654 | |
| 7522 | 7655 | <p> |
| 7523 | −<hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep])</code></a></h3> | |
| 7656 | +<hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep [, rep]])</code></a></h3> | |
| 7524 | 7657 | |
| 7525 | 7658 | |
| 7526 | 7659 | <p> |
| @@ -7528,17 +7661,16 @@ Searches for the given <code>name</code> in the given <code>path</code>. · 1 unmodified line | ||
| 7528 | 7661 | |
| 7529 | 7662 | |
| 7530 | 7663 | <p> |
| 7531 | −A path is string containing a sequence of | |
| 7664 | +A path is a string containing a sequence of | |
| 7532 | 7665 | <em>templates</em> separated by semicolons. |
| 7533 | 7666 | For each template, |
| 7534 | −the function changes each interrogation | |
| 7535 | −mark in the template by a copy of <code>name</code> | |
| 7667 | +the function replaces each interrogation mark (if any) | |
| 7668 | +in the template with a copy of <code>name</code> | |
| 7536 | 7669 | wherein all occurrences of <code>sep</code> |
| 7537 | 7670 | (a dot, by default) |
| 7538 | −were replaced by the system's directory separator, | |
| 7671 | +were replaced by <code>rep</code> | |
| 7672 | +(the system's directory separator, by default), | |
| 7539 | 7673 | and then tries to open the resulting file name. |
| 7540 | −If <code>sep</code> is the empty string, | |
| 7541 | −the replacement is not done. | |
| 7542 | 7674 | |
| 7543 | 7675 | |
| 7544 | 7676 | <p> |
| @@ -7583,7 +7715,7 @@ The string library provides all its functions inside the table · 38 unmodified lines | ||
| 7583 | 7715 | It also sets a metatable for strings |
| 7584 | 7716 | where the <code>__index</code> field points to the <code>string</code> table. |
| 7585 | 7717 | Therefore, you can use the string functions in object-oriented style. |
| 7586 | −For instance, <code>string.byte(s, i)</code> | |
| 7718 | +For instance, <code>string.byte(s,i)</code> | |
| 7587 | 7719 | can be written as <code>s:byte(i)</code>. |
| 7588 | 7720 | |
| 7589 | 7721 | |
| @@ -7594,13 +7726,15 @@ The string library assumes one-byte character encodings. · 4 unmodified lines | ||
| 7594 | 7726 | <p> |
| 7595 | 7727 | <hr><h3><a name="pdf-string.byte"><code>string.byte (s [, i [, j]])</code></a></h3> |
| 7596 | 7728 | Returns the internal numerical codes of the characters <code>s[i]</code>, |
| 7597 | −<code>s[i+1]</code>, ···, <code>s[j]</code>. | |
| 7729 | +<code>s[i+1]</code>, ..., <code>s[j]</code>. | |
| 7598 | 7730 | The default value for <code>i</code> is 1; |
| 7599 | 7731 | the default value for <code>j</code> is <code>i</code>. |
| 7732 | +These indices are corrected | |
| 7733 | +following the same rules of function <a href="#pdf-string.sub"><code>string.sub</code></a>. | |
| 7600 | 7734 | |
| 7601 | 7735 | |
| 7602 | 7736 | <p> |
| 7603 | −Note that numerical codes are not necessarily portable across platforms. | |
| 7737 | +Numerical codes are not necessarily portable across platforms. | |
| 7604 | 7738 | |
| 7605 | 7739 | |
| 7606 | 7740 | |
| @@ -7614,7 +7748,7 @@ to its corresponding argument. · 7 unmodified lines | ||
| 7614 | 7748 | |
| 7615 | 7749 | |
| 7616 | 7750 | <p> |
| 7617 | −Note that numerical codes are not necessarily portable across platforms. | |
| 7751 | +Numerical codes are not necessarily portable across platforms. | |
| 7618 | 7752 | |
| 7619 | 7753 | |
| 7620 | 7754 | |
| @@ -7709,7 +7843,7 @@ it is converted to one following the same rules of <a href="#pdf-tostring"><code · 88 unmodified lines | ||
| 7709 | 7843 | <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern)</code></a></h3> |
| 7710 | 7844 | Returns an iterator function that, |
| 7711 | 7845 | each time it is called, |
| 7712 | −returns the next captures from <code>pattern</code> over string <code>s</code>. | |
| 7846 | +returns the next captures from <code>pattern</code> over the string <code>s</code>. | |
| 7713 | 7847 | If <code>pattern</code> specifies no captures, |
| 7714 | 7848 | then the whole match is produced in each call. |
| 7715 | 7849 | |
| @@ -7737,7 +7871,7 @@ given string into a table: · 21 unmodified lines | ||
| 7737 | 7871 | </pre> |
| 7738 | 7872 | |
| 7739 | 7873 | <p> |
| 7740 | −For this function, a '<code>^</code>' at the start of a pattern does not | |
| 7874 | +For this function, a caret '<code>^</code>' at the start of a pattern does not | |
| 7741 | 7875 | work as an anchor, as this would prevent the iteration. |
| 7742 | 7876 | |
| 7743 | 7877 | |
| @@ -7884,6 +8018,17 @@ and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code> · 140 unmodified lines | ||
| 7884 | 8018 | with length <code>i</code>. |
| 7885 | 8019 | |
| 7886 | 8020 | |
| 8021 | +<p> | |
| 8022 | +If, after the translation of negative indices, | |
| 8023 | +<code>i</code> is less than zero, | |
| 8024 | +it is corrected to zero. | |
| 8025 | +If <code>j</code> is greater than the string length, | |
| 8026 | +it is corrected to that length. | |
| 8027 | +If, after these corrections, | |
| 8028 | +<code>i</code> is greater than <code>j</code>, | |
| 8029 | +the function returns the empty string. | |
| 8030 | + | |
| 8031 | + | |
| 7887 | 8032 | |
| 7888 | 8033 | |
| 7889 | 8034 | <p> |
| @@ -8050,7 +8195,7 @@ they were the character '<code>\0</code>'. · 160 unmodified lines | ||
| 8050 | 8195 | |
| 8051 | 8196 | <h4>Pattern:</h4><p> |
| 8052 | 8197 | A <em>pattern</em> is a sequence of pattern items. |
| 8053 | −A '<code>^</code>' at the beginning of a pattern anchors the match at the | |
| 8198 | +A caret '<code>^</code>' at the beginning of a pattern anchors the match at the | |
| 8054 | 8199 | beginning of the subject string. |
| 8055 | 8200 | A '<code>$</code>' at the end of a pattern anchors the match at the |
| 8056 | 8201 | end of the subject string. |
| @@ -8589,7 +8734,7 @@ result in zero or <code>0xFFFFFFFF</code> (all original bits are shifted out). · 532 unmodified lines | ||
| 8589 | 8734 | |
| 8590 | 8735 | |
| 8591 | 8736 | <p> |
| 8592 | −Returns the bitwise and of its operands. | |
| 8737 | +Returns the bitwise <em>and</em> of its operands. | |
| 8593 | 8738 | |
| 8594 | 8739 | |
| 8595 | 8740 | |
| @@ -8614,7 +8759,7 @@ the following identity holds: · 18 unmodified lines | ||
| 8614 | 8759 | |
| 8615 | 8760 | |
| 8616 | 8761 | <p> |
| 8617 | −Returns the bitwise or of its operands. | |
| 8762 | +Returns the bitwise <em>or</em> of its operands. | |
| 8618 | 8763 | |
| 8619 | 8764 | |
| 8620 | 8765 | |
| @@ -8625,7 +8770,7 @@ Returns the bitwise or of its operands. · 4 unmodified lines | ||
| 8625 | 8770 | |
| 8626 | 8771 | <p> |
| 8627 | 8772 | Returns a boolean signaling |
| 8628 | −whether the bitwise and of its operands is different from zero. | |
| 8773 | +whether the bitwise <em>and</em> of its operands is different from zero. | |
| 8629 | 8774 | |
| 8630 | 8775 | |
| 8631 | 8776 | |
| @@ -8635,7 +8780,7 @@ whether the bitwise and of its operands is different from zero. · 3 unmodified lines | ||
| 8635 | 8780 | |
| 8636 | 8781 | |
| 8637 | 8782 | <p> |
| 8638 | −Returns the bitwise exclusive or of its operands. | |
| 8783 | +Returns the bitwise <em>exclusive or</em> of its operands. | |
| 8639 | 8784 | |
| 8640 | 8785 | |
| 8641 | 8786 | |
| @@ -8845,7 +8990,7 @@ instead of returning an error code. · 203 unmodified lines | ||
| 8845 | 8990 | |
| 8846 | 8991 | |
| 8847 | 8992 | <p> |
| 8848 | −<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] ···)</code></a></h3> | |
| 8993 | +<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename ···])</code></a></h3> | |
| 8849 | 8994 | |
| 8850 | 8995 | |
| 8851 | 8996 | <p> |
| @@ -8863,6 +9008,11 @@ that is, it iterates over the lines of the default input file. · 11 unmodified lines | ||
| 8863 | 9008 | In this case it does not close the file when the loop ends. |
| 8864 | 9009 | |
| 8865 | 9010 | |
| 9011 | +<p> | |
| 9012 | +In case of errors this function raises the error, | |
| 9013 | +instead of returning an error code. | |
| 9014 | + | |
| 9015 | + | |
| 8866 | 9016 | |
| 8867 | 9017 | |
| 8868 | 9018 | <p> |
| @@ -9007,15 +9157,20 @@ each time it is called, · 138 unmodified lines | ||
| 9007 | 9157 | reads the file according to the given formats. |
| 9008 | 9158 | When no format is given, |
| 9009 | 9159 | uses "*l" as a default. |
| 9010 | −Therefore, the construction | |
| 9160 | +As an example, the construction | |
| 9011 | 9161 | |
| 9012 | 9162 | <pre> |
| 9013 | 9163 | for c in file:lines(1) do <em>body</em> end |
| 9014 | 9164 | </pre><p> |
| 9015 | 9165 | will iterate over all characters of the file, |
| 9016 | 9166 | starting at the current position. |
| 9017 | −(Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file | |
| 9018 | −when the loop ends.) | |
| 9167 | +Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file | |
| 9168 | +when the loop ends. | |
| 9169 | + | |
| 9170 | + | |
| 9171 | +<p> | |
| 9172 | +In case of errors this function raises the error, | |
| 9173 | +instead of returning an error code. | |
| 9019 | 9174 | |
| 9020 | 9175 | |
| 9021 | 9176 | |
| @@ -9062,7 +9217,7 @@ returning <b>nil</b> on end of file. · 40 unmodified lines | ||
| 9062 | 9217 | </li> |
| 9063 | 9218 | |
| 9064 | 9219 | <li><b><em>number</em>: </b> |
| 9065 | −reads a string with up to this number of characters, | |
| 9220 | +reads a string with up to this number of bytes, | |
| 9066 | 9221 | returning <b>nil</b> on end of file. |
| 9067 | 9222 | If number is zero, |
| 9068 | 9223 | it reads nothing and returns an empty string, |
| @@ -9088,9 +9243,9 @@ specified by the string <code>whence</code>, as follows: · 19 unmodified lines | ||
| 9088 | 9243 | <li><b>"<code>cur</code>": </b> base is current position;</li> |
| 9089 | 9244 | <li><b>"<code>end</code>": </b> base is end of file;</li> |
| 9090 | 9245 | </ul><p> |
| 9091 | −In case of success, function <code>seek</code> returns the final file position, | |
| 9246 | +In case of success, <code>seek</code> returns the final file position, | |
| 9092 | 9247 | measured in bytes from the beginning of the file. |
| 9093 | −If this function fails, it returns <b>nil</b>, | |
| 9248 | +If <code>seek</code> fails, it returns <b>nil</b>, | |
| 9094 | 9249 | plus a string describing the error. |
| 9095 | 9250 | |
| 9096 | 9251 | |
| @@ -9123,8 +9278,8 @@ no buffering; the result of any output operation appears immediately. · 26 unmodified lines | ||
| 9123 | 9278 | |
| 9124 | 9279 | <li><b>"<code>full</code>": </b> |
| 9125 | 9280 | full buffering; output operation is performed only |
| 9126 | −when the buffer is full (or when you explicitly <code>flush</code> the file | |
| 9127 | −(see <a href="#pdf-io.flush"><code>io.flush</code></a>)). | |
| 9281 | +when the buffer is full or when | |
| 9282 | +you explicitly <code>flush</code> the file (see <a href="#pdf-io.flush"><code>io.flush</code></a>). | |
| 9128 | 9283 | </li> |
| 9129 | 9284 | |
| 9130 | 9285 | <li><b>"<code>line</code>": </b> |
| @@ -9146,11 +9301,8 @@ The default is an appropriate size. · 15 unmodified lines | ||
| 9146 | 9301 | |
| 9147 | 9302 | |
| 9148 | 9303 | <p> |
| 9149 | −Writes the value of each of its arguments to | |
| 9150 | −the <code>file</code>. | |
| 9304 | +Writes the value of each of its arguments to <code>file</code>. | |
| 9151 | 9305 | The arguments must be strings or numbers. |
| 9152 | −To write other values, | |
| 9153 | −use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.format"><code>string.format</code></a> before <code>write</code>. | |
| 9154 | 9306 | |
| 9155 | 9307 | |
| 9156 | 9308 | <p> |
| @@ -9202,8 +9354,8 @@ then the date is formatted in Coordinated Universal Time. · 45 unmodified lines | ||
| 9202 | 9354 | After this optional character, |
| 9203 | 9355 | if <code>format</code> is the string "<code>*t</code>", |
| 9204 | 9356 | then <code>date</code> returns a table with the following fields: |
| 9205 | −<code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31), | |
| 9206 | −<code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61), | |
| 9357 | +<code>year</code> (four digits), <code>month</code> (1–12), <code>day</code> (1–31), | |
| 9358 | +<code>hour</code> (0–23), <code>min</code> (0–59), <code>sec</code> (0–61), | |
| 9207 | 9359 | <code>wday</code> (weekday, Sunday is 1), |
| 9208 | 9360 | <code>yday</code> (day of the year), |
| 9209 | 9361 | and <code>isdst</code> (daylight saving flag, a boolean). |
| @@ -9314,7 +9466,7 @@ or <b>nil</b> if the variable is not defined. · 104 unmodified lines | ||
| 9314 | 9466 | Deletes the file (or empty directory, on POSIX systems) |
| 9315 | 9467 | with the given name. |
| 9316 | 9468 | If this function fails, it returns <b>nil</b>, |
| 9317 | −plus a string describing the error. | |
| 9469 | +plus a string describing the error and the error code. | |
| 9318 | 9470 | |
| 9319 | 9471 | |
| 9320 | 9472 | |
| @@ -9326,7 +9478,7 @@ plus a string describing the error. · 5 unmodified lines | ||
| 9326 | 9478 | <p> |
| 9327 | 9479 | Renames file or directory named <code>oldname</code> to <code>newname</code>. |
| 9328 | 9480 | If this function fails, it returns <b>nil</b>, |
| 9329 | −plus a string describing the error. | |
| 9481 | +plus a string describing the error and the error code. | |
| 9330 | 9482 | |
| 9331 | 9483 | |
| 9332 | 9484 | |
| @@ -9337,7 +9489,7 @@ plus a string describing the error. · 4 unmodified lines | ||
| 9337 | 9489 | |
| 9338 | 9490 | <p> |
| 9339 | 9491 | Sets the current locale of the program. |
| 9340 | −<code>locale</code> is a string specifying a locale; | |
| 9492 | +<code>locale</code> is a system-dependent string specifying a locale; | |
| 9341 | 9493 | <code>category</code> is an optional string describing which category to change: |
| 9342 | 9494 | <code>"all"</code>, <code>"collate"</code>, <code>"ctype"</code>, |
| 9343 | 9495 | <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>; |
| @@ -9369,8 +9521,12 @@ for the given category. · 25 unmodified lines | ||
| 9369 | 9521 | Returns the current time when called without arguments, |
| 9370 | 9522 | or a time representing the date and time specified by the given table. |
| 9371 | 9523 | This table must have fields <code>year</code>, <code>month</code>, and <code>day</code>, |
| 9372 | −and may have fields <code>hour</code>, <code>min</code>, <code>sec</code>, and <code>isdst</code> | |
| 9373 | −(for a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function). | |
| 9524 | +and may have fields | |
| 9525 | +<code>hour</code> (default is 12), | |
| 9526 | +<code>min</code> (default is 0), | |
| 9527 | +<code>sec</code> (default is 0), | |
| 9528 | +and <code>isdst</code> (default is <b>nil</b>). | |
| 9529 | +For a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function. | |
| 9374 | 9530 | |
| 9375 | 9531 | |
| 9376 | 9532 | <p> |
| @@ -9380,7 +9536,7 @@ this number counts the number · 3 unmodified lines | ||
| 9380 | 9536 | of seconds since some given start time (the "epoch"). |
| 9381 | 9537 | In other systems, the meaning is not specified, |
| 9382 | 9538 | and the number returned by <code>time</code> can be used only as an argument to |
| 9383 | −<code>date</code> and <code>difftime</code>. | |
| 9539 | +<a href="#pdf-os.date"><code>os.date</code></a> and <a href="#pdf-os.difftime"><code>os.difftime</code></a>. | |
| 9384 | 9540 | |
| 9385 | 9541 | |
| 9386 | 9542 | |
| @@ -9421,9 +9577,9 @@ which automatically removes the file when the program ends. · 34 unmodified lines | ||
| 9421 | 9577 | |
| 9422 | 9578 | <p> |
| 9423 | 9579 | This library provides |
| 9424 | −the functionality of the debug interface to Lua programs. | |
| 9580 | +the functionality of the debug interface (<a href="#4.9">§4.9</a>) to Lua programs. | |
| 9425 | 9581 | You should exert care when using this library. |
| 9426 | −Several of these functions | |
| 9582 | +Several of its functions | |
| 9427 | 9583 | violate basic assumptions about Lua code |
| 9428 | 9584 | (e.g., that variables local to a function |
| 9429 | 9585 | cannot be accessed from outside; |
| @@ -9458,7 +9614,7 @@ so that the caller continues its execution. · 28 unmodified lines | ||
| 9458 | 9614 | |
| 9459 | 9615 | <p> |
| 9460 | 9616 | Note that commands for <code>debug.debug</code> are not lexically nested |
| 9461 | −within any function, and so have no direct access to local variables. | |
| 9617 | +within any function and so have no direct access to local variables. | |
| 9462 | 9618 | |
| 9463 | 9619 | |
| 9464 | 9620 | |
| @@ -9477,20 +9633,20 @@ and the current hook count · 12 unmodified lines | ||
| 9477 | 9633 | |
| 9478 | 9634 | |
| 9479 | 9635 | <p> |
| 9480 | −<hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] function [, what])</code></a></h3> | |
| 9636 | +<hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] f [, what])</code></a></h3> | |
| 9481 | 9637 | |
| 9482 | 9638 | |
| 9483 | 9639 | <p> |
| 9484 | 9640 | Returns a table with information about a function. |
| 9485 | −You can give the function directly, | |
| 9486 | −or you can give a number as the value of <code>function</code>, | |
| 9487 | −which means the function running at level <code>function</code> of the call stack | |
| 9641 | +You can give the function directly | |
| 9642 | +or you can give a number as the value of <code>f</code>, | |
| 9643 | +which means the function running at level <code>f</code> of the call stack | |
| 9488 | 9644 | of the given thread: |
| 9489 | 9645 | level 0 is the current function (<code>getinfo</code> itself); |
| 9490 | 9646 | level 1 is the function that called <code>getinfo</code> |
| 9491 | 9647 | (except for tail calls, which do not count on the stack); |
| 9492 | 9648 | and so on. |
| 9493 | −If <code>function</code> is a number larger than the number of active functions, | |
| 9649 | +If <code>f</code> is a number larger than the number of active functions, | |
| 9494 | 9650 | then <code>getinfo</code> returns <b>nil</b>. |
| 9495 | 9651 | |
| 9496 | 9652 | |
| @@ -9554,11 +9710,11 @@ In that case, <code>getlocal</code> returns only the name of function parameters · 57 unmodified lines | ||
| 9554 | 9710 | |
| 9555 | 9711 | |
| 9556 | 9712 | <p> |
| 9557 | −<hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (object)</code></a></h3> | |
| 9713 | +<hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (value)</code></a></h3> | |
| 9558 | 9714 | |
| 9559 | 9715 | |
| 9560 | 9716 | <p> |
| 9561 | −Returns the metatable of the given <code>object</code> | |
| 9717 | +Returns the metatable of the given <code>value</code> | |
| 9562 | 9718 | or <b>nil</b> if it does not have a metatable. |
| 9563 | 9719 | |
| 9564 | 9720 | |
| @@ -9575,12 +9731,12 @@ Returns the registry table (see <a href="#4.5">§4.5</a>). · 10 unmodified lines | ||
| 9575 | 9731 | |
| 9576 | 9732 | |
| 9577 | 9733 | <p> |
| 9578 | −<hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (func, up)</code></a></h3> | |
| 9734 | +<hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (f, up)</code></a></h3> | |
| 9579 | 9735 | |
| 9580 | 9736 | |
| 9581 | 9737 | <p> |
| 9582 | 9738 | This function returns the name and the value of the upvalue |
| 9583 | −with index <code>up</code> of the function <code>func</code>. | |
| 9739 | +with index <code>up</code> of the function <code>f</code>. | |
| 9584 | 9740 | The function returns <b>nil</b> if there is no upvalue with the given index. |
| 9585 | 9741 | |
| 9586 | 9742 | |
| @@ -9662,24 +9818,24 @@ variable indices and names. · 75 unmodified lines | ||
| 9662 | 9818 | |
| 9663 | 9819 | |
| 9664 | 9820 | <p> |
| 9665 | −<hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (object, table)</code></a></h3> | |
| 9821 | +<hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (value, table)</code></a></h3> | |
| 9666 | 9822 | |
| 9667 | 9823 | |
| 9668 | 9824 | <p> |
| 9669 | −Sets the metatable for the given <code>object</code> to the given <code>table</code> | |
| 9825 | +Sets the metatable for the given <code>value</code> to the given <code>table</code> | |
| 9670 | 9826 | (which can be <b>nil</b>). |
| 9671 | −Returns <code>object</code>. | |
| 9827 | +Returns <code>value</code>. | |
| 9672 | 9828 | |
| 9673 | 9829 | |
| 9674 | 9830 | |
| 9675 | 9831 | |
| 9676 | 9832 | <p> |
| 9677 | −<hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (func, up, value)</code></a></h3> | |
| 9833 | +<hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (f, up, value)</code></a></h3> | |
| 9678 | 9834 | |
| 9679 | 9835 | |
| 9680 | 9836 | <p> |
| 9681 | 9837 | This function assigns the value <code>value</code> to the upvalue |
| 9682 | −with index <code>up</code> of the function <code>func</code>. | |
| 9838 | +with index <code>up</code> of the function <code>f</code>. | |
| 9683 | 9839 | The function returns <b>nil</b> if there is no upvalue |
| 9684 | 9840 | with the given index. |
| 9685 | 9841 | Otherwise, it returns the name of the upvalue. |
| @@ -9723,7 +9879,7 @@ to start the traceback · 37 unmodified lines | ||
| 9723 | 9879 | |
| 9724 | 9880 | |
| 9725 | 9881 | <p> |
| 9726 | −<hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (function, n)</code></a></h3> | |
| 9882 | +<hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (f, n)</code></a></h3> | |
| 9727 | 9883 | |
| 9728 | 9884 | |
| 9729 | 9885 | <p> |
| @@ -9743,12 +9899,12 @@ will return identical ids for those upvalue indices. · 13 unmodified lines | ||
| 9743 | 9899 | |
| 9744 | 9900 | |
| 9745 | 9901 | <p> |
| 9746 | −<hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (func1, n1, func2, n2)</code></a></h3> | |
| 9902 | +<hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3> | |
| 9747 | 9903 | |
| 9748 | 9904 | |
| 9749 | 9905 | <p> |
| 9750 | −Make the <code>n1</code>-th upvalue of the Lua closure <code>func1</code> | |
| 9751 | −refer to the <code>n2</code>-th upvalue of the Lua closure <code>func2</code>. | |
| 9906 | +Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code> | |
| 9907 | +refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>. | |
| 9752 | 9908 | |
| 9753 | 9909 | |
| 9754 | 9910 | |
| @@ -9779,6 +9935,7 @@ The options are: · 24 unmodified lines | ||
| 9779 | 9935 | <li><b><code>-l <em>mod</em></code>: </b> "requires" <em>mod</em>;</li> |
| 9780 | 9936 | <li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li> |
| 9781 | 9937 | <li><b><code>-v</code>: </b> prints version information;</li> |
| 9938 | +<li><b><code>-E</code>: </b> ignores environment variables;</li> | |
| 9782 | 9939 | <li><b><code>--</code>: </b> stops handling options;</li> |
| 9783 | 9940 | <li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li> |
| 9784 | 9941 | </ul><p> |
| @@ -9791,24 +9948,34 @@ and as <code>lua -</code> otherwise. · 6 unmodified lines | ||
| 9791 | 9948 | |
| 9792 | 9949 | |
| 9793 | 9950 | <p> |
| 9794 | −Before running any argument, | |
| 9951 | +When called without option <code>-E</code>, | |
| 9795 | 9952 | the interpreter checks for an environment variable <a name="pdf-LUA_INIT_5_2"><code>LUA_INIT_5_2</code></a> |
| 9796 | −(or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if it is not defined). | |
| 9797 | −If its format is <code>@<em>filename</em></code>, | |
| 9953 | +(or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if it is not defined) | |
| 9954 | +before running any argument. | |
| 9955 | +If the variable content has the format <code>@<em>filename</em></code>, | |
| 9798 | 9956 | then <code>lua</code> executes the file. |
| 9799 | 9957 | Otherwise, <code>lua</code> executes the string itself. |
| 9800 | 9958 | |
| 9801 | 9959 | |
| 9802 | 9960 | <p> |
| 9803 | −All options are handled in order, except <code>-i</code>. | |
| 9961 | +When called with option <code>-E</code>, | |
| 9962 | +besides ignoring <code>LUA_INIT</code>, | |
| 9963 | +the interpreter also resets the values of | |
| 9964 | +<a href="#pdf-package.path"><code>package.path</code></a> and <a href="#pdf-package.cpath"><code>package.cpath</code></a> | |
| 9965 | +with the default paths defined in <code>luaconf.h</code>, | |
| 9966 | +in effect ignoring the values of <code>LUA_PATH</code> and <code>LUA_CPATH</code>. | |
| 9967 | + | |
| 9968 | + | |
| 9969 | +<p> | |
| 9970 | +All options are handled in order, except <code>-i</code> and <code>-E</code>. | |
| 9804 | 9971 | For instance, an invocation like |
| 9805 | 9972 | |
| 9806 | 9973 | <pre> |
| 9807 | 9974 | $ lua -e'a=1' -e 'print(a)' script.lua |
| 9808 | 9975 | </pre><p> |
| 9809 | −will first set <code>a</code> to 1, then print the value of <code>a</code> (which is '<code>1</code>'), | |
| 9976 | +will first set <code>a</code> to 1, then print the value of <code>a</code>, | |
| 9810 | 9977 | and finally run the file <code>script.lua</code> with no arguments. |
| 9811 | −(Here <code>$</code> is the shell prompt. Your prompt can be different.) | |
| 9978 | +(Here <code>$</code> is the shell prompt. Your prompt may be different.) | |
| 9812 | 9979 | |
| 9813 | 9980 | |
| 9814 | 9981 | <p> |
| @@ -9835,7 +10002,7 @@ then creates a table · 20 unmodified lines | ||
| 9835 | 10002 | [1] = "t1", [2] = "t2" } |
| 9836 | 10003 | </pre><p> |
| 9837 | 10004 | and finally runs the file <code>b.lua</code>. |
| 9838 | −The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ··· | |
| 10005 | +The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ... | |
| 9839 | 10006 | as arguments; |
| 9840 | 10007 | it can also access these arguments with the vararg expression '<code>...</code>'. |
| 9841 | 10008 | |
| @@ -9862,29 +10029,8 @@ the interpreter does not report the error. · 20 unmodified lines | ||
| 9862 | 10029 | When finishing normally, |
| 9863 | 10030 | the interpreter closes its main Lua state |
| 9864 | 10031 | (see <a href="#lua_close"><code>lua_close</code></a>). |
| 9865 | −The script can avoid this step by terminating | |
| 9866 | −through <a href="#pdf-os.exit"><code>os.exit</code></a>. | |
| 9867 | − | |
| 9868 | − | |
| 9869 | −<p> | |
| 9870 | −If the global variable <a name="pdf-_PROMPT"><code>_PROMPT</code></a> contains a string, | |
| 9871 | −then its value is used as the prompt. | |
| 9872 | −Similarly, if the global variable <a name="pdf-_PROMPT2"><code>_PROMPT2</code></a> contains a string, | |
| 9873 | −its value is used as the secondary prompt | |
| 9874 | −(issued during incomplete statements). | |
| 9875 | −Therefore, both prompts can be changed directly on the command line | |
| 9876 | −or in any Lua programs by assigning to <code>_PROMPT</code>. | |
| 9877 | −See the next example: | |
| 9878 | − | |
| 9879 | −<pre> | |
| 9880 | − $ lua -e"_PROMPT='myprompt> '" -i | |
| 9881 | −</pre><p> | |
| 9882 | −(The outer pair of quotes is for the shell, | |
| 9883 | −the inner pair is for Lua.) | |
| 9884 | −Note the use of <code>-i</code> to enter interactive mode; | |
| 9885 | −otherwise, | |
| 9886 | −the program would just end silently | |
| 9887 | −right after the assignment to <code>_PROMPT</code>. | |
| 10032 | +The script can avoid this step by | |
| 10033 | +calling <a href="#pdf-os.exit"><code>os.exit</code></a> to terminate. | |
| 9888 | 10034 | |
| 9889 | 10035 | |
| 9890 | 10036 | <p> |
| @@ -9900,7 +10046,7 @@ as in · 9 unmodified lines | ||
| 9900 | 10046 | #!/usr/local/bin/lua |
| 9901 | 10047 | </pre><p> |
| 9902 | 10048 | (Of course, |
| 9903 | −the location of the Lua interpreter can be different in your machine. | |
| 10049 | +the location of the Lua interpreter may be different in your machine. | |
| 9904 | 10050 | If <code>lua</code> is in your <code>PATH</code>, |
| 9905 | 10051 | then |
| 9906 | 10052 | |
| @@ -9914,9 +10060,9 @@ is a more portable solution.) · 7 unmodified lines | ||
| 9914 | 10060 | <h1>8 – <a name="8">Incompatibilities with the Previous Version</a></h1> |
| 9915 | 10061 | |
| 9916 | 10062 | <p> |
| 9917 | −Here we list the incompatibilities that you can find when moving a program | |
| 10063 | +Here we list the incompatibilities that you may find when moving a program | |
| 9918 | 10064 | from Lua 5.1 to Lua 5.2. |
| 9919 | −You can avoid some incompatibilities compiling Lua with | |
| 10065 | +You can avoid some incompatibilities by compiling Lua with | |
| 9920 | 10066 | appropriate options (see file <code>luaconf.h</code>). |
| 9921 | 10067 | However, |
| 9922 | 10068 | all these compatibility options will be removed in the next version of Lua. |
| @@ -9934,7 +10080,7 @@ use the variable <code>_ENV</code> or the function <a href="#pdf-load"><code>loa · 11 unmodified lines | ||
| 9934 | 10080 | |
| 9935 | 10081 | |
| 9936 | 10082 | <p> |
| 9937 | −C functions do not have environments any more. | |
| 10083 | +C functions no longer have environments. | |
| 9938 | 10084 | Use an upvalue with a shared table if you need to keep |
| 9939 | 10085 | shared state among several C functions. |
| 9940 | 10086 | (You may use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> to open a C library |
| @@ -9964,8 +10110,8 @@ Weak tables with weak keys now perform like <em>ephemeron tables</em>. · 23 unmodified lines | ||
| 9964 | 10110 | <li> |
| 9965 | 10111 | The event <em>tail return</em> in debug hooks was removed. |
| 9966 | 10112 | Instead, tail calls generate a special new event, |
| 9967 | −<em>tail call</em>, so that the debugger can know there will | |
| 9968 | −not be a corresponding return event. | |
| 10113 | +<em>tail call</em>, so that the debugger can know that | |
| 10114 | +there will not be a corresponding return event. | |
| 9969 | 10115 | </li> |
| 9970 | 10116 | |
| 9971 | 10117 | <li> |
| @@ -9985,8 +10131,8 @@ observable difference to the new function. · 13 unmodified lines | ||
| 9985 | 10131 | |
| 9986 | 10132 | <li> |
| 9987 | 10133 | Function <code>module</code> is deprecated. |
| 9988 | −Modules are not expected to set global variables anymore, | |
| 9989 | −and it is easy to set up a module with regular Lua code. | |
| 10134 | +It is easy to set up a module with regular Lua code. | |
| 10135 | +Modules are not expected to set global variables. | |
| 9990 | 10136 | </li> |
| 9991 | 10137 | |
| 9992 | 10138 | <li> |
| @@ -10036,12 +10182,17 @@ So, all functions that load code · 43 unmodified lines | ||
| 10036 | 10182 | (<a href="#pdf-load"><code>load</code></a> and <a href="#pdf-loadfile"><code>loadfile</code></a>) |
| 10037 | 10183 | are potentially insecure when loading untrusted binary data. |
| 10038 | 10184 | (Actually, those functions were already insecure because |
| 10039 | −of bugs in the verification algorithm.) | |
| 10185 | +of flaws in the verification algorithm.) | |
| 10040 | 10186 | When in doubt, |
| 10041 | 10187 | use the <code>mode</code> argument in function <a href="#pdf-load"><code>load</code></a> |
| 10042 | 10188 | to restrict it to loading textual chunks. |
| 10043 | 10189 | </li> |
| 10044 | 10190 | |
| 10191 | +<li> | |
| 10192 | +The standard paths in the official distribution may | |
| 10193 | +change between versions. | |
| 10194 | +</li> | |
| 10195 | + | |
| 10045 | 10196 | </ul> |
| 10046 | 10197 | |
| 10047 | 10198 | |
| @@ -10060,13 +10211,12 @@ You must get the global environment from the registry · 12 unmodified lines | ||
| 10060 | 10211 | Pseudoindex <code>LUA_ENVIRONINDEX</code> |
| 10061 | 10212 | and functions <code>lua_getfenv</code>/<code>lua_setfenv</code> |
| 10062 | 10213 | were removed, |
| 10063 | −as C functions do not have environments any more. | |
| 10214 | +as C functions no longer have environments. | |
| 10064 | 10215 | </li> |
| 10065 | 10216 | |
| 10066 | 10217 | <li> |
| 10067 | 10218 | Function <code>luaL_register</code> is deprecated. |
| 10068 | −Use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> so that your module does not | |
| 10069 | −create globals anymore. | |
| 10219 | +Use <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a> so that your module does not create globals. | |
| 10070 | 10220 | (Modules are not expected to set global variables anymore.) |
| 10071 | 10221 | </li> |
| 10072 | 10222 | |
| @@ -10081,7 +10231,7 @@ the block is new. · 8 unmodified lines | ||
| 10081 | 10231 | |
| 10082 | 10232 | <li> |
| 10083 | 10233 | Finalizers (<code>__gc</code> metamethods) for userdata are called in the |
| 10084 | −reverse order that they were marked, | |
| 10234 | +reverse order that they were marked for finalization, | |
| 10085 | 10235 | not that they were created (see <a href="#2.5.1">§2.5.1</a>). |
| 10086 | 10236 | (Most userdata are marked immediately after they are created.) |
| 10087 | 10237 | Moreover, |
| @@ -10202,10 +10352,10 @@ Here is the complete syntax of Lua in extended BNF. · 114 unmodified lines | ||
| 10202 | 10352 | <HR> |
| 10203 | 10353 | <SMALL CLASS="footer"> |
| 10204 | 10354 | Last update: |
| 10205 | −Fri Jul 8 17:11:02 BRT 2011 | |
| 10355 | +Thu Nov 24 11:54:31 BRST 2011 | |
| 10206 | 10356 | </SMALL> |
| 10207 | 10357 | <!-- |
| 10208 | −Last change: revised for Lua 5.2.0 (beta) | |
| 10358 | +Last change: revised for Lua 5.2.0 | |
| 10209 | 10359 | --> |
| 10210 | 10360 | |
| 10211 | 10361 | </body></html> |
| @@ -6,18 +6,21 @@ · 5 unmodified lines | ||
| 6 | 6 | <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1"> |
| 7 | 7 | <STYLE TYPE="text/css"> |
| 8 | 8 | blockquote, .display { |
| 9 | − color: black ; | |
| 10 | − padding: 8px ; | |
| 11 | 9 | border: solid #a0a0a0 2px ; |
| 12 | − xbackground-color: #EFEFFF ; | |
| 13 | − margin-left: 0px ; | |
| 10 | + padding: 1em ; | |
| 11 | + margin: 0px ; | |
| 12 | +} | |
| 13 | + | |
| 14 | +.display { | |
| 15 | + word-spacing: 0.25em ; | |
| 16 | +} | |
| 17 | + | |
| 18 | +dl.display dd { | |
| 19 | + padding-bottom: 0.2em ; | |
| 14 | 20 | } |
| 15 | 21 | |
| 16 | 22 | tt, kbd, code { |
| 17 | − font-size: 120% ; | |
| 18 | − xcolor: black ; | |
| 19 | − xpadding: 4px ; | |
| 20 | − xbackground-color: #E0E0E0 ; | |
| 23 | + font-size: 12pt ; | |
| 21 | 24 | } |
| 22 | 25 | </STYLE> |
| 23 | 26 | </HEAD> |
| @@ -27,14 +30,9 @@ tt, kbd, code { · 3 unmodified lines | ||
| 27 | 30 | <HR> |
| 28 | 31 | <H1> |
| 29 | 32 | <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> |
| 30 | −Welcome to Lua 5.2 (beta) | |
| 33 | +Welcome to Lua 5.2 | |
| 31 | 34 | </H1> |
| 32 | 35 | |
| 33 | −<P> | |
| 34 | −<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> | |
| 35 | −<EM>This is a beta version of Lua 5.2. | |
| 36 | −Some details may change in the final version.</EM> | |
| 37 | − | |
| 38 | 36 | <P> |
| 39 | 37 | <A HREF="#about">about</A> |
| 40 | 38 | · |
| @@ -86,7 +84,7 @@ form. · 45 unmodified lines | ||
| 86 | 84 | You need to build it before using it. |
| 87 | 85 | Building Lua should be straightforward |
| 88 | 86 | because |
| 89 | −Lua is implemented in pure ANSI C, and compiles unmodified in all known | |
| 87 | +Lua is implemented in pure ANSI C and compiles unmodified in all known | |
| 90 | 88 | platforms that have an ANSI C compiler. |
| 91 | 89 | Lua also compiles unmodified as C++. |
| 92 | 90 | The instructions given below for building Lua are for Unix-like platforms. |
| @@ -120,15 +118,16 @@ Here are the details. · 27 unmodified lines | ||
| 120 | 118 | <OL> |
| 121 | 119 | <LI> |
| 122 | 120 | Open a terminal window and move to |
| 123 | −the top-level directory, which is named lua-5.2.0. | |
| 121 | +the top-level directory, which is named <TT>lua-5.2.0</TT>. | |
| 124 | 122 | The Makefile there controls both the build process and the installation process. |
| 125 | 123 | <P> |
| 126 | 124 | <LI> |
| 127 | 125 | Do "<KBD>make</KBD>" and see if your platform is listed. |
| 128 | 126 | The platforms currently supported are: |
| 129 | −<BLOCKQUOTE> | |
| 130 | − aix ansi bsd freebsd generic linux macosx mingw posix solaris | |
| 131 | −</BLOCKQUOTE> | |
| 127 | +<P> | |
| 128 | +<P CLASS="display"> | |
| 129 | + aix ansi bsd freebsd generic linux macosx mingw posix solaris | |
| 130 | +</P> | |
| 132 | 131 | <P> |
| 133 | 132 | If your platform is listed, just do "<KBD>make xxx</KBD>", where xxx |
| 134 | 133 | is your platform name. |
| @@ -138,7 +137,7 @@ The Makefile there controls both the build process and the installation process. · 3 unmodified lines | ||
| 138 | 137 | <P> |
| 139 | 138 | <LI> |
| 140 | 139 | The compilation takes only a few moments |
| 141 | −and produces three files in the src directory: | |
| 140 | +and produces three files in the <TT>src</TT> directory: | |
| 142 | 141 | lua (the interpreter), |
| 143 | 142 | luac (the compiler), |
| 144 | 143 | and liblua.a (the library). |
| @@ -147,12 +146,15 @@ and liblua.a (the library). · 2 unmodified lines | ||
| 147 | 146 | To check that Lua has been built correctly, do "<KBD>make test</KBD>" |
| 148 | 147 | after building Lua. This will run the interpreter and print its version string. |
| 149 | 148 | </OL> |
| 149 | +<P> | |
| 150 | +If you're running Linux and get compilation errors, | |
| 151 | +make sure you have installed the <TT>readline</TT> development package. | |
| 150 | 152 | |
| 151 | 153 | <H3>Installing Lua</H3> |
| 152 | 154 | <P> |
| 153 | 155 | Once you have built Lua, you may want to install it in an official |
| 154 | 156 | place in your system. In this case, do "<KBD>make install</KBD>". The official |
| 155 | − place and the way to install files are defined in Makefile. You'll | |
| 157 | + place and the way to install files are defined in the Makefile. You'll | |
| 156 | 158 | probably need the right permissions to install files. |
| 157 | 159 | |
| 158 | 160 | <P> |
| @@ -198,9 +200,9 @@ and liblua.a (the library). · 39 unmodified lines | ||
| 198 | 200 | <P> |
| 199 | 201 | Three kinds of things can be customized by editing a file: |
| 200 | 202 | <UL> |
| 201 | − <LI> Where and how to install Lua — edit Makefile. | |
| 202 | − <LI> How to build Lua — edit src/Makefile. | |
| 203 | − <LI> Lua features — edit src/luaconf.h. | |
| 203 | + <LI> Where and how to install Lua — edit <TT>Makefile</TT>. | |
| 204 | + <LI> How to build Lua — edit <TT>src/Makefile</TT>. | |
| 205 | + <LI> Lua features — edit <TT>src/luaconf.h</TT>. | |
| 204 | 206 | </UL> |
| 205 | 207 | |
| 206 | 208 | <P> |
| @@ -211,13 +213,13 @@ and liblua.a (the library). · 4 unmodified lines | ||
| 211 | 213 | |
| 212 | 214 | <P> |
| 213 | 215 | On the other hand, if you need to customize some Lua features, you'll need |
| 214 | − to edit src/luaconf.h before building and installing Lua. | |
| 216 | + to edit <TT>src/luaconf.h</TT> before building and installing Lua. | |
| 215 | 217 | The edited file will be the one installed, and |
| 216 | 218 | it will be used by any Lua clients that you build, to ensure consistency. |
| 217 | 219 | Further customization is available to experts by editing the Lua sources. |
| 218 | 220 | |
| 219 | 221 | <P> |
| 220 | − We strongly recommend that you enable dynamic loading in src/luaconf.h. | |
| 222 | + We strongly recommend that you enable dynamic loading in <TT>src/luaconf.h</TT>. | |
| 221 | 223 | This is done automatically for all platforms listed above that have |
| 222 | 224 | this feature and also for Windows. |
| 223 | 225 | |
| @@ -238,7 +240,6 @@ lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c · 14 unmodified lines | ||
| 238 | 240 | ltm.c lundump.c lvm.c lzio.c |
| 239 | 241 | lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c |
| 240 | 242 | lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c |
| 241 | − | |
| 242 | 243 | <DT> |
| 243 | 244 | interpreter: |
| 244 | 245 | <DD> |
| @@ -257,11 +258,11 @@ compiler: · 12 unmodified lines | ||
| 257 | 258 | those dynamic libraries — but <EM>don't</EM> link the Lua library |
| 258 | 259 | into each dynamic library. For Unix, we recommend that the Lua library |
| 259 | 260 | be linked statically into the host program and its symbols exported for |
| 260 | − dynamic linking; src/Makefile does this for the Lua interpreter. | |
| 261 | + dynamic linking; <TT>src/Makefile</TT> does this for the Lua interpreter. | |
| 261 | 262 | For Windows, we recommend that the Lua library be a DLL. |
| 262 | 263 | |
| 263 | 264 | <P> |
| 264 | − As mentioned above, you may edit src/luaconf.h to customize | |
| 265 | + As mentioned above, you may edit <TT>src/luaconf.h</TT> to customize | |
| 265 | 266 | some features before building Lua. |
| 266 | 267 | |
| 267 | 268 | <H2><A NAME="changes">Changes since Lua 5.1</A></H2> |
| @@ -290,7 +291,7 @@ Here are the other changes introduced in Lua 5.2: · 22 unmodified lines | ||
| 290 | 291 | <UL> |
| 291 | 292 | <LI> no more fenv for threads or functions |
| 292 | 293 | <LI> tables honor the <CODE>__len</CODE> metamethod |
| 293 | −<LI> hex and <CODE>\*</CODE> escapes in strings | |
| 294 | +<LI> hex and <CODE>\z</CODE> escapes in strings | |
| 294 | 295 | <LI> support for hexadecimal floats |
| 295 | 296 | <LI> order metamethods work for different types |
| 296 | 297 | <LI> no more verification of opcode consistency |
| @@ -302,8 +303,8 @@ Here are the other changes introduced in Lua 5.2: · 5 unmodified lines | ||
| 302 | 303 | <H3>Libraries</H3> |
| 303 | 304 | <UL> |
| 304 | 305 | <LI> arguments for function called through <CODE>xpcall</CODE> |
| 305 | −<LI> optional 'mode' argument to load (to control binary x text) | |
| 306 | −<LI> optional 'env' argument to load (environment for loaded chunk) | |
| 306 | +<LI> optional 'mode' argument to load and loadfile (to control binary x text) | |
| 307 | +<LI> optional 'env' argument to load and loadfile (environment for loaded chunk) | |
| 307 | 308 | <LI> <CODE>loadlib</CODE> may load libraries with global names (RTLD_GLOBAL) |
| 308 | 309 | <LI> new function <CODE>package.searchpath</CODE> |
| 309 | 310 | <LI> modules receive their paths when loaded |
| @@ -324,15 +325,23 @@ Here are the other changes introduced in Lua 5.2: · 14 unmodified lines | ||
| 324 | 325 | <H3>C API</H3> |
| 325 | 326 | <UL> |
| 326 | 327 | <LI> main thread predefined in the registry |
| 327 | −<LI> new constants <CODE>LUA_OK</CODE> and <CODE>LUA_ERRGCMM</CODE> | |
| 328 | −<LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE> | |
| 329 | −<LI> new <CODE>lua_version</CODE> and <CODE>luaL_checkversion</CODE> | |
| 328 | +<LI> new functions | |
| 329 | +<CODE>lua_absindex</CODE>, | |
| 330 | +<CODE>lua_arith</CODE>, | |
| 331 | +<CODE>lua_compare</CODE>, | |
| 332 | +<CODE>lua_copy</CODE>, | |
| 333 | +<CODE>lua_len</CODE>, | |
| 334 | +<CODE>lua_rawgetp</CODE>, | |
| 335 | +<CODE>lua_rawsetp</CODE>, | |
| 336 | +<CODE>lua_upvalueid</CODE>, | |
| 337 | +<CODE>lua_upvaluejoin</CODE>, | |
| 338 | +<CODE>lua_version</CODE>. | |
| 339 | +<LI> new functions | |
| 340 | +<CODE>luaL_checkversion</CODE>, | |
| 341 | +<CODE>luaL_setmetatable</CODE>, | |
| 342 | +<CODE>luaL_testudata</CODE>, | |
| 343 | +<CODE>luaL_tolstring</CODE>. | |
| 330 | 344 | <LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string |
| 331 | −<LI> new <CODE>luaL_testudata</CODE> and <CODE>luaL_setmetatable</CODE> | |
| 332 | −<LI> new <CODE>luaL_tolstring</CODE> | |
| 333 | −<LI> new <CODE>lua_copy</CODE> | |
| 334 | −<LI> new <CODE>lua_absindex</CODE> | |
| 335 | −<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE> | |
| 336 | 345 | <LI> <CODE>nparams</CODE> and <CODE>isvararg</CODE> available in debug API |
| 337 | 346 | <LI> new <CODE>lua_Unsigned</CODE> |
| 338 | 347 | </UL> |
| @@ -340,15 +349,17 @@ Here are the other changes introduced in Lua 5.2: · 1 unmodified line | ||
| 340 | 349 | <H3>Implementation</H3> |
| 341 | 350 | <UL> |
| 342 | 351 | <LI> max constants per function raised to 2<SUP>26</SUP> |
| 352 | +<LI> generational mode for garbage collection (experimental) | |
| 353 | +<LI> NaN trick (experimental) | |
| 343 | 354 | <LI> internal (immutable) version of ctypes |
| 344 | 355 | <LI> simpler implementation for string buffers |
| 345 | −<LI> udata with finalizers are kept in a separated list for the GC | |
| 346 | −<LI> <CODE>CallInfo</CODE> stack now is a linked list | |
| 347 | 356 | <LI> parser uses much less C-stack space (no more auto arrays) |
| 348 | −<LI> new hash for floats | |
| 349 | −<LI> handling of non-string error messages in the standalone interpreter | |
| 350 | −<LI> generational mode for garbage collection (experimental) | |
| 351 | −<LI> NaN trick (experimental) | |
| 357 | +</UL> | |
| 358 | + | |
| 359 | +<H3>Lua standalone interpreter</H3> | |
| 360 | +<UL> | |
| 361 | +<LI> new <CODE>-E</CODE> option to avoid environment variables | |
| 362 | +<LI> handling of non-string error messages | |
| 352 | 363 | </UL> |
| 353 | 364 | |
| 354 | 365 | <H2><A NAME="license">License</A></H2> |
| @@ -369,7 +380,7 @@ then you should give us credit by including the appropriate copyright notice som · 14 unmodified lines | ||
| 369 | 380 | For details, see |
| 370 | 381 | <A HREF="http://www.lua.org/license.html">this</A>. |
| 371 | 382 | |
| 372 | −<BLOCKQUOTE> | |
| 383 | +<BLOCKQUOTE STYLE="padding-bottom: 0em"> | |
| 373 | 384 | Copyright © 1994–2011 Lua.org, PUC-Rio. |
| 374 | 385 | |
| 375 | 386 | <P> |
| @@ -393,14 +404,15 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, · 17 unmodified lines | ||
| 393 | 404 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 394 | 405 | THE SOFTWARE. |
| 395 | 406 | </BLOCKQUOTE> |
| 407 | +<P> | |
| 396 | 408 | |
| 397 | 409 | <HR> |
| 398 | 410 | <SMALL CLASS="footer"> |
| 399 | 411 | Last update: |
| 400 | −Fri Jun 24 11:30:57 BRT 2011 | |
| 412 | +Wed Nov 23 16:17:22 BRST 2011 | |
| 401 | 413 | </SMALL> |
| 402 | 414 | <!-- |
| 403 | −Last change: revised for Lua 5.2.0 (beta) | |
| 415 | +Last change: revised for Lua 5.2.0 | |
| 404 | 416 | --> |
| 405 | 417 | |
| 406 | 418 | </BODY> |
| @@ -112,6 +112,7 @@ mingw: · 111 unmodified lines | ||
| 112 | 112 | $(MAKE) "LUA_A=lua52.dll" "LUA_T=lua.exe" \ |
| 113 | 113 | "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ |
| 114 | 114 | "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe |
| 115 | + $(MAKE) "LUAC_T=luac.exe" luac.exe | |
| 115 | 116 | |
| 116 | 117 | posix: |
| 117 | 118 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lapi.c,v 2.149 2011/06/13 14:13:06 roberto Exp $ | |
| 2 | +** $Id: lapi.c,v 2.157 2011/11/16 18:51:36 roberto Exp $ | |
| 3 | 3 | ** Lua API |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -34,9 +34,13 @@ const char lua_ident[] = · 28 unmodified lines | ||
| 34 | 34 | "$LuaAuthors: " LUA_AUTHORS " $"; |
| 35 | 35 | |
| 36 | 36 | |
| 37 | +/* value at a non-valid index */ | |
| 38 | +#define NONVALIDVALUE cast(TValue *, luaO_nilobject) | |
| 37 | 39 | |
| 38 | −#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject, \ | |
| 39 | − "invalid index") | |
| 40 | +/* corresponding test */ | |
| 41 | +#define isvalid(o) ((o) != luaO_nilobject) | |
| 42 | + | |
| 43 | +#define api_checkvalidindex(L, i) api_check(L, isvalid(i), "invalid index") | |
| 40 | 44 | |
| 41 | 45 | |
| 42 | 46 | static TValue *index2addr (lua_State *L, int idx) { |
| @@ -44,7 +48,7 @@ static TValue *index2addr (lua_State *L, int idx) { · 1 unmodified line | ||
| 44 | 48 | if (idx > 0) { |
| 45 | 49 | TValue *o = ci->func + idx; |
| 46 | 50 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); |
| 47 | − if (o >= L->top) return cast(TValue *, luaO_nilobject); | |
| 51 | + if (o >= L->top) return NONVALIDVALUE; | |
| 48 | 52 | else return o; |
| 49 | 53 | } |
| 50 | 54 | else if (idx > LUA_REGISTRYINDEX) { |
| @@ -57,12 +61,10 @@ static TValue *index2addr (lua_State *L, int idx) { · 6 unmodified lines | ||
| 57 | 61 | idx = LUA_REGISTRYINDEX - idx; |
| 58 | 62 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); |
| 59 | 63 | if (ttislcf(ci->func)) /* light C function? */ |
| 60 | − return cast(TValue *, luaO_nilobject); /* it has no upvalues */ | |
| 64 | + return NONVALIDVALUE; /* it has no upvalues */ | |
| 61 | 65 | else { |
| 62 | 66 | CClosure *func = clCvalue(ci->func); |
| 63 | − return (idx <= func->nupvalues) | |
| 64 | − ? &func->upvalue[idx-1] | |
| 65 | − : cast(TValue *, luaO_nilobject); | |
| 67 | + return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; | |
| 66 | 68 | } |
| 67 | 69 | } |
| 68 | 70 | } |
| @@ -237,7 +239,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { · 168 unmodified lines | ||
| 237 | 239 | |
| 238 | 240 | LUA_API int lua_type (lua_State *L, int idx) { |
| 239 | 241 | StkId o = index2addr(L, idx); |
| 240 | − return (o == luaO_nilobject) ? LUA_TNONE : ttypenv(o); | |
| 242 | + return (isvalid(o) ? ttypenv(o) : LUA_TNONE); | |
| 241 | 243 | } |
| 242 | 244 | |
| 243 | 245 | |
| @@ -275,8 +277,7 @@ LUA_API int lua_isuserdata (lua_State *L, int idx) { · 31 unmodified lines | ||
| 275 | 277 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { |
| 276 | 278 | StkId o1 = index2addr(L, index1); |
| 277 | 279 | StkId o2 = index2addr(L, index2); |
| 278 | − return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 | |
| 279 | − : luaV_rawequalobj(o1, o2); | |
| 280 | + return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0; | |
| 280 | 281 | } |
| 281 | 282 | |
| 282 | 283 | |
| @@ -305,17 +306,17 @@ LUA_API void lua_arith (lua_State *L, int op) { · 22 unmodified lines | ||
| 305 | 306 | |
| 306 | 307 | LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { |
| 307 | 308 | StkId o1, o2; |
| 308 | − int i; | |
| 309 | + int i = 0; | |
| 309 | 310 | lua_lock(L); /* may call tag method */ |
| 310 | 311 | o1 = index2addr(L, index1); |
| 311 | 312 | o2 = index2addr(L, index2); |
| 312 | − if (o1 == luaO_nilobject || o2 == luaO_nilobject) | |
| 313 | − i = 0; | |
| 314 | − else switch (op) { | |
| 315 | − case LUA_OPEQ: i = equalobj(L, o1, o2); break; | |
| 316 | − case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; | |
| 317 | − case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; | |
| 318 | − default: api_check(L, 0, "invalid option"); i = 0; | |
| 313 | + if (isvalid(o1) && isvalid(o2)) { | |
| 314 | + switch (op) { | |
| 315 | + case LUA_OPEQ: i = equalobj(L, o1, o2); break; | |
| 316 | + case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; | |
| 317 | + case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; | |
| 318 | + default: api_check(L, 0, "invalid option"); | |
| 319 | + } | |
| 319 | 320 | } |
| 320 | 321 | lua_unlock(L); |
| 321 | 322 | return i; |
| @@ -595,6 +596,17 @@ LUA_API int lua_pushthread (lua_State *L) { · 273 unmodified lines | ||
| 595 | 596 | */ |
| 596 | 597 | |
| 597 | 598 | |
| 599 | +LUA_API void lua_getglobal (lua_State *L, const char *var) { | |
| 600 | + Table *reg = hvalue(&G(L)->l_registry); | |
| 601 | + const TValue *gt; /* global table */ | |
| 602 | + lua_lock(L); | |
| 603 | + gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | |
| 604 | + setsvalue2s(L, L->top++, luaS_new(L, var)); | |
| 605 | + luaV_gettable(L, gt, L->top - 1, L->top - 1); | |
| 606 | + lua_unlock(L); | |
| 607 | +} | |
| 608 | + | |
| 609 | + | |
| 598 | 610 | LUA_API void lua_gettable (lua_State *L, int idx) { |
| 599 | 611 | StkId t; |
| 600 | 612 | lua_lock(L); |
| @@ -628,11 +640,24 @@ LUA_API void lua_rawget (lua_State *L, int idx) { · 27 unmodified lines | ||
| 628 | 640 | |
| 629 | 641 | |
| 630 | 642 | LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { |
| 631 | − StkId o; | |
| 643 | + StkId t; | |
| 632 | 644 | lua_lock(L); |
| 633 | − o = index2addr(L, idx); | |
| 634 | − api_check(L, ttistable(o), "table expected"); | |
| 635 | − setobj2s(L, L->top, luaH_getint(hvalue(o), n)); | |
| 645 | + t = index2addr(L, idx); | |
| 646 | + api_check(L, ttistable(t), "table expected"); | |
| 647 | + setobj2s(L, L->top, luaH_getint(hvalue(t), n)); | |
| 648 | + api_incr_top(L); | |
| 649 | + lua_unlock(L); | |
| 650 | +} | |
| 651 | + | |
| 652 | + | |
| 653 | +LUA_API void lua_rawgetp (lua_State *L, int idx, const void *p) { | |
| 654 | + StkId t; | |
| 655 | + TValue k; | |
| 656 | + lua_lock(L); | |
| 657 | + t = index2addr(L, idx); | |
| 658 | + api_check(L, ttistable(t), "table expected"); | |
| 659 | + setpvalue(&k, cast(void *, p)); | |
| 660 | + setobj2s(L, L->top, luaH_get(hvalue(t), &k)); | |
| 636 | 661 | api_incr_top(L); |
| 637 | 662 | lua_unlock(L); |
| 638 | 663 | } |
| @@ -700,6 +725,19 @@ LUA_API void lua_getuservalue (lua_State *L, int idx) { · 61 unmodified lines | ||
| 700 | 725 | */ |
| 701 | 726 | |
| 702 | 727 | |
| 728 | +LUA_API void lua_setglobal (lua_State *L, const char *var) { | |
| 729 | + Table *reg = hvalue(&G(L)->l_registry); | |
| 730 | + const TValue *gt; /* global table */ | |
| 731 | + lua_lock(L); | |
| 732 | + api_checknelems(L, 1); | |
| 733 | + gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | |
| 734 | + setsvalue2s(L, L->top++, luaS_new(L, var)); | |
| 735 | + luaV_settable(L, gt, L->top - 1, L->top - 2); | |
| 736 | + L->top -= 2; /* pop value and key */ | |
| 737 | + lua_unlock(L); | |
| 738 | +} | |
| 739 | + | |
| 740 | + | |
| 703 | 741 | LUA_API void lua_settable (lua_State *L, int idx) { |
| 704 | 742 | StkId t; |
| 705 | 743 | lua_lock(L); |
| @@ -732,6 +770,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) { · 26 unmodified lines | ||
| 732 | 770 | t = index2addr(L, idx); |
| 733 | 771 | api_check(L, ttistable(t), "table expected"); |
| 734 | 772 | setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); |
| 773 | + invalidateTMcache(hvalue(t)); | |
| 735 | 774 | luaC_barrierback(L, gcvalue(t), L->top-1); |
| 736 | 775 | L->top -= 2; |
| 737 | 776 | lua_unlock(L); |
| @@ -739,13 +778,28 @@ LUA_API void lua_rawset (lua_State *L, int idx) { · 1 unmodified line | ||
| 739 | 778 | |
| 740 | 779 | |
| 741 | 780 | LUA_API void lua_rawseti (lua_State *L, int idx, int n) { |
| 742 | − StkId o; | |
| 781 | + StkId t; | |
| 743 | 782 | lua_lock(L); |
| 744 | 783 | api_checknelems(L, 1); |
| 745 | − o = index2addr(L, idx); | |
| 746 | − api_check(L, ttistable(o), "table expected"); | |
| 747 | − setobj2t(L, luaH_setint(L, hvalue(o), n), L->top-1); | |
| 748 | − luaC_barrierback(L, gcvalue(o), L->top-1); | |
| 784 | + t = index2addr(L, idx); | |
| 785 | + api_check(L, ttistable(t), "table expected"); | |
| 786 | + luaH_setint(L, hvalue(t), n, L->top - 1); | |
| 787 | + luaC_barrierback(L, gcvalue(t), L->top-1); | |
| 788 | + L->top--; | |
| 789 | + lua_unlock(L); | |
| 790 | +} | |
| 791 | + | |
| 792 | + | |
| 793 | +LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { | |
| 794 | + StkId t; | |
| 795 | + TValue k; | |
| 796 | + lua_lock(L); | |
| 797 | + api_checknelems(L, 1); | |
| 798 | + t = index2addr(L, idx); | |
| 799 | + api_check(L, ttistable(t), "table expected"); | |
| 800 | + setpvalue(&k, cast(void *, p)); | |
| 801 | + setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1); | |
| 802 | + luaC_barrierback(L, gcvalue(t), L->top - 1); | |
| 749 | 803 | L->top--; |
| 750 | 804 | lua_unlock(L); |
| 751 | 805 | } |
| @@ -1128,7 +1182,6 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { · 376 unmodified lines | ||
| 1128 | 1182 | |
| 1129 | 1183 | |
| 1130 | 1184 | |
| 1131 | − | |
| 1132 | 1185 | static const char *aux_upvalue (StkId fi, int n, TValue **val, |
| 1133 | 1186 | GCObject **owner) { |
| 1134 | 1187 | switch (ttype(fi)) { |
| @@ -1141,15 +1194,13 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val, · 6 unmodified lines | ||
| 1141 | 1194 | } |
| 1142 | 1195 | case LUA_TLCL: { /* Lua closure */ |
| 1143 | 1196 | LClosure *f = clLvalue(fi); |
| 1144 | − const char *name; | |
| 1197 | + TString *name; | |
| 1145 | 1198 | Proto *p = f->p; |
| 1146 | 1199 | if (!(1 <= n && n <= p->sizeupvalues)) return NULL; |
| 1147 | 1200 | *val = f->upvals[n-1]->v; |
| 1148 | 1201 | if (owner) *owner = obj2gco(f->upvals[n - 1]); |
| 1149 | − name = getstr(p->upvalues[n-1].name); | |
| 1150 | − if (name == NULL) /* no debug information? */ | |
| 1151 | − name = ""; | |
| 1152 | − return name; | |
| 1202 | + name = p->upvalues[n-1].name; | |
| 1203 | + return (name == NULL) ? "" : getstr(name); | |
| 1153 | 1204 | } |
| 1154 | 1205 | default: return NULL; /* not a closure */ |
| 1155 | 1206 | } |
| @@ -1158,7 +1209,7 @@ static const char *aux_upvalue (StkId fi, int n, TValue **val, · 2 unmodified lines | ||
| 1158 | 1209 | |
| 1159 | 1210 | LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { |
| 1160 | 1211 | const char *name; |
| 1161 | − TValue *val; | |
| 1212 | + TValue *val = NULL; /* initialized to avoid warnings */ | |
| 1162 | 1213 | lua_lock(L); |
| 1163 | 1214 | name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL); |
| 1164 | 1215 | if (name) { |
| @@ -1172,8 +1223,8 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { · 7 unmodified lines | ||
| 1172 | 1223 | |
| 1173 | 1224 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { |
| 1174 | 1225 | const char *name; |
| 1175 | − TValue *val; | |
| 1176 | − GCObject *owner; | |
| 1226 | + TValue *val = NULL; /* initialized to avoid warnings */ | |
| 1227 | + GCObject *owner = NULL; /* initialized to avoid warnings */ | |
| 1177 | 1228 | StkId fi; |
| 1178 | 1229 | lua_lock(L); |
| 1179 | 1230 | fi = index2addr(L, funcindex); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lauxlib.c,v 1.233 2011/06/16 14:11:04 roberto Exp $ | |
| 2 | +** $Id: lauxlib.c,v 1.236 2011/11/14 17:10:24 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -41,11 +41,10 @@ · 35 unmodified lines | ||
| 41 | 41 | ** return 1 + string at top if find a good name. |
| 42 | 42 | */ |
| 43 | 43 | static int findfield (lua_State *L, int objidx, int level) { |
| 44 | − int found = 0; | |
| 45 | 44 | if (level == 0 || !lua_istable(L, -1)) |
| 46 | 45 | return 0; /* not found */ |
| 47 | 46 | lua_pushnil(L); /* start 'next' loop */ |
| 48 | − while (!found && lua_next(L, -2)) { /* for each pair in table */ | |
| 47 | + while (lua_next(L, -2)) { /* for each pair in table */ | |
| 49 | 48 | if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ |
| 50 | 49 | if (lua_rawequal(L, objidx, -1)) { /* found object? */ |
| 51 | 50 | lua_pop(L, 1); /* remove value (but keep name) */ |
| @@ -86,7 +85,7 @@ static void pushfuncname (lua_State *L, lua_Debug *ar) { · 34 unmodified lines | ||
| 86 | 85 | lua_pushfstring(L, "function " LUA_QS, ar->name); |
| 87 | 86 | else if (*ar->what == 'm') /* main? */ |
| 88 | 87 | lua_pushfstring(L, "main chunk"); |
| 89 | − else if (*ar->what == 'C' || *ar->what == 't') { | |
| 88 | + else if (*ar->what == 'C') { | |
| 90 | 89 | if (pushglobalfuncname(L, ar)) { |
| 91 | 90 | lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1)); |
| 92 | 91 | lua_remove(L, -2); /* remove name */ |
| @@ -331,7 +330,9 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, · 238 unmodified lines | ||
| 331 | 330 | |
| 332 | 331 | |
| 333 | 332 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { |
| 334 | − if (!lua_checkstack(L, space)) { | |
| 333 | + /* keep some extra space to run error routines, if needed */ | |
| 334 | + const int extra = LUA_MINSTACK; | |
| 335 | + if (!lua_checkstack(L, space + extra)) { | |
| 335 | 336 | if (msg) |
| 336 | 337 | luaL_error(L, "stack overflow (%s)", msg); |
| 337 | 338 | else |
| @@ -591,6 +592,16 @@ static int errfile (lua_State *L, const char *what, int fnameindex) { · 253 unmodified lines | ||
| 591 | 592 | } |
| 592 | 593 | |
| 593 | 594 | |
| 595 | +static int checkmode (lua_State *L, const char *mode, const char *x) { | |
| 596 | + if (mode && strchr(mode, x[0]) == NULL) { | |
| 597 | + lua_pushfstring(L, | |
| 598 | + "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode); | |
| 599 | + return LUA_ERRFILE; | |
| 600 | + } | |
| 601 | + else return LUA_OK; | |
| 602 | +} | |
| 603 | + | |
| 604 | + | |
| 594 | 605 | static int skipBOM (LoadF *lf) { |
| 595 | 606 | const char *p = "\xEF\xBB\xBF"; /* Utf8 BOM mark */ |
| 596 | 607 | int c; |
| @@ -623,7 +634,8 @@ static int skipcomment (LoadF *lf, int *cp) { · 26 unmodified lines | ||
| 623 | 634 | } |
| 624 | 635 | |
| 625 | 636 | |
| 626 | −LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { | |
| 637 | +LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, | |
| 638 | + const char *mode) { | |
| 627 | 639 | LoadF lf; |
| 628 | 640 | int status, readstatus; |
| 629 | 641 | int c; |
| @@ -639,14 +651,23 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { · 9 unmodified lines | ||
| 639 | 651 | } |
| 640 | 652 | if (skipcomment(&lf, &c)) /* read initial portion */ |
| 641 | 653 | lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */ |
| 642 | − if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ | |
| 643 | − lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ | |
| 644 | − if (lf.f == NULL) return errfile(L, "reopen", fnameindex); | |
| 645 | − skipcomment(&lf, &c); /* re-read initial portion */ | |
| 654 | + if (c == LUA_SIGNATURE[0]) { /* binary file? */ | |
| 655 | + if ((status = checkmode(L, mode, "binary")) != LUA_OK) | |
| 656 | + goto closefile; | |
| 657 | + if (filename) { | |
| 658 | + lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ | |
| 659 | + if (lf.f == NULL) return errfile(L, "reopen", fnameindex); | |
| 660 | + skipcomment(&lf, &c); /* re-read initial portion */ | |
| 661 | + } | |
| 662 | + } | |
| 663 | + else { /* text file */ | |
| 664 | + if ((status = checkmode(L, mode, "text")) != LUA_OK) | |
| 665 | + goto closefile; | |
| 646 | 666 | } |
| 647 | 667 | if (c != EOF) |
| 648 | 668 | lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */ |
| 649 | 669 | status = lua_load(L, getF, &lf, lua_tostring(L, -1)); |
| 670 | + closefile: | |
| 650 | 671 | readstatus = ferror(lf.f); |
| 651 | 672 | if (filename) fclose(lf.f); /* close file (even in case of errors) */ |
| 652 | 673 | if (readstatus) { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lauxlib.h,v 1.117 2011/06/16 14:10:12 roberto Exp $ | |
| 2 | +** $Id: lauxlib.h,v 1.119 2011/11/14 17:10:24 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -72,7 +72,11 @@ LUALIB_API int (luaL_execresult) (lua_State *L, int stat); · 66 unmodified lines | ||
| 72 | 72 | LUALIB_API int (luaL_ref) (lua_State *L, int t); |
| 73 | 73 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); |
| 74 | 74 | |
| 75 | −LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); | |
| 75 | +LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, | |
| 76 | + const char *mode); | |
| 77 | + | |
| 78 | +#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) | |
| 79 | + | |
| 76 | 80 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, |
| 77 | 81 | const char *name); |
| 78 | 82 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); |
| @@ -163,6 +167,31 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); · 84 unmodified lines | ||
| 163 | 167 | /* }====================================================== */ |
| 164 | 168 | |
| 165 | 169 | |
| 170 | + | |
| 171 | +/* | |
| 172 | +** {====================================================== | |
| 173 | +** File handles for IO library | |
| 174 | +** ======================================================= | |
| 175 | +*/ | |
| 176 | + | |
| 177 | +/* | |
| 178 | +** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and | |
| 179 | +** initial structure 'luaL_Stream' (it may contain other fields | |
| 180 | +** after that initial structure). | |
| 181 | +*/ | |
| 182 | + | |
| 183 | +#define LUA_FILEHANDLE "FILE*" | |
| 184 | + | |
| 185 | + | |
| 186 | +typedef struct luaL_Stream { | |
| 187 | + FILE *f; /* stream (NULL for incompletely created streams) */ | |
| 188 | + lua_CFunction closef; /* to close stream (NULL for closed streams) */ | |
| 189 | +} luaL_Stream; | |
| 190 | + | |
| 191 | +/* }====================================================== */ | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 166 | 195 | /* compatibility with old module system */ |
| 167 | 196 | #if defined(LUA_COMPAT_MODULE) |
| 168 | 197 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lbaselib.c,v 1.264 2011/07/05 12:49:35 roberto Exp $ | |
| 2 | +** $Id: lbaselib.c,v 1.270 2011/11/23 17:29:04 roberto Exp $ | |
| 3 | 3 | ** Basic library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -46,20 +46,22 @@ static int luaB_print (lua_State *L) { · 40 unmodified lines | ||
| 46 | 46 | #define SPACECHARS " \f\n\r\t\v" |
| 47 | 47 | |
| 48 | 48 | static int luaB_tonumber (lua_State *L) { |
| 49 | − int base = luaL_optint(L, 2, 10); | |
| 50 | − luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); | |
| 51 | − if (base == 10) { /* standard conversion */ | |
| 52 | − luaL_checkany(L, 1); | |
| 53 | − if (lua_isnumber(L, 1)) { | |
| 54 | − lua_pushnumber(L, lua_tonumber(L, 1)); | |
| 49 | + if (lua_isnoneornil(L, 2)) { /* standard conversion */ | |
| 50 | + int isnum; | |
| 51 | + lua_Number n = lua_tonumberx(L, 1, &isnum); | |
| 52 | + if (isnum) { | |
| 53 | + lua_pushnumber(L, n); | |
| 55 | 54 | return 1; |
| 56 | − } /* else not a number */ | |
| 55 | + } /* else not a number; must be something */ | |
| 56 | + luaL_checkany(L, 1); | |
| 57 | 57 | } |
| 58 | 58 | else { |
| 59 | 59 | size_t l; |
| 60 | 60 | const char *s = luaL_checklstring(L, 1, &l); |
| 61 | 61 | const char *e = s + l; /* end point for 's' */ |
| 62 | + int base = luaL_checkint(L, 2); | |
| 62 | 63 | int neg = 0; |
| 64 | + luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); | |
| 63 | 65 | s += strspn(s, SPACECHARS); /* skip initial spaces */ |
| 64 | 66 | if (*s == '-') { s++; neg = 1; } /* handle signal */ |
| 65 | 67 | else if (*s == '+') s++; |
| @@ -158,7 +160,7 @@ static int luaB_rawset (lua_State *L) { · 92 unmodified lines | ||
| 158 | 160 | static int luaB_collectgarbage (lua_State *L) { |
| 159 | 161 | static const char *const opts[] = {"stop", "restart", "collect", |
| 160 | 162 | "count", "step", "setpause", "setstepmul", |
| 161 | − "setmajorinc", "isrunning", "gen", "inc", NULL}; | |
| 163 | + "setmajorinc", "isrunning", "generational", "incremental", NULL}; | |
| 162 | 164 | static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, |
| 163 | 165 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, |
| 164 | 166 | LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC}; |
| @@ -253,7 +255,14 @@ static int load_aux (lua_State *L, int status) { · 88 unmodified lines | ||
| 253 | 255 | |
| 254 | 256 | static int luaB_loadfile (lua_State *L) { |
| 255 | 257 | const char *fname = luaL_optstring(L, 1, NULL); |
| 256 | − return load_aux(L, luaL_loadfile(L, fname)); | |
| 258 | + const char *mode = luaL_optstring(L, 2, NULL); | |
| 259 | + int env = !lua_isnone(L, 3); /* 'env' parameter? */ | |
| 260 | + int status = luaL_loadfilex(L, fname, mode); | |
| 261 | + if (status == LUA_OK && env) { /* 'env' parameter? */ | |
| 262 | + lua_pushvalue(L, 3); | |
| 263 | + lua_setupvalue(L, -2, 1); /* set it as 1st upvalue of loaded chunk */ | |
| 264 | + } | |
| 265 | + return load_aux(L, status); | |
| 257 | 266 | } |
| 258 | 267 | |
| 259 | 268 | |
| @@ -265,7 +274,6 @@ static int luaB_loadfile (lua_State *L) { · 5 unmodified lines | ||
| 265 | 274 | |
| 266 | 275 | |
| 267 | 276 | typedef struct { |
| 268 | −char c; | |
| 269 | 277 | const char *mode; |
| 270 | 278 | } loaddata; |
| 271 | 279 | |
| @@ -276,11 +284,11 @@ char c; · 4 unmodified lines | ||
| 276 | 284 | ** pushed on the stack) in case of errors. |
| 277 | 285 | */ |
| 278 | 286 | static const char *checkrights (lua_State *L, const char *mode, const char *s) { |
| 279 | − if (strchr(mode, 'b') == NULL && *s == LUA_SIGNATURE[0]) | |
| 280 | − return lua_pushstring(L, "attempt to load a binary chunk"); | |
| 281 | − if (strchr(mode, 't') == NULL && *s != LUA_SIGNATURE[0]) | |
| 282 | − return lua_pushstring(L, "attempt to load a text chunk"); | |
| 283 | − return NULL; /* chunk in allowed format */ | |
| 287 | + const char *x = (*s == LUA_SIGNATURE[0]) ? "binary" : "text"; | |
| 288 | + if (strchr(mode, x[0]) == NULL) | |
| 289 | + return lua_pushfstring(L, | |
| 290 | + "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode); | |
| 291 | + else return NULL; | |
| 284 | 292 | } |
| 285 | 293 | |
| 286 | 294 | |
| @@ -390,27 +398,32 @@ static int luaB_select (lua_State *L) { · 103 unmodified lines | ||
| 390 | 398 | } |
| 391 | 399 | |
| 392 | 400 | |
| 393 | −static int pcallcont (lua_State *L) { | |
| 394 | − int errfunc = 0; /* =0 to avoid warnings */ | |
| 395 | − int status = lua_getctx(L, &errfunc); | |
| 396 | − lua_assert(status != LUA_OK); | |
| 397 | − lua_pushboolean(L, (status == LUA_YIELD)); /* first result (status) */ | |
| 398 | − if (errfunc) /* came from xpcall? */ | |
| 399 | − lua_replace(L, 1); /* put first result in place of error function */ | |
| 400 | − else /* came from pcall */ | |
| 401 | − lua_insert(L, 1); /* open space for first result */ | |
| 401 | +static int finishpcall (lua_State *L, int status) { | |
| 402 | + if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */ | |
| 403 | + lua_settop(L, 0); /* create space for return values */ | |
| 404 | + lua_pushboolean(L, 0); | |
| 405 | + lua_pushstring(L, "stack overflow"); | |
| 406 | + return 2; /* return false, msg */ | |
| 407 | + } | |
| 408 | + lua_pushboolean(L, status); /* first result (status) */ | |
| 409 | + lua_replace(L, 1); /* put first result in first slot */ | |
| 402 | 410 | return lua_gettop(L); |
| 403 | 411 | } |
| 404 | 412 | |
| 405 | 413 | |
| 414 | +static int pcallcont (lua_State *L) { | |
| 415 | + int status = lua_getctx(L, NULL); | |
| 416 | + return finishpcall(L, (status == LUA_YIELD)); | |
| 417 | +} | |
| 418 | + | |
| 419 | + | |
| 406 | 420 | static int luaB_pcall (lua_State *L) { |
| 407 | 421 | int status; |
| 408 | 422 | luaL_checkany(L, 1); |
| 409 | − status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, pcallcont); | |
| 410 | − luaL_checkstack(L, 1, NULL); | |
| 411 | − lua_pushboolean(L, (status == LUA_OK)); | |
| 412 | − lua_insert(L, 1); | |
| 413 | − return lua_gettop(L); /* return status + all results */ | |
| 423 | + lua_pushnil(L); | |
| 424 | + lua_insert(L, 1); /* create space for status result */ | |
| 425 | + status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont); | |
| 426 | + return finishpcall(L, (status == LUA_OK)); | |
| 414 | 427 | } |
| 415 | 428 | |
| 416 | 429 | |
| @@ -421,11 +434,8 @@ static int luaB_xpcall (lua_State *L) { · 4 unmodified lines | ||
| 421 | 434 | lua_pushvalue(L, 1); /* exchange function... */ |
| 422 | 435 | lua_copy(L, 2, 1); /* ...and error handler */ |
| 423 | 436 | lua_replace(L, 2); |
| 424 | − status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont); | |
| 425 | − luaL_checkstack(L, 1, NULL); | |
| 426 | − lua_pushboolean(L, (status == LUA_OK)); | |
| 427 | − lua_replace(L, 1); | |
| 428 | − return lua_gettop(L); /* return status + all results */ | |
| 437 | + status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont); | |
| 438 | + return finishpcall(L, (status == LUA_OK)); | |
| 429 | 439 | } |
| 430 | 440 | |
| 431 | 441 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.c,v 2.56 2011/05/31 18:27:56 roberto Exp $ | |
| 2 | +** $Id: lcode.c,v 2.60 2011/08/30 16:26:41 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -44,8 +44,8 @@ void luaK_nil (FuncState *fs, int from, int n) { · 38 unmodified lines | ||
| 44 | 44 | int pl = pfrom + GETARG_B(*previous); |
| 45 | 45 | if ((pfrom <= from && from <= pl + 1) || |
| 46 | 46 | (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */ |
| 47 | − if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ | |
| 48 | − if (pl > l) l = pl; /* l = max(l, pl) */ | |
| 47 | + if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ | |
| 48 | + if (pl > l) l = pl; /* l = max(l, pl) */ | |
| 49 | 49 | SETARG_A(*previous, from); |
| 50 | 50 | SETARG_B(*previous, l - from); |
| 51 | 51 | return; |
| @@ -213,11 +213,11 @@ static int luaK_code (FuncState *fs, Instruction i) { · 161 unmodified lines | ||
| 213 | 213 | Proto *f = fs->f; |
| 214 | 214 | dischargejpc(fs); /* `pc' will change */ |
| 215 | 215 | /* put new instruction in code array */ |
| 216 | − luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction, | |
| 216 | + luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction, | |
| 217 | 217 | MAX_INT, "opcodes"); |
| 218 | 218 | f->code[fs->pc] = i; |
| 219 | 219 | /* save corresponding line information */ |
| 220 | − luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int, | |
| 220 | + luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int, | |
| 221 | 221 | MAX_INT, "opcodes"); |
| 222 | 222 | f->lineinfo[fs->pc] = fs->ls->lastline; |
| 223 | 223 | return fs->pc++; |
| @@ -289,7 +289,7 @@ static void freeexp (FuncState *fs, expdesc *e) { · 65 unmodified lines | ||
| 289 | 289 | |
| 290 | 290 | |
| 291 | 291 | static int addk (FuncState *fs, TValue *key, TValue *v) { |
| 292 | − lua_State *L = fs->L; | |
| 292 | + lua_State *L = fs->ls->L; | |
| 293 | 293 | TValue *idx = luaH_set(L, fs->h, key); |
| 294 | 294 | Proto *f = fs->f; |
| 295 | 295 | int k, oldsize; |
| @@ -304,6 +304,8 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { · 8 unmodified lines | ||
| 304 | 304 | /* constant not found; create a new entry */ |
| 305 | 305 | oldsize = f->sizek; |
| 306 | 306 | k = fs->nk; |
| 307 | + /* numerical value does not need GC barrier; | |
| 308 | + table has no metatable, so it does not need to invalidate cache */ | |
| 307 | 309 | setnvalue(idx, cast_num(k)); |
| 308 | 310 | luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants"); |
| 309 | 311 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); |
| @@ -316,14 +318,14 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { · 6 unmodified lines | ||
| 316 | 318 | |
| 317 | 319 | int luaK_stringK (FuncState *fs, TString *s) { |
| 318 | 320 | TValue o; |
| 319 | − setsvalue(fs->L, &o, s); | |
| 321 | + setsvalue(fs->ls->L, &o, s); | |
| 320 | 322 | return addk(fs, &o, &o); |
| 321 | 323 | } |
| 322 | 324 | |
| 323 | 325 | |
| 324 | 326 | int luaK_numberK (FuncState *fs, lua_Number r) { |
| 325 | 327 | int n; |
| 326 | − lua_State *L = fs->L; | |
| 328 | + lua_State *L = fs->ls->L; | |
| 327 | 329 | TValue o; |
| 328 | 330 | setnvalue(&o, r); |
| 329 | 331 | if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */ |
| @@ -350,7 +352,7 @@ static int nilK (FuncState *fs) { · 20 unmodified lines | ||
| 350 | 352 | TValue k, v; |
| 351 | 353 | setnilvalue(&v); |
| 352 | 354 | /* cannot use nil as key; instead use table itself to represent nil */ |
| 353 | − sethvalue(fs->L, &k, fs->h); | |
| 355 | + sethvalue(fs->ls->L, &k, fs->h); | |
| 354 | 356 | return addk(fs, &k, &v); |
| 355 | 357 | } |
| 356 | 358 | |
| @@ -641,7 +643,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 284 unmodified lines | ||
| 641 | 643 | } |
| 642 | 644 | |
| 643 | 645 | |
| 644 | −static void luaK_goiffalse (FuncState *fs, expdesc *e) { | |
| 646 | +void luaK_goiffalse (FuncState *fs, expdesc *e) { | |
| 645 | 647 | int pc; /* pc of last jump */ |
| 646 | 648 | luaK_dischargevars(fs, e); |
| 647 | 649 | switch (e->k) { |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcode.h,v 1.57 2011/04/07 18:14:12 roberto Exp $ | |
| 2 | +** $Id: lcode.h,v 1.58 2011/08/30 16:26:41 roberto Exp $ | |
| 3 | 3 | ** Code generator for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -62,6 +62,7 @@ LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); · 56 unmodified lines | ||
| 62 | 62 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); |
| 63 | 63 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); |
| 64 | 64 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); |
| 65 | +LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); | |
| 65 | 66 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); |
| 66 | 67 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); |
| 67 | 68 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lcorolib.c,v 1.2 2010/07/02 11:38:13 roberto Exp $ | |
| 2 | +** $Id: lcorolib.c,v 1.3 2011/08/23 17:24:34 roberto Exp $ | |
| 3 | 3 | ** Coroutine Library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -28,7 +28,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { · 22 unmodified lines | ||
| 28 | 28 | return -1; /* error flag */ |
| 29 | 29 | } |
| 30 | 30 | lua_xmove(L, co, narg); |
| 31 | − status = lua_resume(co, narg); | |
| 31 | + status = lua_resume(co, L, narg); | |
| 32 | 32 | if (status == LUA_OK || status == LUA_YIELD) { |
| 33 | 33 | int nres = lua_gettop(co); |
| 34 | 34 | if (!lua_checkstack(L, nres + 1)) { |
| @@ -1,9 +1,12 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lctype.c,v 1.10 2011/06/24 12:25:33 roberto Exp $ | |
| 2 | +** $Id: lctype.c,v 1.11 2011/10/03 16:19:23 roberto Exp $ | |
| 3 | 3 | ** 'ctype' functions for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | +#define lctype_c | |
| 8 | +#define LUA_CORE | |
| 9 | + | |
| 7 | 10 | #include "lctype.h" |
| 8 | 11 | |
| 9 | 12 | #if !LUA_USE_CTYPE /* { */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lctype.h,v 1.11 2011/06/27 18:22:46 roberto Exp $ | |
| 2 | +** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ | |
| 3 | 3 | ** 'ctype' functions for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -11,7 +11,7 @@ · 5 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | /* |
| 14 | −** WARNING: the functions defined here do not necessarily correspond | |
| 14 | +** WARNING: the functions defined here do not necessarily correspond | |
| 15 | 15 | ** to the similar functions in the standard C ctype.h. They are |
| 16 | 16 | ** optimized for the specific needs of Lua |
| 17 | 17 | */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldblib.c,v 1.130 2011/04/08 19:17:36 roberto Exp $ | |
| 2 | +** $Id: ldblib.c,v 1.131 2011/10/24 14:54:05 roberto Exp $ | |
| 3 | 3 | ** Interface from Lua to its debug API |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -260,8 +260,7 @@ static void hookf (lua_State *L, lua_Debug *ar) { · 254 unmodified lines | ||
| 260 | 260 | static const char *const hooknames[] = |
| 261 | 261 | {"call", "return", "line", "count", "tail call"}; |
| 262 | 262 | gethooktable(L); |
| 263 | − lua_pushlightuserdata(L, L); | |
| 264 | − lua_rawget(L, -2); | |
| 263 | + lua_rawgetp(L, -1, L); | |
| 265 | 264 | if (lua_isfunction(L, -1)) { |
| 266 | 265 | lua_pushstring(L, hooknames[(int)ar->event]); |
| 267 | 266 | if (ar->currentline >= 0) |
| @@ -308,9 +307,8 @@ static int db_sethook (lua_State *L) { · 40 unmodified lines | ||
| 308 | 307 | func = hookf; mask = makemask(smask, count); |
| 309 | 308 | } |
| 310 | 309 | gethooktable(L); |
| 311 | − lua_pushlightuserdata(L, L1); | |
| 312 | 310 | lua_pushvalue(L, arg+1); |
| 313 | − lua_rawset(L, -3); /* set new hook */ | |
| 311 | + lua_rawsetp(L, -2, L1); /* set new hook */ | |
| 314 | 312 | lua_pop(L, 1); /* remove hook table */ |
| 315 | 313 | lua_sethook(L1, func, mask, count); /* set hooks */ |
| 316 | 314 | return 0; |
| @@ -327,8 +325,7 @@ static int db_gethook (lua_State *L) { · 10 unmodified lines | ||
| 327 | 325 | lua_pushliteral(L, "external hook"); |
| 328 | 326 | else { |
| 329 | 327 | gethooktable(L); |
| 330 | − lua_pushlightuserdata(L, L1); | |
| 331 | − lua_rawget(L, -2); /* get hook */ | |
| 328 | + lua_rawgetp(L, -1, L1); /* get hook */ | |
| 332 | 329 | lua_remove(L, -2); /* remove hook table */ |
| 333 | 330 | } |
| 334 | 331 | lua_pushstring(L, unmakemask(mask, buff)); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldebug.c,v 2.82 2011/06/02 19:31:40 roberto Exp $ | |
| 2 | +** $Id: ldebug.c,v 2.87 2011/10/07 20:45:19 roberto Exp $ | |
| 3 | 3 | ** Debug Interface |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -94,6 +94,13 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { · 88 unmodified lines | ||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
| 97 | +static const char *upvalname (Proto *p, int uv) { | |
| 98 | + TString *s = check_exp(uv < p->sizeupvalues, p->upvalues[uv].name); | |
| 99 | + if (s == NULL) return "?"; | |
| 100 | + else return getstr(s); | |
| 101 | +} | |
| 102 | + | |
| 103 | + | |
| 97 | 104 | static const char *findvararg (CallInfo *ci, int n, StkId *pos) { |
| 98 | 105 | int nparams = clLvalue(ci->func)->p->numparams; |
| 99 | 106 | if (n >= ci->u.l.base - ci->func - nparams) |
| @@ -190,12 +197,14 @@ static void collectvalidlines (lua_State *L, Closure *f) { · 90 unmodified lines | ||
| 190 | 197 | } |
| 191 | 198 | else { |
| 192 | 199 | int i; |
| 200 | + TValue v; | |
| 193 | 201 | int *lineinfo = f->l.p->lineinfo; |
| 194 | − Table *t = luaH_new(L); | |
| 195 | − sethvalue(L, L->top, t); | |
| 202 | + Table *t = luaH_new(L); /* new table to store active lines */ | |
| 203 | + sethvalue(L, L->top, t); /* push it on stack */ | |
| 196 | 204 | incr_top(L); |
| 197 | − for (i=0; i<f->l.p->sizelineinfo; i++) | |
| 198 | − setbvalue(luaH_setint(L, t, lineinfo[i]), 1); | |
| 205 | + setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */ | |
| 206 | + for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */ | |
| 207 | + luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */ | |
| 199 | 208 | } |
| 200 | 209 | } |
| 201 | 210 | |
| @@ -230,7 +239,11 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, · 28 unmodified lines | ||
| 230 | 239 | break; |
| 231 | 240 | } |
| 232 | 241 | case 'n': { |
| 233 | − ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; | |
| 242 | + /* calling function is a known Lua function? */ | |
| 243 | + if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous)) | |
| 244 | + ar->namewhat = getfuncname(L, ci->previous, &ar->name); | |
| 245 | + else | |
| 246 | + ar->namewhat = NULL; | |
| 234 | 247 | if (ar->namewhat == NULL) { |
| 235 | 248 | ar->namewhat = ""; /* not found */ |
| 236 | 249 | ar->name = NULL; |
| @@ -284,17 +297,16 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { · 47 unmodified lines | ||
| 284 | 297 | ** ======================================================= |
| 285 | 298 | */ |
| 286 | 299 | |
| 287 | −static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |
| 300 | +static const char *getobjname (Proto *p, int lastpc, int reg, | |
| 288 | 301 | const char **name); |
| 289 | 302 | |
| 290 | 303 | |
| 291 | 304 | /* |
| 292 | 305 | ** find a "name" for the RK value 'c' |
| 293 | 306 | */ |
| 294 | −static void kname (lua_State *L, CallInfo *ci, int c, int oreg, | |
| 295 | − const char *what, const char **name) { | |
| 307 | +static void kname (Proto *p, int pc, int c, const char **name) { | |
| 296 | 308 | if (ISK(c)) { /* is 'c' a constant? */ |
| 297 | − TValue *kvalue = &ci_func(ci)->p->k[INDEXK(c)]; | |
| 309 | + TValue *kvalue = &p->k[INDEXK(c)]; | |
| 298 | 310 | if (ttisstring(kvalue)) { /* literal constant? */ |
| 299 | 311 | *name = svalue(kvalue); /* it is its own name */ |
| 300 | 312 | return; |
| @@ -302,8 +314,7 @@ static void kname (lua_State *L, CallInfo *ci, int c, int oreg, · 1 unmodified line | ||
| 302 | 314 | /* else no reasonable name found */ |
| 303 | 315 | } |
| 304 | 316 | else { /* 'c' is a register */ |
| 305 | − if (c != oreg) /* not the original register? */ | |
| 306 | − what = getobjname(L, ci, c, name); /* search for 'c' */ | |
| 317 | + const char *what = getobjname(p, pc, c, name); /* search for 'c' */ | |
| 307 | 318 | if (what && *what == 'c') { /* found a constant name? */ |
| 308 | 319 | return; /* 'name' already filled */ |
| 309 | 320 | } |
| @@ -313,85 +324,30 @@ static void kname (lua_State *L, CallInfo *ci, int c, int oreg, · 3 unmodified lines | ||
| 313 | 324 | } |
| 314 | 325 | |
| 315 | 326 | |
| 316 | −static const char *getobjname (lua_State *L, CallInfo *ci, int reg, | |
| 317 | − const char **name) { | |
| 318 | − Proto *p = ci_func(ci)->p; | |
| 319 | − const char *what = NULL; | |
| 320 | − int lastpc = currentpc(ci); | |
| 327 | +/* | |
| 328 | +** try to find last instruction before 'lastpc' that modified register 'reg' | |
| 329 | +*/ | |
| 330 | +static int findsetreg (Proto *p, int lastpc, int reg) { | |
| 321 | 331 | int pc; |
| 322 | − *name = luaF_getlocalname(p, reg + 1, lastpc); | |
| 323 | − if (*name) /* is a local? */ | |
| 324 | − return "local"; | |
| 325 | − /* else try symbolic execution */ | |
| 332 | + int setreg = -1; /* keep last instruction that changed 'reg' */ | |
| 326 | 333 | for (pc = 0; pc < lastpc; pc++) { |
| 327 | 334 | Instruction i = p->code[pc]; |
| 328 | 335 | OpCode op = GET_OPCODE(i); |
| 329 | 336 | int a = GETARG_A(i); |
| 330 | 337 | switch (op) { |
| 331 | − case OP_MOVE: { | |
| 332 | − if (reg == a) { | |
| 333 | − int b = GETARG_B(i); /* move from 'b' to 'a' */ | |
| 334 | − if (b < a) | |
| 335 | − what = getobjname(L, ci, b, name); /* get name for 'b' */ | |
| 336 | − else what = NULL; | |
| 337 | − } | |
| 338 | − break; | |
| 339 | − } | |
| 340 | − case OP_GETTABUP: | |
| 341 | − case OP_GETTABLE: { | |
| 342 | − if (reg == a) { | |
| 343 | − int k = GETARG_C(i); /* key index */ | |
| 344 | − int t = GETARG_B(i); | |
| 345 | − const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ | |
| 346 | − ? luaF_getlocalname(p, t + 1, pc) | |
| 347 | − : getstr(p->upvalues[t].name); | |
| 348 | − kname(L, ci, k, a, what, name); | |
| 349 | − what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; | |
| 350 | − } | |
| 351 | − break; | |
| 352 | − } | |
| 353 | − case OP_GETUPVAL: { | |
| 354 | − if (reg == a) { | |
| 355 | − int u = GETARG_B(i); /* upvalue index */ | |
| 356 | − TString *tn = p->upvalues[u].name; | |
| 357 | − *name = tn ? getstr(tn) : "?"; | |
| 358 | − what = "upvalue"; | |
| 359 | − } | |
| 360 | − break; | |
| 361 | − } | |
| 362 | − case OP_LOADK: | |
| 363 | − case OP_LOADKX: { | |
| 364 | − if (reg == a) { | |
| 365 | − int b = (op == OP_LOADK) ? GETARG_Bx(i) | |
| 366 | − : GETARG_Ax(p->code[pc + 1]); | |
| 367 | − if (ttisstring(&p->k[b])) { | |
| 368 | − what = "constant"; | |
| 369 | − *name = svalue(&p->k[b]); | |
| 370 | − } | |
| 371 | − } | |
| 372 | − break; | |
| 373 | − } | |
| 374 | 338 | case OP_LOADNIL: { |
| 375 | 339 | int b = GETARG_B(i); |
| 376 | 340 | if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */ |
| 377 | − what = NULL; | |
| 378 | − break; | |
| 379 | − } | |
| 380 | − case OP_SELF: { | |
| 381 | − if (reg == a) { | |
| 382 | − int k = GETARG_C(i); /* key index */ | |
| 383 | − kname(L, ci, k, a, what, name); | |
| 384 | − what = "method"; | |
| 385 | − } | |
| 341 | + setreg = pc; | |
| 386 | 342 | break; |
| 387 | 343 | } |
| 388 | 344 | case OP_TFORCALL: { |
| 389 | − if (reg >= a + 2) what = NULL; /* affect all regs above its base */ | |
| 345 | + if (reg >= a + 2) setreg = pc; /* affect all regs above its base */ | |
| 390 | 346 | break; |
| 391 | 347 | } |
| 392 | 348 | case OP_CALL: |
| 393 | 349 | case OP_TAILCALL: { |
| 394 | − if (reg >= a) what = NULL; /* affect all registers above base */ | |
| 350 | + if (reg >= a) setreg = pc; /* affect all registers above base */ | |
| 395 | 351 | break; |
| 396 | 352 | } |
| 397 | 353 | case OP_JMP: { |
| @@ -403,35 +359,87 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, · 5 unmodified lines | ||
| 403 | 359 | break; |
| 404 | 360 | } |
| 405 | 361 | case OP_TEST: { |
| 406 | − if (reg == a) what = NULL; /* jumped code can change 'a' */ | |
| 362 | + if (reg == a) setreg = pc; /* jumped code can change 'a' */ | |
| 407 | 363 | break; |
| 408 | 364 | } |
| 409 | 365 | default: |
| 410 | − if (testAMode(op) && reg == a) what = NULL; | |
| 366 | + if (testAMode(op) && reg == a) /* any instruction that set A */ | |
| 367 | + setreg = pc; | |
| 411 | 368 | break; |
| 412 | 369 | } |
| 413 | 370 | } |
| 414 | − return what; | |
| 371 | + return setreg; | |
| 372 | +} | |
| 373 | + | |
| 374 | + | |
| 375 | +static const char *getobjname (Proto *p, int lastpc, int reg, | |
| 376 | + const char **name) { | |
| 377 | + int pc; | |
| 378 | + *name = luaF_getlocalname(p, reg + 1, lastpc); | |
| 379 | + if (*name) /* is a local? */ | |
| 380 | + return "local"; | |
| 381 | + /* else try symbolic execution */ | |
| 382 | + pc = findsetreg(p, lastpc, reg); | |
| 383 | + if (pc != -1) { /* could find instruction? */ | |
| 384 | + Instruction i = p->code[pc]; | |
| 385 | + OpCode op = GET_OPCODE(i); | |
| 386 | + switch (op) { | |
| 387 | + case OP_MOVE: { | |
| 388 | + int b = GETARG_B(i); /* move from 'b' to 'a' */ | |
| 389 | + if (b < GETARG_A(i)) | |
| 390 | + return getobjname(p, pc, b, name); /* get name for 'b' */ | |
| 391 | + break; | |
| 392 | + } | |
| 393 | + case OP_GETTABUP: | |
| 394 | + case OP_GETTABLE: { | |
| 395 | + int k = GETARG_C(i); /* key index */ | |
| 396 | + int t = GETARG_B(i); /* table index */ | |
| 397 | + const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ | |
| 398 | + ? luaF_getlocalname(p, t + 1, pc) | |
| 399 | + : upvalname(p, t); | |
| 400 | + kname(p, pc, k, name); | |
| 401 | + return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; | |
| 402 | + } | |
| 403 | + case OP_GETUPVAL: { | |
| 404 | + *name = upvalname(p, GETARG_B(i)); | |
| 405 | + return "upvalue"; | |
| 406 | + } | |
| 407 | + case OP_LOADK: | |
| 408 | + case OP_LOADKX: { | |
| 409 | + int b = (op == OP_LOADK) ? GETARG_Bx(i) | |
| 410 | + : GETARG_Ax(p->code[pc + 1]); | |
| 411 | + if (ttisstring(&p->k[b])) { | |
| 412 | + *name = svalue(&p->k[b]); | |
| 413 | + return "constant"; | |
| 414 | + } | |
| 415 | + break; | |
| 416 | + } | |
| 417 | + case OP_SELF: { | |
| 418 | + int k = GETARG_C(i); /* key index */ | |
| 419 | + kname(p, pc, k, name); | |
| 420 | + return "method"; | |
| 421 | + } | |
| 422 | + default: break; /* go through to return NULL */ | |
| 423 | + } | |
| 424 | + } | |
| 425 | + return NULL; /* could not find reasonable name */ | |
| 415 | 426 | } |
| 416 | 427 | |
| 417 | 428 | |
| 418 | 429 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { |
| 419 | 430 | TMS tm; |
| 420 | − Instruction i; | |
| 421 | − if ((ci->callstatus & CIST_TAIL) || !isLua(ci->previous)) | |
| 422 | − return NULL; /* calling function is not Lua (or is unknown) */ | |
| 423 | − ci = ci->previous; /* calling function */ | |
| 424 | − i = ci_func(ci)->p->code[currentpc(ci)]; | |
| 425 | − if (GET_OPCODE(i) == OP_EXTRAARG) /* extra argument? */ | |
| 426 | − i = ci_func(ci)->p->code[currentpc(ci) - 1]; /* get 'real' instruction */ | |
| 431 | + Proto *p = ci_func(ci)->p; /* calling function */ | |
| 432 | + int pc = currentpc(ci); /* calling instruction index */ | |
| 433 | + Instruction i = p->code[pc]; /* calling instruction */ | |
| 427 | 434 | switch (GET_OPCODE(i)) { |
| 428 | 435 | case OP_CALL: |
| 429 | − case OP_TAILCALL: | |
| 430 | − return getobjname(L, ci, GETARG_A(i), name); | |
| 431 | − case OP_TFORCALL: { | |
| 436 | + case OP_TAILCALL: /* get function name */ | |
| 437 | + return getobjname(p, pc, GETARG_A(i), name); | |
| 438 | + case OP_TFORCALL: { /* for iterator */ | |
| 432 | 439 | *name = "for iterator"; |
| 433 | 440 | return "for iterator"; |
| 434 | 441 | } |
| 442 | + /* all other instructions can call only through metamethods */ | |
| 435 | 443 | case OP_SELF: |
| 436 | 444 | case OP_GETTABUP: |
| 437 | 445 | case OP_GETTABLE: tm = TM_INDEX; break; |
| @@ -473,12 +481,12 @@ static int isinstack (CallInfo *ci, const TValue *o) { · 35 unmodified lines | ||
| 473 | 481 | |
| 474 | 482 | |
| 475 | 483 | static const char *getupvalname (CallInfo *ci, const TValue *o, |
| 476 | − const char **name) { | |
| 484 | + const char **name) { | |
| 477 | 485 | LClosure *c = ci_func(ci); |
| 478 | 486 | int i; |
| 479 | 487 | for (i = 0; i < c->nupvalues; i++) { |
| 480 | 488 | if (c->upvals[i]->v == o) { |
| 481 | − *name = getstr(c->p->upvalues[i].name); | |
| 489 | + *name = upvalname(c->p, i); | |
| 482 | 490 | return "upvalue"; |
| 483 | 491 | } |
| 484 | 492 | } |
| @@ -494,7 +502,8 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 9 unmodified lines | ||
| 494 | 502 | if (isLua(ci)) { |
| 495 | 503 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ |
| 496 | 504 | if (!kind && isinstack(ci, o)) /* no? try a register */ |
| 497 | − kind = getobjname(L, ci, cast_int(o - ci->u.l.base), &name); | |
| 505 | + kind = getobjname(ci_func(ci)->p, currentpc(ci), | |
| 506 | + cast_int(o - ci->u.l.base), &name); | |
| 498 | 507 | } |
| 499 | 508 | if (kind) |
| 500 | 509 | luaG_runerror(L, "attempt to %s %s " LUA_QS " (a %s value)", |
| @@ -511,7 +520,7 @@ void luaG_concaterror (lua_State *L, StkId p1, StkId p2) { · 10 unmodified lines | ||
| 511 | 520 | } |
| 512 | 521 | |
| 513 | 522 | |
| 514 | −void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { | |
| 523 | +l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { | |
| 515 | 524 | TValue temp; |
| 516 | 525 | if (luaV_tonumber(p1, &temp) == NULL) |
| 517 | 526 | p2 = p1; /* first operand is wrong */ |
| @@ -519,14 +528,13 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { · 1 unmodified line | ||
| 519 | 528 | } |
| 520 | 529 | |
| 521 | 530 | |
| 522 | −int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { | |
| 531 | +l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { | |
| 523 | 532 | const char *t1 = objtypename(p1); |
| 524 | 533 | const char *t2 = objtypename(p2); |
| 525 | 534 | if (t1 == t2) |
| 526 | 535 | luaG_runerror(L, "attempt to compare two %s values", t1); |
| 527 | 536 | else |
| 528 | 537 | luaG_runerror(L, "attempt to compare %s with %s", t1, t2); |
| 529 | − return 0; | |
| 530 | 538 | } |
| 531 | 539 | |
| 532 | 540 | |
| @@ -546,7 +554,7 @@ static void addinfo (lua_State *L, const char *msg) { · 13 unmodified lines | ||
| 546 | 554 | } |
| 547 | 555 | |
| 548 | 556 | |
| 549 | −void luaG_errormsg (lua_State *L) { | |
| 557 | +l_noret luaG_errormsg (lua_State *L) { | |
| 550 | 558 | if (L->errfunc != 0) { /* is there an error handling function? */ |
| 551 | 559 | StkId errfunc = restorestack(L, L->errfunc); |
| 552 | 560 | if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); |
| @@ -559,7 +567,7 @@ void luaG_errormsg (lua_State *L) { · 6 unmodified lines | ||
| 559 | 567 | } |
| 560 | 568 | |
| 561 | 569 | |
| 562 | −void luaG_runerror (lua_State *L, const char *fmt, ...) { | |
| 570 | +l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { | |
| 563 | 571 | va_list argp; |
| 564 | 572 | va_start(argp, fmt); |
| 565 | 573 | addinfo(L, luaO_pushvfstring(L, fmt, argp)); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldebug.h,v 2.6 2011/06/02 19:31:40 roberto Exp $ | |
| 2 | +** $Id: ldebug.h,v 2.7 2011/10/07 20:45:19 roberto Exp $ | |
| 3 | 3 | ** Auxiliary functions from Debug Interface module |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -21,14 +21,14 @@ · 15 unmodified lines | ||
| 21 | 21 | #define ci_func(ci) (clLvalue((ci)->func)) |
| 22 | 22 | |
| 23 | 23 | |
| 24 | −LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, | |
| 25 | − const char *opname); | |
| 26 | −LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); | |
| 27 | −LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, | |
| 28 | − const TValue *p2); | |
| 29 | −LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, | |
| 30 | − const TValue *p2); | |
| 31 | −LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); | |
| 32 | −LUAI_FUNC void luaG_errormsg (lua_State *L); | |
| 24 | +LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, | |
| 25 | + const char *opname); | |
| 26 | +LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2); | |
| 27 | +LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1, | |
| 28 | + const TValue *p2); | |
| 29 | +LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, | |
| 30 | + const TValue *p2); | |
| 31 | +LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); | |
| 32 | +LUAI_FUNC l_noret luaG_errormsg (lua_State *L); | |
| 33 | 33 | |
| 34 | 34 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldo.c,v 2.98 2011/06/28 15:42:04 roberto Exp $ | |
| 2 | +** $Id: ldo.c,v 2.101 2011/10/07 20:45:19 roberto Exp $ | |
| 3 | 3 | ** Stack and Call structure of Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -100,7 +100,7 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { · 94 unmodified lines | ||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | −void luaD_throw (lua_State *L, int errcode) { | |
| 103 | +l_noret luaD_throw (lua_State *L, int errcode) { | |
| 104 | 104 | if (L->errorJmp) { /* thread has an error handler? */ |
| 105 | 105 | L->errorJmp->status = errcode; /* set status */ |
| 106 | 106 | LUAI_THROW(L, L->errorJmp); /* jump to it */ |
| @@ -123,7 +123,7 @@ void luaD_throw (lua_State *L, int errcode) { · 16 unmodified lines | ||
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { |
| 126 | − unsigned short oldnCcalls = G(L)->nCcalls; | |
| 126 | + unsigned short oldnCcalls = L->nCcalls; | |
| 127 | 127 | struct lua_longjmp lj; |
| 128 | 128 | lj.status = LUA_OK; |
| 129 | 129 | lj.previous = L->errorJmp; /* chain new error handler */ |
| @@ -132,7 +132,7 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { · 2 unmodified lines | ||
| 132 | 132 | (*f)(L, ud); |
| 133 | 133 | ); |
| 134 | 134 | L->errorJmp = lj.previous; /* restore old error handler */ |
| 135 | − G(L)->nCcalls = oldnCcalls; | |
| 135 | + L->nCcalls = oldnCcalls; | |
| 136 | 136 | return lj.status; |
| 137 | 137 | } |
| 138 | 138 | |
| @@ -344,7 +344,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { · 205 unmodified lines | ||
| 344 | 344 | } |
| 345 | 345 | default: { /* not a function */ |
| 346 | 346 | func = tryfuncTM(L, func); /* retry with 'function' tag method */ |
| 347 | − return luaD_precall(L, func, nresults); | |
| 347 | + return luaD_precall(L, func, nresults); /* now it must be a function */ | |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | } |
| @@ -382,18 +382,17 @@ int luaD_poscall (lua_State *L, StkId firstResult) { · 31 unmodified lines | ||
| 382 | 382 | ** function position. |
| 383 | 383 | */ |
| 384 | 384 | void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) { |
| 385 | − global_State *g = G(L); | |
| 386 | − if (++g->nCcalls >= LUAI_MAXCCALLS) { | |
| 387 | − if (g->nCcalls == LUAI_MAXCCALLS) | |
| 385 | + if (++L->nCcalls >= LUAI_MAXCCALLS) { | |
| 386 | + if (L->nCcalls == LUAI_MAXCCALLS) | |
| 388 | 387 | luaG_runerror(L, "C stack overflow"); |
| 389 | − else if (g->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) | |
| 388 | + else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) | |
| 390 | 389 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ |
| 391 | 390 | } |
| 392 | 391 | if (!allowyield) L->nny++; |
| 393 | 392 | if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ |
| 394 | 393 | luaV_execute(L); /* call it */ |
| 395 | 394 | if (!allowyield) L->nny--; |
| 396 | − g->nCcalls--; | |
| 395 | + L->nCcalls--; | |
| 397 | 396 | luaC_checkGC(L); |
| 398 | 397 | } |
| 399 | 398 | |
| @@ -404,7 +403,7 @@ static void finishCcall (lua_State *L) { · 4 unmodified lines | ||
| 404 | 403 | lua_assert(ci->u.c.k != NULL); /* must have a continuation */ |
| 405 | 404 | lua_assert(L->nny == 0); |
| 406 | 405 | /* finish 'luaD_call' */ |
| 407 | − G(L)->nCcalls--; | |
| 406 | + L->nCcalls--; | |
| 408 | 407 | /* finish 'lua_callk' */ |
| 409 | 408 | adjustresults(L, ci->nresults); |
| 410 | 409 | /* call continuation function */ |
| @@ -473,7 +472,7 @@ static int recover (lua_State *L, int status) { · 62 unmodified lines | ||
| 473 | 472 | ** coroutine itself. (Such errors should not be handled by any coroutine |
| 474 | 473 | ** error handler and should not kill the coroutine.) |
| 475 | 474 | */ |
| 476 | −static void resume_error (lua_State *L, const char *msg, StkId firstArg) { | |
| 475 | +static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) { | |
| 477 | 476 | L->top = firstArg; /* remove args from the stack */ |
| 478 | 477 | setsvalue2s(L, L->top, luaS_new(L, msg)); /* push error message */ |
| 479 | 478 | incr_top(L); |
| @@ -487,7 +486,7 @@ static void resume_error (lua_State *L, const char *msg, StkId firstArg) { · 7 unmodified lines | ||
| 487 | 486 | static void resume (lua_State *L, void *ud) { |
| 488 | 487 | StkId firstArg = cast(StkId, ud); |
| 489 | 488 | CallInfo *ci = L->ci; |
| 490 | − if (G(L)->nCcalls >= LUAI_MAXCCALLS) | |
| 489 | + if (L->nCcalls >= LUAI_MAXCCALLS) | |
| 491 | 490 | resume_error(L, "C stack overflow", firstArg); |
| 492 | 491 | if (L->status == LUA_OK) { /* may be starting a coroutine */ |
| 493 | 492 | if (ci != &L->base_ci) /* not in base level? */ |
| @@ -514,7 +513,7 @@ static void resume (lua_State *L, void *ud) { · 20 unmodified lines | ||
| 514 | 513 | api_checknelems(L, n); |
| 515 | 514 | firstArg = L->top - n; /* yield results come from continuation */ |
| 516 | 515 | } |
| 517 | − G(L)->nCcalls--; /* finish 'luaD_call' */ | |
| 516 | + L->nCcalls--; /* finish 'luaD_call' */ | |
| 518 | 517 | luaD_poscall(L, firstArg); /* finish 'luaD_precall' */ |
| 519 | 518 | } |
| 520 | 519 | unroll(L, NULL); |
| @@ -522,11 +521,11 @@ static void resume (lua_State *L, void *ud) { · 1 unmodified line | ||
| 522 | 521 | } |
| 523 | 522 | |
| 524 | 523 | |
| 525 | −LUA_API int lua_resume (lua_State *L, int nargs) { | |
| 524 | +LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) { | |
| 526 | 525 | int status; |
| 527 | 526 | lua_lock(L); |
| 528 | 527 | luai_userstateresume(L, nargs); |
| 529 | − ++G(L)->nCcalls; /* count resume */ | |
| 528 | + L->nCcalls = (from) ? from->nCcalls + 1 : 1; | |
| 530 | 529 | L->nny = 0; /* allow yields */ |
| 531 | 530 | api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs); |
| 532 | 531 | status = luaD_rawrunprotected(L, resume, L->top - nargs); |
| @@ -546,7 +545,8 @@ LUA_API int lua_resume (lua_State *L, int nargs) { · 13 unmodified lines | ||
| 546 | 545 | lua_assert(status == L->status); |
| 547 | 546 | } |
| 548 | 547 | L->nny = 1; /* do not allow yields */ |
| 549 | − --G(L)->nCcalls; | |
| 548 | + L->nCcalls--; | |
| 549 | + lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0)); | |
| 550 | 550 | lua_unlock(L); |
| 551 | 551 | return status; |
| 552 | 552 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldo.h,v 2.18 2009/12/17 12:28:57 roberto Exp $ | |
| 2 | +** $Id: ldo.h,v 2.19 2011/10/07 20:45:19 roberto Exp $ | |
| 3 | 3 | ** Stack and Call structure of Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -38,7 +38,7 @@ LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); · 32 unmodified lines | ||
| 38 | 38 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); |
| 39 | 39 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); |
| 40 | 40 | |
| 41 | −LUAI_FUNC void luaD_throw (lua_State *L, int errcode); | |
| 41 | +LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); | |
| 42 | 42 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); |
| 43 | 43 | |
| 44 | 44 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ldump.c,v 1.18 2011/05/06 13:35:17 lhf Exp $ | |
| 2 | +** $Id: ldump.c,v 1.19 2011/11/23 17:48:18 lhf Exp $ | |
| 3 | 3 | ** save precompiled Lua chunks |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -111,8 +111,8 @@ static void DumpUpvalues(const Proto* f, DumpState* D) · 105 unmodified lines | ||
| 111 | 111 | DumpInt(n,D); |
| 112 | 112 | for (i=0; i<n; i++) |
| 113 | 113 | { |
| 114 | − DumpChar(f->upvalues[i].instack, D); | |
| 115 | − DumpChar(f->upvalues[i].idx, D); | |
| 114 | + DumpChar(f->upvalues[i].instack,D); | |
| 115 | + DumpChar(f->upvalues[i].idx,D); | |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lgc.c,v 2.109 2011/05/05 19:42:25 roberto Exp $ | |
| 2 | +** $Id: lgc.c,v 2.114 2011/10/03 17:54:25 roberto Exp $ | |
| 3 | 3 | ** Garbage Collector |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -100,12 +100,13 @@ static void reallymarkobject (global_State *g, GCObject *o); · 94 unmodified lines | ||
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | /* |
| 103 | −** mark a table entry as dead (therefore removing it from the table) | |
| 103 | +** if key is not marked, mark its entry as dead (therefore removing it | |
| 104 | +** from the table) | |
| 104 | 105 | */ |
| 105 | 106 | static void removeentry (Node *n) { |
| 106 | 107 | lua_assert(ttisnil(gval(n))); |
| 107 | − if (iscollectable(gkey(n))) | |
| 108 | − setdeadvalue(gkey(n)); /* dead key; remove it */ | |
| 108 | + if (valiswhite(gkey(n))) | |
| 109 | + setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */ | |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | 112 | |
| @@ -116,13 +117,13 @@ static void removeentry (Node *n) { · 4 unmodified lines | ||
| 116 | 117 | ** other objects: if really collected, cannot keep them; for objects |
| 117 | 118 | ** being finalized, keep them in keys, but not in values |
| 118 | 119 | */ |
| 119 | −static int iscleared (const TValue *o, int iskey) { | |
| 120 | +static int iscleared (const TValue *o) { | |
| 120 | 121 | if (!iscollectable(o)) return 0; |
| 121 | 122 | else if (ttisstring(o)) { |
| 122 | 123 | stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */ |
| 123 | 124 | return 0; |
| 124 | 125 | } |
| 125 | − else return iswhite(gcvalue(o)) || (!iskey && isfinalized(gcvalue(o))); | |
| 126 | + else return iswhite(gcvalue(o)); | |
| 126 | 127 | } |
| 127 | 128 | |
| 128 | 129 | |
| @@ -152,7 +153,7 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { · 23 unmodified lines | ||
| 152 | 153 | */ |
| 153 | 154 | void luaC_barrierback_ (lua_State *L, GCObject *o) { |
| 154 | 155 | global_State *g = G(L); |
| 155 | − lua_assert(isblack(o) && !isdead(g, o)); | |
| 156 | + lua_assert(isblack(o) && !isdead(g, o) && gch(o)->tt == LUA_TTABLE); | |
| 156 | 157 | black2gray(o); /* make object gray (again) */ |
| 157 | 158 | gco2t(o)->gclist = g->grayagain; |
| 158 | 159 | g->grayagain = o; |
| @@ -342,6 +343,9 @@ static void markroot (global_State *g) { · 183 unmodified lines | ||
| 342 | 343 | |
| 343 | 344 | static void traverseweakvalue (global_State *g, Table *h) { |
| 344 | 345 | Node *n, *limit = gnode(h, sizenode(h)); |
| 346 | + /* if there is array part, assume it may have white values (do not | |
| 347 | + traverse it just to check) */ | |
| 348 | + int hasclears = (h->sizearray > 0); | |
| 345 | 349 | for (n = gnode(h, 0); n < limit; n++) { |
| 346 | 350 | checkdeadkey(n); |
| 347 | 351 | if (ttisnil(gval(n))) /* entry is empty? */ |
| @@ -349,15 +353,21 @@ static void traverseweakvalue (global_State *g, Table *h) { · 1 unmodified line | ||
| 349 | 353 | else { |
| 350 | 354 | lua_assert(!ttisnil(gkey(n))); |
| 351 | 355 | markvalue(g, gkey(n)); /* mark key */ |
| 356 | + if (!hasclears && iscleared(gval(n))) /* is there a white value? */ | |
| 357 | + hasclears = 1; /* table will have to be cleared */ | |
| 352 | 358 | } |
| 353 | 359 | } |
| 354 | − linktable(h, &g->weak); /* link into appropriate list */ | |
| 360 | + if (hasclears) | |
| 361 | + linktable(h, &g->weak); /* has to be cleared later */ | |
| 362 | + else /* no white values */ | |
| 363 | + linktable(h, &g->grayagain); /* no need to clean */ | |
| 355 | 364 | } |
| 356 | 365 | |
| 357 | 366 | |
| 358 | 367 | static int traverseephemeron (global_State *g, Table *h) { |
| 359 | 368 | int marked = 0; /* true if an object is marked in this traversal */ |
| 360 | − int hasclears = 0; /* true if table has unmarked pairs */ | |
| 369 | + int hasclears = 0; /* true if table has white keys */ | |
| 370 | + int prop = 0; /* true if table has entry "white-key -> white-value" */ | |
| 361 | 371 | Node *n, *limit = gnode(h, sizenode(h)); |
| 362 | 372 | int i; |
| 363 | 373 | /* traverse array part (numeric keys are 'strong') */ |
| @@ -372,19 +382,22 @@ static int traverseephemeron (global_State *g, Table *h) { · 8 unmodified lines | ||
| 372 | 382 | checkdeadkey(n); |
| 373 | 383 | if (ttisnil(gval(n))) /* entry is empty? */ |
| 374 | 384 | removeentry(n); /* remove it */ |
| 385 | + else if (iscleared(gkey(n))) { /* key is not marked (yet)? */ | |
| 386 | + hasclears = 1; /* table must be cleared */ | |
| 387 | + if (valiswhite(gval(n))) /* value not marked yet? */ | |
| 388 | + prop = 1; /* must propagate again */ | |
| 389 | + } | |
| 375 | 390 | else if (valiswhite(gval(n))) { /* value not marked yet? */ |
| 376 | − if (iscleared(gkey(n), 1)) /* key is not marked (yet)? */ | |
| 377 | − hasclears = 1; /* may have to propagate mark from key to value */ | |
| 378 | − else { /* key is marked, so mark value */ | |
| 379 | − marked = 1; /* value was not marked */ | |
| 380 | − reallymarkobject(g, gcvalue(gval(n))); | |
| 381 | − } | |
| 391 | + marked = 1; | |
| 392 | + reallymarkobject(g, gcvalue(gval(n))); /* mark it now */ | |
| 382 | 393 | } |
| 383 | 394 | } |
| 384 | − if (hasclears) /* does table have unmarked pairs? */ | |
| 385 | − linktable(h, &g->ephemeron); /* will have to propagate again */ | |
| 386 | − else /* nothing to propagate */ | |
| 387 | − linktable(h, &g->weak); /* avoid convergence phase */ | |
| 395 | + if (prop) | |
| 396 | + linktable(h, &g->ephemeron); /* have to propagate again */ | |
| 397 | + else if (hasclears) /* does table have white keys? */ | |
| 398 | + linktable(h, &g->allweak); /* may have to clean white keys */ | |
| 399 | + else /* no white keys */ | |
| 400 | + linktable(h, &g->grayagain); /* no need to clean */ | |
| 388 | 401 | return marked; |
| 389 | 402 | } |
| 390 | 403 | |
| @@ -526,11 +539,26 @@ static void propagateall (global_State *g) { · 135 unmodified lines | ||
| 526 | 539 | } |
| 527 | 540 | |
| 528 | 541 | |
| 529 | −static void traverselistofgrays (global_State *g, GCObject **l) { | |
| 542 | +static void propagatelist (global_State *g, GCObject *l) { | |
| 530 | 543 | lua_assert(g->gray == NULL); /* no grays left */ |
| 531 | − g->gray = *l; /* now 'l' is new gray list */ | |
| 532 | − *l = NULL; | |
| 533 | − propagateall(g); | |
| 544 | + g->gray = l; | |
| 545 | + propagateall(g); /* traverse all elements from 'l' */ | |
| 546 | +} | |
| 547 | + | |
| 548 | +/* | |
| 549 | +** retraverse all gray lists. Because tables may be reinserted in other | |
| 550 | +** lists when traversed, traverse the original lists to avoid traversing | |
| 551 | +** twice the same table (which is not wrong, but inefficient) | |
| 552 | +*/ | |
| 553 | +static void retraversegrays (global_State *g) { | |
| 554 | + GCObject *weak = g->weak; /* save original lists */ | |
| 555 | + GCObject *grayagain = g->grayagain; | |
| 556 | + GCObject *ephemeron = g->ephemeron; | |
| 557 | + g->weak = g->grayagain = g->ephemeron = NULL; | |
| 558 | + propagateall(g); /* traverse main gray list */ | |
| 559 | + propagatelist(g, grayagain); | |
| 560 | + propagatelist(g, weak); | |
| 561 | + propagatelist(g, ephemeron); | |
| 534 | 562 | } |
| 535 | 563 | |
| 536 | 564 | |
| @@ -562,21 +590,39 @@ static void convergeephemerons (global_State *g) { · 25 unmodified lines | ||
| 562 | 590 | |
| 563 | 591 | |
| 564 | 592 | /* |
| 565 | −** clear collected entries from all weaktables in list 'l' | |
| 593 | +** clear entries with unmarked keys from all weaktables in list 'l' up | |
| 594 | +** to element 'f' | |
| 595 | +*/ | |
| 596 | +static void clearkeys (GCObject *l, GCObject *f) { | |
| 597 | + for (; l != f; l = gco2t(l)->gclist) { | |
| 598 | + Table *h = gco2t(l); | |
| 599 | + Node *n, *limit = gnode(h, sizenode(h)); | |
| 600 | + for (n = gnode(h, 0); n < limit; n++) { | |
| 601 | + if (!ttisnil(gval(n)) && (iscleared(gkey(n)))) { | |
| 602 | + setnilvalue(gval(n)); /* remove value ... */ | |
| 603 | + removeentry(n); /* and remove entry from table */ | |
| 604 | + } | |
| 605 | + } | |
| 606 | + } | |
| 607 | +} | |
| 608 | + | |
| 609 | + | |
| 610 | +/* | |
| 611 | +** clear entries with unmarked values from all weaktables in list 'l' up | |
| 612 | +** to element 'f' | |
| 566 | 613 | */ |
| 567 | −static void cleartable (GCObject *l) { | |
| 568 | − for (; l != NULL; l = gco2t(l)->gclist) { | |
| 614 | +static void clearvalues (GCObject *l, GCObject *f) { | |
| 615 | + for (; l != f; l = gco2t(l)->gclist) { | |
| 569 | 616 | Table *h = gco2t(l); |
| 570 | 617 | Node *n, *limit = gnode(h, sizenode(h)); |
| 571 | 618 | int i; |
| 572 | 619 | for (i = 0; i < h->sizearray; i++) { |
| 573 | 620 | TValue *o = &h->array[i]; |
| 574 | − if (iscleared(o, 0)) /* value was collected? */ | |
| 621 | + if (iscleared(o)) /* value was collected? */ | |
| 575 | 622 | setnilvalue(o); /* remove value */ |
| 576 | 623 | } |
| 577 | 624 | for (n = gnode(h, 0); n < limit; n++) { |
| 578 | − if (!ttisnil(gval(n)) && /* non-empty entry? */ | |
| 579 | − (iscleared(gkey(n), 1) || iscleared(gval(n), 0))) { | |
| 625 | + if (!ttisnil(gval(n)) && iscleared(gval(n))) { | |
| 580 | 626 | setnilvalue(gval(n)); /* remove value ... */ |
| 581 | 627 | removeentry(n); /* and remove entry from table */ |
| 582 | 628 | } |
| @@ -743,10 +789,10 @@ static void GCTM (lua_State *L, int propagateerrors) { · 160 unmodified lines | ||
| 743 | 789 | |
| 744 | 790 | |
| 745 | 791 | /* |
| 746 | −** move all unreachable objects that need finalization from list 'finobj' | |
| 747 | −** to list 'tobefnz' | |
| 792 | +** move all unreachable objects (or 'all' objects) that need | |
| 793 | +** finalization from list 'finobj' to list 'tobefnz' (to be finalized) | |
| 748 | 794 | */ |
| 749 | −void luaC_separateudata (lua_State *L, int all) { | |
| 795 | +static void separatetobefnz (lua_State *L, int all) { | |
| 750 | 796 | global_State *g = G(L); |
| 751 | 797 | GCObject **p = &g->finobj; |
| 752 | 798 | GCObject *curr; |
| @@ -842,14 +888,13 @@ static void callallpendingfinalizers (lua_State *L, int propagateerrors) { · 89 unmodified lines | ||
| 842 | 888 | void luaC_freeallobjects (lua_State *L) { |
| 843 | 889 | global_State *g = G(L); |
| 844 | 890 | int i; |
| 891 | + separatetobefnz(L, 1); /* separate all objects with finalizers */ | |
| 892 | + lua_assert(g->finobj == NULL); | |
| 845 | 893 | callallpendingfinalizers(L, 0); |
| 846 | − /* following "white" makes all objects look dead */ | |
| 847 | − g->currentwhite = WHITEBITS; | |
| 894 | + g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */ | |
| 848 | 895 | g->gckind = KGC_NORMAL; |
| 849 | − sweepwholelist(L, &g->finobj); | |
| 850 | − lua_assert(g->finobj == NULL); | |
| 896 | + sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */ | |
| 851 | 897 | sweepwholelist(L, &g->allgc); |
| 852 | − lua_assert(g->allgc == NULL); | |
| 853 | 898 | for (i = 0; i < g->strt.size; i++) /* free all string lists */ |
| 854 | 899 | sweepwholelist(L, &g->strt.hash[i]); |
| 855 | 900 | lua_assert(g->strt.nuse == 0); |
| @@ -858,6 +903,7 @@ void luaC_freeallobjects (lua_State *L) { · 2 unmodified lines | ||
| 858 | 903 | |
| 859 | 904 | static void atomic (lua_State *L) { |
| 860 | 905 | global_State *g = G(L); |
| 906 | + GCObject *origweak, *origall; | |
| 861 | 907 | lua_assert(!iswhite(obj2gco(g->mainthread))); |
| 862 | 908 | markobject(g, L); /* mark running thread */ |
| 863 | 909 | /* registry and global metatables may be changed by API */ |
| @@ -866,20 +912,24 @@ static void atomic (lua_State *L) { · 2 unmodified lines | ||
| 866 | 912 | /* remark occasional upvalues of (maybe) dead threads */ |
| 867 | 913 | remarkupvals(g); |
| 868 | 914 | /* traverse objects caught by write barrier and by 'remarkupvals' */ |
| 869 | − propagateall(g); | |
| 870 | − traverselistofgrays(g, &g->weak); /* remark weak tables */ | |
| 871 | − traverselistofgrays(g, &g->ephemeron); /* remark ephemeron tables */ | |
| 872 | − traverselistofgrays(g, &g->grayagain); /* remark gray again */ | |
| 915 | + retraversegrays(g); | |
| 873 | 916 | convergeephemerons(g); |
| 874 | 917 | /* at this point, all strongly accessible objects are marked. */ |
| 875 | − luaC_separateudata(L, 0); /* separate userdata to be finalized */ | |
| 918 | + /* clear values from weak tables, before checking finalizers */ | |
| 919 | + clearvalues(g->weak, NULL); | |
| 920 | + clearvalues(g->allweak, NULL); | |
| 921 | + origweak = g->weak; origall = g->allweak; | |
| 922 | + separatetobefnz(L, 0); /* separate objects to be finalized */ | |
| 876 | 923 | markbeingfnz(g); /* mark userdata that will be finalized */ |
| 877 | 924 | propagateall(g); /* remark, to propagate `preserveness' */ |
| 878 | 925 | convergeephemerons(g); |
| 879 | − /* remove collected objects from weak tables */ | |
| 880 | − cleartable(g->weak); | |
| 881 | − cleartable(g->ephemeron); | |
| 882 | − cleartable(g->allweak); | |
| 926 | + /* at this point, all resurrected objects are marked. */ | |
| 927 | + /* remove dead objects from weak tables */ | |
| 928 | + clearkeys(g->ephemeron, NULL); /* clear keys from all ephemeron tables */ | |
| 929 | + clearkeys(g->allweak, NULL); /* clear keys from all allweak tables */ | |
| 930 | + /* clear values from resurrected weak tables */ | |
| 931 | + clearvalues(g->weak, origweak); | |
| 932 | + clearvalues(g->allweak, origall); | |
| 883 | 933 | g->sweepstrgc = 0; /* prepare to sweep strings */ |
| 884 | 934 | g->gcstate = GCSsweepstring; |
| 885 | 935 | g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lgc.h,v 2.50 2011/01/26 16:30:02 roberto Exp $ | |
| 2 | +** $Id: lgc.h,v 2.52 2011/10/03 17:54:25 roberto Exp $ | |
| 3 | 3 | ** Garbage Collector |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -63,9 +63,6 @@ · 57 unmodified lines | ||
| 63 | 63 | #define l_setbit(x,b) setbits(x, bitmask(b)) |
| 64 | 64 | #define resetbit(x,b) resetbits(x, bitmask(b)) |
| 65 | 65 | #define testbit(x,b) testbits(x, bitmask(b)) |
| 66 | −#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) | |
| 67 | −#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) | |
| 68 | − | |
| 69 | 66 | |
| 70 | 67 | |
| 71 | 68 | /* Layout for bit use in `marked' field: */ |
| @@ -125,7 +122,6 @@ · 53 unmodified lines | ||
| 125 | 122 | #define luaC_barrierproto(L,p,c) \ |
| 126 | 123 | { if (isblack(obj2gco(p))) luaC_barrierproto_(L,p,c); } |
| 127 | 124 | |
| 128 | −LUAI_FUNC void luaC_separateudata (lua_State *L, int all); | |
| 129 | 125 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); |
| 130 | 126 | LUAI_FUNC void luaC_step (lua_State *L); |
| 131 | 127 | LUAI_FUNC void luaC_forcestep (lua_State *L); |
| @@ -1,10 +1,20 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: liolib.c,v 2.101 2011/06/27 19:42:31 roberto Exp $ | |
| 2 | +** $Id: liolib.c,v 2.107 2011/11/14 16:55:35 roberto Exp $ | |
| 3 | 3 | ** Standard I/O (and system) library |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | |
| 8 | +/* | |
| 9 | +** POSIX idiosyncrasy! | |
| 10 | +** This definition must come before the inclusion of 'stdio.h'; it | |
| 11 | +** should not affect non-POSIX systems | |
| 12 | +*/ | |
| 13 | +#if !defined(_FILE_OFFSET_BITS) | |
| 14 | +#define _FILE_OFFSET_BITS 64 | |
| 15 | +#endif | |
| 16 | + | |
| 17 | + | |
| 8 | 18 | #include <errno.h> |
| 9 | 19 | #include <stdio.h> |
| 10 | 20 | #include <stdlib.h> |
| @@ -21,9 +31,12 @@ · 10 unmodified lines | ||
| 21 | 31 | |
| 22 | 32 | |
| 23 | 33 | /* |
| 24 | −** lua_popen spawns a new process connected to the current one through | |
| 25 | −** the file streams. | |
| 34 | +** {====================================================== | |
| 35 | +** lua_popen spawns a new process connected to the current | |
| 36 | +** one through the file streams. | |
| 37 | +** ======================================================= | |
| 26 | 38 | */ |
| 39 | + | |
| 27 | 40 | #if !defined(lua_popen) /* { */ |
| 28 | 41 | |
| 29 | 42 | #if defined(LUA_USE_POPEN) /* { */ |
| @@ -48,22 +61,48 @@ · 18 unmodified lines | ||
| 48 | 61 | |
| 49 | 62 | #endif /* } */ |
| 50 | 63 | |
| 64 | +/* }====================================================== */ | |
| 65 | + | |
| 66 | + | |
| 67 | +/* | |
| 68 | +** {====================================================== | |
| 69 | +** lua_fseek/lua_ftell: configuration for longer offsets | |
| 70 | +** ======================================================= | |
| 71 | +*/ | |
| 72 | + | |
| 73 | +#if !defined(lua_fseek) /* { */ | |
| 74 | + | |
| 75 | +#if defined(LUA_USE_POSIX) | |
| 76 | + | |
| 77 | +#define l_fseek(f,o,w) fseeko(f,o,w) | |
| 78 | +#define l_ftell(f) ftello(f) | |
| 79 | +#define l_seeknum off_t | |
| 80 | + | |
| 81 | +#elif defined(LUA_WIN) | |
| 82 | + | |
| 83 | +#define l_fseek(f,o,w) _fseeki64(f,o,w) | |
| 84 | +#define l_ftell(f) _ftelli64(f) | |
| 85 | +#define l_seeknum __int64 | |
| 86 | + | |
| 87 | +#else | |
| 88 | + | |
| 89 | +#define l_fseek(f,o,w) fseek(f,o,w) | |
| 90 | +#define l_ftell(f) ftell(f) | |
| 91 | +#define l_seeknum long | |
| 92 | + | |
| 93 | +#endif | |
| 94 | + | |
| 95 | +#endif /* } */ | |
| 96 | + | |
| 97 | +/* }====================================================== */ | |
| 98 | + | |
| 51 | 99 | |
| 52 | 100 | #define IO_PREFIX "_IO_" |
| 53 | 101 | #define IO_INPUT (IO_PREFIX "input") |
| 54 | 102 | #define IO_OUTPUT (IO_PREFIX "output") |
| 55 | 103 | |
| 56 | 104 | |
| 57 | −typedef struct LStream { | |
| 58 | − FILE *f; /* stream */ | |
| 59 | − lua_CFunction closef; /* to close stream (NULL for closed streams) */ | |
| 60 | −} LStream; | |
| 61 | − | |
| 62 | − | |
| 63 | −static void fileerror (lua_State *L, int arg, const char *filename) { | |
| 64 | − lua_pushfstring(L, "%s: %s", filename, strerror(errno)); | |
| 65 | − luaL_argerror(L, arg, lua_tostring(L, -1)); | |
| 66 | −} | |
| 105 | +typedef luaL_Stream LStream; | |
| 67 | 106 | |
| 68 | 107 | |
| 69 | 108 | #define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE)) |
| @@ -159,6 +198,14 @@ static LStream *newfile (lua_State *L) { · 89 unmodified lines | ||
| 159 | 198 | } |
| 160 | 199 | |
| 161 | 200 | |
| 201 | +static void opencheck (lua_State *L, const char *fname, const char *mode) { | |
| 202 | + LStream *p = newfile(L); | |
| 203 | + p->f = fopen(fname, mode); | |
| 204 | + if (p->f == NULL) | |
| 205 | + luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno)); | |
| 206 | +} | |
| 207 | + | |
| 208 | + | |
| 162 | 209 | static int io_open (lua_State *L) { |
| 163 | 210 | const char *filename = luaL_checkstring(L, 1); |
| 164 | 211 | const char *mode = luaL_optstring(L, 2, "r"); |
| @@ -169,7 +216,7 @@ static int io_open (lua_State *L) { · 4 unmodified lines | ||
| 169 | 216 | (mode[i] != '+' || ++i) && /* skip if char is '+' */ |
| 170 | 217 | (mode[i] != 'b' || ++i) && /* skip if char is 'b' */ |
| 171 | 218 | (mode[i] == '\0'))) |
| 172 | − return luaL_error(L, "invalid mode " LUA_QL("%s") | |
| 219 | + return luaL_error(L, "invalid mode " LUA_QS | |
| 173 | 220 | " (should match " LUA_QL("[rwa]%%+?b?") ")", mode); |
| 174 | 221 | p->f = fopen(filename, mode); |
| 175 | 222 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; |
| @@ -215,12 +262,8 @@ static FILE *getiofile (lua_State *L, const char *findex) { · 39 unmodified lines | ||
| 215 | 262 | static int g_iofile (lua_State *L, const char *f, const char *mode) { |
| 216 | 263 | if (!lua_isnoneornil(L, 1)) { |
| 217 | 264 | const char *filename = lua_tostring(L, 1); |
| 218 | − if (filename) { | |
| 219 | − LStream *p = newfile(L); | |
| 220 | − p->f = fopen(filename, mode); | |
| 221 | − if (p->f == NULL) | |
| 222 | − fileerror(L, 1, filename); | |
| 223 | − } | |
| 265 | + if (filename) | |
| 266 | + opencheck(L, filename, mode); | |
| 224 | 267 | else { |
| 225 | 268 | tofile(L); /* check that it's a valid file handle */ |
| 226 | 269 | lua_pushvalue(L, 1); |
| @@ -277,10 +320,7 @@ static int io_lines (lua_State *L) { · 50 unmodified lines | ||
| 277 | 320 | } |
| 278 | 321 | else { /* open a new file */ |
| 279 | 322 | const char *filename = luaL_checkstring(L, 1); |
| 280 | − LStream *p = newfile(L); | |
| 281 | − p->f = fopen(filename, "r"); | |
| 282 | − if (p->f == NULL) | |
| 283 | − fileerror(L, 1, filename); | |
| 323 | + opencheck(L, filename, "r"); | |
| 284 | 324 | lua_replace(L, 1); /* put file at index 1 */ |
| 285 | 325 | toclose = 1; /* close it after iteration */ |
| 286 | 326 | } |
| @@ -444,9 +484,10 @@ static int io_readline (lua_State *L) { · 157 unmodified lines | ||
| 444 | 484 | if (!lua_isnil(L, -n)) /* read at least one value? */ |
| 445 | 485 | return n; /* return them */ |
| 446 | 486 | else { /* first result is nil: EOF or error */ |
| 447 | − if (!lua_isnil(L, -1)) /* is there error information? */ | |
| 448 | − return luaL_error(L, "%s", lua_tostring(L, -1)); /* error */ | |
| 449 | − /* else EOF */ | |
| 487 | + if (n > 1) { /* is there error information? */ | |
| 488 | + /* 2nd result is error message */ | |
| 489 | + return luaL_error(L, "%s", lua_tostring(L, -n + 1)); | |
| 490 | + } | |
| 450 | 491 | if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */ |
| 451 | 492 | lua_settop(L, 0); |
| 452 | 493 | lua_pushvalue(L, lua_upvalueindex(1)); |
| @@ -496,12 +537,15 @@ static int f_seek (lua_State *L) { · 43 unmodified lines | ||
| 496 | 537 | static const char *const modenames[] = {"set", "cur", "end", NULL}; |
| 497 | 538 | FILE *f = tofile(L); |
| 498 | 539 | int op = luaL_checkoption(L, 2, "cur", modenames); |
| 499 | − long offset = luaL_optlong(L, 3, 0); | |
| 500 | − op = fseek(f, offset, mode[op]); | |
| 540 | + lua_Number p3 = luaL_optnumber(L, 3, 0); | |
| 541 | + l_seeknum offset = (l_seeknum)p3; | |
| 542 | + luaL_argcheck(L, (lua_Number)offset == p3, 3, | |
| 543 | + "not an integer in proper range"); | |
| 544 | + op = l_fseek(f, offset, mode[op]); | |
| 501 | 545 | if (op) |
| 502 | 546 | return luaL_fileresult(L, 0, NULL); /* error */ |
| 503 | 547 | else { |
| 504 | − lua_pushinteger(L, ftell(f)); | |
| 548 | + lua_pushnumber(L, (lua_Number)l_ftell(f)); | |
| 505 | 549 | return 1; |
| 506 | 550 | } |
| 507 | 551 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llex.c,v 2.53 2011/07/08 20:01:38 roberto Exp $ | |
| 2 | +** $Id: llex.c,v 2.58 2011/08/15 19:41:58 roberto Exp $ | |
| 3 | 3 | ** Lexical Analyzer |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -126,8 +126,10 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) { · 120 unmodified lines | ||
| 126 | 126 | TValue *o; /* entry for `str' */ |
| 127 | 127 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
| 128 | 128 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ |
| 129 | − o = luaH_setstr(L, ls->fs->h, ts); | |
| 130 | − if (ttisnil(o)) { | |
| 129 | + o = luaH_set(L, ls->fs->h, L->top - 1); | |
| 130 | + if (ttisnil(o)) { /* not in use yet? (see 'addK') */ | |
| 131 | + /* boolean value does not need GC barrier; | |
| 132 | + table has no metatable, so it does not need to invalidate cache */ | |
| 131 | 133 | setbvalue(o, 1); /* t[string] = true */ |
| 132 | 134 | luaC_checkGC(L); |
| 133 | 135 | } |
| @@ -297,39 +299,29 @@ static void escerror (LexState *ls, int *c, int n, const char *msg) { · 163 unmodified lines | ||
| 297 | 299 | |
| 298 | 300 | |
| 299 | 301 | static int readhexaesc (LexState *ls) { |
| 300 | − int c[3]; /* keep input for error message */ | |
| 301 | − int i = 2; /* at least 'x?' will go to error message */ | |
| 302 | − c[0] = 'x'; | |
| 303 | − c[1] = next(ls); /* first hexa digit */ | |
| 304 | − if (lisxdigit(c[1])) { | |
| 305 | − c[i++] = next(ls); /* second hexa digit */ | |
| 306 | − if (lisxdigit(c[2])) | |
| 307 | − return (luaO_hexavalue(c[1]) << 4) + luaO_hexavalue(c[2]); | |
| 308 | − /* else go through to error */ | |
| 302 | + int c[3], i; /* keep input for error message */ | |
| 303 | + int r = 0; /* result accumulator */ | |
| 304 | + c[0] = 'x'; /* for error message */ | |
| 305 | + for (i = 1; i < 3; i++) { /* read two hexa digits */ | |
| 306 | + c[i] = next(ls); | |
| 307 | + if (!lisxdigit(c[i])) | |
| 308 | + escerror(ls, c, i + 1, "hexadecimal digit expected"); | |
| 309 | + r = (r << 4) + luaO_hexavalue(c[i]); | |
| 309 | 310 | } |
| 310 | − escerror(ls, c, i, "hexadecimal digit expected"); | |
| 311 | − return 0; /* to avoid warnings */ | |
| 311 | + return r; | |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
| 315 | 315 | static int readdecesc (LexState *ls) { |
| 316 | − int c[3], r; | |
| 317 | − int i = 2; /* at least two chars will be read */ | |
| 318 | − c[0] = ls->current; /* first char must be a digit */ | |
| 319 | − c[1] = next(ls); /* read second char */ | |
| 320 | − r = c[0] - '0'; /* partial result */ | |
| 321 | − if (lisdigit(c[1])) { | |
| 322 | − c[i++] = next(ls); /* read third char */ | |
| 323 | − r = 10*r + c[1] - '0'; /* update result */ | |
| 324 | − if (lisdigit(c[2])) { | |
| 325 | − r = 10*r + c[2] - '0'; /* update result */ | |
| 326 | − if (r > UCHAR_MAX) | |
| 327 | − escerror(ls, c, i, "decimal escape too large"); | |
| 328 | − return r; | |
| 329 | − } | |
| 316 | + int c[3], i; | |
| 317 | + int r = 0; /* result accumulator */ | |
| 318 | + for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ | |
| 319 | + c[i] = ls->current; | |
| 320 | + r = 10*r + c[i] - '0'; | |
| 321 | + next(ls); | |
| 330 | 322 | } |
| 331 | − /* else, has read one character that was not a digit */ | |
| 332 | − zungetc(ls->z); /* return it to input stream */ | |
| 323 | + if (r > UCHAR_MAX) | |
| 324 | + escerror(ls, c, i, "decimal escape too large"); | |
| 333 | 325 | return r; |
| 334 | 326 | } |
| 335 | 327 | |
| @@ -349,37 +341,38 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { · 13 unmodified lines | ||
| 349 | 341 | int c; /* final character to be saved */ |
| 350 | 342 | next(ls); /* do not save the `\' */ |
| 351 | 343 | switch (ls->current) { |
| 352 | − case 'a': c = '\a'; break; | |
| 353 | − case 'b': c = '\b'; break; | |
| 354 | − case 'f': c = '\f'; break; | |
| 355 | − case 'n': c = '\n'; break; | |
| 356 | − case 'r': c = '\r'; break; | |
| 357 | − case 't': c = '\t'; break; | |
| 358 | − case 'v': c = '\v'; break; | |
| 359 | − case 'x': c = readhexaesc(ls); break; | |
| 360 | − case '\n': | |
| 361 | − case '\r': save(ls, '\n'); inclinenumber(ls); continue; | |
| 362 | − case '\\': case '\"': case '\'': c = ls->current; break; | |
| 363 | − case EOZ: continue; /* will raise an error next loop */ | |
| 344 | + case 'a': c = '\a'; goto read_save; | |
| 345 | + case 'b': c = '\b'; goto read_save; | |
| 346 | + case 'f': c = '\f'; goto read_save; | |
| 347 | + case 'n': c = '\n'; goto read_save; | |
| 348 | + case 'r': c = '\r'; goto read_save; | |
| 349 | + case 't': c = '\t'; goto read_save; | |
| 350 | + case 'v': c = '\v'; goto read_save; | |
| 351 | + case 'x': c = readhexaesc(ls); goto read_save; | |
| 352 | + case '\n': case '\r': | |
| 353 | + inclinenumber(ls); c = '\n'; goto only_save; | |
| 354 | + case '\\': case '\"': case '\'': | |
| 355 | + c = ls->current; goto read_save; | |
| 356 | + case EOZ: goto no_save; /* will raise an error next loop */ | |
| 364 | 357 | case 'z': { /* zap following span of spaces */ |
| 365 | 358 | next(ls); /* skip the 'z' */ |
| 366 | 359 | while (lisspace(ls->current)) { |
| 367 | 360 | if (currIsNewline(ls)) inclinenumber(ls); |
| 368 | 361 | else next(ls); |
| 369 | 362 | } |
| 370 | − continue; /* do not save 'c' */ | |
| 363 | + goto no_save; | |
| 371 | 364 | } |
| 372 | 365 | default: { |
| 373 | 366 | if (!lisdigit(ls->current)) |
| 374 | 367 | escerror(ls, &ls->current, 1, "invalid escape sequence"); |
| 375 | 368 | /* digital escape \ddd */ |
| 376 | 369 | c = readdecesc(ls); |
| 377 | − break; | |
| 370 | + goto only_save; | |
| 378 | 371 | } |
| 379 | 372 | } |
| 380 | − next(ls); | |
| 381 | − save(ls, c); | |
| 382 | − break; | |
| 373 | + read_save: next(ls); /* read next character */ | |
| 374 | + only_save: save(ls, c); /* save 'c' */ | |
| 375 | + no_save: break; | |
| 383 | 376 | } |
| 384 | 377 | default: |
| 385 | 378 | save_and_next(ls); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: llimits.h,v 1.90 2011/07/02 15:57:25 roberto Exp $ | |
| 2 | +** $Id: llimits.h,v 1.93 2011/10/07 20:45:19 roberto Exp $ | |
| 3 | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -30,7 +30,6 @@ typedef unsigned char lu_byte; · 24 unmodified lines | ||
| 30 | 30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) |
| 31 | 31 | |
| 32 | 32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) |
| 33 | −#define MIN_LMEM ((l_mem)~((~(lu_mem)0)>>1)) | |
| 34 | 33 | |
| 35 | 34 | |
| 36 | 35 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ |
| @@ -62,9 +61,9 @@ typedef LUAI_UACNUMBER l_uacNumber; · 25 unmodified lines | ||
| 62 | 61 | /* to avoid problems with conditions too long */ |
| 63 | 62 | #define lua_longassert(c) { if (!(c)) lua_assert(0); } |
| 64 | 63 | #else |
| 65 | −#define lua_assert(c) /* empty */ | |
| 64 | +#define lua_assert(c) ((void)0) | |
| 66 | 65 | #define check_exp(c,e) (e) |
| 67 | −#define lua_longassert(c) /* empty */ | |
| 66 | +#define lua_longassert(c) ((void)0) | |
| 68 | 67 | #endif |
| 69 | 68 | |
| 70 | 69 | /* |
| @@ -97,6 +96,19 @@ typedef LUAI_UACNUMBER l_uacNumber; · 26 unmodified lines | ||
| 97 | 96 | #define cast_uchar(i) cast(unsigned char, (i)) |
| 98 | 97 | |
| 99 | 98 | |
| 99 | +/* | |
| 100 | +** non-return type | |
| 101 | +*/ | |
| 102 | +#if defined(__GNUC__) | |
| 103 | +#define l_noret void __attribute__((noreturn)) | |
| 104 | +#elif defined(_MSC_VER) | |
| 105 | +#define l_noret void __declspec(noreturn) | |
| 106 | +#else | |
| 107 | +#define l_noret void | |
| 108 | +#endif | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 100 | 112 | /* |
| 101 | 113 | ** maximum depth for nested C calls and syntactical nested non-terminals |
| 102 | 114 | ** in a program. (Value must fit in an unsigned short int.) |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lmem.c,v 1.81 2010/12/20 19:40:07 roberto Exp $ | |
| 2 | +** $Id: lmem.c,v 1.82 2011/09/20 19:25:23 roberto Exp $ | |
| 3 | 3 | ** Interface to Memory Manager |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -106,7 +106,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { · 100 unmodified lines | ||
| 106 | 106 | if ((total % 200) == 0) { |
| 107 | 107 | if (f == NULL) f = fopen(TRACEMEM, "w"); |
| 108 | 108 | fprintf(f, "%lu %u %d %d\n", total, |
| 109 | − g->totalbytes, g->GCdebt, g->gcstate * 1000); | |
| 109 | + gettotalbytes(g), g->GCdebt, g->gcstate * 10000); | |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | #endif |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: loadlib.c,v 1.100 2011/07/05 12:49:35 roberto Exp $ | |
| 2 | +** $Id: loadlib.c,v 1.104 2011/11/10 11:42:58 roberto Exp $ | |
| 3 | 3 | ** Dynamic library loader for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | ** |
| @@ -9,6 +9,14 @@ · 3 unmodified lines | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | |
| 12 | +/* | |
| 13 | +** if needed, includes windows header before everything else | |
| 14 | +*/ | |
| 15 | +#if defined(LUA_DL_DLL) | |
| 16 | +#include <windows.h> | |
| 17 | +#endif | |
| 18 | + | |
| 19 | + | |
| 12 | 20 | #include <stdlib.h> |
| 13 | 21 | #include <string.h> |
| 14 | 22 | |
| @@ -62,6 +70,20 @@ · 47 unmodified lines | ||
| 62 | 70 | #endif |
| 63 | 71 | |
| 64 | 72 | |
| 73 | +/* | |
| 74 | +** LUA_CSUBSEP is the character that replaces dots in submodule names | |
| 75 | +** when searching for a C loader. | |
| 76 | +** LUA_LSUBSEP is the character that replaces dots in submodule names | |
| 77 | +** when searching for a Lua loader. | |
| 78 | +*/ | |
| 79 | +#if !defined(LUA_CSUBSEP) | |
| 80 | +#define LUA_CSUBSEP LUA_DIRSEP | |
| 81 | +#endif | |
| 82 | + | |
| 83 | +#if !defined(LUA_LSUBSEP) | |
| 84 | +#define LUA_LSUBSEP LUA_DIRSEP | |
| 85 | +#endif | |
| 86 | + | |
| 65 | 87 | |
| 66 | 88 | /* prefix for open functions in C libraries */ |
| 67 | 89 | #define LUA_POF "luaopen_" |
| @@ -133,8 +155,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 65 unmodified lines | ||
| 133 | 155 | ** ======================================================================= |
| 134 | 156 | */ |
| 135 | 157 | |
| 136 | −#include <windows.h> | |
| 137 | − | |
| 138 | 158 | #undef setprogdir |
| 139 | 159 | |
| 140 | 160 | /* |
| @@ -322,10 +342,12 @@ static const char *pushnexttemplate (lua_State *L, const char *path) { · 181 unmodified lines | ||
| 322 | 342 | |
| 323 | 343 | static const char *searchpath (lua_State *L, const char *name, |
| 324 | 344 | const char *path, |
| 325 | − const char *sep) { | |
| 345 | + const char *sep, | |
| 346 | + const char *dirsep) { | |
| 347 | + luaL_Buffer msg; /* to build error message */ | |
| 348 | + luaL_buffinit(L, &msg); | |
| 326 | 349 | if (*sep != '\0') /* non-empty separator? */ |
| 327 | − name = luaL_gsub(L, name, sep, LUA_DIRSEP); /* replace it by proper one */ | |
| 328 | − lua_pushliteral(L, ""); /* error accumulator */ | |
| 350 | + name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */ | |
| 329 | 351 | while ((path = pushnexttemplate(L, path)) != NULL) { |
| 330 | 352 | const char *filename = luaL_gsub(L, lua_tostring(L, -1), |
| 331 | 353 | LUA_PATH_MARK, name); |
| @@ -334,8 +356,9 @@ static const char *searchpath (lua_State *L, const char *name, · 2 unmodified lines | ||
| 334 | 356 | return filename; /* return that file name */ |
| 335 | 357 | lua_pushfstring(L, "\n\tno file " LUA_QS, filename); |
| 336 | 358 | lua_remove(L, -2); /* remove file name */ |
| 337 | − lua_concat(L, 2); /* add entry to possible error message */ | |
| 359 | + luaL_addvalue(&msg); /* concatenate error msg. entry */ | |
| 338 | 360 | } |
| 361 | + luaL_pushresult(&msg); /* create error message */ | |
| 339 | 362 | return NULL; /* not found */ |
| 340 | 363 | } |
| 341 | 364 | |
| @@ -343,7 +366,8 @@ static const char *searchpath (lua_State *L, const char *name, · 1 unmodified line | ||
| 343 | 366 | static int ll_searchpath (lua_State *L) { |
| 344 | 367 | const char *f = searchpath(L, luaL_checkstring(L, 1), |
| 345 | 368 | luaL_checkstring(L, 2), |
| 346 | − luaL_optstring(L, 3, ".")); | |
| 369 | + luaL_optstring(L, 3, "."), | |
| 370 | + luaL_optstring(L, 4, LUA_DIRSEP)); | |
| 347 | 371 | if (f != NULL) return 1; |
| 348 | 372 | else { /* error message is on top of the stack */ |
| 349 | 373 | lua_pushnil(L); |
| @@ -354,13 +378,14 @@ static int ll_searchpath (lua_State *L) { · 4 unmodified lines | ||
| 354 | 378 | |
| 355 | 379 | |
| 356 | 380 | static const char *findfile (lua_State *L, const char *name, |
| 357 | − const char *pname) { | |
| 381 | + const char *pname, | |
| 382 | + const char *dirsep) { | |
| 358 | 383 | const char *path; |
| 359 | 384 | lua_getfield(L, lua_upvalueindex(1), pname); |
| 360 | 385 | path = lua_tostring(L, -1); |
| 361 | 386 | if (path == NULL) |
| 362 | 387 | luaL_error(L, LUA_QL("package.%s") " must be a string", pname); |
| 363 | − return searchpath(L, name, path, "."); | |
| 388 | + return searchpath(L, name, path, ".", dirsep); | |
| 364 | 389 | } |
| 365 | 390 | |
| 366 | 391 | |
| @@ -379,7 +404,7 @@ static int checkload (lua_State *L, int stat, const char *filename) { · 12 unmodified lines | ||
| 379 | 404 | static int searcher_Lua (lua_State *L) { |
| 380 | 405 | const char *filename; |
| 381 | 406 | const char *name = luaL_checkstring(L, 1); |
| 382 | − filename = findfile(L, name, "path"); | |
| 407 | + filename = findfile(L, name, "path", LUA_LSUBSEP); | |
| 383 | 408 | if (filename == NULL) return 1; /* module not found in this path */ |
| 384 | 409 | return checkload(L, (luaL_loadfile(L, filename) == LUA_OK), filename); |
| 385 | 410 | } |
| @@ -405,7 +430,7 @@ static int loadfunc (lua_State *L, const char *filename, const char *modname) { · 19 unmodified lines | ||
| 405 | 430 | |
| 406 | 431 | static int searcher_C (lua_State *L) { |
| 407 | 432 | const char *name = luaL_checkstring(L, 1); |
| 408 | − const char *filename = findfile(L, name, "cpath"); | |
| 433 | + const char *filename = findfile(L, name, "cpath", LUA_CSUBSEP); | |
| 409 | 434 | if (filename == NULL) return 1; /* module not found in this path */ |
| 410 | 435 | return checkload(L, (loadfunc(L, filename, name) == 0), filename); |
| 411 | 436 | } |
| @@ -418,7 +443,7 @@ static int searcher_Croot (lua_State *L) { · 6 unmodified lines | ||
| 418 | 443 | int stat; |
| 419 | 444 | if (p == NULL) return 0; /* is root */ |
| 420 | 445 | lua_pushlstring(L, name, p - name); |
| 421 | − filename = findfile(L, lua_tostring(L, -1), "cpath"); | |
| 446 | + filename = findfile(L, lua_tostring(L, -1), "cpath", LUA_CSUBSEP); | |
| 422 | 447 | if (filename == NULL) return 1; /* root not found */ |
| 423 | 448 | if ((stat = loadfunc(L, filename, name)) != 0) { |
| 424 | 449 | if (stat != ERRFUNC) |
| @@ -444,35 +469,46 @@ static int searcher_preload (lua_State *L) { · 19 unmodified lines | ||
| 444 | 469 | } |
| 445 | 470 | |
| 446 | 471 | |
| 447 | −static int ll_require (lua_State *L) { | |
| 448 | − const char *name = luaL_checkstring(L, 1); | |
| 472 | +static void findloader (lua_State *L, const char *name) { | |
| 449 | 473 | int i; |
| 450 | − lua_settop(L, 1); /* _LOADED table will be at index 2 */ | |
| 451 | − lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); | |
| 452 | − lua_getfield(L, 2, name); | |
| 453 | − if (lua_toboolean(L, -1)) /* is it there? */ | |
| 454 | − return 1; /* package is already loaded */ | |
| 455 | − /* else must load it; iterate over available seachers to find a loader */ | |
| 456 | − lua_getfield(L, lua_upvalueindex(1), "searchers"); | |
| 457 | − if (!lua_istable(L, -1)) | |
| 474 | + luaL_Buffer msg; /* to build error message */ | |
| 475 | + luaL_buffinit(L, &msg); | |
| 476 | + lua_getfield(L, lua_upvalueindex(1), "searchers"); /* will be at index 3 */ | |
| 477 | + if (!lua_istable(L, 3)) | |
| 458 | 478 | luaL_error(L, LUA_QL("package.searchers") " must be a table"); |
| 459 | − lua_pushliteral(L, ""); /* error message accumulator */ | |
| 460 | − for (i=1; ; i++) { | |
| 461 | − lua_rawgeti(L, -2, i); /* get a seacher */ | |
| 462 | − if (lua_isnil(L, -1)) /* no more searchers? */ | |
| 479 | + /* iterate over available seachers to find a loader */ | |
| 480 | + for (i = 1; ; i++) { | |
| 481 | + lua_rawgeti(L, 3, i); /* get a seacher */ | |
| 482 | + if (lua_isnil(L, -1)) { /* no more searchers? */ | |
| 483 | + lua_pop(L, 1); /* remove nil */ | |
| 484 | + luaL_pushresult(&msg); /* create error message */ | |
| 463 | 485 | luaL_error(L, "module " LUA_QS " not found:%s", |
| 464 | − name, lua_tostring(L, -2)); | |
| 486 | + name, lua_tostring(L, -1)); | |
| 487 | + } | |
| 465 | 488 | lua_pushstring(L, name); |
| 466 | 489 | lua_call(L, 1, 2); /* call it */ |
| 467 | 490 | if (lua_isfunction(L, -2)) /* did it find a loader? */ |
| 468 | − break; /* module loader found */ | |
| 491 | + return; /* module loader found */ | |
| 469 | 492 | else if (lua_isstring(L, -2)) { /* searcher returned error message? */ |
| 470 | 493 | lua_pop(L, 1); /* remove extra return */ |
| 471 | − lua_concat(L, 2); /* accumulate error message */ | |
| 494 | + luaL_addvalue(&msg); /* concatenate error message */ | |
| 472 | 495 | } |
| 473 | 496 | else |
| 474 | 497 | lua_pop(L, 2); /* remove both returns */ |
| 475 | 498 | } |
| 499 | +} | |
| 500 | + | |
| 501 | + | |
| 502 | +static int ll_require (lua_State *L) { | |
| 503 | + const char *name = luaL_checkstring(L, 1); | |
| 504 | + lua_settop(L, 1); /* _LOADED table will be at index 2 */ | |
| 505 | + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); | |
| 506 | + lua_getfield(L, 2, name); /* _LOADED[name] */ | |
| 507 | + if (lua_toboolean(L, -1)) /* is it there? */ | |
| 508 | + return 1; /* package is already loaded */ | |
| 509 | + /* else must load package */ | |
| 510 | + lua_pop(L, 1); /* remove 'getfield' result */ | |
| 511 | + findloader(L, name); | |
| 476 | 512 | lua_pushstring(L, name); /* pass name as argument to module loader */ |
| 477 | 513 | lua_insert(L, -2); /* name is 1st argument (before search data) */ |
| 478 | 514 | lua_call(L, 2, 1); /* run loader to load module */ |
| @@ -516,9 +552,11 @@ static void set_env (lua_State *L) { · 37 unmodified lines | ||
| 516 | 552 | static void dooptions (lua_State *L, int n) { |
| 517 | 553 | int i; |
| 518 | 554 | for (i = 2; i <= n; i++) { |
| 519 | − lua_pushvalue(L, i); /* get option (a function) */ | |
| 520 | − lua_pushvalue(L, -2); /* module */ | |
| 521 | − lua_call(L, 1, 0); | |
| 555 | + if (lua_isfunction(L, i)) { /* avoid 'calling' extra info. */ | |
| 556 | + lua_pushvalue(L, i); /* get option (a function) */ | |
| 557 | + lua_pushvalue(L, -2); /* module */ | |
| 558 | + lua_call(L, 1, 0); | |
| 559 | + } | |
| 522 | 560 | } |
| 523 | 561 | } |
| 524 | 562 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lobject.c,v 2.52 2011/06/24 12:25:02 roberto Exp $ | |
| 2 | +** $Id: lobject.c,v 2.53 2011/07/27 12:13:08 roberto Exp $ | |
| 3 | 3 | ** Some generic functions over Lua objects |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -103,8 +103,8 @@ static int isneg (const char **s) { · 97 unmodified lines | ||
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | static lua_Number readhexa (const char **s, lua_Number r, int *count) { |
| 106 | − while (lisxdigit(cast_uchar(**s))) { /* read integer part */ | |
| 107 | − r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(*(*s)++))); | |
| 106 | + for (; lisxdigit(cast_uchar(**s)); (*s)++) { /* read integer part */ | |
| 107 | + r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(**s))); | |
| 108 | 108 | (*count)++; |
| 109 | 109 | } |
| 110 | 110 | return r; |
| @@ -157,7 +157,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { · 46 unmodified lines | ||
| 157 | 157 | |
| 158 | 158 | int luaO_str2d (const char *s, size_t len, lua_Number *result) { |
| 159 | 159 | char *endptr; |
| 160 | − if (strpbrk(s, "xX")) /* hexa? */ | |
| 160 | + if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ | |
| 161 | + return 0; | |
| 162 | + else if (strpbrk(s, "xX")) /* hexa? */ | |
| 161 | 163 | *result = lua_strx2number(s, &endptr); |
| 162 | 164 | else |
| 163 | 165 | *result = lua_str2number(s, &endptr); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp $ | |
| 2 | +** $Id: lobject.h,v 2.64 2011/10/31 17:48:22 roberto Exp $ | |
| 3 | 3 | ** Type definitions for Lua objects |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -132,7 +132,7 @@ typedef struct lua_TValue TValue; · 126 unmodified lines | ||
| 132 | 132 | #define ttislcf(o) checktag((o), LUA_TLCF) |
| 133 | 133 | #define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA)) |
| 134 | 134 | #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) |
| 135 | −#define ttisdeadkey(o) checktag((o), ctb(LUA_TDEADKEY)) | |
| 135 | +#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY) | |
| 136 | 136 | |
| 137 | 137 | #define ttisequal(o1,o2) (rttype(o1) == rttype(o2)) |
| 138 | 138 | |
| @@ -151,6 +151,8 @@ typedef struct lua_TValue TValue; · 12 unmodified lines | ||
| 151 | 151 | #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) |
| 152 | 152 | #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) |
| 153 | 153 | #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) |
| 154 | +/* a dead value may get the 'gc' field, but cannot access its contents */ | |
| 155 | +#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc)) | |
| 154 | 156 | |
| 155 | 157 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) |
| 156 | 158 | |
| @@ -224,7 +226,7 @@ typedef struct lua_TValue TValue; · 67 unmodified lines | ||
| 224 | 226 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \ |
| 225 | 227 | checkliveness(G(L),io); } |
| 226 | 228 | |
| 227 | −#define setdeadvalue(obj) settt_(obj, ctb(LUA_TDEADKEY)) | |
| 229 | +#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) | |
| 228 | 230 | |
| 229 | 231 | |
| 230 | 232 | |
| @@ -262,51 +264,73 @@ typedef struct lua_TValue TValue; · 31 unmodified lines | ||
| 262 | 264 | ** ======================================================= |
| 263 | 265 | */ |
| 264 | 266 | |
| 265 | −#if defined(LUA_NANTRICKLE) || defined(LUA_NANTRICKBE) | |
| 267 | +#if defined(LUA_NANTRICK) \ | |
| 268 | + || defined(LUA_NANTRICK_LE) \ | |
| 269 | + || defined(LUA_NANTRICK_BE) | |
| 266 | 270 | |
| 267 | 271 | /* |
| 268 | 272 | ** numbers are represented in the 'd_' field. All other values have the |
| 269 | −** value (NNMARK | tag) in 'tt_'. A number with such pattern would be | |
| 273 | +** value (NNMARK | tag) in 'tt__'. A number with such pattern would be | |
| 270 | 274 | ** a "signaled NaN", which is never generated by regular operations by |
| 271 | 275 | ** the CPU (nor by 'strtod') |
| 272 | 276 | */ |
| 273 | 277 | #if !defined(NNMARK) |
| 274 | 278 | #define NNMARK 0x7FF7A500 |
| 279 | +#define NNMASK 0x7FFFFF00 | |
| 275 | 280 | #endif |
| 276 | 281 | |
| 277 | 282 | #undef TValuefields |
| 278 | 283 | #undef NILCONSTANT |
| 279 | −#if defined(LUA_NANTRICKLE) | |
| 284 | + | |
| 285 | +#if defined(LUA_NANTRICK_LE) | |
| 286 | + | |
| 280 | 287 | /* little endian */ |
| 281 | 288 | #define TValuefields \ |
| 282 | − union { struct { Value v_; int tt_; } i; double d_; } u | |
| 289 | + union { struct { Value v__; int tt__; } i; double d__; } u | |
| 283 | 290 | #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} |
| 284 | −#else | |
| 291 | +/* field-access macros */ | |
| 292 | +#define v_(o) ((o)->u.i.v__) | |
| 293 | +#define d_(o) ((o)->u.d__) | |
| 294 | +#define tt_(o) ((o)->u.i.tt__) | |
| 295 | + | |
| 296 | +#elif defined(LUA_NANTRICK_BE) | |
| 297 | + | |
| 285 | 298 | /* big endian */ |
| 286 | 299 | #define TValuefields \ |
| 287 | − union { struct { int tt_; Value v_; } i; double d_; } u | |
| 300 | + union { struct { int tt__; Value v__; } i; double d__; } u | |
| 288 | 301 | #define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}} |
| 302 | +/* field-access macros */ | |
| 303 | +#define v_(o) ((o)->u.i.v__) | |
| 304 | +#define d_(o) ((o)->u.d__) | |
| 305 | +#define tt_(o) ((o)->u.i.tt__) | |
| 306 | + | |
| 307 | +#elif !defined(TValuefields) | |
| 308 | +#error option 'LUA_NANTRICK' needs declaration for 'TValuefields' | |
| 309 | + | |
| 289 | 310 | #endif |
| 290 | 311 | |
| 312 | + | |
| 313 | +/* correspondence with standard representation */ | |
| 314 | +#undef val_ | |
| 315 | +#define val_(o) v_(o) | |
| 316 | +#undef num_ | |
| 317 | +#define num_(o) d_(o) | |
| 318 | + | |
| 319 | + | |
| 291 | 320 | #undef numfield |
| 292 | 321 | #define numfield /* no such field; numbers are the entire struct */ |
| 293 | 322 | |
| 294 | 323 | /* basic check to distinguish numbers from non-numbers */ |
| 295 | 324 | #undef ttisnumber |
| 296 | −#define ttisnumber(o) (((o)->u.i.tt_ & 0x7fffff00) != NNMARK) | |
| 325 | +#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK) | |
| 297 | 326 | |
| 298 | 327 | #define tag2tt(t) (NNMARK | (t)) |
| 299 | 328 | |
| 300 | −#undef val_ | |
| 301 | −#define val_(o) ((o)->u.i.v_) | |
| 302 | −#undef num_ | |
| 303 | −#define num_(o) ((o)->u.d_) | |
| 304 | − | |
| 305 | 329 | #undef rttype |
| 306 | −#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : (o)->u.i.tt_ & 0xff) | |
| 330 | +#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff) | |
| 307 | 331 | |
| 308 | 332 | #undef settt_ |
| 309 | −#define settt_(o,t) ((o)->u.i.tt_=tag2tt(t)) | |
| 333 | +#define settt_(o,t) (tt_(o) = tag2tt(t)) | |
| 310 | 334 | |
| 311 | 335 | #undef setnvalue |
| 312 | 336 | #define setnvalue(obj,x) \ |
| @@ -324,11 +348,11 @@ typedef struct lua_TValue TValue; · 11 unmodified lines | ||
| 324 | 348 | */ |
| 325 | 349 | |
| 326 | 350 | #undef checktag |
| 327 | −#define checktag(o,t) ((o)->u.i.tt_ == tag2tt(t)) | |
| 351 | +#define checktag(o,t) (tt_(o) == tag2tt(t)) | |
| 328 | 352 | |
| 329 | 353 | #undef ttisequal |
| 330 | 354 | #define ttisequal(o1,o2) \ |
| 331 | − (ttisnumber(o1) ? ttisnumber(o2) : ((o1)->u.i.tt_ == (o2)->u.i.tt_)) | |
| 355 | + (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2))) | |
| 332 | 356 | |
| 333 | 357 | |
| 334 | 358 | |
| @@ -435,11 +459,11 @@ typedef struct Proto { · 100 unmodified lines | ||
| 435 | 459 | TValue *k; /* constants used by the function */ |
| 436 | 460 | Instruction *code; |
| 437 | 461 | struct Proto **p; /* functions defined inside the function */ |
| 438 | − int *lineinfo; /* map from opcodes to source lines */ | |
| 439 | − LocVar *locvars; /* information about local variables */ | |
| 462 | + int *lineinfo; /* map from opcodes to source lines (debug information) */ | |
| 463 | + LocVar *locvars; /* information about local variables (debug information) */ | |
| 440 | 464 | Upvaldesc *upvalues; /* upvalue information */ |
| 441 | 465 | union Closure *cache; /* last created closure with this prototype */ |
| 442 | − TString *source; | |
| 466 | + TString *source; /* used for debug information */ | |
| 443 | 467 | int sizeupvalues; /* size of 'upvalues' */ |
| 444 | 468 | int sizek; /* size of `k' */ |
| 445 | 469 | int sizecode; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lopcodes.h,v 1.141 2011/04/19 16:22:13 roberto Exp $ | |
| 2 | +** $Id: lopcodes.h,v 1.142 2011/07/15 12:50:29 roberto Exp $ | |
| 3 | 3 | ** Opcodes for Lua virtual machine |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -196,7 +196,7 @@ OP_LEN,/* A B R(A) := length of R(B) */ · 190 unmodified lines | ||
| 196 | 196 | |
| 197 | 197 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ |
| 198 | 198 | |
| 199 | −OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */ | |
| 199 | +OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A) + 1 */ | |
| 200 | 200 | OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ |
| 201 | 201 | OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ |
| 202 | 202 | OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lparser.c,v 2.113 2011/07/02 15:58:14 roberto Exp $ | |
| 2 | +** $Id: lparser.c,v 2.122 2011/10/31 17:46:04 roberto Exp $ | |
| 3 | 3 | ** Lua Parser |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -41,8 +41,8 @@ · 35 unmodified lines | ||
| 41 | 41 | */ |
| 42 | 42 | typedef struct BlockCnt { |
| 43 | 43 | struct BlockCnt *previous; /* chain */ |
| 44 | − int firstlabel; /* index of first label in this block */ | |
| 45 | − int firstgoto; /* index of first pending goto in this block */ | |
| 44 | + short firstlabel; /* index of first label in this block */ | |
| 45 | + short firstgoto; /* index of first pending goto in this block */ | |
| 46 | 46 | lu_byte nactvar; /* # active locals outside the block */ |
| 47 | 47 | lu_byte upval; /* true if some variable in the block is an upvalue */ |
| 48 | 48 | lu_byte isloop; /* true if `block' is a loop */ |
| @@ -81,13 +81,14 @@ static void error_expected (LexState *ls, int token) { · 32 unmodified lines | ||
| 81 | 81 | |
| 82 | 82 | |
| 83 | 83 | static void errorlimit (FuncState *fs, int limit, const char *what) { |
| 84 | + lua_State *L = fs->ls->L; | |
| 84 | 85 | const char *msg; |
| 85 | 86 | int line = fs->f->linedefined; |
| 86 | 87 | const char *where = (line == 0) |
| 87 | 88 | ? "main function" |
| 88 | − : luaO_pushfstring(fs->L, "function at line %d", line); | |
| 89 | − msg = luaO_pushfstring(fs->L, "too many %s (limit is %d) in %s", | |
| 90 | − what, limit, where); | |
| 89 | + : luaO_pushfstring(L, "function at line %d", line); | |
| 90 | + msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s", | |
| 91 | + what, limit, where); | |
| 91 | 92 | luaX_syntaxerror(fs->ls, msg); |
| 92 | 93 | } |
| 93 | 94 | |
| @@ -182,7 +183,7 @@ static void new_localvar (LexState *ls, TString *name) { · 88 unmodified lines | ||
| 182 | 183 | MAXVARS, "local variables"); |
| 183 | 184 | luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1, |
| 184 | 185 | dyd->actvar.size, Vardesc, MAX_INT, "local variables"); |
| 185 | − dyd->actvar.arr[dyd->actvar.n++].idx = cast(unsigned short, reg); | |
| 186 | + dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg); | |
| 186 | 187 | } |
| 187 | 188 | |
| 188 | 189 | |
| @@ -231,13 +232,13 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) { · 42 unmodified lines | ||
| 231 | 232 | Proto *f = fs->f; |
| 232 | 233 | int oldsize = f->sizeupvalues; |
| 233 | 234 | checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); |
| 234 | − luaM_growvector(fs->L, f->upvalues, fs->nups, f->sizeupvalues, | |
| 235 | + luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, | |
| 235 | 236 | Upvaldesc, MAXUPVAL, "upvalues"); |
| 236 | 237 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL; |
| 237 | 238 | f->upvalues[fs->nups].instack = (v->k == VLOCAL); |
| 238 | 239 | f->upvalues[fs->nups].idx = cast_byte(v->u.info); |
| 239 | 240 | f->upvalues[fs->nups].name = name; |
| 240 | − luaC_objbarrier(fs->L, f, name); | |
| 241 | + luaC_objbarrier(fs->ls->L, f, name); | |
| 241 | 242 | return fs->nups++; |
| 242 | 243 | } |
| 243 | 244 | |
| @@ -327,13 +328,13 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { · 83 unmodified lines | ||
| 327 | 328 | |
| 328 | 329 | |
| 329 | 330 | static void enterlevel (LexState *ls) { |
| 330 | − global_State *g = G(ls->L); | |
| 331 | − ++g->nCcalls; | |
| 332 | − checklimit(ls->fs, g->nCcalls, LUAI_MAXCCALLS, "syntax levels"); | |
| 331 | + lua_State *L = ls->L; | |
| 332 | + ++L->nCcalls; | |
| 333 | + checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "syntax levels"); | |
| 333 | 334 | } |
| 334 | 335 | |
| 335 | 336 | |
| 336 | −#define leavelevel(ls) (G((ls)->L)->nCcalls--) | |
| 337 | +#define leavelevel(ls) ((ls)->L->nCcalls--) | |
| 337 | 338 | |
| 338 | 339 | |
| 339 | 340 | static void closegoto (LexState *ls, int g, Labeldesc *label) { |
| @@ -343,9 +344,10 @@ static void closegoto (LexState *ls, int g, Labeldesc *label) { · 3 unmodified lines | ||
| 343 | 344 | Labeldesc *gt = &gl->arr[g]; |
| 344 | 345 | lua_assert(eqstr(gt->name, label->name)); |
| 345 | 346 | if (gt->nactvar < label->nactvar) { |
| 347 | + TString *vname = getlocvar(fs, gt->nactvar)->varname; | |
| 346 | 348 | const char *msg = luaO_pushfstring(ls->L, |
| 347 | 349 | "<goto %s> at line %d jumps into the scope of local " LUA_QS, |
| 348 | − getstr(gt->name), gt->line, getstr(getlocvar(fs, gt->nactvar)->varname)); | |
| 350 | + getstr(gt->name), gt->line, getstr(vname)); | |
| 349 | 351 | semerror(ls, msg); |
| 350 | 352 | } |
| 351 | 353 | luaK_patchlist(fs, gt->pc, label->pc); |
| @@ -382,7 +384,8 @@ static int findlabel (LexState *ls, int g) { · 30 unmodified lines | ||
| 382 | 384 | static int newlabelentry (LexState *ls, Labellist *l, TString *name, |
| 383 | 385 | int line, int pc) { |
| 384 | 386 | int n = l->n; |
| 385 | − luaM_growvector(ls->L, l->arr, n, l->size, Labeldesc, MAX_INT, "labels"); | |
| 387 | + luaM_growvector(ls->L, l->arr, n, l->size, | |
| 388 | + Labeldesc, SHRT_MAX, "labels/gotos"); | |
| 386 | 389 | l->arr[n].name = name; |
| 387 | 390 | l->arr[n].line = line; |
| 388 | 391 | l->arr[n].nactvar = ls->fs->nactvar; |
| @@ -418,7 +421,7 @@ static void movegotosout (FuncState *fs, BlockCnt *bl) { · 29 unmodified lines | ||
| 418 | 421 | int i = bl->firstgoto; |
| 419 | 422 | Labellist *gl = &fs->ls->dyd->gt; |
| 420 | 423 | /* correct pending gotos to current block and try to close it |
| 421 | − with visible labels */ | |
| 424 | + with visible labels */ | |
| 422 | 425 | while (i < gl->n) { |
| 423 | 426 | Labeldesc *gt = &gl->arr[i]; |
| 424 | 427 | if (gt->nactvar > bl->nactvar) { |
| @@ -514,7 +517,6 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { · 89 unmodified lines | ||
| 514 | 517 | Proto *f; |
| 515 | 518 | fs->prev = ls->fs; /* linked list of funcstates */ |
| 516 | 519 | fs->ls = ls; |
| 517 | − fs->L = L; | |
| 518 | 520 | ls->fs = fs; |
| 519 | 521 | fs->pc = 0; |
| 520 | 522 | fs->lasttarget = 0; |
| @@ -1039,7 +1041,7 @@ static const struct { · 518 unmodified lines | ||
| 1039 | 1041 | ** subexpr -> (simpleexp | unop subexpr) { binop subexpr } |
| 1040 | 1042 | ** where `binop' is any binary operator with a priority higher than `limit' |
| 1041 | 1043 | */ |
| 1042 | −static BinOpr subexpr (LexState *ls, expdesc *v, unsigned int limit) { | |
| 1044 | +static BinOpr subexpr (LexState *ls, expdesc *v, int limit) { | |
| 1043 | 1045 | BinOpr op; |
| 1044 | 1046 | UnOpr uop; |
| 1045 | 1047 | enterlevel(ls); |
| @@ -1105,31 +1107,34 @@ struct LHS_assign { · 59 unmodified lines | ||
| 1105 | 1107 | |
| 1106 | 1108 | |
| 1107 | 1109 | /* |
| 1108 | −** check whether, in an assignment to a local variable, the local variable | |
| 1109 | −** is needed in a previous assignment (to a table). If so, save original | |
| 1110 | −** local value in a safe place and use this safe copy in the previous | |
| 1111 | −** assignment. | |
| 1110 | +** check whether, in an assignment to an upvalue/local variable, the | |
| 1111 | +** upvalue/local variable is begin used in a previous assignment to a | |
| 1112 | +** table. If so, save original upvalue/local value in a safe place and | |
| 1113 | +** use this safe copy in the previous assignment. | |
| 1112 | 1114 | */ |
| 1113 | 1115 | static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { |
| 1114 | 1116 | FuncState *fs = ls->fs; |
| 1115 | 1117 | int extra = fs->freereg; /* eventual position to save local variable */ |
| 1116 | 1118 | int conflict = 0; |
| 1117 | − for (; lh; lh = lh->prev) { | |
| 1118 | − /* conflict in table 't'? */ | |
| 1119 | − if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) { | |
| 1120 | − conflict = 1; | |
| 1121 | − lh->v.u.ind.vt = VLOCAL; | |
| 1122 | − lh->v.u.ind.t = extra; /* previous assignment will use safe copy */ | |
| 1123 | − } | |
| 1124 | − /* conflict in index 'idx'? */ | |
| 1125 | − if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) { | |
| 1126 | − conflict = 1; | |
| 1127 | − lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ | |
| 1119 | + for (; lh; lh = lh->prev) { /* check all previous assignments */ | |
| 1120 | + if (lh->v.k == VINDEXED) { /* assigning to a table? */ | |
| 1121 | + /* table is the upvalue/local being assigned now? */ | |
| 1122 | + if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) { | |
| 1123 | + conflict = 1; | |
| 1124 | + lh->v.u.ind.vt = VLOCAL; | |
| 1125 | + lh->v.u.ind.t = extra; /* previous assignment will use safe copy */ | |
| 1126 | + } | |
| 1127 | + /* index is the local being assigned? (index cannot be upvalue) */ | |
| 1128 | + if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) { | |
| 1129 | + conflict = 1; | |
| 1130 | + lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ | |
| 1131 | + } | |
| 1128 | 1132 | } |
| 1129 | 1133 | } |
| 1130 | 1134 | if (conflict) { |
| 1135 | + /* copy upvalue/local value to a temporary (in position 'extra') */ | |
| 1131 | 1136 | OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; |
| 1132 | − luaK_codeABC(fs, op, fs->freereg, v->u.info, 0); /* make copy */ | |
| 1137 | + luaK_codeABC(fs, op, extra, v->u.info, 0); | |
| 1133 | 1138 | luaK_reserveregs(fs, 1); |
| 1134 | 1139 | } |
| 1135 | 1140 | } |
| @@ -1144,7 +1149,7 @@ static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { · 8 unmodified lines | ||
| 1144 | 1149 | primaryexp(ls, &nv.v); |
| 1145 | 1150 | if (nv.v.k != VINDEXED) |
| 1146 | 1151 | check_conflict(ls, lh, &nv.v); |
| 1147 | − checklimit(ls->fs, nvars, LUAI_MAXCCALLS - G(ls->L)->nCcalls, | |
| 1152 | + checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls, | |
| 1148 | 1153 | "variable names"); |
| 1149 | 1154 | assignment(ls, &nv, nvars+1); |
| 1150 | 1155 | } |
| @@ -1178,10 +1183,18 @@ static int cond (LexState *ls) { · 27 unmodified lines | ||
| 1178 | 1183 | } |
| 1179 | 1184 | |
| 1180 | 1185 | |
| 1181 | −static void gotostat (LexState *ls, TString *label, int line) { | |
| 1182 | − /* create new entry for this goto */ | |
| 1183 | − int g = newlabelentry(ls, &ls->dyd->gt, label, line, luaK_jump(ls->fs)); | |
| 1184 | − findlabel(ls, g); | |
| 1186 | +static void gotostat (LexState *ls, int pc) { | |
| 1187 | + int line = ls->linenumber; | |
| 1188 | + TString *label; | |
| 1189 | + int g; | |
| 1190 | + if (testnext(ls, TK_GOTO)) | |
| 1191 | + label = str_checkname(ls); | |
| 1192 | + else { | |
| 1193 | + luaX_next(ls); /* skip break */ | |
| 1194 | + label = luaS_new(ls->L, "break"); | |
| 1195 | + } | |
| 1196 | + g = newlabelentry(ls, &ls->dyd->gt, label, line, pc); | |
| 1197 | + findlabel(ls, g); /* close it if label already defined */ | |
| 1185 | 1198 | } |
| 1186 | 1199 | |
| 1187 | 1200 | |
| @@ -1190,7 +1203,7 @@ static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) { · 2 unmodified lines | ||
| 1190 | 1203 | int i; |
| 1191 | 1204 | for (i = fs->bl->firstlabel; i < ll->n; i++) { |
| 1192 | 1205 | if (eqstr(label, ll->arr[i].name)) { |
| 1193 | − const char *msg = luaO_pushfstring(fs->ls->L, | |
| 1206 | + const char *msg = luaO_pushfstring(fs->ls->L, | |
| 1194 | 1207 | "label " LUA_QS " already defined on line %d", |
| 1195 | 1208 | getstr(label), ll->arr[i].line); |
| 1196 | 1209 | semerror(fs->ls, msg); |
| @@ -1360,38 +1373,51 @@ static void forstat (LexState *ls, int line) { · 163 unmodified lines | ||
| 1360 | 1373 | } |
| 1361 | 1374 | |
| 1362 | 1375 | |
| 1363 | −static int test_then_block (LexState *ls) { | |
| 1376 | +static void test_then_block (LexState *ls, int *escapelist) { | |
| 1364 | 1377 | /* test_then_block -> [IF | ELSEIF] cond THEN block */ |
| 1365 | − int condexit; | |
| 1378 | + BlockCnt bl; | |
| 1379 | + FuncState *fs = ls->fs; | |
| 1380 | + expdesc v; | |
| 1381 | + int jf; /* instruction to skip 'then' code (if condition is false) */ | |
| 1366 | 1382 | luaX_next(ls); /* skip IF or ELSEIF */ |
| 1367 | − condexit = cond(ls); | |
| 1383 | + expr(ls, &v); /* read condition */ | |
| 1368 | 1384 | checknext(ls, TK_THEN); |
| 1369 | − block(ls); /* `then' part */ | |
| 1370 | − return condexit; | |
| 1385 | + if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) { | |
| 1386 | + luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */ | |
| 1387 | + enterblock(fs, &bl, 0); /* must enter block before 'goto' */ | |
| 1388 | + gotostat(ls, v.t); /* handle goto/break */ | |
| 1389 | + if (block_follow(ls, 0)) { /* 'goto' is the entire block? */ | |
| 1390 | + leaveblock(fs); | |
| 1391 | + return; /* and that is it */ | |
| 1392 | + } | |
| 1393 | + else /* must skip over 'then' part if condition is false */ | |
| 1394 | + jf = luaK_jump(fs); | |
| 1395 | + } | |
| 1396 | + else { /* regular case (not goto/break) */ | |
| 1397 | + luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */ | |
| 1398 | + enterblock(fs, &bl, 0); | |
| 1399 | + jf = v.f; | |
| 1400 | + } | |
| 1401 | + statlist(ls); /* `then' part */ | |
| 1402 | + leaveblock(fs); | |
| 1403 | + if (ls->t.token == TK_ELSE || | |
| 1404 | + ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */ | |
| 1405 | + luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */ | |
| 1406 | + luaK_patchtohere(fs, jf); | |
| 1371 | 1407 | } |
| 1372 | 1408 | |
| 1373 | 1409 | |
| 1374 | 1410 | static void ifstat (LexState *ls, int line) { |
| 1375 | 1411 | /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ |
| 1376 | 1412 | FuncState *fs = ls->fs; |
| 1377 | − int flist; | |
| 1378 | − int escapelist = NO_JUMP; | |
| 1379 | − flist = test_then_block(ls); /* IF cond THEN block */ | |
| 1380 | − while (ls->t.token == TK_ELSEIF) { | |
| 1381 | − luaK_concat(fs, &escapelist, luaK_jump(fs)); | |
| 1382 | − luaK_patchtohere(fs, flist); | |
| 1383 | − flist = test_then_block(ls); /* ELSEIF cond THEN block */ | |
| 1384 | − } | |
| 1385 | − if (ls->t.token == TK_ELSE) { | |
| 1386 | − luaK_concat(fs, &escapelist, luaK_jump(fs)); | |
| 1387 | − luaK_patchtohere(fs, flist); | |
| 1388 | − luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ | |
| 1413 | + int escapelist = NO_JUMP; /* exit list for finished parts */ | |
| 1414 | + test_then_block(ls, &escapelist); /* IF cond THEN block */ | |
| 1415 | + while (ls->t.token == TK_ELSEIF) | |
| 1416 | + test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */ | |
| 1417 | + if (testnext(ls, TK_ELSE)) | |
| 1389 | 1418 | block(ls); /* `else' part */ |
| 1390 | − } | |
| 1391 | − else | |
| 1392 | − luaK_concat(fs, &escapelist, flist); | |
| 1393 | − luaK_patchtohere(fs, escapelist); | |
| 1394 | 1419 | check_match(ls, TK_END, TK_IF, line); |
| 1420 | + luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */ | |
| 1395 | 1421 | } |
| 1396 | 1422 | |
| 1397 | 1423 | |
| @@ -1551,15 +1577,9 @@ static void statement (LexState *ls) { · 153 unmodified lines | ||
| 1551 | 1577 | retstat(ls); |
| 1552 | 1578 | break; |
| 1553 | 1579 | } |
| 1554 | − case TK_BREAK: { /* stat -> breakstat */ | |
| 1555 | − luaX_next(ls); /* skip BREAK */ | |
| 1556 | − /* code it as "goto 'break'" */ | |
| 1557 | − gotostat(ls, luaS_new(ls->L, "break"), line); | |
| 1558 | − break; | |
| 1559 | − } | |
| 1580 | + case TK_BREAK: /* stat -> breakstat */ | |
| 1560 | 1581 | case TK_GOTO: { /* stat -> 'goto' NAME */ |
| 1561 | − luaX_next(ls); /* skip GOTO */ | |
| 1562 | − gotostat(ls, str_checkname(ls), line); | |
| 1582 | + gotostat(ls, luaK_jump(ls->fs)); | |
| 1563 | 1583 | break; |
| 1564 | 1584 | } |
| 1565 | 1585 | default: { /* stat -> func | assignment */ |
| @@ -1595,8 +1615,8 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, · 29 unmodified lines | ||
| 1595 | 1615 | close_func(&lexstate); |
| 1596 | 1616 | L->top--; /* pop name */ |
| 1597 | 1617 | lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); |
| 1598 | − return funcstate.f; | |
| 1599 | 1618 | /* all scopes should be correctly finished */ |
| 1600 | 1619 | lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); |
| 1620 | + return funcstate.f; | |
| 1601 | 1621 | } |
| 1602 | 1622 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp $ | |
| 2 | +** $Id: lparser.h,v 1.69 2011/07/27 18:09:01 roberto Exp $ | |
| 3 | 3 | ** Lua Parser |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -55,7 +55,7 @@ typedef struct expdesc { · 49 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | /* description of active local variable */ |
| 57 | 57 | typedef struct Vardesc { |
| 58 | − unsigned short idx; /* variable index in stack */ | |
| 58 | + short idx; /* variable index in stack */ | |
| 59 | 59 | } Vardesc; |
| 60 | 60 | |
| 61 | 61 | |
| @@ -98,18 +98,17 @@ typedef struct FuncState { · 36 unmodified lines | ||
| 98 | 98 | Table *h; /* table to find (and reuse) elements in `k' */ |
| 99 | 99 | struct FuncState *prev; /* enclosing function */ |
| 100 | 100 | struct LexState *ls; /* lexical state */ |
| 101 | − struct lua_State *L; /* copy of the Lua state */ | |
| 102 | 101 | struct BlockCnt *bl; /* chain of current blocks */ |
| 103 | 102 | int pc; /* next position to code (equivalent to `ncode') */ |
| 104 | − int lasttarget; /* `pc' of last `jump target' */ | |
| 103 | + int lasttarget; /* 'label' of last 'jump label' */ | |
| 105 | 104 | int jpc; /* list of pending jumps to `pc' */ |
| 106 | − int freereg; /* first free register */ | |
| 107 | 105 | int nk; /* number of elements in `k' */ |
| 108 | 106 | int np; /* number of elements in `p' */ |
| 109 | − int firstlocal; /* index of first local var of this function */ | |
| 110 | − short nlocvars; /* number of elements in `locvars' */ | |
| 107 | + int firstlocal; /* index of first local var (in Dyndata array) */ | |
| 108 | + short nlocvars; /* number of elements in 'f->locvars' */ | |
| 111 | 109 | lu_byte nactvar; /* number of active local variables */ |
| 112 | 110 | lu_byte nups; /* number of upvalues */ |
| 111 | + lu_byte freereg; /* first free register */ | |
| 113 | 112 | } FuncState; |
| 114 | 113 | |
| 115 | 114 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstate.c,v 2.89 2010/12/20 19:40:07 roberto Exp $ | |
| 2 | +** $Id: lstate.c,v 2.92 2011/10/03 17:54:25 roberto Exp $ | |
| 3 | 3 | ** Global State |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -136,10 +136,10 @@ static void init_registry (lua_State *L, global_State *g) { · 130 unmodified lines | ||
| 136 | 136 | luaH_resize(L, registry, LUA_RIDX_LAST, 0); |
| 137 | 137 | /* registry[LUA_RIDX_MAINTHREAD] = L */ |
| 138 | 138 | setthvalue(L, &mt, L); |
| 139 | − setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt); | |
| 139 | + luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &mt); | |
| 140 | 140 | /* registry[LUA_RIDX_GLOBALS] = table of globals */ |
| 141 | 141 | sethvalue(L, &mt, luaH_new(L)); |
| 142 | − setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt); | |
| 142 | + luaH_setint(L, registry, LUA_RIDX_GLOBALS, &mt); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
| @@ -171,6 +171,7 @@ static void preinit_state (lua_State *L, global_State *g) { · 25 unmodified lines | ||
| 171 | 171 | L->ci = NULL; |
| 172 | 172 | L->stacksize = 0; |
| 173 | 173 | L->errorJmp = NULL; |
| 174 | + L->nCcalls = 0; | |
| 174 | 175 | L->hook = NULL; |
| 175 | 176 | L->hookmask = 0; |
| 176 | 177 | L->basehookcount = 0; |
| @@ -191,7 +192,7 @@ static void close_state (lua_State *L) { · 14 unmodified lines | ||
| 191 | 192 | luaZ_freebuffer(L, &g->buff); |
| 192 | 193 | freestack(L); |
| 193 | 194 | lua_assert(gettotalbytes(g) == sizeof(LG)); |
| 194 | − (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); | |
| 195 | + (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ | |
| 195 | 196 | } |
| 196 | 197 | |
| 197 | 198 | |
| @@ -237,7 +238,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 39 unmodified lines | ||
| 237 | 238 | g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); |
| 238 | 239 | L->marked = luaC_white(g); |
| 239 | 240 | g->gckind = KGC_NORMAL; |
| 240 | − g->nCcalls = 0; | |
| 241 | 241 | preinit_state(L, g); |
| 242 | 242 | g->frealloc = f; |
| 243 | 243 | g->ud = ud; |
| @@ -279,9 +279,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { · 35 unmodified lines | ||
| 279 | 279 | LUA_API void lua_close (lua_State *L) { |
| 280 | 280 | L = G(L)->mainthread; /* only the main thread can be closed */ |
| 281 | 281 | lua_lock(L); |
| 282 | − luaF_close(L, L->stack); /* close all upvalues for this thread */ | |
| 283 | − luaC_separateudata(L, 1); /* separate all udata with GC metamethods */ | |
| 284 | − lua_assert(L->next == NULL); | |
| 285 | 282 | luai_userstateclose(L); |
| 286 | 283 | close_state(L); |
| 287 | 284 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstate.h,v 2.72 2011/06/02 19:31:40 roberto Exp $ | |
| 2 | +** $Id: lstate.h,v 2.74 2011/09/30 12:45:07 roberto Exp $ | |
| 3 | 3 | ** Global State |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -47,8 +47,6 @@ struct lua_longjmp; /* defined in ldo.c */ · 41 unmodified lines | ||
| 47 | 47 | #define EXTRA_STACK 5 |
| 48 | 48 | |
| 49 | 49 | |
| 50 | −#define BASIC_CI_SIZE 8 | |
| 51 | − | |
| 52 | 50 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) |
| 53 | 51 | |
| 54 | 52 | |
| @@ -118,7 +116,6 @@ typedef struct global_State { · 63 unmodified lines | ||
| 118 | 116 | lu_mem lastmajormem; /* memory in use after last major collection */ |
| 119 | 117 | stringtable strt; /* hash table for strings */ |
| 120 | 118 | TValue l_registry; |
| 121 | − unsigned short nCcalls; /* number of nested C calls */ | |
| 122 | 119 | lu_byte currentwhite; |
| 123 | 120 | lu_byte gcstate; /* state of garbage collector */ |
| 124 | 121 | lu_byte gckind; /* kind of GC running */ |
| @@ -161,6 +158,7 @@ struct lua_State { · 36 unmodified lines | ||
| 161 | 158 | StkId stack; /* stack base */ |
| 162 | 159 | int stacksize; |
| 163 | 160 | unsigned short nny; /* number of non-yieldable calls in stack */ |
| 161 | + unsigned short nCcalls; /* number of nested C calls */ | |
| 164 | 162 | lu_byte hookmask; |
| 165 | 163 | lu_byte allowhook; |
| 166 | 164 | int basehookcount; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lstrlib.c,v 1.170 2011/06/28 17:13:52 roberto Exp $ | |
| 2 | +** $Id: lstrlib.c,v 1.172 2011/10/25 12:01:20 roberto Exp $ | |
| 3 | 3 | ** Standard library for string operations and pattern-matching |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -138,7 +138,7 @@ static int str_byte (lua_State *L) { · 132 unmodified lines | ||
| 138 | 138 | if (pose > l) pose = l; |
| 139 | 139 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 140 | 140 | n = (int)(pose - posi + 1); |
| 141 | − if (posi + n <= pose) /* overflow? */ | |
| 141 | + if (posi + n <= pose) /* (size_t -> int) overflow? */ | |
| 142 | 142 | return luaL_error(L, "string slice too long"); |
| 143 | 143 | luaL_checkstack(L, n, "string slice too long"); |
| 144 | 144 | for (i=0; i<n; i++) |
| @@ -154,7 +154,7 @@ static int str_char (lua_State *L) { · 9 unmodified lines | ||
| 154 | 154 | char *p = luaL_buffinitsize(L, &b, n); |
| 155 | 155 | for (i=1; i<=n; i++) { |
| 156 | 156 | int c = luaL_checkint(L, i); |
| 157 | − luaL_argcheck(L, uchar(c) == c, i, "invalid value"); | |
| 157 | + luaL_argcheck(L, uchar(c) == c, i, "value out of range"); | |
| 158 | 158 | p[i - 1] = uchar(c); |
| 159 | 159 | } |
| 160 | 160 | luaL_pushresultsize(&b, n); |
| @@ -865,11 +865,20 @@ static int str_format (lua_State *L) { · 704 unmodified lines | ||
| 865 | 865 | nb = sprintf(buff, form, luaL_checkint(L, arg)); |
| 866 | 866 | break; |
| 867 | 867 | } |
| 868 | − case 'd': case 'i': | |
| 868 | + case 'd': case 'i': { | |
| 869 | + lua_Number n = luaL_checknumber(L, arg); | |
| 870 | + LUA_INTFRM_T r = (LUA_INTFRM_T)n; | |
| 871 | + luaL_argcheck(L, (lua_Number)r == n, arg, | |
| 872 | + "not an integer in proper range"); | |
| 873 | + addlenmod(form, LUA_INTFRMLEN); | |
| 874 | + nb = sprintf(buff, form, r); | |
| 875 | + break; | |
| 876 | + } | |
| 869 | 877 | case 'o': case 'u': case 'x': case 'X': { |
| 870 | 878 | lua_Number n = luaL_checknumber(L, arg); |
| 871 | − LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n : | |
| 872 | − (LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n; | |
| 879 | + unsigned LUA_INTFRM_T r = (unsigned LUA_INTFRM_T)n; | |
| 880 | + luaL_argcheck(L, (lua_Number)r == n, arg, | |
| 881 | + "not a non-negative integer in proper range"); | |
| 873 | 882 | addlenmod(form, LUA_INTFRMLEN); |
| 874 | 883 | nb = sprintf(buff, form, r); |
| 875 | 884 | break; |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltable.c,v 2.60 2011/06/16 14:14:31 roberto Exp $ | |
| 2 | +** $Id: ltable.c,v 2.65 2011/09/30 12:45:27 roberto Exp $ | |
| 3 | 3 | ** Lua tables (hash) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -64,13 +64,6 @@ · 58 unmodified lines | ||
| 64 | 64 | #define hashpointer(t,p) hashmod(t, IntPoint(p)) |
| 65 | 65 | |
| 66 | 66 | |
| 67 | −/* | |
| 68 | −** number of ints inside a lua_Number | |
| 69 | −*/ | |
| 70 | −#define numints cast_int(sizeof(lua_Number)/sizeof(int)) | |
| 71 | − | |
| 72 | − | |
| 73 | − | |
| 74 | 67 | #define dummynode (&dummynode_) |
| 75 | 68 | |
| 76 | 69 | #define isdummy(n) ((n) == dummynode) |
| @@ -152,7 +145,7 @@ static int findindex (lua_State *L, Table *t, StkId key) { · 75 unmodified lines | ||
| 152 | 145 | /* key may be dead already, but it is ok to use it in `next' */ |
| 153 | 146 | if (luaV_rawequalobj(gkey(n), key) || |
| 154 | 147 | (ttisdeadkey(gkey(n)) && iscollectable(key) && |
| 155 | − gcvalue(gkey(n)) == gcvalue(key))) { | |
| 148 | + deadvalue(gkey(n)) == gcvalue(key))) { | |
| 156 | 149 | i = cast_int(n - gnode(t, 0)); /* key index in hash table */ |
| 157 | 150 | /* hash elements are numbered after array ones */ |
| 158 | 151 | return i + t->sizearray; |
| @@ -314,7 +307,7 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 155 unmodified lines | ||
| 314 | 307 | /* re-insert elements from vanishing slice */ |
| 315 | 308 | for (i=nasize; i<oldasize; i++) { |
| 316 | 309 | if (!ttisnil(&t->array[i])) |
| 317 | − setobjt2t(L, luaH_setint(L, t, i+1), &t->array[i]); | |
| 310 | + luaH_setint(L, t, i + 1, &t->array[i]); | |
| 318 | 311 | } |
| 319 | 312 | /* shrink array */ |
| 320 | 313 | luaM_reallocvector(L, t->array, oldasize, nasize, TValue); |
| @@ -322,8 +315,11 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) { · 1 unmodified line | ||
| 322 | 315 | /* re-insert elements from hash part */ |
| 323 | 316 | for (i = twoto(oldhsize) - 1; i >= 0; i--) { |
| 324 | 317 | Node *old = nold+i; |
| 325 | − if (!ttisnil(gval(old))) | |
| 318 | + if (!ttisnil(gval(old))) { | |
| 319 | + /* doesn't need barrier/invalidate cache, as entry was | |
| 320 | + already present in the table */ | |
| 326 | 321 | setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old)); |
| 322 | + } | |
| 327 | 323 | } |
| 328 | 324 | if (!isdummy(nold)) |
| 329 | 325 | luaM_freearray(L, nold, twoto(oldhsize)); /* free old array */ |
| @@ -398,14 +394,19 @@ static Node *getfreepos (Table *t) { · 68 unmodified lines | ||
| 398 | 394 | ** put new key in its main position; otherwise (colliding node is in its main |
| 399 | 395 | ** position), new key goes to an empty position. |
| 400 | 396 | */ |
| 401 | −static TValue *newkey (lua_State *L, Table *t, const TValue *key) { | |
| 402 | − Node *mp = mainposition(t, key); | |
| 397 | +TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |
| 398 | + Node *mp; | |
| 399 | + if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | |
| 400 | + else if (ttisnumber(key) && luai_numisnan(L, nvalue(key))) | |
| 401 | + luaG_runerror(L, "table index is NaN"); | |
| 402 | + mp = mainposition(t, key); | |
| 403 | 403 | if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */ |
| 404 | 404 | Node *othern; |
| 405 | 405 | Node *n = getfreepos(t); /* get a free place */ |
| 406 | 406 | if (n == NULL) { /* cannot find a free place? */ |
| 407 | 407 | rehash(L, t, key); /* grow table */ |
| 408 | − return luaH_set(L, t, key); /* re-insert key into grown table */ | |
| 408 | + /* whatever called 'newkey' take care of TM cache and GC barrier */ | |
| 409 | + return luaH_set(L, t, key); /* insert key into grown table */ | |
| 409 | 410 | } |
| 410 | 411 | lua_assert(!isdummy(n)); |
| 411 | 412 | othern = mainposition(t, gkey(mp)); |
| @@ -493,41 +494,29 @@ const TValue *luaH_get (Table *t, const TValue *key) { · 81 unmodified lines | ||
| 493 | 494 | } |
| 494 | 495 | |
| 495 | 496 | |
| 497 | +/* | |
| 498 | +** beware: when using this function you probably need to check a GC | |
| 499 | +** barrier and invalidate the TM cache. | |
| 500 | +*/ | |
| 496 | 501 | TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { |
| 497 | 502 | const TValue *p = luaH_get(t, key); |
| 498 | − t->flags = 0; | |
| 499 | 503 | if (p != luaO_nilobject) |
| 500 | 504 | return cast(TValue *, p); |
| 501 | − else { | |
| 502 | − if (ttisnil(key)) luaG_runerror(L, "table index is nil"); | |
| 503 | − else if (ttisnumber(key) && luai_numisnan(L, nvalue(key))) | |
| 504 | − luaG_runerror(L, "table index is NaN"); | |
| 505 | − return newkey(L, t, key); | |
| 506 | − } | |
| 505 | + else return luaH_newkey(L, t, key); | |
| 507 | 506 | } |
| 508 | 507 | |
| 509 | 508 | |
| 510 | −TValue *luaH_setint (lua_State *L, Table *t, int key) { | |
| 509 | +void luaH_setint (lua_State *L, Table *t, int key, TValue *value) { | |
| 511 | 510 | const TValue *p = luaH_getint(t, key); |
| 511 | + TValue *cell; | |
| 512 | 512 | if (p != luaO_nilobject) |
| 513 | − return cast(TValue *, p); | |
| 513 | + cell = cast(TValue *, p); | |
| 514 | 514 | else { |
| 515 | 515 | TValue k; |
| 516 | 516 | setnvalue(&k, cast_num(key)); |
| 517 | − return newkey(L, t, &k); | |
| 518 | − } | |
| 519 | −} | |
| 520 | − | |
| 521 | − | |
| 522 | −TValue *luaH_setstr (lua_State *L, Table *t, TString *key) { | |
| 523 | − const TValue *p = luaH_getstr(t, key); | |
| 524 | − if (p != luaO_nilobject) | |
| 525 | − return cast(TValue *, p); | |
| 526 | − else { | |
| 527 | − TValue k; | |
| 528 | − setsvalue(L, &k, key); | |
| 529 | − return newkey(L, t, &k); | |
| 517 | + cell = luaH_newkey(L, t, &k); | |
| 530 | 518 | } |
| 519 | + setobj2t(L, cell, value); | |
| 531 | 520 | } |
| 532 | 521 | |
| 533 | 522 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltable.h,v 2.14 2010/06/25 12:18:10 roberto Exp $ | |
| 2 | +** $Id: ltable.h,v 2.16 2011/08/17 20:26:47 roberto Exp $ | |
| 3 | 3 | ** Lua tables (hash) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -15,12 +15,14 @@ · 9 unmodified lines | ||
| 15 | 15 | #define gval(n) (&(n)->i_val) |
| 16 | 16 | #define gnext(n) ((n)->i_key.nk.next) |
| 17 | 17 | |
| 18 | +#define invalidateTMcache(t) ((t)->flags = 0) | |
| 19 | + | |
| 18 | 20 | |
| 19 | 21 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key); |
| 20 | −LUAI_FUNC TValue *luaH_setint (lua_State *L, Table *t, int key); | |
| 22 | +LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value); | |
| 21 | 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); |
| 22 | −LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); | |
| 23 | 24 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); |
| 25 | +LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); | |
| 24 | 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); |
| 25 | 27 | LUAI_FUNC Table *luaH_new (lua_State *L); |
| 26 | 28 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: ltablib.c,v 1.61 2011/07/05 12:49:35 roberto Exp $ | |
| 2 | +** $Id: ltablib.c,v 1.62 2011/09/30 12:45:45 roberto Exp $ | |
| 3 | 3 | ** Library for Table Manipulation |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -86,7 +86,7 @@ static void addfield (lua_State *L, luaL_Buffer *b, int i) { · 80 unmodified lines | ||
| 86 | 86 | if (!lua_isstring(L, -1)) |
| 87 | 87 | luaL_error(L, "invalid value (%s) at index %d in table for " |
| 88 | 88 | LUA_QL("concat"), luaL_typename(L, -1), i); |
| 89 | − luaL_addvalue(b); | |
| 89 | + luaL_addvalue(b); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.c,v 1.200 2011/06/16 14:30:58 roberto Exp $ | |
| 2 | +** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp $ | |
| 3 | 3 | ** Lua stand-alone interpreter |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -118,6 +118,7 @@ static void print_usage (const char *badoption) { · 112 unmodified lines | ||
| 118 | 118 | " -i enter interactive mode after executing " LUA_QL("script") "\n" |
| 119 | 119 | " -l name require library " LUA_QL("name") "\n" |
| 120 | 120 | " -v show version information\n" |
| 121 | + " -E ignore environment variables\n" | |
| 121 | 122 | " -- stop handling options\n" |
| 122 | 123 | " - stop handling options and execute stdin\n" |
| 123 | 124 | , |
| @@ -348,7 +349,16 @@ static int handle_script (lua_State *L, char **argv, int n) { · 224 unmodified lines | ||
| 348 | 349 | #define noextrachars(x) {if ((x)[2] != '\0') return -1;} |
| 349 | 350 | |
| 350 | 351 | |
| 351 | −static int collectargs (char **argv, int *pi, int *pv, int *pe) { | |
| 352 | +/* indices of various argument indicators in array args */ | |
| 353 | +#define has_i 0 /* -i */ | |
| 354 | +#define has_v 1 /* -v */ | |
| 355 | +#define has_e 2 /* -e */ | |
| 356 | +#define has_E 3 /* -E */ | |
| 357 | + | |
| 358 | +#define num_has 4 /* number of 'has_*' */ | |
| 359 | + | |
| 360 | + | |
| 361 | +static int collectargs (char **argv, int *args) { | |
| 352 | 362 | int i; |
| 353 | 363 | for (i = 1; argv[i] != NULL; i++) { |
| 354 | 364 | if (argv[i][0] != '-') /* not an option? */ |
| @@ -359,15 +369,18 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 4 unmodified lines | ||
| 359 | 369 | return (argv[i+1] != NULL ? i+1 : 0); |
| 360 | 370 | case '\0': |
| 361 | 371 | return i; |
| 372 | + case 'E': | |
| 373 | + args[has_E] = 1; | |
| 374 | + break; | |
| 362 | 375 | case 'i': |
| 363 | 376 | noextrachars(argv[i]); |
| 364 | − *pi = 1; /* go through */ | |
| 377 | + args[has_i] = 1; /* go through */ | |
| 365 | 378 | case 'v': |
| 366 | 379 | noextrachars(argv[i]); |
| 367 | − *pv = 1; | |
| 380 | + args[has_v] = 1; | |
| 368 | 381 | break; |
| 369 | 382 | case 'e': |
| 370 | − *pe = 1; /* go through */ | |
| 383 | + args[has_e] = 1; /* go through */ | |
| 371 | 384 | case 'l': /* both options need an argument */ |
| 372 | 385 | if (argv[i][2] == '\0') { /* no concatenated argument? */ |
| 373 | 386 | i++; /* try next 'argv' */ |
| @@ -426,32 +439,46 @@ static int handle_luainit (lua_State *L) { · 52 unmodified lines | ||
| 426 | 439 | } |
| 427 | 440 | |
| 428 | 441 | |
| 442 | +static void resetpaths (lua_State *L) { | |
| 443 | + lua_getglobal(L, "package"); | |
| 444 | + if (!lua_istable(L, -1)) /* no module 'package'? */ | |
| 445 | + return; /* nothing to be done */ | |
| 446 | + lua_pushliteral(L, LUA_PATH_DEFAULT); | |
| 447 | + lua_setfield(L, -2, "path"); /* package.path = default */ | |
| 448 | + lua_pushliteral(L, LUA_CPATH_DEFAULT); | |
| 449 | + lua_setfield(L, -2, "cpath"); /* package.cpath = default */ | |
| 450 | + lua_pop(L, 1); /* remove 'package' */ | |
| 451 | +} | |
| 452 | + | |
| 453 | + | |
| 429 | 454 | static int pmain (lua_State *L) { |
| 430 | 455 | int argc = (int)lua_tointeger(L, 1); |
| 431 | 456 | char **argv = (char **)lua_touserdata(L, 2); |
| 432 | 457 | int script; |
| 433 | − int has_i = 0, has_v = 0, has_e = 0; | |
| 458 | + int args[num_has]; | |
| 459 | + args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0; | |
| 434 | 460 | if (argv[0] && argv[0][0]) progname = argv[0]; |
| 435 | − script = collectargs(argv, &has_i, &has_v, &has_e); | |
| 461 | + script = collectargs(argv, args); | |
| 436 | 462 | if (script < 0) { /* invalid arg? */ |
| 437 | 463 | print_usage(argv[-script]); |
| 438 | 464 | return 0; |
| 439 | 465 | } |
| 440 | − if (has_v) print_version(); | |
| 466 | + if (args[has_v]) print_version(); | |
| 441 | 467 | /* open standard libraries */ |
| 442 | 468 | luaL_checkversion(L); |
| 443 | 469 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ |
| 444 | 470 | luaL_openlibs(L); /* open libraries */ |
| 445 | 471 | lua_gc(L, LUA_GCRESTART, 0); |
| 446 | − /* run LUA_INIT */ | |
| 447 | − if (handle_luainit(L) != LUA_OK) return 0; | |
| 472 | + if (args[has_E]) /* avoid LUA_INIT? */ | |
| 473 | + resetpaths(L); | |
| 474 | + else if (handle_luainit(L) != LUA_OK) return 0; | |
| 448 | 475 | /* execute arguments -e and -l */ |
| 449 | 476 | if (!runargs(L, argv, (script > 0) ? script : argc)) return 0; |
| 450 | 477 | /* execute main script (if there is one) */ |
| 451 | 478 | if (script && handle_script(L, argv, script) != LUA_OK) return 0; |
| 452 | − if (has_i) /* -i option? */ | |
| 479 | + if (args[has_i]) /* -i option? */ | |
| 453 | 480 | dotty(L); |
| 454 | − else if (script == 0 && !has_e && !has_v) { /* no arguments? */ | |
| 481 | + else if (script == 0 && !args[has_e] && !args[has_v]) { /* no arguments? */ | |
| 455 | 482 | if (lua_stdin_is_tty()) { |
| 456 | 483 | print_version(); |
| 457 | 484 | dotty(L); |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.h,v 1.278 2011/07/02 16:00:15 roberto Exp $ | |
| 2 | +** $Id: lua.h,v 1.281 2011/10/24 16:53:05 roberto Exp $ | |
| 3 | 3 | ** Lua - A Scripting Language |
| 4 | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | 5 | ** See Copyright Notice at the end of this file |
| @@ -19,7 +19,7 @@ · 13 unmodified lines | ||
| 19 | 19 | #define LUA_VERSION_MAJOR "5" |
| 20 | 20 | #define LUA_VERSION_MINOR "2" |
| 21 | 21 | #define LUA_VERSION_NUM 502 |
| 22 | −#define LUA_VERSION_RELEASE "0" " (beta)" | |
| 22 | +#define LUA_VERSION_RELEASE "0" | |
| 23 | 23 | |
| 24 | 24 | #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR |
| 25 | 25 | #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE |
| @@ -215,10 +215,12 @@ LUA_API int (lua_pushthread) (lua_State *L); · 189 unmodified lines | ||
| 215 | 215 | /* |
| 216 | 216 | ** get functions (Lua -> stack) |
| 217 | 217 | */ |
| 218 | +LUA_API void (lua_getglobal) (lua_State *L, const char *var); | |
| 218 | 219 | LUA_API void (lua_gettable) (lua_State *L, int idx); |
| 219 | 220 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); |
| 220 | 221 | LUA_API void (lua_rawget) (lua_State *L, int idx); |
| 221 | 222 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); |
| 223 | +LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p); | |
| 222 | 224 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); |
| 223 | 225 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); |
| 224 | 226 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex); |
| @@ -228,10 +230,12 @@ LUA_API void (lua_getuservalue) (lua_State *L, int idx); · 3 unmodified lines | ||
| 228 | 230 | /* |
| 229 | 231 | ** set functions (stack -> Lua) |
| 230 | 232 | */ |
| 233 | +LUA_API void (lua_setglobal) (lua_State *L, const char *var); | |
| 231 | 234 | LUA_API void (lua_settable) (lua_State *L, int idx); |
| 232 | 235 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); |
| 233 | 236 | LUA_API void (lua_rawset) (lua_State *L, int idx); |
| 234 | 237 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); |
| 238 | +LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p); | |
| 235 | 239 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex); |
| 236 | 240 | LUA_API void (lua_setuservalue) (lua_State *L, int idx); |
| 237 | 241 | |
| @@ -261,7 +265,7 @@ LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); · 23 unmodified lines | ||
| 261 | 265 | LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx, |
| 262 | 266 | lua_CFunction k); |
| 263 | 267 | #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) |
| 264 | −LUA_API int (lua_resume) (lua_State *L, int narg); | |
| 268 | +LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg); | |
| 265 | 269 | LUA_API int (lua_status) (lua_State *L); |
| 266 | 270 | |
| 267 | 271 | /* |
| @@ -314,13 +318,6 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); · 46 unmodified lines | ||
| 314 | 318 | |
| 315 | 319 | #define lua_newtable(L) lua_createtable(L, 0, 0) |
| 316 | 320 | |
| 317 | −#define lua_setglobal(L,s) \ | |
| 318 | − (lua_pushglobaltable(L), lua_pushvalue(L, -2), \ | |
| 319 | − lua_setfield(L, -2, (s)), lua_pop(L, 2)) | |
| 320 | − | |
| 321 | −#define lua_getglobal(L,s) \ | |
| 322 | − (lua_pushglobaltable(L), lua_getfield(L, -1, (s)), lua_remove(L, -2)) | |
| 323 | − | |
| 324 | 321 | #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) |
| 325 | 322 | |
| 326 | 323 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: luac.c,v 1.67 2011/06/21 12:29:00 lhf Exp $ | |
| 2 | +** $Id: luac.c,v 1.68 2011/11/23 17:48:18 lhf Exp $ | |
| 3 | 3 | ** Lua compiler (saves bytecodes to files; also list bytecodes) |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -53,7 +53,7 @@ static void usage(const char* message) · 47 unmodified lines | ||
| 53 | 53 | fprintf(stderr, |
| 54 | 54 | "usage: %s [options] [filenames]\n" |
| 55 | 55 | "Available options are:\n" |
| 56 | − " -l list\n" | |
| 56 | + " -l list (use -l -l for full listing)\n" | |
| 57 | 57 | " -o name output to file " LUA_QL("name") " (default is \"%s\")\n" |
| 58 | 58 | " -p parse only\n" |
| 59 | 59 | " -s strip debug information\n" |
| @@ -203,7 +203,7 @@ int main(int argc, char* argv[]) · 143 unmodified lines | ||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /* |
| 206 | −** $Id: print.c,v 1.67 2011/05/06 13:37:15 lhf Exp $ | |
| 206 | +** $Id: print.c,v 1.68 2011/09/30 10:21:20 lhf Exp $ | |
| 207 | 207 | ** print bytecodes |
| 208 | 208 | ** See Copyright Notice in lua.h |
| 209 | 209 | */ |
| @@ -218,7 +218,6 @@ int main(int argc, char* argv[]) · 8 unmodified lines | ||
| 218 | 218 | #include "lobject.h" |
| 219 | 219 | #include "lopcodes.h" |
| 220 | 220 | |
| 221 | −#define Sizeof(x) ((int)sizeof(x)) | |
| 222 | 221 | #define VOID(p) ((const void*)(p)) |
| 223 | 222 | |
| 224 | 223 | static void PrintString(const TString* ts) |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: luaconf.h,v 1.161 2011/07/08 20:07:11 roberto Exp $ | |
| 2 | +** $Id: luaconf.h,v 1.166 2011/11/09 14:47:14 roberto Exp $ | |
| 3 | 3 | ** Configuration file for Lua |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -29,8 +29,8 @@ · 23 unmodified lines | ||
| 29 | 29 | #endif |
| 30 | 30 | |
| 31 | 31 | |
| 32 | −#if !defined(LUA_ANSI) && defined(_WIN32) | |
| 33 | −#define LUA_WIN | |
| 32 | +#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE) | |
| 33 | +#define LUA_WIN /* enable goodies for regular Windows platforms */ | |
| 34 | 34 | #endif |
| 35 | 35 | |
| 36 | 36 | #if defined(LUA_WIN) |
| @@ -210,10 +210,14 @@ · 173 unmodified lines | ||
| 210 | 210 | |
| 211 | 211 | /* |
| 212 | 212 | @@ luai_writestring/luai_writeline define how 'print' prints its results. |
| 213 | +** They are only used in libraries and the stand-alone program. (The #if | |
| 214 | +** avoids including 'stdio.h' everywhere.) | |
| 213 | 215 | */ |
| 216 | +#if defined(LUA_LIB) || defined(lua_c) || defined(luaall_c) | |
| 214 | 217 | #include <stdio.h> |
| 215 | 218 | #define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout) |
| 216 | 219 | #define luai_writeline() (luai_writestring("\n", 1), fflush(stdout)) |
| 220 | +#endif | |
| 217 | 221 | |
| 218 | 222 | /* |
| 219 | 223 | @@ luai_writestringerror defines how to print error messages. |
| @@ -459,7 +463,7 @@ · 239 unmodified lines | ||
| 459 | 463 | |
| 460 | 464 | /* On a Microsoft compiler on a Pentium, use assembler to avoid clashes |
| 461 | 465 | with a DirectX idiosyncrasy */ |
| 462 | −#if defined(_MSC_VER) && defined(M_IX86) /* { */ | |
| 466 | +#if defined(LUA_WIN) && defined(_M_IX86) /* { */ | |
| 463 | 467 | |
| 464 | 468 | #define MS_ASMTRICK |
| 465 | 469 | |
| @@ -492,12 +496,13 @@ · 26 unmodified lines | ||
| 492 | 496 | |
| 493 | 497 | |
| 494 | 498 | /* |
| 495 | −@@ LUA_NANTRICKLE/LUA_NANTRICKBE controls the use of a trick to pack all | |
| 496 | −** types into a single double value, using NaN values to represent | |
| 497 | −** non-number values. The trick only works on 32-bit machines (ints and | |
| 498 | −** pointers are 32-bit values) with numbers represented as IEEE 754-2008 | |
| 499 | −** doubles with conventional endianess (12345678 or 87654321), in CPUs | |
| 500 | −** that do not produce signaling NaN values (all NaNs are quiet). | |
| 499 | +@@ LUA_NANTRICK_LE/LUA_NANTRICK_BE controls the use of a trick to | |
| 500 | +** pack all types into a single double value, using NaN values to | |
| 501 | +** represent non-number values. The trick only works on 32-bit machines | |
| 502 | +** (ints and pointers are 32-bit values) with numbers represented as | |
| 503 | +** IEEE 754-2008 doubles with conventional endianess (12345678 or | |
| 504 | +** 87654321), in CPUs that do not produce signaling NaN values (all NaNs | |
| 505 | +** are quiet). | |
| 501 | 506 | */ |
| 502 | 507 | #if defined(LUA_CORE) && \ |
| 503 | 508 | defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */ |
| @@ -506,7 +511,7 @@ · 2 unmodified lines | ||
| 506 | 511 | #if defined(__i386__) || defined(__i386) || defined(__X86__) || \ |
| 507 | 512 | defined(_M_IX86) |
| 508 | 513 | |
| 509 | −#define LUA_NANTRICKLE | |
| 514 | +#define LUA_NANTRICK_LE | |
| 510 | 515 | |
| 511 | 516 | #endif |
| 512 | 517 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lvm.c,v 2.141 2011/06/09 18:24:22 roberto Exp $ | |
| 2 | +** $Id: lvm.c,v 2.144 2011/10/07 20:45:19 roberto Exp $ | |
| 3 | 3 | ** Lua virtual machine |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -127,29 +127,38 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { · 121 unmodified lines | ||
| 127 | 127 | |
| 128 | 128 | void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { |
| 129 | 129 | int loop; |
| 130 | − TValue temp; | |
| 131 | 130 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 132 | 131 | const TValue *tm; |
| 133 | 132 | if (ttistable(t)) { /* `t' is a table? */ |
| 134 | 133 | Table *h = hvalue(t); |
| 135 | − TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ | |
| 136 | − if (!ttisnil(oldval) || /* result is not nil? */ | |
| 137 | − (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ | |
| 138 | − setobj2t(L, oldval, val); | |
| 134 | + TValue *oldval = cast(TValue *, luaH_get(h, key)); | |
| 135 | + /* if previous value is not nil, there must be a previous entry | |
| 136 | + in the table; moreover, a metamethod has no relevance */ | |
| 137 | + if (!ttisnil(oldval) || | |
| 138 | + /* previous value is nil; must check the metamethod */ | |
| 139 | + ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL && | |
| 140 | + /* no metamethod; is there a previous entry in the table? */ | |
| 141 | + (oldval != luaO_nilobject || | |
| 142 | + /* no previous entry; must create one. (The next test is | |
| 143 | + always true; we only need the assignment.) */ | |
| 144 | + (oldval = luaH_newkey(L, h, key), 1)))) { | |
| 145 | + /* no metamethod and (now) there is an entry with given key */ | |
| 146 | + setobj2t(L, oldval, val); /* assign new value to that entry */ | |
| 147 | + invalidateTMcache(h); | |
| 139 | 148 | luaC_barrierback(L, obj2gco(h), val); |
| 140 | 149 | return; |
| 141 | 150 | } |
| 142 | − /* else will try the tag method */ | |
| 151 | + /* else will try the metamethod */ | |
| 143 | 152 | } |
| 144 | − else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) | |
| 145 | − luaG_typeerror(L, t, "index"); | |
| 153 | + else /* not a table; check metamethod */ | |
| 154 | + if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) | |
| 155 | + luaG_typeerror(L, t, "index"); | |
| 156 | + /* there is a metamethod */ | |
| 146 | 157 | if (ttisfunction(tm)) { |
| 147 | 158 | callTM(L, tm, t, key, val, 0); |
| 148 | 159 | return; |
| 149 | 160 | } |
| 150 | − /* else repeat with 'tm' */ | |
| 151 | − setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */ | |
| 152 | − t = &temp; | |
| 161 | + t = tm; /* else repeat with 'tm' */ | |
| 153 | 162 | } |
| 154 | 163 | luaG_runerror(L, "loop in settable"); |
| 155 | 164 | } |
| @@ -217,9 +226,9 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 61 unmodified lines | ||
| 217 | 226 | return luai_numlt(L, nvalue(l), nvalue(r)); |
| 218 | 227 | else if (ttisstring(l) && ttisstring(r)) |
| 219 | 228 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; |
| 220 | − else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) | |
| 221 | − return res; | |
| 222 | − return luaG_ordererror(L, l, r); | |
| 229 | + else if ((res = call_orderTM(L, l, r, TM_LT)) < 0) | |
| 230 | + luaG_ordererror(L, l, r); | |
| 231 | + return res; | |
| 223 | 232 | } |
| 224 | 233 | |
| 225 | 234 | |
| @@ -229,11 +238,11 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { · 3 unmodified lines | ||
| 229 | 238 | return luai_numle(L, nvalue(l), nvalue(r)); |
| 230 | 239 | else if (ttisstring(l) && ttisstring(r)) |
| 231 | 240 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; |
| 232 | − else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ | |
| 241 | + else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */ | |
| 233 | 242 | return res; |
| 234 | − else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ | |
| 235 | − return !res; | |
| 236 | − return luaG_ordererror(L, l, r); | |
| 243 | + else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */ | |
| 244 | + luaG_ordererror(L, l, r); | |
| 245 | + return !res; | |
| 237 | 246 | } |
| 238 | 247 | |
| 239 | 248 | |
| @@ -808,7 +817,7 @@ void luaV_execute (lua_State *L) { · 568 unmodified lines | ||
| 808 | 817 | luaH_resizearray(L, h, last); /* pre-allocate it at once */ |
| 809 | 818 | for (; n > 0; n--) { |
| 810 | 819 | TValue *val = ra+n; |
| 811 | − setobj2t(L, luaH_setint(L, h, last--), val); | |
| 820 | + luaH_setint(L, h, last--, val); | |
| 812 | 821 | luaC_barrierback(L, obj2gco(h), val); |
| 813 | 822 | } |
| 814 | 823 | L->top = ci->top; /* correct top (in case of previous open call) */ |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lzio.c,v 1.33 2011/02/23 13:13:10 roberto Exp $ | |
| 2 | +** $Id: lzio.c,v 1.34 2011/07/15 12:35:32 roberto Exp $ | |
| 3 | 3 | ** a generic input stream interface |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -29,7 +29,7 @@ int luaZ_fill (ZIO *z) { · 23 unmodified lines | ||
| 29 | 29 | return EOZ; |
| 30 | 30 | z->n = size - 1; /* discount char being returned */ |
| 31 | 31 | z->p = buff; |
| 32 | − return char2int(*(z->p++)); | |
| 32 | + return cast_uchar(*(z->p++)); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lzio.h,v 1.24 2011/02/23 13:13:10 roberto Exp $ | |
| 2 | +** $Id: lzio.h,v 1.26 2011/07/15 12:48:03 roberto Exp $ | |
| 3 | 3 | ** Buffered streams |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -17,11 +17,7 @@ · 11 unmodified lines | ||
| 17 | 17 | |
| 18 | 18 | typedef struct Zio ZIO; |
| 19 | 19 | |
| 20 | −#define char2int(c) cast(int, cast(unsigned char, (c))) | |
| 21 | − | |
| 22 | −#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) | |
| 23 | − | |
| 24 | −#define zungetc(z) ((z)->n++, (z)->p--) | |
| 20 | +#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) | |
| 25 | 21 | |
| 26 | 22 | |
| 27 | 23 | typedef struct Mbuffer { |