diff options
author | Lua Team <team@lua.org> | 2011-06-27 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2011-06-27 12:00:00 +0000 |
commit | 24a2997ef4f198da94a3f209a22c4647e4dc483c (patch) | |
tree | c20fc70b9735ad83025190495678c3681bd7791e | |
parent | 16559ecd52698cfead11eca834903b686bf62d65 (diff) | |
download | lua-github-24a2997ef4f198da94a3f209a22c4647e4dc483c.tar.gz |
Lua 5.2.0-beta-rc35.2.0-beta-rc3
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | doc/manual.html | 412 | ||||
-rw-r--r-- | doc/readme.html | 8 | ||||
-rw-r--r-- | src/Makefile | 11 | ||||
-rw-r--r-- | src/lctype.c | 49 | ||||
-rw-r--r-- | src/lctype.h | 95 | ||||
-rw-r--r-- | src/llex.c | 68 | ||||
-rw-r--r-- | src/lobject.c | 19 | ||||
-rw-r--r-- | src/lparser.c | 33 | ||||
-rw-r--r-- | src/lparser.h | 5 |
10 files changed, 436 insertions, 266 deletions
@@ -1,5 +1,5 @@ -This is Lua 5.2 (beta), released on 13 Jun 2011. +This is Lua 5.2 (beta), released on 27 Jun 2011. For installation instructions, license details, and further information about Lua, see doc/readme.html. diff --git a/doc/manual.html b/doc/manual.html index af2e34ce..02fe012f 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -38,7 +38,7 @@ Freely available under the terms of the <!-- ====================================================================== --> <p> -<!-- $Id: manual.of,v 1.79 2011/06/21 14:35:46 roberto Exp $ --> +<!-- $Id: manual.of,v 1.80 2011/06/27 18:26:28 roberto Exp $ --> @@ -209,10 +209,11 @@ Thus tables can also carry <em>methods</em> (see <a href="#3.4.10">§3.4.10< <p> The indexing of tables follows -the definition of equality in the language. +the definition of raw equality in the language. The expressions <code>a[i]</code> and <code>a[j]</code> denote the same table element -if and only if <code>i == j</code>. +if and only if <code>i</code> and <code>j</code> are raw equal +(that is, equal without metamethods). <p> @@ -328,7 +329,7 @@ you may give an <em>message handler</em> to be called in case of errors. This function is called with the original error message and returns a new error message. -It is called before the error unwonds the stack, +It is called before the error unwinds the stack, so that it can gather more information about the error, for instance by inspecting the stack and creating a stack traceback. This message handler is still protected by the protected call; @@ -443,7 +444,7 @@ in the following code. <ul> -<li><b>"add":</b> +<li><b>"add": </b> the <code>+</code> operation. @@ -481,25 +482,25 @@ the behavior of the <code>op1 + op2</code> is </pre><p> </li> -<li><b>"sub":</b> +<li><b>"sub": </b> the <code>-</code> operation. Behavior similar to the "add" operation. </li> -<li><b>"mul":</b> +<li><b>"mul": </b> the <code>*</code> operation. Behavior similar to the "add" operation. </li> -<li><b>"div":</b> +<li><b>"div": </b> the <code>/</code> operation. Behavior similar to the "add" operation. </li> -<li><b>"mod":</b> +<li><b>"mod": </b> the <code>%</code> operation. Behavior similar to the "add" operation, @@ -507,7 +508,7 @@ with the operation <code>o1 - floor(o1/o2)*o2</code> as the primitive operation. </li> -<li><b>"pow":</b> +<li><b>"pow": </b> the <code>^</code> (exponentiation) operation. Behavior similar to the "add" operation, @@ -515,7 +516,7 @@ with the function <code>pow</code> (from the C math library) as the primitive operation. </li> -<li><b>"unm":</b> +<li><b>"unm": </b> the unary <code>-</code> operation. @@ -538,7 +539,7 @@ the unary <code>-</code> operation. </pre><p> </li> -<li><b>"concat":</b> +<li><b>"concat": </b> the <code>..</code> (concatenation) operation. @@ -559,7 +560,7 @@ the <code>..</code> (concatenation) operation. </pre><p> </li> -<li><b>"len":</b> +<li><b>"len": </b> the <code>#</code> operation. @@ -582,7 +583,7 @@ the <code>#</code> operation. See <a href="#3.4.6">§3.4.6</a> for a description of the length of a table. </li> -<li><b>"eq":</b> +<li><b>"eq": </b> the <code>==</code> operation. The function <code>getequalhandler</code> defines how Lua chooses a metamethod @@ -620,7 +621,7 @@ The "eq" event is defined as follows: </pre><p> </li> -<li><b>"lt":</b> +<li><b>"lt": </b> the <code><</code> operation. @@ -642,7 +643,7 @@ the <code><</code> operation. </pre><p> </li> -<li><b>"le":</b> +<li><b>"le": </b> the <code><=</code> operation. @@ -672,7 +673,7 @@ Lua tries the "lt", assuming that <code>a <= b</code> is equivalent to <code>not (b < a)</code>. </li> -<li><b>"index":</b> +<li><b>"index": </b> The indexing access <code>table[key]</code>. Note that the metamethod is tried only when <code>key</code> is not present in <code>table</code>. @@ -704,7 +705,7 @@ so the metamethod is always tried.) </pre><p> </li> -<li><b>"newindex":</b> +<li><b>"newindex": </b> The indexing assignment <code>table[key] = value</code>. Note that the metamethod is tried only when <code>key</code> is not present in <code>table</code>. @@ -733,7 +734,7 @@ when <code>key</code> is not present in <code>table</code>. </pre><p> </li> -<li><b>"call":</b> +<li><b>"call": </b> called when Lua calls a value. @@ -845,7 +846,7 @@ and the metatable has a field indexed by the string "<code>__gc</code>". Note that if you set a metatable without a <code>__gc</code> field and later create that field in the metatable, the object will not be marked for finalization. -However, after a userdata is marked, +However, after an object is marked, you can freely change the <code>__gc</code> field of its metatable. @@ -873,7 +874,16 @@ the reverse order that they were marked for collection, among those collected in that cycle; that is, the first finalizer to be called is the one associated with the object marked last in the program. -The object memory is freed only in the next garbage-collection cycle. +The execution of each finalizer may occur at any point during +the execution of the regular code. + + +<p> +Because the object being collected must still be used by the finalizer +and even <em>resurrected</em>resurrection +(e.g., stored by the finalizer in a global variable), +the object memory is freed only when it becomes completely inaccessible +(that is, in the next garbage-collection cycle unless it was resurrected). @@ -1536,9 +1546,10 @@ labels in Lua are considered statements too: </pre> <p> -A label is visible in the entire block where it is defined -(including nested blocks, but not nested functions). -A function cannot have more than one label with a given name. +A label is visible in the entire block where it is defined, +except +inside nested blocks where a label with the same name is defined and +inside nested functions. A goto may jump to any visible label as long as it does not enter into the scope of a local variable. @@ -2592,12 +2603,12 @@ defined as constants in <code>lua.h</code>. The following constants are defined: <ul> -<li><b>LUA_RIDX_MAINTHREAD:</b> At this index the registry has +<li><b>LUA_RIDX_MAINTHREAD: </b> At this index the registry has the main thread of the state. (The main thread is the one created together with the state.) </li> -<li><b>LUA_RIDX_GLOBALS:</b> At this index the registry has +<li><b>LUA_RIDX_GLOBALS: </b> At this index the registry has the global environment. This is the C equivalent to the <a href="#pdf-_G"><code>_G</code></a> global variable. </li> @@ -2840,7 +2851,7 @@ but it seems a safe assumption. <hr><h3><a name="lua_arith"><code>lua_arith</code></a></h3><p> -<span class="apii">[-(2/1), +1, <em>e</em>]</span> +<span class="apii">[-(2|1), +1, <em>e</em>]</span> <pre>int lua_arith (lua_State *L, int op);</pre> <p> @@ -2858,13 +2869,13 @@ The value of <code>op</code> must be one of the following constants: <ul> -<li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>:</b>performs addition (<code>+</code>)</li> -<li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>:</b>performs subtraction (<code>-</code>)</li> -<li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>:</b>performs multiplication (<code>*</code>)</li> -<li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>:</b>performs division (<code>/</code>)</li> -<li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>:</b>performs modulo (<code>%</code>)</li> -<li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>:</b>performs exponentiation (<code>^</code>)</li> -<li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>:</b>performs mathematical negation (unary <code>-</code>)</li> +<li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)</li> +<li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code>)</li> +<li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</code>)</li> +<li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>: </b> performs division (<code>/</code>)</li> +<li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</li> +<li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</code>)</li> +<li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (unary <code>-</code>)</li> </ul> @@ -3068,9 +3079,9 @@ The value of <code>op</code> must be one of the following constants: <ul> -<li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>:</b>compares for equality (<code>==</code>)</li> -<li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>:</b>compares for less than (<code><</code>)</li> -<li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>:</b>compares for less or equal (<code><=</code>)</li> +<li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code>)</li> +<li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>: </b> compares for less than (<code><</code>)</li> +<li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code><=</code>)</li> </ul> @@ -3186,28 +3197,28 @@ according to the value of the parameter <code>what</code>: <ul> -<li><b><code>LUA_GCSTOP</code>:</b> +<li><b><code>LUA_GCSTOP</code>: </b> stops the garbage collector. </li> -<li><b><code>LUA_GCRESTART</code>:</b> +<li><b><code>LUA_GCRESTART</code>: </b> restarts the garbage collector. </li> -<li><b><code>LUA_GCCOLLECT</code>:</b> +<li><b><code>LUA_GCCOLLECT</code>: </b> performs a full garbage-collection cycle. </li> -<li><b><code>LUA_GCCOUNT</code>:</b> +<li><b><code>LUA_GCCOUNT</code>: </b> returns the current amount of memory (in Kbytes) in use by Lua. </li> -<li><b><code>LUA_GCCOUNTB</code>:</b> +<li><b><code>LUA_GCCOUNTB</code>: </b> returns the remainder of dividing the current amount of bytes of memory in use by Lua by 1024. </li> -<li><b><code>LUA_GCSTEP</code>:</b> +<li><b><code>LUA_GCSTEP</code>: </b> performs an incremental step of garbage collection. The step "size" is controlled by <code>data</code> (larger values mean more steps) in a non-specified way. @@ -3217,19 +3228,19 @@ The function returns 1 if the step finished a garbage-collection cycle. </li> -<li><b><code>LUA_GCSETPAUSE</code>:</b> +<li><b><code>LUA_GCSETPAUSE</code>: </b> sets <code>data</code> as the new value for the <em>pause</em> of the collector (see <a href="#2.5">§2.5</a>). The function returns the previous value of the pause. </li> -<li><b><code>LUA_GCSETSTEPMUL</code>:</b> +<li><b><code>LUA_GCSETSTEPMUL</code>: </b> sets <code>data</code> as the new value for the <em>step multiplier</em> of the collector (see <a href="#2.5">§2.5</a>). The function returns the previous value of the step multiplier. </li> -<li><b><code>LUA_GCISRUNNING</code>:</b> +<li><b><code>LUA_GCISRUNNING</code>: </b> returns a boolean that tells whether the collector is running (i.e., not stopped). </li> @@ -3293,19 +3304,6 @@ as in the case of an yield. -<hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p> -<span class="apii">[-0, +1, <em>-</em>]</span> -<pre>void lua_getuservalue (lua_State *L, int index);</pre> - -<p> -Pushes onto the stack the Lua value associated with the userdata -at the given index. -This Lua value must be a table or <b>nil</b>. - - - - - <hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3><p> <span class="apii">[-0, +1, <em>e</em>]</span> <pre>void lua_getfield (lua_State *L, int index, const char *k);</pre> @@ -3381,6 +3379,19 @@ this result is equal to the number of elements in the stack +<hr><h3><a name="lua_getuservalue"><code>lua_getuservalue</code></a></h3><p> +<span class="apii">[-0, +1, <em>-</em>]</span> +<pre>void lua_getuservalue (lua_State *L, int index);</pre> + +<p> +Pushes onto the stack the Lua value associated with the userdata +at the given index. +This Lua value must be a table or <b>nil</b>. + + + + + <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p> <span class="apii">[-1, +1, <em>-</em>]</span> <pre>void lua_insert (lua_State *L, int index);</pre> @@ -3590,15 +3601,15 @@ The return values of <a href="#lua_load"><code>lua_load</code></a> are: <ul> -<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a> (0):</b> no errors;</li> +<li><b><a href="#pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> no errors;</li> -<li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>:</b> +<li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b> syntax error during pre-compilation;</li> -<li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>:</b> +<li><b><a href="#pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b> memory allocation error.</li> -<li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>:</b> +<li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b> error while running a <code>__gc</code> metamethod. (This error has no relation with the chunk being loaded. It is generated by the garbage collector.) @@ -3707,13 +3718,6 @@ and you can detect when it is being collected. A full userdata is only equal to itself (under raw equality). -<p> -When Lua collects a full userdata with a <code>gc</code> metamethod, -Lua calls the metamethod and marks the userdata as finalized. -When this userdata is collected again then -Lua frees its corresponding memory. - - @@ -3823,23 +3827,23 @@ The <a href="#lua_pcall"><code>lua_pcall</code></a> function returns one of the <ul> -<li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0):</b> +<li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> success.</li> -<li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>:</b> +<li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>: </b> a runtime error. </li> -<li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>:</b> +<li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b> memory allocation error. For such errors, Lua does not call the message handler. </li> -<li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>:</b> +<li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>: </b> error while running the message handler. </li> -<li><b><a name="pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>:</b> +<li><b><a name="pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b> error while running a <code>__gc</code> metamethod. (This error typically has no relation with the function being called. It is generated by the garbage collector.) @@ -4018,7 +4022,7 @@ light userdata with the same C address. <hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p> <span class="apii">[-0, +1, <em>m</em>]</span> -<pre>void lua_pushliteral (lua_State *L, const char *s);</pre> +<pre>const char *lua_pushliteral (lua_State *L, const char *s);</pre> <p> This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>, @@ -4341,18 +4345,6 @@ with user data <code>ud</code>. -<hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p> -<span class="apii">[-1, +0, <em>-</em>]</span> -<pre>void lua_setuservalue (lua_State *L, int index);</pre> - -<p> -Pops a table or <b>nil</b> from the stack and sets it as -the new value associated to the userdata at the given index. - - - - - <hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3><p> <span class="apii">[-1, +0, <em>e</em>]</span> <pre>void lua_setfield (lua_State *L, int index, const char *k);</pre> @@ -4433,6 +4425,18 @@ If <code>index</code> is 0, then all stack elements are removed. +<hr><h3><a name="lua_setuservalue"><code>lua_setuservalue</code></a></h3><p> +<span class="apii">[-1, +0, <em>-</em>]</span> +<pre>void lua_setuservalue (lua_State *L, int index);</pre> + +<p> +Pops a table or <b>nil</b> from the stack and sets it as +the new value associated to the userdata at the given index. + + + + + <hr><h3><a name="lua_State"><code>lua_State</code></a></h3> <pre>typedef struct lua_State lua_State;</pre> @@ -4919,7 +4923,7 @@ The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following <ul> -<li><b><code>source</code>:</b> +<li><b><code>source</code>: </b> the source of the chunk that created the function. If <code>source</code> starts with a '<code>@</code>', it means that the function was defined in a file where @@ -4931,31 +4935,31 @@ the function was defined in a string where <code>source</code> is that string. </li> -<li><b><code>short_src</code>:</b> +<li><b><code>short_src</code>: </b> a "printable" version of <code>source</code>, to be used in error messages. </li> -<li><b><code>linedefined</code>:</b> +<li><b><code>linedefined</code>: </b> the line number where the definition of the function starts. </li> -<li><b><code>lastlinedefined</code>:</b> +<li><b><code>lastlinedefined</code>: </b> the line number where the definition of the function ends. </li> -<li><b><code>what</code>:</b> +<li><b><code>what</code>: </b> the string <code>"Lua"</code> if the function is a Lua function, <code>"C"</code> if it is a C function, <code>"main"</code> if it is the main part of a chunk. </li> -<li><b><code>currentline</code>:</b> +<li><b><code>currentline</code>: </b> the current line where the given function is executing. When no line information is available, <code>currentline</code> is set to -1. </li> -<li><b><code>name</code>:</b> +<li><b><code>name</code>: </b> a reasonable name for the given function. Because functions in Lua are first-class values, they do not have a fixed name: @@ -4967,7 +4971,7 @@ If it cannot find a name, then <code>name</code> is set to <code>NULL</code>. </li> -<li><b><code>namewhat</code>:</b> +<li><b><code>namewhat</code>: </b> explains the <code>name</code> field. The value of <code>namewhat</code> can be <code>"global"</code>, <code>"local"</code>, <code>"method"</code>, @@ -4976,21 +4980,21 @@ according to how the function was called. (Lua uses the empty string when no other option seems to apply.) </li> -<li><b><code>istailcall</code>:</b> +<li><b><code>istailcall</code>: </b> true if this function invocation was called by a tail call. In this case, the caller of this level is not in the stack. </li> -<li><b><code>nups</code>:</b> +<li><b><code>nups</code>: </b> the number of upvalues of the function. </li> -<li><b><code>nparams</code>:</b> +<li><b><code>nparams</code>: </b> the number of fixed parameters of the function (always 0 for C functions). </li> -<li><b><code>isvararg</code>:</b> +<li><b><code>isvararg</code>: </b> whether the function is a vararg function (always true for C functions). </li> @@ -5070,29 +5074,30 @@ a value to be pushed on the stack: <ul> -<li><b>'<code>n</code>':</b> fills in the field <code>name</code> and <code>namewhat</code>; +<li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>; </li> -<li><b>'<code>S</code>':</b> +<li><b>'<code>S</code>': </b> fills in the fields <code>source</code>, <code>short_src</code>, <code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>; </li> -<li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>; +<li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>; </li> -<li><b>'<code>t</code>':</b> fills in the field <code>istailcall</code>; +<li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>; </li> -<li><b>'<code>u</code>':</b> fills in the field <code>nups</code>; +<li><b>'<code>u</code>': </b> fills in the fields +<code>nups</code>, <code>nparams</code>, and <code>isvararg</code>; </li> -<li><b>'<code>f</code>':</b> +<li><b>'<code>f</code>': </b> pushes onto the stack the function that is running at the given level; </li> -<li><b>'<code>L</code>':</b> +<li><b>'<code>L</code>': </b> pushes onto the stack a table whose indices are the numbers of the lines that are valid on the function. (A <em>valid line</em> is a line with some associated code, @@ -5164,7 +5169,8 @@ This function fills parts of a <a href="#lua_Debug"><code>lua_Debug</code></a> s an identification of the <em>activation record</em> of the function executing at a given level. Level 0 is the current running function, -whereas level <em>n+1</em> is the function that has called level <em>n</em>. +whereas level <em>n+1</em> is the function that has called level <em>n</em> +(except for tail calls, which do not count on the stack). When there are no errors, <a href="#lua_getstack"><code>lua_getstack</code></a> returns 1; when called with a level greater than the stack depth, it returns 0. @@ -5257,24 +5263,24 @@ For each event, the hook is called as explained below: <ul> -<li><b>The call hook:</b> is called when the interpreter calls a function. +<li><b>The call hook: </b> is called when the interpreter calls a function. The hook is called just after Lua enters the new function, before the function gets its arguments. </li> -<li><b>The return hook:</b> is called when the interpreter returns from a function. +<li><b>The return hook: </b> is called when the interpreter returns from a function. The hook is called just before Lua leaves the function. There is no standard way to access the values to be returned by the function. </li> -<li><b>The line hook:</b> is called when the interpreter is about to +<li><b>The line hook: </b> is called when the interpreter is about to start the execution of a new line of code, or when it jumps back in the code (even to the same line). (This event only happens while Lua is executing a Lua function.) </li> -<li><b>The count hook:</b> is called after the interpreter executes every +<li><b>The count hook: </b> is called after the interpreter executes every <code>count</code> instructions. (This event only happens while Lua is executing a Lua function.) </li> @@ -5333,7 +5339,7 @@ when the index is greater than the number of upvalues. <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p> <span class="apii">[-0, +0, <em>-</em>]</span> -<pre>void *(lua_upvalueid) (lua_State *L, int funcindex, int n);</pre> +<pre>void *lua_upvalueid (lua_State *L, int funcindex, int n);</pre> <p> Returns an unique identifier for the upvalue numbered <code>n</code> @@ -5832,7 +5838,7 @@ and returns this number cast to a <a href="#lua_Unsigned"><code>lua_Unsigned</co <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p> <span class="apii">[-0, +0, <em>-</em>]</span> -<pre>void *luaL_checkversion (lua_State *L);</pre> +<pre>void luaL_checkversion (lua_State *L);</pre> <p> Checks whether the core running the call, @@ -5919,9 +5925,9 @@ process-related functions in the standard library <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p> -<span class="apii">[-0, +(1/3), <em>m</em>]</span> +<span class="apii">[-0, +(1|3), <em>m</em>]</span> <pre>int luaL_fileresult (lua_State *L, int stat, - const char *fname)</pre> + const char *fname);</pre> <p> This function produces the return values for @@ -6650,22 +6656,22 @@ It performs different functions according to its first argument, <code>opt</code <ul> -<li><b>"collect":</b> +<li><b>"collect": </b> performs a full garbage-collection cycle. This is the default option. </li> -<li><b>"stop":</b> +<li><b>"stop": </b> stops automatic invocation of the garbage collector. The collector will run only when explcitly invoked, until a call to restart it. </li> -<li><b>"restart":</b> +<li><b>"restart": </b> restarts automatic invocation the garbage collector. </li> -<li><b>"count":</b> +<li><b>"count": </b> returns the total memory in use by Lua (in Kbytes) and a second value with the total memory in bytes modulo 1024. The first value has a fractional part, @@ -6679,7 +6685,7 @@ so the following equality is always true: with a non floating-point type for numbers.) </li> -<li><b>"step":</b> +<li><b>"step": </b> performs a garbage-collection step. The step "size" is controlled by <code>arg</code> (larger values mean more steps) in a non-specified way. @@ -6688,19 +6694,19 @@ you must experimentally tune the value of <code>arg</code>. Returns <b>true</b> if the step finished a collection cycle. </li> -<li><b>"setpause":</b> +<li><b>"setpause": </b> sets <code>arg</code> as the new value for the <em>pause</em> of the collector (see <a href="#2.5">§2.5</a>). Returns the previous value for <em>pause</em>. </li> -<li><b>"setstepmul":</b> +<li><b>"setstepmul": </b> sets <code>arg</code> as the new value for the <em>step multiplier</em> of the collector (see <a href="#2.5">§2.5</a>). Returns the previous value for <em>step</em>. </li> -<li><b>"isrunning":</b> +<li><b>"isrunning": </b> returns a boolean that tells whether the collector is running (i.e., not stopped). </li> @@ -7757,9 +7763,9 @@ The name <code>gsub</code> comes from <em>Global SUBstitution</em>. <p> If <code>repl</code> is a string, then its value is used for replacement. The character <code>%</code> works as an escape character: -any sequence in <code>repl</code> of the form <code>%<em>n</em></code>, -with <em>n</em> between 1 and 9, -stands for the value of the <em>n</em>-th captured substring (see below). +any sequence in <code>repl</code> of the form <code>%<em>d</em></code>, +with <em>d</em> between 1 and 9, +stands for the value of the <em>d</em>-th captured substring (see below). The sequence <code>%0</code> stands for the whole match. The sequence <code>%%</code> stands for a single <code>%</code>. @@ -7903,35 +7909,35 @@ The following combinations are allowed in describing a character class: <ul> -<li><b><em>x</em>:</b> +<li><b><em>x</em>: </b> (where <em>x</em> is not one of the <em>magic characters</em> <code>^$()%.[]*+-?</code>) represents the character <em>x</em> itself. </li> -<li><b><code>.</code>:</b> (a dot) represents all characters.</li> +<li><b><code>.</code>: </b> (a dot) represents all characters.</li> -<li><b><code>%a</code>:</b> represents all letters.</li> +<li><b><code>%a</code>: </b> represents all letters.</li> -<li><b><code>%c</code>:</b> represents all control characters.</li> +<li><b><code>%c</code>: </b> represents all control characters.</li> -<li><b><code>%d</code>:</b> represents all digits.</li> +<li><b><code>%d</code>: </b> represents all digits.</li> -<li><b><code>%g</code>:</b> represents all printable characters except space.</li> +<li><b><code>%g</code>: </b> represents all printable characters except space.</li> -<li><b><code>%l</code>:</b> represents all lowercase letters.</li> +<li><b><code>%l</code>: </b> represents all lowercase letters.</li> -<li><b><code>%p</code>:</b> represents all punctuation characters.</li> +<li><b><code>%p</code>: </b> represents all punctuation characters.</li> -<li><b><code>%s</code>:</b> represents all space characters.</li> +<li><b><code>%s</code>: </b> represents all space characters.</li> -<li><b><code>%u</code>:</b> represents all uppercase letters.</li> +<li><b><code>%u</code>: </b> represents all uppercase letters.</li> -<li><b><code>%w</code>:</b> represents all alphanumeric characters.</li> +<li><b><code>%w</code>: </b> represents all alphanumeric characters.</li> -<li><b><code>%x</code>:</b> represents all hexadecimal digits.</li> +<li><b><code>%x</code>: </b> represents all hexadecimal digits.</li> -<li><b><code>%<em>x</em></code>:</b> (where <em>x</em> is any non-alphanumeric character) +<li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character) represents the character <em>x</em>. This is the standard way to escape the magic characters. Any punctuation character (even the non magic) @@ -7939,7 +7945,7 @@ can be preceded by a '<code>%</code>' when used to represent itself in a pattern. </li> -<li><b><code>[<em>set</em>]</code>:</b> +<li><b><code>[<em>set</em>]</code>: </b> represents the class which is the union of all characters in <em>set</em>. A range of characters can be specified by @@ -7961,7 +7967,7 @@ Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code> have no meaning. </li> -<li><b><code>[^<em>set</em>]</code>:</b> +<li><b><code>[^<em>set</em>]</code>: </b> represents the complement of <em>set</em>, where <em>set</em> is interpreted as above. </li> @@ -8097,13 +8103,11 @@ It provides all its functions inside the table <a name="pdf-table"><code>table</ <p> -Currently, all functions in the table library, -except <a href="#pdf-table.pack"><code>table.pack</code></a>, -work on lists. -A list here means a proper sequence -or a table with a <code>__len</code> metamethod (see <a href="#3.4.6">§3.4.6</a>). -In particular, all functions ignore non-numeric keys -in lists given as arguments. +Remember that, whenever an operation needs the length of a table, +the table should be a proper sequence +or have a <code>__len</code> metamethod (see <a href="#3.4.6">§3.4.6</a>). +All functions ignore non-numeric keys +in tables given as arguments. <p> @@ -8642,7 +8646,7 @@ Returns the bitwise exclusive or of its operands. <p> -<hr><h3><a name="pdf-bit32.extract"><code>bit32.extract (n, field, width)</code></a></h3> +<hr><h3><a name="pdf-bit32.extract"><code>bit32.extract (n, field [, width])</code></a></h3> <p> @@ -8652,10 +8656,14 @@ Bits are numbered from 0 (least significant) to 31 (most significant). All accessed bits must be in the range <em>[0, 31]</em>. +<p> +The default for <code>width</code> is 1. + + <p> -<hr><h3><a name="pdf-bit32.replace"><code>bit32.replace (n, v, field, width)</code></a></h3> +<hr><h3><a name="pdf-bit32.replace"><code>bit32.replace (n, v, field [, width])</code></a></h3> <p> @@ -8848,7 +8856,7 @@ instead of returning an error code. <p> Opens the given file name in read mode and returns an iterator function that -works like <code>file:lines(···)</code> over the oppened file. +works like <code>file:lines(···)</code> over the opened file. When the iterator function detects the end of file, it returns <b>nil</b> (to finish the loop) and automatically closes the file. @@ -8877,12 +8885,12 @@ or, in case of errors, <b>nil</b> plus an error message. The <code>mode</code> string can be any of the following: <ul> -<li><b>"r":</b> read mode (the default);</li> -<li><b>"w":</b> write mode;</li> -<li><b>"a":</b> append mode;</li> -<li><b>"r+":</b> update mode, all previous data is preserved;</li> -<li><b>"w+":</b> update mode, all previous data is erased;</li> -<li><b>"a+":</b> append update mode, previous data is preserved, +<li><b>"r": </b> read mode (the default);</li> +<li><b>"w": </b> write mode;</li> +<li><b>"a": </b> append mode;</li> +<li><b>"r+": </b> update mode, all previous data is preserved;</li> +<li><b>"w+": </b> update mode, all previous data is erased;</li> +<li><b>"a+": </b> append update mode, previous data is preserved, writing is only allowed at the end of file.</li> </ul><p> The <code>mode</code> string can also have a '<code>b</code>' at the end, @@ -9037,28 +9045,28 @@ The available formats are <ul> -<li><b>"*n":</b> +<li><b>"*n": </b> reads a number; this is the only format that returns a number instead of a string. </li> -<li><b>"*a":</b> +<li><b>"*a": </b> reads the whole file, starting at the current position. On end of file, it returns the empty string. </li> -<li><b>"*l":</b> +<li><b>"*l": </b> reads the next line skipping the end of line, returning <b>nil</b> on end of file. This is the default format. </li> -<li><b>"*L":</b> +<li><b>"*L": </b> reads the next line keeping the end of line (if present), returning <b>nil</b> on end of file. </li> -<li><b><em>number</em>:</b> +<li><b><em>number</em>: </b> reads a string with up to this number of characters, returning <b>nil</b> on end of file. If number is zero, @@ -9081,9 +9089,9 @@ to the position given by <code>offset</code> plus a base specified by the string <code>whence</code>, as follows: <ul> -<li><b>"set":</b> base is position 0 (beginning of the file);</li> -<li><b>"cur":</b> base is current position;</li> -<li><b>"end":</b> base is end of file;</li> +<li><b>"set": </b> base is position 0 (beginning of the file);</li> +<li><b>"cur": </b> base is current position;</li> +<li><b>"end": </b> base is end of file;</li> </ul><p> In case of success, function <code>seek</code> returns the final file position, measured in bytes from the beginning of the file. @@ -9114,17 +9122,17 @@ There are three available modes: <ul> -<li><b>"no":</b> +<li><b>"no": </b> no buffering; the result of any output operation appears immediately. </li> -<li><b>"full":</b> +<li><b>"full": </b> full buffering; output operation is performed only when the buffer is full (or when you explicitly <code>flush</code> the file (see <a href="#pdf-io.flush"><code>io.flush</code></a>)). </li> -<li><b>"line":</b> +<li><b>"line": </b> line buffering; output is buffered until a newline is output or there is any input from some special files (such as a terminal device). @@ -9251,12 +9259,12 @@ as follows: <ul> -<li><b>"<code>exit</code>":</b> +<li><b>"<code>exit</code>": </b> the command terminated normally; the following number is the exit status of the command. </li> -<li><b>"<code>signal</code>":</b> +<li><b>"<code>signal</code>": </b> the command was terminated by a signal; the following number is the signal that terminated the command. </li> @@ -9461,18 +9469,6 @@ within any function, and so have no direct access to local variables. <p> -<hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u)</code></a></h3> - - -<p> -Returns the Lua value associated to <code>u</code>. -If <code>u</code> is not a userdata, -returns <b>nil</b>. - - - - -<p> <hr><h3><a name="pdf-debug.gethook"><code>debug.gethook ([thread])</code></a></h3> @@ -9596,18 +9592,13 @@ The function returns <b>nil</b> if there is no upvalue with the given index. <p> -<hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value)</code></a></h3> - - -<p> -Sets the given <code>value</code> as -the Lua value associated to the given <code>udata</code>. -<code>value</code> must be a table or <b>nil</b>; -<code>udata</code> must be a full userdata. +<hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u)</code></a></h3> <p> -Returns <code>udata</code>. +Returns the Lua value associated to <code>u</code>. +If <code>u</code> is not a userdata, +returns <b>nil</b>. @@ -9624,9 +9615,9 @@ The string mask may have the following characters, with the given meaning: <ul> -<li><b><code>"c"</code>:</b> the hook is called every time Lua calls a function;</li> -<li><b><code>"r"</code>:</b> the hook is called every time Lua returns from a function;</li> -<li><b><code>"l"</code>:</b> the hook is called every time Lua enters a new line of code.</li> +<li><b><code>"c"</code>: </b> the hook is called every time Lua calls a function;</li> +<li><b><code>"r"</code>: </b> the hook is called every time Lua returns from a function;</li> +<li><b><code>"l"</code>: </b> the hook is called every time Lua enters a new line of code.</li> </ul><p> With a <code>count</code> different from zero, the hook is called after every <code>count</code> instructions. @@ -9702,6 +9693,23 @@ Otherwise, it returns the name of the upvalue. <p> +<hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value)</code></a></h3> + + +<p> +Sets the given <code>value</code> as +the Lua value associated to the given <code>udata</code>. +<code>value</code> must be a table or <b>nil</b>; +<code>udata</code> must be a full userdata. + + +<p> +Returns <code>udata</code>. + + + + +<p> <hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message [, level]])</code></a></h3> @@ -9772,12 +9780,12 @@ Its usage is: The options are: <ul> -<li><b><code>-e <em>stat</em></code>:</b> executes string <em>stat</em>;</li> -<li><b><code>-l <em>mod</em></code>:</b> "requires" <em>mod</em>;</li> -<li><b><code>-i</code>:</b> enters interactive mode after running <em>script</em>;</li> -<li><b><code>-v</code>:</b> prints version information;</li> -<li><b><code>--</code>:</b> stops handling options;</li> -<li><b><code>-</code>:</b> executes <code>stdin</code> as a file and stops handling options.</li> +<li><b><code>-e <em>stat</em></code>: </b> executes string <em>stat</em>;</li> +<li><b><code>-l <em>mod</em></code>: </b> "requires" <em>mod</em>;</li> +<li><b><code>-i</code>: </b> enters interactive mode after running <em>script</em>;</li> +<li><b><code>-v</code>: </b> prints version information;</li> +<li><b><code>--</code>: </b> stops handling options;</li> +<li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li> </ul><p> After handling its options, <code>lua</code> runs the given <em>script</em>, passing to it the given <em>args</em> as string arguments. @@ -10195,7 +10203,7 @@ Here is the complete syntax of Lua in extended BNF. <HR> <SMALL CLASS="footer"> Last update: -Tue Jun 21 19:09:27 BRT 2011 +Mon Jun 27 15:48:15 BRT 2011 </SMALL> <!-- Last change: revised for Lua 5.2.0 (beta) diff --git a/doc/readme.html b/doc/readme.html index 79c8d2e9..5cb41d49 100644 --- a/doc/readme.html +++ b/doc/readme.html @@ -145,9 +145,7 @@ and liblua.a (the library). <P> <LI> To check that Lua has been built correctly, do "<KBD>make test</KBD>" - after building Lua. This will run the interpreter on a simple "Hello world" - Lua program from the test directory. - You may want to try other example programs in that directory. + after building Lua. This will run the interpreter and print its version string. </OL> <H3>Installing Lua</H3> @@ -162,7 +160,7 @@ and liblua.a (the library). where xxx is your platform name. <P> - To install Lua locally, then do "<KBD>make local</KBD>". + To install Lua locally, do "<KBD>make local</KBD>". This will create a directory <TT>install</TT> with subdirectories <TT>bin</TT>, <TT>include</TT>, <TT>lib</TT>, <TT>man</TT>, and install Lua as listed below. @@ -399,7 +397,7 @@ THE SOFTWARE. <HR> <SMALL CLASS="footer"> Last update: -Thu Jun 16 08:21:17 BRT 2011 +Fri Jun 24 11:30:57 BRT 2011 </SMALL> <!-- Last change: revised for Lua 5.2.0 (beta) diff --git a/src/Makefile b/src/Makefile index ba25b206..9c08aa76 100644 --- a/src/Makefile +++ b/src/Makefile @@ -28,7 +28,7 @@ MYLIBS= PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris LUA_A= liblua.a -CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ +CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \ ltm.o lundump.o lvm.o lzio.o LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \ @@ -132,6 +132,7 @@ lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \ lstring.h ltable.h lvm.h lcorolib.o: lcorolib.c lua.h luaconf.h lauxlib.h lualib.h +lctype.o: lctype.c lctype.h lua.h luaconf.h llimits.h ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h ldebug.o: ldebug.c lua.h luaconf.h lapi.h llimits.h lstate.h lobject.h \ ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h ldebug.h ldo.h \ @@ -147,14 +148,14 @@ lgc.o: lgc.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h linit.o: linit.c lua.h luaconf.h lualib.h lauxlib.h liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h -llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ - lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h +llex.o: llex.c lua.h luaconf.h lctype.h llimits.h ldo.h lobject.h \ + lstate.h ltm.h lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ ltm.h lzio.h lmem.h ldo.h lgc.h loadlib.o: loadlib.c lua.h luaconf.h lauxlib.h lualib.h -lobject.o: lobject.c lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h +lobject.o: lobject.c lua.h luaconf.h lctype.h llimits.h ldebug.h lstate.h \ + lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h lvm.h lopcodes.o: lopcodes.c lopcodes.h llimits.h lua.h luaconf.h loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ diff --git a/src/lctype.c b/src/lctype.c new file mode 100644 index 00000000..387c93aa --- /dev/null +++ b/src/lctype.c @@ -0,0 +1,49 @@ +/* +** $Id: lctype.c,v 1.10 2011/06/24 12:25:33 roberto Exp $ +** 'ctype' functions for Lua +** See Copyright Notice in lua.h +*/ + +#include "lctype.h" + +#if !LUA_USE_CTYPE /* { */ + +#include <limits.h> + +LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { + 0x00, /* EOZ */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ + 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ + 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, + 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ + 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +#endif /* } */ diff --git a/src/lctype.h b/src/lctype.h new file mode 100644 index 00000000..b24d9250 --- /dev/null +++ b/src/lctype.h @@ -0,0 +1,95 @@ +/* +** $Id: lctype.h,v 1.11 2011/06/27 18:22:46 roberto Exp $ +** 'ctype' functions for Lua +** See Copyright Notice in lua.h +*/ + +#ifndef lctype_h +#define lctype_h + +#include "lua.h" + + +/* +** WARNING: the functions defined here do not necessarily correspond +** to the similar functions in the standard C ctype.h. They are +** optimized for the specific needs of Lua +*/ + +#if !defined(LUA_USE_CTYPE) + +#if 'A' == 65 && '0' == 48 +/* ASCII case: can use its own tables; faster and fixed */ +#define LUA_USE_CTYPE 0 +#else +/* must use standard C ctype */ +#define LUA_USE_CTYPE 1 +#endif + +#endif + + +#if !LUA_USE_CTYPE /* { */ + +#include <limits.h> + +#include "llimits.h" + + +#define ALPHABIT 0 +#define DIGITBIT 1 +#define PRINTBIT 2 +#define SPACEBIT 3 +#define XDIGITBIT 4 + + +#define MASK(B) (1 << (B)) + + +/* +** add 1 to char to allow index -1 (EOZ) +*/ +#define testprop(c,p) (luai_ctype_[(c)+1] & (p)) + +/* +** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' +*/ +#define lislalpha(c) testprop(c, MASK(ALPHABIT)) +#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) +#define lisdigit(c) testprop(c, MASK(DIGITBIT)) +#define lisspace(c) testprop(c, MASK(SPACEBIT)) +#define lisprint(c) testprop(c, MASK(PRINTBIT)) +#define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) + +/* +** this 'ltolower' only works for alphabetic characters +*/ +#define ltolower(c) ((c) | ('A' ^ 'a')) + + +/* two more entries for 0 and -1 (EOZ) */ +LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; + + +#else /* }{ */ + +/* +** use standard C ctypes +*/ + +#include <ctype.h> + + +#define lislalpha(c) (isalpha(c) || (c) == '_') +#define lislalnum(c) (isalnum(c) || (c) == '_') +#define lisdigit(c) (isdigit(c)) +#define lisspace(c) (isspace(c)) +#define lisprint(c) (isprint(c)) +#define lisxdigit(c) (isxdigit(c)) + +#define ltolower(c) (tolower(c)) + +#endif /* } */ + +#endif + @@ -1,11 +1,11 @@ /* -** $Id: llex.c,v 2.50 2011/06/20 16:52:48 roberto Exp $ +** $Id: llex.c,v 2.49 2011/06/23 14:54:48 roberto Exp $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ -#include <ctype.h> +#include <locale.h> #include <string.h> #define llex_c @@ -13,6 +13,7 @@ #include "lua.h" +#include "lctype.h" #include "ldo.h" #include "llex.h" #include "lobject.h" @@ -74,7 +75,7 @@ void luaX_init (lua_State *L) { const char *luaX_token2str (LexState *ls, int token) { if (token < FIRST_RESERVED) { lua_assert(token == cast(unsigned char, token)); - return (isprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) : + return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) : luaO_pushfstring(ls->L, "char(%d)", token); } else { @@ -184,24 +185,52 @@ static int check_next (LexState *ls, const char *set) { } +/* +** change all characters 'from' in buffer to 'to' +*/ +static void buffreplace (LexState *ls, char from, char to) { + size_t n = luaZ_bufflen(ls->buff); + char *p = luaZ_buffer(ls->buff); + while (n--) + if (p[n] == from) p[n] = to; +} + + +#if !defined(getlocaledecpoint) +#define getlocaledecpoint() (localeconv()->decimal_point[0]) +#endif + #define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e) +/* +** in case of format error, try to change decimal point separator to +** the one defined in the current locale and check again +*/ +static void trydecpoint (LexState *ls, SemInfo *seminfo) { + char old = ls->decpoint; + ls->decpoint = getlocaledecpoint(); + buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ + if (!buff2d(ls->buff, &seminfo->r)) { + /* format error with correct decimal point: no more options */ + buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ + lexerror(ls, "malformed number", TK_NUMBER); + } +} + /* LUA_NUMBER */ static void read_numeral (LexState *ls, SemInfo *seminfo) { - lua_assert(isdigit(ls->current)); + lua_assert(lisdigit(ls->current)); do { save_and_next(ls); if (check_next(ls, "EePp")) /* exponent part? */ check_next(ls, "+-"); /* optional exponent sign */ - } while (isalnum(ls->current) || ls->current == '.'); + } while (lislalnum(ls->current) || ls->current == '.'); save(ls, '\0'); - if (!luaO_str2d(luaZ_buffer(ls->buff), - luaZ_bufflen(ls->buff) - 1, - &seminfo->r)) /* format error? */ - lexerror(ls, "malformed number", TK_NUMBER); - + buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ + if (!buff2d(ls->buff, &seminfo->r)) /* format error? */ + trydecpoint(ls, seminfo); /* try to update decimal point separator */ } @@ -260,9 +289,9 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { static int readhexaesc (LexState *ls) { int c1 = next(ls); int c2 = EOZ; - if (isxdigit(c1)) { + if (lisxdigit(c1)) { c2 = next(ls); - if (isxdigit(c2)) + if (lisxdigit(c2)) return (luaO_hexavalue(c1) << 4) + luaO_hexavalue(c2); /* else go through to error */ } @@ -279,10 +308,10 @@ static int readdecesc (LexState *ls) { int c1 = ls->current; /* first char must be a digit */ int c2 = next(ls); /* read second char */ int c = c1 - '0'; /* partial result */ - if (isdigit(c2)) { + if (lisdigit(c2)) { int c3 = next(ls); /* read third char */ c = 10*c + c2 - '0'; /* update result */ - if (isdigit(c3)) { + if (lisdigit(c3)) { c = 10*c + c3 - '0'; /* update result */ if (c > UCHAR_MAX) { luaZ_resetbuffer(ls->buff); /* prepare error message */ @@ -327,14 +356,14 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { case EOZ: continue; /* will raise an error next loop */ case '*': { /* skip following span of spaces */ next(ls); /* skip the '*' */ - while (isspace(ls->current)) { + while (lisspace(ls->current)) { if (currIsNewline(ls)) inclinenumber(ls); else next(ls); } continue; /* do not save 'c' */ } default: { - if (!isdigit(ls->current)) + if (!lisdigit(ls->current)) c = ls->current; /* handles \\, \", \', and \? */ else /* digital escape \ddd */ c = readdecesc(ls); @@ -431,7 +460,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_DOTS; /* '...' */ else return TK_CONCAT; /* '..' */ } - else if (!isdigit(ls->current)) return '.'; + else if (!lisdigit(ls->current)) return '.'; /* else go through */ } case '0': case '1': case '2': case '3': case '4': @@ -443,12 +472,11 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_EOS; } default: { - if (isalpha(ls->current) || ls->current == '_') { - /* identifier or reserved word */ + if (lislalpha(ls->current)) { /* identifier or reserved word? */ TString *ts; do { save_and_next(ls); - } while (isalnum(ls->current) || ls->current == '_'); + } while (lislalnum(ls->current)); ts = luaX_newstring(ls, luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff)); seminfo->ts = ts; diff --git a/src/lobject.c b/src/lobject.c index fecd88ed..d8cc3ce9 100644 --- a/src/lobject.c +++ b/src/lobject.c @@ -1,10 +1,9 @@ /* -** $Id: lobject.c,v 2.51 2011/06/18 17:25:15 roberto Exp $ +** $Id: lobject.c,v 2.52 2011/06/24 12:25:02 roberto Exp $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ -#include <ctype.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -15,6 +14,7 @@ #include "lua.h" +#include "lctype.h" #include "ldebug.h" #include "ldo.h" #include "lmem.h" @@ -85,9 +85,8 @@ lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { int luaO_hexavalue (int c) { - lua_assert(isxdigit(c)); - if (isdigit(c)) return c - '0'; - else return toupper(c) - 'A' + 10; + if (lisdigit(c)) return c - '0'; + else return ltolower(c) - 'a' + 10; } @@ -104,7 +103,7 @@ static int isneg (const char **s) { static lua_Number readhexa (const char **s, lua_Number r, int *count) { - while (isxdigit(cast_uchar(**s))) { /* read integer part */ + while (lisxdigit(cast_uchar(**s))) { /* read integer part */ r = (r * 16.0) + cast_num(luaO_hexavalue(cast_uchar(*(*s)++))); (*count)++; } @@ -121,7 +120,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { int e = 0, i = 0; int neg = 0; /* 1 if number is negative */ *endptr = cast(char *, s); /* nothing is valid yet */ - while (isspace(cast_uchar(*s))) s++; /* skip initial spaces */ + while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ neg = isneg(&s); /* check signal */ if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))) /* check '0x' */ return 0.0; /* invalid format (no '0x') */ @@ -140,9 +139,9 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { int neg1; s++; /* skip 'p' */ neg1 = isneg(&s); /* signal */ - if (!isdigit(cast_uchar(*s))) + if (!lisdigit(cast_uchar(*s))) goto ret; /* must have at least one digit */ - while (isdigit(cast_uchar(*s))) /* read exponent */ + while (lisdigit(cast_uchar(*s))) /* read exponent */ exp1 = exp1 * 10 + *(s++) - '0'; if (neg1) exp1 = -exp1; e += exp1; @@ -163,7 +162,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { else *result = lua_str2number(s, &endptr); if (endptr == s) return 0; /* nothing recognized */ - while (isspace(cast_uchar(*endptr))) endptr++; + while (lisspace(cast_uchar(*endptr))) endptr++; return (endptr == s + len); /* OK if no trailing characters */ } diff --git a/src/lparser.c b/src/lparser.c index 0d4382a4..6ffecc43 100644 --- a/src/lparser.c +++ b/src/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 2.111 2011/06/20 16:52:48 roberto Exp $ +** $Id: lparser.c,v 2.112 2011/06/27 18:18:59 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -367,7 +367,7 @@ static int findlabel (LexState *ls, int g) { /* check labels in current block for a match */ for (i = bl->firstlabel; i < dyd->label.n; i++) { Labeldesc *lb = &dyd->label.arr[i]; - if (eqstr(lb->name, gt->name) && lb->pc != -1) { /* correct label? */ + if (eqstr(lb->name, gt->name)) { /* correct label? */ if (gt->nactvar > lb->nactvar && (bl->upval || dyd->label.n > bl->firstlabel)) luaK_patchclose(ls->fs, gt->pc, lb->nactvar); @@ -466,12 +466,6 @@ static void undefgoto (LexState *ls, Labeldesc *gt) { } -static void invalidatelabels (Labellist *ll, int level) { - for (; level < ll->n; level++) - ll->arr[level].pc = -1; /* mark label as out of scope */ -} - - static void leaveblock (FuncState *fs) { BlockCnt *bl = fs->bl; LexState *ls = fs->ls; @@ -487,7 +481,7 @@ static void leaveblock (FuncState *fs) { removevars(fs, bl->nactvar); lua_assert(bl->nactvar == fs->nactvar); fs->freereg = fs->nactvar; /* free registers */ - invalidatelabels(&ls->dyd->label, bl->firstlabel); /* remove local labels */ + ls->dyd->label.n = bl->firstlabel; /* remove local labels */ if (bl->previous) /* inner block? */ movegotosout(fs, bl); /* update pending gotos to outer block */ else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */ @@ -532,7 +526,6 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) { fs->nlocvars = 0; fs->nactvar = 0; fs->firstlocal = ls->dyd->actvar.n; - fs->firstlabel = ls->dyd->label.n; fs->bl = NULL; f = luaF_newproto(L); fs->f = f; @@ -555,7 +548,6 @@ static void close_func (LexState *ls) { Proto *f = fs->f; luaK_ret(fs, 0, 0); /* final return */ leaveblock(fs); - ls->dyd->label.n = fs->firstlabel; /* remove labels */ luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); f->sizecode = fs->pc; luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); @@ -1193,16 +1185,15 @@ static void gotostat (LexState *ls, TString *label, int line) { } -/* check for repeated labels on the same function */ -static void checkrepeated (LexState *ls, FuncState *fs, Labellist *ll, - TString *label) { +/* check for repeated labels on the same block */ +static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) { int i; - for (i = fs->firstlabel; i < ll->n; i++) { + for (i = fs->bl->firstlabel; i < ll->n; i++) { if (eqstr(label, ll->arr[i].name)) { - const char *msg = luaO_pushfstring(ls->L, - "label " LUA_QS " already defined on line %d", - getstr(label), ll->arr[i].line); - semerror(ls, msg); + const char *msg = luaO_pushfstring(fs->ls->L, + "label " LUA_QS " already defined on line %d", + getstr(label), ll->arr[i].line); + semerror(fs->ls, msg); } } } @@ -1213,7 +1204,7 @@ static void labelstat (LexState *ls, TString *label, int line) { FuncState *fs = ls->fs; Labellist *ll = &ls->dyd->label; int l; /* index of new label being created */ - checkrepeated(ls, fs, ll, label); /* check for repeated labels */ + checkrepeated(fs, ll, label); /* check for repeated labels */ checknext(ls, TK_DBCOLON); /* skip double colon */ /* create new entry for this label */ l = newlabelentry(ls, ll, label, line, fs->pc); @@ -1607,5 +1598,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, L->top--; /* pop name */ lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs); return funcstate.f; + /* all scopes should be correctly finished */ + lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0); } diff --git a/src/lparser.h b/src/lparser.h index 47bbf12d..4e7e06fc 100644 --- a/src/lparser.h +++ b/src/lparser.h @@ -1,5 +1,5 @@ /* -** $Id: lparser.h,v 1.69 2011/06/16 16:36:39 roberto Exp $ +** $Id: lparser.h,v 1.68 2011/02/23 13:13:10 roberto Exp $ ** Lua Parser ** See Copyright Notice in lua.h */ @@ -62,7 +62,7 @@ typedef struct Vardesc { /* description of pending goto statements and label statements */ typedef struct Labeldesc { TString *name; /* label identifier */ - int pc; /* position in code (for labels, -1 means out of scope) */ + int pc; /* position in code */ int line; /* line where it appeared */ lu_byte nactvar; /* local level where it appears in current block */ } Labeldesc; @@ -107,7 +107,6 @@ typedef struct FuncState { int nk; /* number of elements in `k' */ int np; /* number of elements in `p' */ int firstlocal; /* index of first local var of this function */ - int firstlabel; /* index of first label of this function */ short nlocvars; /* number of elements in `locvars' */ lu_byte nactvar; /* number of active local variables */ lu_byte nups; /* number of upvalues */ |