diffs-lua-5.3.0-lua-5.3.1
Makefile
49c49
< R= $V.0
> R= $V.1
README
2c2
< This is Lua 5.3.0, released on 06 Jan 2015.
> This is Lua 5.3.1, released on 10 Jun 2015.
doc/contents.html
5a6
> <LINK REL="stylesheet" TYPE="text/css" HREF="index.css">
7,12d7
< <STYLE TYPE="text/css">
< ul {
< list-style-type: none ;
< list-style-position: outside ;
< }
< </STYLE>
17d11
< <HR>
19c13
< <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="" BORDER=0></A>
> <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua"></A>
24a19
> <BR>
28c23
< <P>
> <DIV CLASS="menubar">
34c29,33
< <HR>
> ·
> <A HREF="http://www.lua.org/manual/">other versions</A>
> </DIV>
>
> <P>
42c41
< <UL style="padding: 0">
> <UL CLASS="contents menubar">
139,140c138,139
< <TABLE WIDTH="100%">
< <TR VALIGN="top">
> <TABLE CLASS="menubar" WIDTH="100%">
> <TR>
147d145
<
323a322
> <P>
548a548
> <P>
609,610c609
< <HR>
< <SMALL CLASS="footer">
> <P CLASS="footer">
612,613c611,612
< Tue Dec 9 21:26:07 BRST 2014
< </SMALL>
> Wed Jun 3 08:27:30 BRT 2015
> </P>
615c614
< Last change: updated for Lua 5.3.0 (final)
> Last change: revised for Lua 5.3.1
Only in lua-5.3.1/doc: index.css
doc/lua.css
6,10d5
< border: solid #a0a0a0 1px ;
< border-radius: 20px ;
< padding: 26px ;
< margin: 16px ;
< color: #000000 ;
11a7
> color: #000000 ;
13a10,16
> line-height: 1.25 ;
> margin: 16px auto ;
> padding: 32px ;
> border: solid #a0a0a0 1px ;
> border-radius: 20px ;
> max-width: 70em ;
> width: 90% ;
16a20
> color: #000080 ;
19a24
> text-align: left ;
22,29c27,28
< h2 {
< padding-top: 0.4em ;
< padding-bottom: 0.4em ;
< padding-left: 0.8em ;
< padding-right: 0.8em ;
< background-color: #D0D0FF ;
< border-radius: 8px ;
< border: solid #a0a0a0 1px ;
> h1 {
> font-size: 28pt ;
32,34c31,32
< h3 {
< padding-left: 0.5em ;
< border-left: solid #D0D0FF 1em ;
> h1 img {
> vertical-align: text-bottom ;
37,39c35,37
< table h3 {
< padding-left: 0px ;
< border-left: none ;
> h2:before {
> content: "\2756" ;
> padding-right: 0.5em ;
42,44c40
< a:link {
< color: #000080 ;
< background-color: inherit ;
> a {
48,50c44,45
< a:visited {
< background-color: inherit ;
< text-decoration: none ;
> a:link {
> color: #000080 ;
54d48
< color: #000080 ;
56c50,51
< border-radius: 4px;
> color: #000080 ;
> border-radius: 4px ;
63,64c58,59
< h1 a img {
< vertical-align: text-bottom ;
> div.menubar {
> padding-bottom: 0.5em ;
67,72c62,63
< hr {
< border: 0 ;
< height: 1px ;
< color: #a0a0a0 ;
< background-color: #a0a0a0 ;
< display: none ;
> p.menubar {
> margin-left: 2.5em ;
75,76c66,69
< table hr {
< display: block ;
> .menubar a:hover {
> margin: -3px -3px -3px -3px ;
> padding: 3px 3px 3px 3px ;
> border-radius: 4px ;
80c73,74
< background-color: #F8F8F8 ;
> background-color: #F0F0F0 ;
> margin: -8px ;
82d75
< border: solid #a0a0a0 2px ;
83a77,89
> outline: none ;
> }
>
> hr {
> display: none ;
> }
>
> table hr {
> background-color: #a0a0a0 ;
> color: #a0a0a0 ;
> border: 0 ;
> height: 1px ;
> display: block ;
105a112,133
>
> td.gutter {
> width: 4% ;
> }
>
> table.columns {
> border: none ;
> border-spacing: 0 ;
> border-collapse: collapse ;
> }
>
> table.columns td {
> vertical-align: top ;
> padding: 0 ;
> padding-bottom: 1em ;
> text-align: justify ;
> line-height: 1.25 ;
> }
>
> p.logos a:link:hover, p.logos a:visited:hover {
> background-color: inherit ;
> }
doc/manual.css
10a11
> color: gray ;
15d15
< color: gray ;
18,26c18,20
< p+h1, ul+h1 {
< font-style: normal ;
< padding-top: 0.4em ;
< padding-bottom: 0.4em ;
< padding-left: 16px ;
< margin-left: -16px ;
< background-color: #D0D0FF ;
< border-radius: 8px ;
< border: solid #000080 1px ;
> h2:before {
> content: "" ;
> padding-right: 0em ;
doc/manual.html
2,7c2,6
< <html>
<
< <head>
< <title>Lua 5.3 Reference Manual</title>
< <link rel="stylesheet" type="text/css" href="lua.css">
< <link rel="stylesheet" type="text/css" href="manual.css">
> <HTML>
> <HEAD>
> <TITLE>Lua 5.3 Reference Manual</TITLE>
> <LINK REL="stylesheet" TYPE="text/css" HREF="lua.css">
> <LINK REL="stylesheet" TYPE="text/css" HREF="manual.css">
9c8
< </head>
> </HEAD>
11c10
< <body>
> <BODY>
13,15c12,13
< <hr>
< <h1>
< <a href="http://www.lua.org/"><img src="logo.gif" alt="" border="0"></a>
> <H1>
> <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua"></A>
17c15
< </h1>
> </H1>
18a17
> <P>
20,21c19,21
< <p>
< <small>
>
> <P>
> <SMALL>
25,27c25
< </small>
< <hr>
< <p>
> </SMALL>
29c27,30
< <a href="contents.html#contents">contents</A>
> <DIV CLASS="menubar">
> <A HREF="contents.html#contents">contents</A>
> ·
> <A HREF="contents.html#index">index</A>
31c32,33
< <a href="contents.html#index">index</A>
> <A HREF="http://www.lua.org/manual/">other versions</A>
> </DIV>
36c38
< <!-- $Id: manual.of,v 1.146 2015/01/06 11:23:01 roberto Exp $ -->
> <!-- $Id: manual.of,v 1.151 2015/06/10 21:08:57 roberto Exp $ -->
116c118
< <em>Nil</em> is the type of the value <b>nil</b>,
> The type <em>nil</em> has one single value, <b>nil</b>,
119c121
< <em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>.
> The type <em>boolean</em> has two values, <b>false</b> and <b>true</b>.
122c124
< <em>Number</em> represents both
> The type <em>number</em> represents both
124c126
< <em>String</em> represents immutable sequences of bytes.
> The type <em>string</em> represents immutable sequences of bytes.
134a137
> or two subtypes,
145c148
< The option with 32 bits for both integers and floats
> The option with 32 bits for both integers and floats
188,189c191,192
< (<em>Not a Number</em> is a special numeric value used to represent
< undefined or unrepresentable results, such as <code>0/0</code>.)
> (<em>Not a Number</em> is a special value used to represent
> undefined or unrepresentable numerical results, such as <code>0/0</code>.)
396c399
< You cannot change the metatable of other types from Lua
> You cannot change the metatable of other types from Lua code
428,429d430
< You can emulate how Lua queries a metamethod for an object <code>obj</code>
< with the following code:
431,433d431
< <pre>
< rawget(getmetatable(obj) or {}, "__" .. event_name)
< </pre>
513c511
< if any operator is neither an integer
> if any operand is neither an integer
552c550
< if any operator is neither a string nor a number
> if any operand is neither a string nor a number
601a600,601
> (This use of the "<code>__lt</code>" event can be removed in future versions;
> it is also slower than a real "<code>__le</code>" metamethod.)
663a664,670
> <p>
> It is a good practice to add all needed metamethods to a table
> before setting it as a metatable of some object.
> In particular, the "<code>__gc</code>" metamethod works only when this order
> is followed (see <a href="#2.5.1">§2.5.1</a>).
>
>
755,756d761
< However, after an object has been marked,
< you can freely change the <code>__gc</code> field of its metatable.
797c802
< the object memory is freed only in the GC cycle where
> the object memory is freed only in a GC cycle where
825,826c830,831
< A table with weak keys allows the collection of its keys,
< but prevents the collection of its values.
> A table with weak values allows the collection of its values,
> but prevents the collection of its keys.
916,917c921,922
< the coroutine starts its execution,
< at the first line of its main function.
> the coroutine starts its execution by
> calling its main function.
919c924
< as arguments to the coroutine's main function.
> as arguments to that function.
1114c1119
< we can specify any byte in a literal string by its numerical value.
> we can specify any byte in a literal string by its numeric value.
1189c1194
< A <em>numerical constant</em> (or <em>numeral</em>)
> A <em>numeric constant</em> (or <em>numeral</em>)
1584c1589
< one numeric and one generic.
> one numerical and one generic.
1588c1593
< The numeric <b>for</b> loop repeats a block of code while a
> The numerical <b>for</b> loop repeats a block of code while a
1882c1887
< that rounds the quotient towards minus infinite,
> that rounds the quotient towards minus infinity,
1888c1893
< that rounds the quotient towards minus infinite (floor division).
> that rounds the quotient towards minus infinity (floor division).
1975,1976c1980,1982
< Then, the resulting number is converted to the required type
< (float or integer) according to the previous rules.
> Then, the resulting number (float or integer)
> is converted to the type (float or integer) required by the context
> (e.g., the operation that forced the conversion).
2009,2013c2015
< Numbers follow the usual rule for binary operations:
< if both operands are integers,
< they are compared as integers;
< otherwise, they are converted to floats
< and compared as such.
> Numbers are equal if they denote the same mathematical value.
2048,2049c2050,2051
< then they are compared following
< the usual rule for binary operations.
> then they are compared according to their mathematical values
> (regardless of their subtypes).
2057a2060,2065
> <p>
> Following the IEEE 754 standard,
> NaN is considered neither smaller than,
> nor equal to, nor greater than any value (including itself).
>
>
2639,2652c2647,2654
< real position within the stack, that is,
< its position lies between 1 and the stack top
< (<code>1 ≤ abs(index) ≤ top</code>).
<
< Usually, functions that can modify the value at an index
< require valid indices.
<
<
< <p>
< Unless otherwise noted,
< any function that accepts valid indices also accepts <em>pseudo-indices</em>,
< which represent some Lua values that are accessible to C code
< but which are not in the stack.
< Pseudo-indices are used to access the registry
> position that stores a modifiable Lua value.
> It comprises stack indices between 1 and the stack top
> (<code>1 ≤ abs(index) ≤ top</code>)
>
> plus <em>pseudo-indices</em>,
> which represent some positions that are accessible to C code
> but that are not in the stack.
> Pseudo-indices are used to access the registry (see <a href="#4.5">§4.5</a>)
2657,2658c2659,2660
< Functions that do not need a specific stack position,
< but only a value in the stack (e.g., query functions),
> Functions that do not need a specific mutable position,
> but only a value (e.g., query functions),
2661d2662
< including the pseudo-indices,
2704c2705
< The first value associated with a function is at position
> The first upvalue associated with a function is at index
2722,2723c2723
< <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>,
< which is a valid index.
> <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>.
2984c2984,2985
< Converts the acceptable index <code>idx</code> into an absolute index
> Converts the acceptable index <code>idx</code>
> into an equivalent absolute index
3227c3228
< of numerical arguments and returns their average and their sum:
> of numeric arguments and returns their average and their sum:
3386,3387c3387,3389
< the binary representation is created without debug information
< about the function.
> the binary representation may not include all debug information
> about the function,
> to save space.
3664c3666
< (See <code>LUA_INT</code> in <code>luaconf.h</code>.)
> (See <code>LUA_INT_TYPE</code> in <code>luaconf.h</code>.)
3853c3855
< It must be a numerical type.
> It must be a numeric type.
4071c4073
< <pre>typedef double lua_Number;</pre>
> <pre>typedef ... lua_Number;</pre>
4079,4080c4081,4082
< but that can be changed to a single float.
< (See <code>LUA_REAL</code> in <code>luaconf.h</code>.)
> but that can be changed to a single float or a long double.
> (See <code>LUA_FLOAT_TYPE</code> in <code>luaconf.h</code>.)
4136c4138
< (In the current implementation, this index cannot be a pseudo-index.)
> (This index cannot be a pseudo-index.)
4270c4272
< Any function to be registered in Lua must
> Any function to be callable by Lua must
4275,4283d4276
< <p>
< <code>lua_pushcfunction</code> is defined as a macro:
<
< <pre>
< #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
< </pre><p>
< Note that <code>f</code> is used twice.
<
<
4312c4305
< '<code>%L</code>' (inserts a <a href="#lua_Integer"><code>lua_Integer</code></a>),
> '<code>%I</code>' (inserts a <a href="#lua_Integer"><code>lua_Integer</code></a>),
4372,4374c4365,4366
< This macro is equivalent to <a href="#lua_pushlstring"><code>lua_pushlstring</code></a>,
< but can be used only when <code>s</code> is a literal string.
< It automatically provides the string length.
> This macro is equivalent to <a href="#lua_pushstring"><code>lua_pushstring</code></a>,
> but should be used only when <code>s</code> is a literal string.
4601c4593
< Does the equivalent of <code>t[k] = v</code>,
> Does the equivalent of <code>t[p] = v</code>,
4603c4595
< <code>k</code> is the pointer <code>p</code> represented as a light userdata,
> <code>p</code> is encoded as a light userdata,
4675c4667
< (therefore replacing the value at the given index),
> (therefore replacing the value at that given index),
4687c4679
< Starts and resumes a coroutine in a given thread.
> Starts and resumes a coroutine in the given thread <code>L</code>.
4734,4735c4726,4729
< Rotates the stack elements from <code>idx</code> to the top <code>n</code> positions
< in the direction of the top, for a positive <code>n</code>,
> Rotates the stack elements between the valid index <code>idx</code>
> and the top of the stack.
> The elements are rotated <code>n</code> positions in the direction of the top,
> for a positive <code>n</code>,
4739a4734,4735
> This function cannot be called with a pseudo-index,
> because a pseudo-index is not an actual stack position.
5075c5071
< Typically this function is used only for debug information.
> Typically this function is used only for hashing and debug information.
5130c5126
< <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>,
> <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a> (0),
5621,5626c5617,5619
< Gets information about a closure's upvalue.
< (For Lua functions,
< upvalues are the external local variables that the function uses,
< and that are consequently included in its closure.)
< <a href="#lua_getupvalue"><code>lua_getupvalue</code></a> gets the index <code>n</code> of an upvalue,
< pushes the upvalue's value onto the stack,
> Gets information about the <code>n</code>-th upvalue
> of the closure at index <code>funcindex</code>.
> It pushes the upvalue's value onto the stack
5628,5631c5621,5622
< <code>funcindex</code> points to the closure in the stack.
< (Upvalues have no particular order,
< as they are active through the whole function.
< So, they are numbered in an arbitrary order.)
> Returns <code>NULL</code> (and pushes nothing)
> when the index <code>n</code> is greater than the number of upvalues.
5635,5636d5625
< Returns <code>NULL</code> (and pushes nothing)
< when the index is greater than the number of upvalues.
5638a5628,5636
> (For Lua functions,
> upvalues are the external local variables that the function uses,
> and that are consequently included in its closure.)
>
>
> <p>
> Upvalues have no particular order,
> as they are active through the whole function.
> They are numbered in an arbitrary order.
5683,5686c5681,5684
< Only count and line events can yield
< and they cannot yield any value;
< to yield a hook function must finish its execution
< calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero.
> Only count and line events can yield;
> to yield, a hook function must finish its execution
> calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero
> (that is, with no values).
5751,5753c5749
< Parameters <code>ar</code> and <code>n</code> are as in <a href="#lua_getlocal"><code>lua_getlocal</code></a>
< (see <a href="#lua_getlocal"><code>lua_getlocal</code></a>).
< <a href="#lua_setlocal"><code>lua_setlocal</code></a> assigns the value at the top of the stack
> It assigns the value at the top of the stack
5763a5760,5763
> <p>
> Parameters <code>ar</code> and <code>n</code> are as in function <a href="#lua_getlocal"><code>lua_getlocal</code></a>.
>
>
5776,5777d5775
< Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
< (see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>).
5782c5780,5784
< when the index is greater than the number of upvalues.
> when the index <code>n</code> is greater than the number of upvalues.
>
>
> <p>
> Parameters <code>funcindex</code> and <code>n</code> are as in function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>.
5795,5797d5796
< Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>
< (see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>)
< (but <code>n</code> cannot be greater than the number of upvalues).
5807a5807,5811
> <p>
> Parameters <code>funcindex</code> and <code>n</code> are as in function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>,
> but <code>n</code> cannot be greater than the number of upvalues.
>
>
6370,6372c6374,6376
< in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
< If there is no metatable associated with <code>tname</code>,
< returns false and pushes <b>nil</b>.
> in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>)
> (<b>nil</b> if there is no metatable associated with that name).
> Returns the type of the pushed value.
7336c7340
< (To traverse a table in numeric order,
> (To traverse a table in numerical order,
7525,7526d7528
< Floats always produce strings with some
< floating-point indication (either a decimal dot or an exponent).
7582,7583c7584,7585
< The operations related to coroutines comprise a sub-library of
< the basic library and come inside the table <a name="pdf-coroutine"><code>coroutine</code></a>.
> This library comprises the operations to manipulate coroutines,
> which come inside the table <a name="pdf-coroutine"><code>coroutine</code></a>.
7593c7595
< <code>f</code> must be a Lua function.
> <code>f</code> must be a function.
7677c7679
< <code>f</code> must be a Lua function.
> <code>f</code> must be a function.
8076c8078
< Returns the internal numerical codes of the characters <code>s[i]</code>,
> Returns the internal numeric codes of the characters <code>s[i]</code>,
8085c8087
< Numerical codes are not necessarily portable across platforms.
> Numeric codes are not necessarily portable across platforms.
8094c8096
< in which each character has the internal numerical code equal
> in which each character has the internal numeric code equal
8099c8101
< Numerical codes are not necessarily portable across platforms.
> Numeric codes are not necessarily portable across platforms.
8115,8117c8117,8119
< the binary representation is created without debug information
< about the function
< (local variable names, lines, etc.).
> the binary representation may not include all debug information
> about the function,
> to save space.
8141c8143
< A third, optional numerical argument <code>init</code> specifies
> A third, optional numeric argument <code>init</code> specifies
8189,8190c8191
< <code>A</code> and <code>a</code> (when available),
< <code>E</code>, <code>e</code>, <code>f</code>,
> <code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,
8195,8197c8196,8198
< Option <code>q</code> expects a string;
< option <code>s</code> expects a string without embedded zeros.
< If the argument to option <code>s</code> is not a string,
> Option <code>q</code> expects a string.
> Option <code>s</code> expects a string without embedded zeros;
> if its argument is not a string,
8200a8202,8207
> <p>
> When Lua is compiled with a non-C99 compiler,
> options <code>A</code> and <code>a</code> (hexadecimal floats)
> do not support any modifier (flags, width, length).
>
>
8347c8354
< A third, optional numerical argument <code>init</code> specifies
> A third, optional numeric argument <code>init</code> specifies
8502c8509
< (including all punctuations, even the non-magical)
> (including all punctuation characters, even the non-magical)
8907c8914
< Index <code>f</code> must be positive.
> The number of elements to be moved must fit in a Lua integer.
9123c9130
< a value larger than any other numerical value.
> a value larger than any other numeric value.
9605,9606c9612,9613
< is a valid prefix for a number;
< if that prefix does not form a valid number
> is a valid prefix for a numeral;
> if that prefix does not form a valid numeral
9611,9614d9617
< <li><b>"<code>i</code>": </b>
< reads an integral number and returns it as an integer.
< </li>
<
9949c9952
< or a time representing the date and time specified by the given table.
> or a time representing the local date and time specified by the given table.
9955a9959
> Other fields are ignored.
9959a9964,9971
> The values in these fields do not need to be inside their valid ranges.
> For instance, if <code>sec</code> is -10,
> it means -10 seconds from the time specified by the other fields;
> if <code>hour</code> is 1000,
> it means +1000 hours from the time specified by the other fields.
>
>
> <p>
10096c10108
< a table with a name for the current function,
> a name for the current function,
10602c10614,10615
< while the bitwise operators in standard Lua operate on 64-bit integers.)
> while the bitwise operators in Lua 5.3 operate on Lua integers,
> which by default have 64 bits.)
10617c10630
< For compatibility, Lua will continue to ignore this character.
> For compatibility, Lua will continue to accept (and ignore) this character.
10643a10657,10662
> <li>
> The call <code>collectgarbage("count")</code> now returns only one result.
> (You can compute that second result from the fractional part
> of the first result.)
> </li>
>
10779,10780c10798
< <HR>
< <SMALL CLASS="footer">
> <P CLASS="footer">
10782,10783c10800,10801
< Tue Jan 6 10:10:50 BRST 2015
< </SMALL>
> Wed Jun 10 18:31:15 BRT 2015
> </P>
10785c10803
< Last change: revised for Lua 5.3.0 (final)
> Last change: revised for Lua 5.3.1
doc/readme.html
9a10
> border-radius: 8px ;
12d12
< border-radius: 8px ;
31d30
< <HR>
33,34c32,33
< <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
< Welcome to Lua 5.3.0
> <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua"></A>
> Welcome to Lua 5.3
37c36
< <P>
> <DIV CLASS="menubar">
46a46
> </DIV>
49d48
<
79d77
<
105d102
<
113c110
< the top-level directory, which is named <TT>lua-5.3.0</TT>.
> the top-level directory, which is named <TT>lua-5.3.x</TT>.
143c140,141
< make sure you have installed the <TT>readline</TT> development package.
> make sure you have installed the <TT>readline</TT> development package
> (which is probably named <TT>libreadline-dev</TT> or <TT>readline-devel</TT>).
177c175
< lauxlib.h lua.h lua.hpp luaconf.h lualib.h
> lua.h luaconf.h lualib.h lauxlib.h lua.hpp
218d215
<
261d257
<
317a314
> <P>
319c316
< <IMG SRC="osi-certified-72x60.png" ALIGN="right" BORDER="0" ALT="[osi certified]" STYLE="padding-left: 30px ;">
> <IMG SRC="osi-certified-72x60.png" ALIGN="right" ALT="[osi certified]" STYLE="padding-left: 30px ;">
321,322d317
<
< <P>
361,362c356
< <HR>
< <SMALL CLASS="footer">
> <P CLASS="footer">
364,365c358,359
< Fri Dec 12 09:58:42 BRST 2014
< </SMALL>
> Mon Jun 1 21:48:24 BRT 2015
> </P>
367c361
< Last change: updated for Lua 5.3.0 (final)
> Last change: revised for Lua 5.3.1
src/Makefile
133,134c133,134
< lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \
< ltable.h lundump.h lvm.h
> lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \
> ltable.h lundump.h lvm.h
139,140c139,140
< 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
> 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
145,146c145,146
< lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \
< ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h
> lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \
> ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h
148,149c148,149
< lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \
< lparser.h lstring.h ltable.h lundump.h lvm.h
> lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \
> lparser.h lstring.h ltable.h lundump.h lvm.h
151c151
< ltm.h lzio.h lmem.h lundump.h
> ltm.h lzio.h lmem.h lundump.h
153c153
< lgc.h lstate.h ltm.h lzio.h lmem.h
> lgc.h lstate.h ltm.h lzio.h lmem.h
155c155
< llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
> llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
158,160c158,160
< llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldo.h \
< lobject.h lstate.h ltm.h lzio.h lmem.h lgc.h llex.h lparser.h lstring.h \
< ltable.h
> llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \
> lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \
> lstring.h ltable.h
163c163
< llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h
> llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h
166,167c166,167
< ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \
< lvm.h
> ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \
> lvm.h
171,172c171,172
< llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
< ldo.h lfunc.h lstring.h lgc.h ltable.h
> llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
> ldo.h lfunc.h lstring.h lgc.h ltable.h
174,175c174,175
< lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \
< lstring.h ltable.h
> lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \
> lstring.h ltable.h
177c177
< lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h
> lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h
180c180
< llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
> llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
183c183
< llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h
> llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h
186c186
< lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h
> lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h
188,189c188,189
< lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \
< lundump.h
> lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \
> lundump.h
192,193c192,193
< llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \
< ltable.h lvm.h
> llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \
> ltable.h lvm.h
195c195
< lobject.h ltm.h lzio.h
> lobject.h ltm.h lzio.h
src/lapi.c
2c2
< ** $Id: lapi.c,v 2.244 2014/12/26 14:43:45 roberto Exp $
> ** $Id: lapi.c,v 2.249 2015/04/06 12:23:48 roberto Exp $
54c54
< #define api_checkvalidindex(o) api_check(isvalid(o), "invalid index")
> #define api_checkvalidindex(l,o) api_check(l, isvalid(o), "invalid index")
56,57c56,57
< #define api_checkstackindex(i, o) \
< api_check(isstackindex(i, o), "index not in the stack")
> #define api_checkstackindex(l, i, o) \
> api_check(l, isstackindex(i, o), "index not in the stack")
64c64
< api_check(idx <= ci->top - (ci->func + 1), "unacceptable index");
> api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index");
69c69
< api_check(idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
> api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
76c76
< api_check(idx <= MAXUPVAL + 1, "upvalue index too large");
> api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large");
101c101
< api_check(n >= 0, "negative 'n'");
> api_check(L, n >= 0, "negative 'n'");
123,124c123,124
< api_check(G(from) == G(to), "moving among independent states");
< api_check(to->ci->top - to->top >= n, "not enough elements to move");
> api_check(from, G(from) == G(to), "moving among independent states");
> api_check(from, to->ci->top - to->top >= n, "not enough elements to move");
127c127,128
< setobj2s(to, to->top++, from->top + i);
> setobj2s(to, to->top, from->top + i);
> api_incr_top(to);
162c163
< : cast_int(L->top - L->ci->func + idx);
> : cast_int(L->top - L->ci->func) + idx;
175c176
< api_check(idx <= L->stack_last - (func + 1), "new top too large");
> api_check(L, idx <= L->stack_last - (func + 1), "new top too large");
181c182
< api_check(-(idx+1) <= (L->top - (func + 1)), "invalid new top");
> api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
211,212c212,213
< api_checkstackindex(idx, p);
< api_check((n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
> api_checkstackindex(L, idx, p);
> api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
226c227
< api_checkvalidindex(to);
> api_checkvalidindex(L, to);
258c259
< api_check(LUA_TNONE <= t && t < LUA_NUMTAGS, "invalid tag");
> api_check(L, LUA_TNONE <= t && t < LUA_NUMTAGS, "invalid tag");
308c309
< L->top++;
> api_incr_top(L);
328c329
< default: api_check(0, "invalid option");
> default: api_check(L, 0, "invalid option");
385c386,387
< if (len != NULL) *len = tsvalue(o)->len;
> if (len != NULL)
> *len = vslen(o);
392,393c394,396
< switch (ttnov(o)) {
< case LUA_TSTRING: return tsvalue(o)->len;
> switch (ttype(o)) {
> case LUA_TSHRSTR: return tsvalue(o)->shrlen;
> case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;
434,436c437,438
< case LUA_TUSERDATA:
< case LUA_TLIGHTUSERDATA:
< return lua_touserdata(L, idx);
> case LUA_TUSERDATA: return getudatamem(uvalue(o));
> case LUA_TLIGHTUSERDATA: return pvalue(o);
485,488c487,489
< if (s == NULL) {
< lua_pushnil(L);
< return NULL;
< }
> lua_lock(L);
> if (s == NULL)
> setnilvalue(L->top);
491d491
< lua_lock(L);
495,497c495
< api_incr_top(L);
< lua_unlock(L);
< return getstr(ts);
> s = getstr(ts); /* internal copy's address */
498a497,499
> api_incr_top(L);
> lua_unlock(L);
> return s;
534c535
< api_check(n <= MAXUPVAL, "upvalue index too large");
> api_check(L, n <= MAXUPVAL, "upvalue index too large");
586c587,588
< setsvalue2s(L, L->top++, luaS_new(L, name));
> setsvalue2s(L, L->top, luaS_new(L, name));
> api_incr_top(L);
631c633
< api_check(ttistable(t), "table expected");
> api_check(L, ttistable(t), "table expected");
642c644
< api_check(ttistable(t), "table expected");
> api_check(L, ttistable(t), "table expected");
655c657
< api_check(ttistable(t), "table expected");
> api_check(L, ttistable(t), "table expected");
708c710
< api_check(ttisfulluserdata(o), "full userdata expected");
> api_check(L, ttisfulluserdata(o), "full userdata expected");
727c729,730
< setsvalue2s(L, L->top++, luaS_new(L, name));
> setsvalue2s(L, L->top, luaS_new(L, name));
> api_incr_top(L);
750c753,754
< setsvalue2s(L, L->top++, luaS_new(L, k));
> setsvalue2s(L, L->top, luaS_new(L, k));
> api_incr_top(L);
762c766,767
< setivalue(L->top++, n);
> setivalue(L->top, n);
> api_incr_top(L);
775c780
< api_check(ttistable(o), "table expected");
> api_check(L, ttistable(o), "table expected");
791c796
< api_check(ttistable(o), "table expected");
> api_check(L, ttistable(o), "table expected");
807c812
< api_check(ttistable(o), "table expected");
> api_check(L, ttistable(o), "table expected");
826c831
< api_check(ttistable(L->top - 1), "table expected");
> api_check(L, ttistable(L->top - 1), "table expected");
862c867
< api_check(ttisfulluserdata(o), "full userdata expected");
> api_check(L, ttisfulluserdata(o), "full userdata expected");
876c881
< api_check((nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
> api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
884c889
< api_check(k == NULL || !isLua(L->ci),
> api_check(L, k == NULL || !isLua(L->ci),
887c892
< api_check(L->status == LUA_OK, "cannot do calls on non-normal thread");
> api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
925c930
< api_check(k == NULL || !isLua(L->ci),
> api_check(L, k == NULL || !isLua(L->ci),
928c933
< api_check(L->status == LUA_OK, "cannot do calls on non-normal thread");
> api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread");
934c939
< api_checkstackindex(errfunc, o);
> api_checkstackindex(L, errfunc, o);
1099c1104
< api_check(ttistable(t), "table expected");
> api_check(L, ttistable(t), "table expected");
1231c1236
< api_check(ttisLclosure(fi), "Lua function expected");
> api_check(L, ttisLclosure(fi), "Lua function expected");
1233c1238
< api_check((1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
> api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
1247c1252
< api_check(1 <= n && n <= f->nupvalues, "invalid upvalue index");
> api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index");
1251c1256
< api_check(0, "closure expected");
> api_check(L, 0, "closure expected");
src/lapi.h
2c2
< ** $Id: lapi.h,v 2.8 2014/07/15 21:26:50 roberto Exp $
> ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $
14c14
< #define api_incr_top(L) {L->top++; api_check(L->top <= L->ci->top, \
> #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
20c20
< #define api_checknelems(L,n) api_check((n) < (L->top - L->ci->func), \
> #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
src/lauxlib.c
2c2
< ** $Id: lauxlib.c,v 1.279 2014/12/14 18:32:26 roberto Exp $
> ** $Id: lauxlib.c,v 1.280 2015/02/03 17:38:24 roberto Exp $
289c289
< if (luaL_getmetatable(L, tname)) /* name already in use? */
> if (luaL_getmetatable(L, tname) != LUA_TNIL) /* name already in use? */
src/lbaselib.c
2c2
< ** $Id: lbaselib.c,v 1.309 2014/12/10 12:26:42 roberto Exp $
> ** $Id: lbaselib.c,v 1.310 2015/03/28 19:14:47 roberto Exp $
58c58
< : toupper((unsigned char)*s) - 'A' + 10;
> : (toupper((unsigned char)*s) - 'A') + 10;
src/lcode.c
2c2
< ** $Id: lcode.c,v 2.99 2014/12/29 16:49:25 roberto Exp $
> ** $Id: lcode.c,v 2.101 2015/04/29 18:24:11 roberto Exp $
32,33c32,33
< /* Maximum number of registers in a Lua function */
< #define MAXREGS 250
> /* Maximum number of registers in a Lua function (must fit in 8 bits) */
> #define MAXREGS 255
282c282,283
< luaX_syntaxerror(fs->ls, "function or expression too complex");
> luaX_syntaxerror(fs->ls,
> "function or expression needs too many registers");
576d576
< /* go through */
577a578
> /* FALLTHROUGH */
796c797
< if (op <= OP_BNOT && constfolding(fs, op - OP_ADD + LUA_OPADD, e1, e2))
> if (op <= OP_BNOT && constfolding(fs, (op - OP_ADD) + LUA_OPADD, e1, e2))
923c924
< codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
> codecomp(fs, cast(OpCode, (op - OPR_EQ) + OP_EQ), 1, e1, e2);
927c928
< codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
> codecomp(fs, cast(OpCode, (op - OPR_NE) + OP_EQ), 0, e1, e2);
src/ldblib.c
2c2
< ** $Id: ldblib.c,v 1.148 2015/01/02 12:52:22 roberto Exp $
> ** $Id: ldblib.c,v 1.149 2015/02/19 17:06:21 roberto Exp $
29a30,40
> /*
> ** If L1 != L, L1 can be in any state, and therefore there is no
> ** garanties about its stack space; any push in L1 must be
> ** checked.
> */
> static void checkstack (lua_State *L, lua_State *L1, int n) {
> if (L != L1 && !lua_checkstack(L1, n))
> luaL_error(L, "stack overflow");
> }
>
>
129a141,143
> ** L1 needs stack space for an optional input (function) plus
> ** two optional outputs (function and line table) from function
> ** 'lua_getinfo'.
135a150
> checkstack(L, L1, 3);
192a208
> checkstack(L, L1, 1);
218a235
> checkstack(L, L1, 1);
352a370
> checkstack(L, L1, 1);
372a391
> checkstack(L, L1, 1);
src/ldebug.c
2c2
< ** $Id: ldebug.c,v 2.110 2015/01/02 12:52:22 roberto Exp $
> ** $Id: ldebug.c,v 2.115 2015/05/22 17:45:56 roberto Exp $
36a37,40
> /* Active Lua function (given call info) */
> #define ci_func(ci) (clLvalue((ci)->func))
>
>
51a56,71
> ** If function yielded, its 'func' can be in the 'extra' field. The
> ** next function restores 'func' to its correct value for debugging
> ** purposes. (It exchanges 'func' and 'extra'; so, when called again,
> ** after debugging, it also "re-restores" ** 'func' to its altered value.
> */
> static void swapextra (lua_State *L) {
> if (L->status == LUA_YIELD) {
> CallInfo *ci = L->ci; /* get function that yielded */
> StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
> ci->func = restorestack(L, ci->extra);
> ci->extra = savestack(L, temp);
> }
> }
>
>
> /*
109c129
< if (n >= ci->u.l.base - ci->func - nparams)
> if (n >= cast_int(ci->u.l.base - ci->func) - nparams)
146a167
> swapextra(L);
154c175
< StkId pos = 0; /* to avoid warnings */
> StkId pos = NULL; /* to avoid warnings */
160a182
> swapextra(L);
167,168c189,190
< StkId pos = 0; /* to avoid warnings */
< const char *name = findlocal(L, ar->i_ci, n, &pos);
> StkId pos = NULL; /* to avoid warnings */
> const char *name;
169a192,193
> swapextra(L);
> name = findlocal(L, ar->i_ci, n, &pos);
173a198
> swapextra(L);
272a298
> swapextra(L);
276c302
< api_check(ttisfunction(func), "function expected");
> api_check(L, ttisfunction(func), "function expected");
290a317
> swapextra(L); /* correct before option 'L', which can raise a mem. error */
575,586c602,609
< static void addinfo (lua_State *L, const char *msg) {
< CallInfo *ci = L->ci;
< if (isLua(ci)) { /* is Lua code? */
< char buff[LUA_IDSIZE]; /* add file:line information */
< int line = currentline(ci);
< TString *src = ci_func(ci)->p->source;
< if (src)
< luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
< else { /* no source available; use "?" instead */
< buff[0] = '?'; buff[1] = '\0';
< }
< luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
> /* add src:line information to 'msg' */
> const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
> int line) {
> char buff[LUA_IDSIZE];
> if (src)
> luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
> else { /* no source available; use "?" instead */
> buff[0] = '?'; buff[1] = '\0';
587a611
> return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
603a628,629
> CallInfo *ci = L->ci;
> const char *msg;
606c632
< addinfo(L, luaO_pushvfstring(L, fmt, argp));
> msg = luaO_pushvfstring(L, fmt, argp); /* format message */
607a634,635
> if (isLua(ci)) /* if Lua function, add source:line information */
> luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci));
src/ldebug.h
2c2
< ** $Id: ldebug.h,v 2.12 2014/11/10 14:46:05 roberto Exp $
> ** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $
20,22d19
< /* Active Lua function (given call info) */
< #define ci_func(ci) (clLvalue((ci)->func))
<
35a33,34
> LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,
> TString *src, int line);
src/ldo.c
2c2
< ** $Id: ldo.c,v 2.135 2014/11/11 17:13:39 roberto Exp $
> ** $Id: ldo.c,v 2.138 2015/05/22 17:48:19 roberto Exp $
325a326
> luaC_checkGC(L); /* stack grow uses memory */
333d333
< luaC_checkGC(L); /* stack grow uses memory */
340c340
< luaD_poscall(L, L->top - n);
> luaD_poscall(L, L->top - n, n);
346a347
> luaC_checkGC(L); /* stack grow uses memory */
367d367
< luaC_checkGC(L); /* stack grow uses memory */
382c382
< int luaD_poscall (lua_State *L, StkId firstResult) {
> int luaD_poscall (lua_State *L, StkId firstResult, int nres) {
396c396
< L->ci = ci = ci->previous; /* back to caller */
> L->ci = ci->previous; /* back to caller */
398c398
< for (i = wanted; i != 0 && firstResult < L->top; i--)
> for (i = wanted; i != 0 && nres-- > 0; i--)
452c452
< luaD_poscall(L, L->top - n);
> luaD_poscall(L, L->top - n, n);
536c536,537
< StkId firstArg = cast(StkId, ud);
> int n = *(cast(int*, ud)); /* number of arguments */
> StkId firstArg = L->top - n; /* first argument */
556d556
< int n;
563c563
< luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
> luaD_poscall(L, firstArg, n); /* finish 'luaD_precall' */
579c579
< status = luaD_rawrunprotected(L, resume, L->top - nargs);
> status = luaD_rawrunprotected(L, resume, &nargs);
622c622
< api_check(k == NULL, "hooks cannot continue after yielding");
> api_check(L, k == NULL, "hooks cannot continue after yielding");
src/ldo.h
2c2
< ** $Id: ldo.h,v 2.21 2014/10/25 11:50:46 roberto Exp $
> ** $Id: ldo.h,v 2.22 2015/05/22 17:48:19 roberto Exp $
37c37
< LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
> LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult, int nres);
src/ldump.c
2c2
< ** $Id: ldump.c,v 2.34 2014/11/02 19:19:04 roberto Exp $
> ** $Id: ldump.c,v 2.36 2015/03/30 15:43:51 roberto Exp $
77c77,78
< size_t size = s->len + 1; /* include trailing '\0' */
> size_t size = tsslen(s) + 1; /* include trailing '\0' */
> const char *str = getstr(s);
84c85
< DumpVector(getstr(s), size - 1, D); /* no need to save '\0' */
> DumpVector(str, size - 1, D); /* no need to save '\0' */
src/lfunc.h
2c2
< ** $Id: lfunc.h,v 2.14 2014/06/19 18:27:20 roberto Exp $
> ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $
25a26,32
> ** maximum number of upvalues in a closure (both C and Lua). (Value
> ** must fit in a VM register.)
> */
> #define MAXUPVAL 255
>
>
> /*
src/lgc.c
2c2
< ** $Id: lgc.c,v 2.201 2014/12/20 13:58:15 roberto Exp $
> ** $Id: lgc.c,v 2.205 2015/03/25 13:42:19 roberto Exp $
86,87c86,92
< #define markobject(g,t) \
< { if ((t) && iswhite(t)) reallymarkobject(g, obj2gco(t)); }
> #define markobject(g,t) { if (iswhite(t)) reallymarkobject(g, obj2gco(t)); }
>
> /*
> ** mark an object that can be NULL (either because it is really optional,
> ** or it was stripped as debug info, or inside an uncompleted structure)
> */
> #define markobjectN(g,t) { if (t) markobject(g,t); }
229c234,238
< case LUA_TSHRSTR:
> case LUA_TSHRSTR: {
> gray2black(o);
> g->GCmemtrav += sizelstring(gco2ts(o)->shrlen);
> break;
> }
232c241
< g->GCmemtrav += sizestring(gco2ts(o));
> g->GCmemtrav += sizelstring(gco2ts(o)->u.lnglen);
237c246
< markobject(g, gco2u(o)->metatable); /* mark its metatable */
> markobjectN(g, gco2u(o)->metatable); /* mark its metatable */
278c287
< markobject(g, g->mt[i]);
> markobjectN(g, g->mt[i]);
440c449
< markobject(g, h->metatable);
> markobjectN(g, h->metatable);
459a469,473
> /*
> ** Traverse a prototype. (While a prototype is being build, its
> ** arrays can be larger than needed; the extra slots are filled with
> ** NULL, so the use of 'markobjectN')
> */
464c478
< markobject(g, f->source);
> markobjectN(g, f->source);
468c482
< markobject(g, f->upvalues[i].name);
> markobjectN(g, f->upvalues[i].name);
470c484
< markobject(g, f->p[i]);
> markobjectN(g, f->p[i]);
472c486
< markobject(g, f->locvars[i].varname);
> markobjectN(g, f->locvars[i].varname);
497c511
< markobject(g, cl->p); /* mark its prototype */
> markobjectN(g, cl->p); /* mark its prototype */
692c706,707
< /* go through */
> luaM_freemem(L, o, sizelstring(gco2ts(o)->shrlen));
> break;
694c709
< luaM_freemem(L, o, sizestring(gco2ts(o)));
> luaM_freemem(L, o, sizelstring(gco2ts(o)->u.lnglen));
1004a1020
> luaS_clearcache(g);
src/liolib.c
2c2
< ** $Id: liolib.c,v 2.142 2015/01/02 12:50:28 roberto Exp $
> ** $Id: liolib.c,v 2.144 2015/04/03 18:41:57 roberto Exp $
413,418d412
< /* access to locale "radix character" (decimal point) */
< #if !defined(l_getlocaledecpoint)
< #define l_getlocaledecpoint() (localeconv()->decimal_point[0])
< #endif
<
<
428c422
< char decp[2] = ".";
> char decp[2];
430c424,425
< decp[0] = l_getlocaledecpoint(); /* get decimal point from locale */
> decp[0] = lua_getlocaledecpoint(); /* get decimal point from locale */
> decp[1] = '\0';
460c455
< lua_pushlstring(L, NULL, 0);
> lua_pushliteral(L, "");
src/llex.c
2c2
< ** $Id: llex.c,v 2.89 2014/11/14 16:06:09 roberto Exp $
> ** $Id: llex.c,v 2.93 2015/05/22 17:45:56 roberto Exp $
18a19
> #include "ldebug.h"
71c72
< TString *e = luaS_new(L, LUA_ENV); /* create env name */
> TString *e = luaS_newliteral(L, LUA_ENV); /* create env name */
109,111c110
< char buff[LUA_IDSIZE];
< luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE);
< msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
> msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber);
175c174
< ls->envn = luaS_new(L, LUA_ENV); /* get env name */
> ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */
224,228d222
< #if !defined(l_getlocaledecpoint)
< #define l_getlocaledecpoint() (localeconv()->decimal_point[0])
< #endif
<
<
237c231
< ls->decpoint = l_getlocaledecpoint();
> ls->decpoint = lua_getlocaledecpoint();
286,287c280,282
< ** skip a sequence '[=*[' or ']=*]' and return its number of '='s or
< ** -1 if sequence is malformed
> ** skip a sequence '[=*[' or ']=*]'; if sequence is wellformed, return
> ** its number of '='s; otherwise, return a negative number (-1 iff there
> ** are no '='s after initial bracket)
504,505c499,501
< else if (sep == -1) return '[';
< else lexerror(ls, "invalid long string delimiter", TK_STRING);
> else if (sep != -1) /* '[=...' missing second bracket */
> lexerror(ls, "invalid long string delimiter", TK_STRING);
> return '[';
src/llimits.h
2c2
< ** $Id: llimits.h,v 1.125 2014/12/19 13:30:23 roberto Exp $
> ** $Id: llimits.h,v 1.135 2015/06/09 14:21:00 roberto Exp $
55c55
< ** conversion of pointer to integer:
> ** conversion of pointer to unsigned integer:
59c59
< #define point2int(p) ((unsigned int)((size_t)(p) & UINT_MAX))
> #define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX))
91,95c91,92
< #if defined(LUA_USE_APICHECK)
< #include <assert.h>
< #define luai_apicheck(e) assert(e)
< #else
< #define luai_apicheck(e) lua_assert(e)
> #if !defined(luai_apicheck)
> #define luai_apicheck(l,e) lua_assert(e)
98,99c95
<
< #define api_check(e,msg) luai_apicheck((e) && msg)
> #define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
101a98
> /* macro to avoid warnings about unused variables */
103c100
< #define UNUSED(x) ((void)(x)) /* to avoid warnings */
> #define UNUSED(x) ((void)(x))
106a104
> /* type casts (a macro highlights casts in the code) */
152,156d149
< /*
< ** maximum number of upvalues in a closure (both C and Lua). (Value
< ** must fit in an unsigned char.)
< */
< #define MAXUPVAL UCHAR_MAX
170a164,172
> /*
> ** Maximum length for short strings, that is, strings that are
> ** internalized. (Cannot be smaller than reserved words or tags for
> ** metamethods, as these strings must be internalized;
> ** #("function") = 8, #("__newindex") = 10.)
> */
> #if !defined(LUAI_MAXSHORTLEN)
> #define LUAI_MAXSHORTLEN 40
> #endif
172c174,180
< /* minimum size for the string table (must be power of 2) */
>
> /*
> ** Initial size for the string table (must be power of 2).
> ** The Lua core alone registers ~50 strings (reserved words +
> ** metaevent keys + a few others). Libraries would typically add
> ** a few dozens more.
> */
174c182,190
< #define MINSTRTABSIZE 64 /* minimum size for "predefined" strings */
> #define MINSTRTABSIZE 128
> #endif
>
>
> /*
> ** Size of cache for strings in the API (better be a prime)
> */
> #if !defined(STRCACHE_SIZE)
> #define STRCACHE_SIZE 127
183a200,203
> /*
> ** macros that are executed whenether program enters the Lua core
> ** ('lua_lock') and leaves the core ('lua_unlock')
> */
188a209,212
> /*
> ** macro executed during Lua functions at points where the
> ** function can yield.
> */
225a250,296
> ** The luai_num* macros define the primitive operations over numbers.
> */
>
> /* floor division (defined as 'floor(a/b)') */
> #if !defined(luai_numidiv)
> #define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b)))
> #endif
>
> /* float division */
> #if !defined(luai_numdiv)
> #define luai_numdiv(L,a,b) ((a)/(b))
> #endif
>
> /*
> ** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when
> ** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of
> ** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b)
> ** ~= floor(a/b)'. That happens when the division has a non-integer
> ** negative result, which is equivalent to the test below.
> */
> #if !defined(luai_nummod)
> #define luai_nummod(L,a,b,m) \
> { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }
> #endif
>
> /* exponentiation */
> #if !defined(luai_numpow)
> #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b))
> #endif
>
> /* the others are quite standard operations */
> #if !defined(luai_numadd)
> #define luai_numadd(L,a,b) ((a)+(b))
> #define luai_numsub(L,a,b) ((a)-(b))
> #define luai_nummul(L,a,b) ((a)*(b))
> #define luai_numunm(L,a) (-(a))
> #define luai_numeq(a,b) ((a)==(b))
> #define luai_numlt(a,b) ((a)<(b))
> #define luai_numle(a,b) ((a)<=(b))
> #define luai_numisnan(a) (!luai_numeq((a), (a)))
> #endif
>
>
>
>
>
> /*
src/lmathlib.c
2c2
< ** $Id: lmathlib.c,v 1.114 2014/12/27 20:32:26 roberto Exp $
> ** $Id: lmathlib.c,v 1.115 2015/03/12 14:04:04 roberto Exp $
185a186,188
> #if !defined(LUA_USE_C89)
> if (base == 2.0) res = l_mathop(log2)(x); else
> #endif
src/lmem.c
2c2
< ** $Id: lmem.c,v 1.89 2014/11/02 19:33:33 roberto Exp $
> ** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $
88,91c88,92
< api_check( nsize > realosize,
< "realloc cannot fail when shrinking a block");
< luaC_fullgc(L, 1); /* try to free some memory... */
< newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
> lua_assert(nsize > realosize); /* cannot fail when shrinking a block */
> if (g->version) { /* is state fully built? */
> luaC_fullgc(L, 1); /* try to free some memory... */
> newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
> }
src/loadlib.c
2c2
< ** $Id: loadlib.c,v 1.124 2015/01/05 13:51:39 roberto Exp $
> ** $Id: loadlib.c,v 1.126 2015/02/16 13:14:33 roberto Exp $
16a17
> #include <stdio.h>
139,140c140,141
< ** Macro to covert pointer to void* to pointer to function. This cast
< ** is undefined according to ISO C, but POSIX assumes that it must work.
> ** Macro to convert pointer-to-void* to pointer-to-function. This cast
> ** is undefined according to ISO C, but POSIX assumes that it works.
src/lobject.c
2c2
< ** $Id: lobject.c,v 2.101 2014/12/26 14:43:45 roberto Exp $
> ** $Id: lobject.c,v 2.104 2015/04/11 18:30:08 roberto Exp $
12a13,14
> #include <locale.h>
> #include <math.h>
42,43c44,49
< while (x >= 0x10) {
< x = (x+1) >> 1;
> while (x >= (8 << 4)) { /* coarse steps */
> x = (x + 0xf) >> 4; /* x = ceil(x / 16) */
> e += 4;
> }
> while (x >= (8 << 1)) { /* fine steps */
> x = (x + 1) >> 1; /* x = ceil(x / 2) */
57a64,66
> /*
> ** Computes ceil(log2(x))
> */
59c68
< static const lu_byte log_2[256] = {
> static const lu_byte log_2[256] = { /* log_2[i] = ceil(log2(i - 1)) */
152c161
< luaT_trybinTM(L, p1, p2, res, cast(TMS, op - LUA_OPADD + TM_ADD));
> luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));
158c167
< else return ltolower(c) - 'a' + 10;
> else return (ltolower(c) - 'a') + 10;
175d183
< #if !defined(lua_strx2number)
177c185
< #include <math.h>
> #if !defined(lua_strx2number)
187a196
> int dot = lua_getlocaledecpoint();
193c202
< int dot = 0; /* true after seen a dot */
> int hasdot = 0; /* true after seen a dot */
200,202c209,211
< if (*s == '.') {
< if (dot) break; /* second dot? stop loop */
< else dot = 1;
> if (*s == dot) {
> if (hasdot) break; /* second dot? stop loop */
> else hasdot = 1;
210c219
< if (dot) e--; /* decimal digit? correct exponent */
> if (hasdot) e--; /* decimal digit? correct exponent */
247c256
< if (endptr == s) return 0; /* nothing recognized */
> if (endptr == s) return NULL; /* nothing recognized */
293c302
< return (e - s + 1); /* success; return string size */
> return (e - s) + 1; /* success; return string size */
332c341
< buff[len++] = '.';
> buff[len++] = lua_getlocaledecpoint();
src/lobject.h
2c2
< ** $Id: lobject.h,v 2.106 2015/01/05 13:52:37 roberto Exp $
> ** $Id: lobject.h,v 2.111 2015/06/09 14:21:42 roberto Exp $
38,39d37
< #define VARBITS (3 << 4)
<
192a191,193
> #define chgfltvalue(obj,x) \
> { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
>
195a197,199
> #define chgivalue(obj,x) \
> { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
>
305a310
> lu_byte shrlen; /* length for short strings */
307,308c312,315
< size_t len; /* number of characters in string */
< struct TString *hnext; /* linked list for hash table */
> union {
> size_t lnglen; /* length for long strings */
> struct TString *hnext; /* linked list for hash table */
> } u;
331a339,344
> /* get string length from 'TString *s' */
> #define tsslen(s) ((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen)
>
> /* get string length from 'TValue *o' */
> #define vslen(o) tsslen(tsvalue(o))
>
364c377
< iu->user_ = io->value_; iu->ttuv_ = io->tt_; \
> iu->user_ = io->value_; iu->ttuv_ = rttype(io); \
370c383
< io->value_ = iu->user_; io->tt_ = iu->ttuv_; \
> io->value_ = iu->user_; settt_(io, iu->ttuv_); \
379c392
< lu_byte instack; /* whether it is in stack */
> lu_byte instack; /* whether it is in stack (register) */
402c415
< lu_byte maxstacksize; /* maximum stack used by this function */
> lu_byte maxstacksize; /* number of registers needed by this function */
412c425
< Instruction *code;
> Instruction *code; /* opcodes */
417c430
< struct LClosure *cache; /* last created closure with this prototype */
> struct LClosure *cache; /* last-created closure with this prototype */
src/loslib.c
2c2
< ** $Id: loslib.c,v 1.54 2014/12/26 14:46:07 roberto Exp $
> ** $Id: loslib.c,v 1.57 2015/04/10 17:41:04 roberto Exp $
25d24
< #if !defined(LUA_STRFTIMEOPTIONS) /* { */
26a26
> ** {==================================================================
27a28
> ** ===================================================================
28a30
> #if !defined(LUA_STRFTIMEOPTIONS) /* { */
39a42
> /* }================================================================== */
41a45,49
> /*
> ** {==================================================================
> ** Configuration for time-related stuff
> ** ===================================================================
> */
53a62,84
> #if !defined(l_gmtime) /* { */
> /*
> ** By default, Lua uses gmtime/localtime, except when POSIX is available,
> ** where it uses gmtime_r/localtime_r
> */
>
> #if defined(LUA_USE_POSIX) /* { */
>
> #define l_gmtime(t,r) gmtime_r(t,r)
> #define l_localtime(t,r) localtime_r(t,r)
>
> #else /* }{ */
>
> /* ISO C definitions */
> #define l_gmtime(t,r) ((void)(r)->tm_sec, gmtime(t))
> #define l_localtime(t,r) ((void)(r)->tm_sec, localtime(t))
>
> #endif /* } */
>
> #endif /* } */
>
> /* }================================================================== */
>
55d85
< #if !defined(lua_tmpnam) /* { */
57,58c87,91
< ** By default, Lua uses tmpnam except when POSIX is available, where it
< ** uses mkstemp.
> ** {==================================================================
> ** Configuration for 'tmpnam':
> ** By default, Lua uses tmpnam except when POSIX is available, where
> ** it uses mkstemp.
> ** ===================================================================
59a93
> #if !defined(lua_tmpnam) /* { */
85a120
> /* }================================================================== */
89,110d123
< #if !defined(l_gmtime) /* { */
< /*
< ** By default, Lua uses gmtime/localtime, except when POSIX is available,
< ** where it uses gmtime_r/localtime_r
< */
<
< #if defined(LUA_USE_POSIX) /* { */
<
< #define l_gmtime(t,r) gmtime_r(t,r)
< #define l_localtime(t,r) localtime_r(t,r)
<
< #else /* }{ */
<
< /* ISO C definitions */
< #define l_gmtime(t,r) ((void)(r)->tm_sec, gmtime(t))
< #define l_localtime(t,r) ((void)(r)->tm_sec, localtime(t))
<
< #endif /* } */
<
< #endif /* } */
<
<
290c303
< luaL_error(L, "time result cannot be represented in this Lua instalation");
> luaL_error(L, "time result cannot be represented in this Lua installation");
300,301c313,315
< double res = difftime((l_checktime(L, 1)), (l_checktime(L, 2)));
< lua_pushnumber(L, (lua_Number)res);
> time_t t1 = l_checktime(L, 1);
> time_t t2 = l_checktime(L, 2);
> lua_pushnumber(L, (lua_Number)difftime(t1, t2));
src/lstate.c
2c2
< ** $Id: lstate.c,v 2.127 2014/11/02 19:33:33 roberto Exp $
> ** $Id: lstate.c,v 2.128 2015/03/04 13:31:21 roberto Exp $
40,42d39
< #define MEMERRMSG "not enough memory"
<
<
203c200
< luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
> luaS_init(L);
206,208d202
< /* pre-create memory-error message */
< g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
< luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
src/lstate.h
2c2
< ** $Id: lstate.h,v 2.119 2014/10/30 18:53:28 roberto Exp $
> ** $Id: lstate.h,v 2.122 2015/06/01 16:34:37 roberto Exp $
96a97
> #define CIST_LEQ (1<<7) /* using __lt for __le */
142a144
> TString *strcache[STRCACHE_SIZE][1]; /* cache for strings in API */
src/lstring.c
2c2
< ** $Id: lstring.c,v 2.45 2014/11/02 19:19:04 roberto Exp $
> ** $Id: lstring.c,v 2.49 2015/06/01 16:34:37 roberto Exp $
24a25,26
> #define MEMERRMSG "not enough memory"
>
39c41
< size_t len = a->len;
> size_t len = a->u.lnglen;
42c44
< ((len == b->len) && /* equal length and ... */
> ((len == b->u.lnglen) && /* equal length and ... */
72c74
< TString *hnext = p->hnext; /* save next */
> TString *hnext = p->u.hnext; /* save next */
74c76
< p->hnext = tb->hash[h]; /* chain it */
> p->u.hnext = tb->hash[h]; /* chain it */
87a90,117
> /*
> ** Clear API string cache. (Entries cannot be empty, so fill them with
> ** a non-collectable string.)
> */
> void luaS_clearcache (global_State *g) {
> int i;
> for (i = 0; i < STRCACHE_SIZE; i++) {
> if (iswhite(g->strcache[i][0])) /* will entry be collected? */
> g->strcache[i][0] = g->memerrmsg; /* replace it with something fixed */
> }
> }
>
>
> /*
> ** Initialize the string table and the string cache
> */
> void luaS_init (lua_State *L) {
> global_State *g = G(L);
> int i;
> luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
> /* pre-create memory-error message */
> g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
> luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
> for (i = 0; i < STRCACHE_SIZE; i++) /* fill cache with valid strings */
> g->strcache[i][0] = g->memerrmsg;
> }
>
>
100d129
< ts->len = l;
113,114c142,143
< p = &(*p)->hnext;
< *p = (*p)->hnext; /* remove element from its list */
> p = &(*p)->u.hnext;
> *p = (*p)->u.hnext; /* remove element from its list */
127,128c156,157
< for (ts = *list; ts != NULL; ts = ts->hnext) {
< if (l == ts->len &&
> for (ts = *list; ts != NULL; ts = ts->u.hnext) {
> if (l == ts->shrlen &&
141c170,171
< ts->hnext = *list;
> ts->shrlen = cast_byte(l);
> ts->u.hnext = *list;
154a185
> TString *ts;
157c188,190
< return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed);
> ts = createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed);
> ts->u.lnglen = l;
> return ts;
163c196,199
< ** new zero-terminated string
> ** Create or reuse a zero-terminated string, first checking in the
> ** cache (using the string address as a key). The cache can contain
> ** only zero-terminated strings, so it is safe to use 'strcmp' to
> ** check hits.
166c202,210
< return luaS_newlstr(L, str, strlen(str));
> unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */
> TString **p = G(L)->strcache[i];
> if (strcmp(str, getstr(p[0])) == 0) /* hit? */
> return p[0]; /* that it is */
> else { /* normal route */
> TString *s = luaS_newlstr(L, str, strlen(str));
> p[0] = s;
> return s;
> }
src/lstring.h
2c2
< ** $Id: lstring.h,v 1.56 2014/07/18 14:46:47 roberto Exp $
> ** $Id: lstring.h,v 1.59 2015/03/25 13:42:19 roberto Exp $
16d15
< #define sizestring(s) sizelstring((s)->len)
39a39,40
> LUAI_FUNC void luaS_clearcache (global_State *g);
> LUAI_FUNC void luaS_init (lua_State *L);
src/lstrlib.c
2c2
< ** $Id: lstrlib.c,v 1.221 2014/12/11 14:03:07 roberto Exp $
> ** $Id: lstrlib.c,v 1.229 2015/05/20 17:39:23 roberto Exp $
13a14
> #include <float.h>
73c74
< lua_pushlstring(L, s + start - 1, (size_t)(end - start + 1));
> lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1);
152,153c153
< n = (int)(pose - posi + 1);
< if (posi + n <= pose) /* arithmetic overflow? */
> if (pose - posi >= INT_MAX) /* arithmetic overflow? */
154a155
> n = (int)(pose - posi) + 1;
502c503
< /* go through */
> /* FALLTHROUGH */
557c558
< lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
> lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);
601,602c602,603
< lua_pushinteger(L, s2 - s + 1);
< lua_pushinteger(L, s2 - s + lp);
> lua_pushinteger(L, (s2 - s) + 1);
> lua_pushinteger(L, (s2 - s) + lp);
624c625
< lua_pushinteger(L, s1 - s + 1); /* start */
> lua_pushinteger(L, (s1 - s) + 1); /* start */
800,801c801,886
< /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
< #define MAX_ITEM 512
> #if !defined(lua_number2strx) /* { */
>
> /*
> ** Hexadecimal floating-point formatter
> */
>
> #include <locale.h>
> #include <math.h>
>
> #define SIZELENMOD (sizeof(LUA_NUMBER_FRMLEN)/sizeof(char))
>
>
> /*
> ** Number of bits that goes into the first digit. It can be any value
> ** between 1 and 4; the following definition tries to align the number
> ** to nibble boundaries by making what is left after that first digit a
> ** multiple of 4.
> */
> #define L_NBFD ((l_mathlim(MANT_DIG) - 1)%4 + 1)
>
>
> /*
> ** Add integer part of 'x' to buffer and return new 'x'
> */
> static lua_Number adddigit (char *buff, int n, lua_Number x) {
> lua_Number dd = l_mathop(floor)(x); /* get integer part from 'x' */
> int d = (int)dd;
> buff[n] = (d < 10 ? d + '0' : d - 10 + 'a'); /* add to buffer */
> return x - dd; /* return what is left */
> }
>
>
> static int num2straux (char *buff, lua_Number x) {
> if (x != x || x == HUGE_VAL || x == -HUGE_VAL) /* inf or NaN? */
> return sprintf(buff, LUA_NUMBER_FMT, x); /* equal to '%g' */
> else if (x == 0) { /* can be -0... */
> sprintf(buff, LUA_NUMBER_FMT, x);
> strcat(buff, "x0p+0"); /* reuses '0/-0' from 'sprintf'... */
> return strlen(buff);
> }
> else {
> int e;
> lua_Number m = l_mathop(frexp)(x, &e); /* 'x' fraction and exponent */
> int n = 0; /* character count */
> if (m < 0) { /* is number negative? */
> buff[n++] = '-'; /* add signal */
> m = -m; /* make it positive */
> }
> buff[n++] = '0'; buff[n++] = 'x'; /* add "0x" */
> m = adddigit(buff, n++, m * (1 << L_NBFD)); /* add first digit */
> e -= L_NBFD; /* this digit goes before the radix point */
> if (m > 0) { /* more digits? */
> buff[n++] = lua_getlocaledecpoint(); /* add radix point */
> do { /* add as many digits as needed */
> m = adddigit(buff, n++, m * 16);
> } while (m > 0);
> }
> n += sprintf(buff + n, "p%+d", e); /* add exponent */
> return n;
> }
> }
>
>
> static int lua_number2strx (lua_State *L, char *buff, const char *fmt,
> lua_Number x) {
> int n = num2straux(buff, x);
> if (fmt[SIZELENMOD] == 'A') {
> int i;
> for (i = 0; i < n; i++)
> buff[i] = toupper(uchar(buff[i]));
> }
> else if (fmt[SIZELENMOD] != 'a')
> luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented");
> return n;
> }
>
> #endif /* } */
>
>
> /*
> ** Maximum size of each formatted item. This maximum size is produced
> ** by format('%.99f', minfloat), and is equal to 99 + 2 ('-' and '.') +
> ** number of decimal digits to represent minfloat.
> */
> #define MAX_ITEM (120 + l_mathlim(MAX_10_EXP))
>
808d892
< ** (+2 for length modifiers; +10 accounts for %99.99x plus margin of error)
810c894
< #define MAX_FORMAT (sizeof(FLAGS) + 2 + 10)
> #define MAX_FORMAT 32
852,853c936,937
< memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char));
< form += p - strfrmt + 1;
> memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));
> form += (p - strfrmt) + 1;
904d987
< #if defined(LUA_USE_AFORMAT)
906c989,991
< #endif
> addlenmod(form, LUA_NUMBER_FRMLEN);
> nb = lua_number2strx(L, buff, form, luaL_checknumber(L, arg));
> break;
924d1008
< break;
929d1012
< break;
930a1014
> break;
1252c1336
< case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE); /* go through */
> case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE); /* FALLTHROUGH */
src/ltable.c
2c2
< ** $Id: ltable.c,v 2.100 2015/01/05 13:52:37 roberto Exp $
> ** $Id: ltable.c,v 2.111 2015/06/09 14:21:13 roberto Exp $
17,18c17,18
< ** part. The actual size of the array is the largest 'n' such that at
< ** least half the slots between 0 and n are in use.
> ** part. The actual size of the array is the largest 'n' such that
> ** more than half the slots between 1 and n are in use.
26d25
< #include <float.h>
28d26
< #include <string.h>
74c72
< #define hashpointer(t,p) hashmod(t, point2int(p))
> #define hashpointer(t,p) hashmod(t, point2uint(p))
88,89c86,96
< ** Checks whether a float has a value representable as a lua_Integer
< ** (and does the conversion if so)
> ** Hash for floating-point numbers.
> ** The main computation should be just
> ** n = frepx(n, &i); return (n * INT_MAX) + i
> ** but there are some numerical subtleties.
> ** In a two-complement representation, INT_MAX does not has an exact
> ** representation as a float, but INT_MIN does; because the absolute
> ** value of 'frexp' is smaller than 1 (unless 'n' is inf/NaN), the
> ** absolute value of the product 'frexp * -INT_MIN' is smaller or equal
> ** to INT_MAX. Next, the use of 'unsigned int' avoids overflows when
> ** adding 'i'; the use of '~u' (instead of '-u') avoids problems with
> ** INT_MIN.
91,101c98,99
< static int numisinteger (lua_Number x, lua_Integer *p) {
< if ((x) == l_floor(x)) /* integral value? */
< return lua_numbertointeger(x, p); /* try as an integer */
< else return 0;
< }
<
<
< /*
< ** hash for floating-point numbers
< */
< static Node *hashfloat (const Table *t, lua_Number n) {
> #if !defined(l_hashfloat)
> static int l_hashfloat (lua_Number n) {
103,108c101,109
< n = l_mathop(frexp)(n, &i) * cast_num(INT_MAX - DBL_MAX_EXP);
< i += cast_int(n);
< if (i < 0) {
< if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
< i = 0; /* handle INT_MIN */
< i = -i; /* must be a positive value */
> lua_Integer ni;
> n = l_mathop(frexp)(n, &i) * -cast_num(INT_MIN);
> if (!lua_numbertointeger(n, &ni)) { /* is 'n' inf/-inf/NaN? */
> lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == HUGE_VAL);
> return 0;
> }
> else { /* normal case */
> unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni);
> return cast_int(u <= cast(unsigned int, INT_MAX) ? u : ~u);
110d110
< return hashmod(t, i);
112c112
<
> #endif
124c124
< return hashfloat(t, fltvalue(key));
> return hashmod(t, l_hashfloat(fltvalue(key)));
130c130
< s->hash = luaS_hash(getstr(s), s->len, s->hash);
> s->hash = luaS_hash(getstr(s), s->u.lnglen, s->hash);
222,223c222,224
< ** between 2^(i - 1) + 1 and 2^i. Put in '*narray' the optimal size, and
< ** return the number of elements that will go to that part.
> ** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of
> ** integer keys in the table and leaves with the number of keys that
> ** will go to the array part; return the optimal size.
225c226
< static unsigned int computesizes (unsigned int nums[], unsigned int *narray) {
> static unsigned int computesizes (unsigned int nums[], unsigned int *pna) {
227c228
< unsigned int twotoi; /* 2^i */
> unsigned int twotoi; /* 2^i (candidate for optimal size) */
230,231c231,233
< unsigned int n = 0; /* optimal size for array part */
< for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
> unsigned int optimal = 0; /* optimal size for array part */
> /* loop while keys can fill more than half of total size */
> for (i = 0, twotoi = 1; *pna > twotoi / 2; i++, twotoi *= 2) {
235,236c237,238
< n = twotoi; /* optimal size (till now) */
< na = a; /* all elements up to 'n' will go to array part */
> optimal = twotoi; /* optimal size (till now) */
> na = a; /* all elements up to 'optimal' will go to array part */
239d240
< if (a == *narray) break; /* all elements already counted */
241,243c242,244
< *narray = n;
< lua_assert(*narray/2 <= na && na <= *narray);
< return na;
> lua_assert((optimal == 0 || optimal / 2 < na) && na <= optimal);
> *pna = na;
> return optimal;
257a259,263
> /*
> ** Count keys in array part of table 't': Fill 'nums[i]' with
> ** number of keys that will go into corresponding slice and return
> ** total number of non-nil keys.
> */
284,285c290
< static int numusehash (const Table *t, unsigned int *nums,
< unsigned int *pnasize) {
> static int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) {
296c301
< *pnasize += ause;
> *pna += ause;
366c371
< luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
> luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old hash */
379c384,385
< unsigned int nasize, na;
> unsigned int asize; /* optimal size for array part */
> unsigned int na; /* number of keys in the array part */
384,386c390,392
< nasize = numusearray(t, nums); /* count keys in array part */
< totaluse = nasize; /* all those keys are integer keys */
< totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */
> na = numusearray(t, nums); /* count keys in array part */
> totaluse = na; /* all those keys are integer keys */
> totaluse += numusehash(t, nums, &na); /* count keys in hash part */
388c394
< nasize += countint(ek, nums);
> na += countint(ek, nums);
391c397
< na = computesizes(nums, &nasize);
> asize = computesizes(nums, &na);
393c399
< luaH_resize(L, t, nasize, totaluse - na);
> luaH_resize(L, t, asize, totaluse - na);
446d451
< lua_Number n = fltvalue(key);
448,450c453
< if (luai_numisnan(n))
< luaG_runerror(L, "table index is NaN");
< if (numisinteger(n, &k)) { /* index is int? */
> if (luaV_tointeger(key, &k, 0)) { /* index is int? */
453a457,458
> else if (luai_numisnan(fltvalue(key)))
> luaG_runerror(L, "table index is NaN");
547c552
< if (numisinteger(fltvalue(key), &k)) /* index is int? */
> if (luaV_tointeger(key, &k, 0)) /* index is int? */
549,550c554,555
< /* else go through */
< }
> /* else... */
> } /* FALLTHROUGH */
src/ltablib.c
2c2
< ** $Id: ltablib.c,v 1.79 2014/11/02 19:19:04 roberto Exp $
> ** $Id: ltablib.c,v 1.80 2015/01/13 16:27:29 roberto Exp $
127,128d126
< /* the following restriction avoids several problems with overflows */
< luaL_argcheck(L, f > 0, 2, "initial position must be positive");
136a135,136
> luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3,
> "too many elements to move");
137a138,139
> luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,
> "destination wrap around");
src/ltm.c
2c2
< ** $Id: ltm.c,v 2.33 2014/11/21 12:15:57 roberto Exp $
> ** $Id: ltm.c,v 2.34 2015/03/30 15:42:27 roberto Exp $
119a120
> /* call never returns, but to avoid warnings: *//* FALLTHROUGH */
127d127
< /* else go through */
128a129
> /* calls never return, but to avoid warnings: *//* FALLTHROUGH */
src/lua.c
2c2
< ** $Id: lua.c,v 1.222 2014/11/11 19:41:27 roberto Exp $
> ** $Id: lua.c,v 1.225 2015/03/30 15:42:59 roberto Exp $
83,85c83
< #define lua_saveline(L,idx) \
< if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \
< add_history(lua_tostring(L, idx)); /* add it to history */
> #define lua_saveline(L,line) ((void)L, add_history(line))
93c91
< #define lua_saveline(L,idx) { (void)L; (void)idx; }
> #define lua_saveline(L,line) { (void)L; (void)line; }
318c316
< b[l-1] = '\0'; /* remove it */
> b[--l] = '\0'; /* remove it */
322c320
< lua_pushstring(L, b);
> lua_pushlstring(L, b, l);
339c337
< if ((status = luaL_loadbuffer(L, line, len, "=stdin")) == LUA_OK)
> if ((status = luaL_loadbuffer(L, line, len, "=stdin")) == LUA_OK) {
340a339,342
> line += sizeof("return")/sizeof(char); /* remove 'return' for history */
> if (line[0] != '\0') /* non empty? */
> lua_saveline(L, line); /* keep history */
> }
355c357,358
< if (!incomplete(L, status) || !pushline(L, 0))
> if (!incomplete(L, status) || !pushline(L, 0)) {
> lua_saveline(L, line); /* keep history */
356a360
> }
377d380
< lua_saveline(L, 1); /* keep history */
485c488
< args |= has_i; /* goes through (-i implies -v) */
> args |= has_i; /* (-i implies -v) *//* FALLTHROUGH */
492c495
< args |= has_e; /* go through */
> args |= has_e; /* FALLTHROUGH */
516d518
< int status;
519a522
> int status;
523,526c526,528
< if (option == 'e')
< status = dostring(L, extra, "=(command line)");
< else
< status = dolibrary(L, extra);
> status = (option == 'e')
> ? dostring(L, extra, "=(command line)")
> : dolibrary(L, extra);
src/lua.h
2c2
< ** $Id: lua.h,v 1.325 2014/12/26 17:24:27 roberto Exp $
> ** $Id: lua.h,v 1.328 2015/06/03 13:03:38 roberto Exp $
22c22
< #define LUA_VERSION_RELEASE "0"
> #define LUA_VERSION_RELEASE "1"
38c38,40
< ** pseudo-indices
> ** Pseudo-indices
> ** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
> ** space after that to help overflow detection)
40c42
< #define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX
> #define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
359,360c361
< #define lua_pushliteral(L, s) \
< lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
> #define lua_pushliteral(L, s) lua_pushstring(L, "" s)
src/luac.c
2c2
< ** $Id: luac.c,v 1.72 2015/01/06 03:09:13 lhf Exp $
> ** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $
209c209
< ** $Id: print.c,v 1.76 2015/01/05 16:12:50 lhf Exp $
> ** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $
229c229
< size_t i,n=ts->len;
> size_t i,n=tsslen(ts);
src/luaconf.h
2c2
< ** $Id: luaconf.h,v 1.238 2014/12/29 13:27:55 roberto Exp $
> ** $Id: luaconf.h,v 1.251 2015/05/20 17:39:23 roberto Exp $
99,102c99,100
< @@ LUA_INT_INT / LUA_INT_LONG / LUA_INT_LONGLONG defines the type for
< ** Lua integers.
< @@ LUA_REAL_FLOAT / LUA_REAL_DOUBLE / LUA_REAL_LONGDOUBLE defines
< ** the type for Lua floats.
> @@ LUA_INT_TYPE defines the type for Lua integers.
> @@ LUA_FLOAT_TYPE defines the type for Lua floats.
109a108,117
> /* predefined options for LUA_INT_TYPE */
> #define LUA_INT_INT 1
> #define LUA_INT_LONG 2
> #define LUA_INT_LONGLONG 3
>
> /* predefined options for LUA_FLOAT_TYPE */
> #define LUA_FLOAT_FLOAT 1
> #define LUA_FLOAT_DOUBLE 2
> #define LUA_FLOAT_LONGDOUBLE 3
>
115c123
< #define LUA_INT_INT
> #define LUA_INT_TYPE LUA_INT_INT
117c125
< #define LUA_INT_LONG
> #define LUA_INT_TYPE LUA_INT_LONG
119c127
< #define LUA_REAL_FLOAT
> #define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
125,126c133,137
< #define LUA_INT_LONG
< #define LUA_REAL_DOUBLE
> #define LUA_INT_TYPE LUA_INT_LONG
> #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
>
> #endif /* } */
>
128d138
< #else /* }{ */
132,133c142,144
< #define LUA_INT_LONGLONG
< #define LUA_REAL_DOUBLE
> #if !defined(LUA_INT_TYPE)
> #define LUA_INT_TYPE LUA_INT_LONGLONG
> #endif
134a146,147
> #if !defined(LUA_FLOAT_TYPE)
> #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
158c171
< #if defined(_WIN32) /* { */
> #if defined(_WIN32) /* { */
303,311d315
<
< /*
< @@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
< @@ a float mark ('.0').
< ** This macro is not on by default even in compatibility mode,
< ** because this is not really an incompatibility.
< */
< /* #define LUA_COMPAT_FLOATSTRING */
<
316a321,324
> /* Incompatibilities from 5.2 -> 5.3 */
> #define LUA_COMPAT_MATHLIB
> #define LUA_COMPAT_APIINTCASTS
>
375a384,392
>
> /*
> @@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
> @@ a float mark ('.0').
> ** This macro is not on by default even in compatibility mode,
> ** because this is not really an incompatibility.
> */
> /* #define LUA_COMPAT_FLOATSTRING */
>
383c400
< ** Change these definitions if no predefined LUA_REAL_* / LUA_INT_*
> ** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
390d406
< **
393c409,410
< **
> @@ l_mathlim(x) corrects limit name 'x' to the proper float type
> ** by prefixing it with one of FLT/DBL/LDBL.
397d413
< **
399d414
< **
403c418
< #if defined(LUA_REAL_FLOAT) /* { single float */
> #if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
406a422,423
> #define l_mathlim(n) (FLT_##n)
>
417c434
< #elif defined(LUA_REAL_LONGDOUBLE) /* }{ long double */
> #elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
420a438,439
> #define l_mathlim(n) (LDBL_##n)
>
430c449
< #elif defined(LUA_REAL_DOUBLE) /* }{ double */
> #elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
433a453,454
> #define l_mathlim(n) (DBL_##n)
>
443c464
< #else /* }{ */
> #else /* }{ */
445c466
< #error "numeric real type not defined"
> #error "numeric float type not defined"
469,508d489
< /*
< @@ The luai_num* macros define the primitive operations over numbers.
< ** They should work for any size of floating numbers.
< */
<
< /* the following operations need the math library */
< #if defined(lobject_c) || defined(lvm_c)
< #include <math.h>
<
< /* floor division (defined as 'floor(a/b)') */
< #define luai_numidiv(L,a,b) ((void)L, l_mathop(floor)(luai_numdiv(L,a,b)))
<
< /*
< ** module: defined as 'a - floor(a/b)*b'; the previous definition gives
< ** NaN when 'b' is huge, but the result should be 'a'. 'fmod' gives the
< ** result of 'a - trunc(a/b)*b', and therefore must be corrected when
< ** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a
< ** non-integer negative result, which is equivalent to the test below
< */
< #define luai_nummod(L,a,b,m) \
< { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }
<
< /* exponentiation */
< #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b))
<
< #endif
<
< /* these are quite standard operations */
< #if defined(LUA_CORE)
< #define luai_numadd(L,a,b) ((a)+(b))
< #define luai_numsub(L,a,b) ((a)-(b))
< #define luai_nummul(L,a,b) ((a)*(b))
< #define luai_numdiv(L,a,b) ((a)/(b))
< #define luai_numunm(L,a) (-(a))
< #define luai_numeq(a,b) ((a)==(b))
< #define luai_numlt(a,b) ((a)<(b))
< #define luai_numle(a,b) ((a)<=(b))
< #define luai_numisnan(a) (!luai_numeq((a), (a)))
< #endif
<
541c522
< #if defined(LUA_INT_INT) /* { int */
> #if LUA_INT_TYPE == LUA_INT_INT /* { int */
549c530
< #elif defined(LUA_INT_LONG) /* }{ long */
> #elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
557c538
< #elif defined(LUA_INT_LONGLONG) /* }{ long long */
> #elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
595c576
< ** Dependencies with C99
> ** Dependencies with C99 and other C details
601c582
< ** In C99, 'strtod' does both conversions. Otherwise, you can
> ** In C99, 'strtod' does that conversion. Otherwise, you can
611,613c592,595
< @@ LUA_USE_AFORMAT allows '%a'/'%A' specifiers in 'string.format'
< ** Enable it if the C function 'printf' supports these specifiers.
< ** (C99 demands it and Windows also supports it.)
> @@ lua_number2strx converts a float to an hexadecimal numeric string.
> ** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
> ** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
> ** provide its own implementation.
615,616c597,598
< #if !defined(LUA_USE_C89) || defined(LUA_USE_WINDOWS)
< #define LUA_USE_AFORMAT
> #if !defined(LUA_USE_C89)
> #define lua_number2strx(L,b,f,n) sprintf(b,f,n)
645c627
< #if defined (INTPTR_MAX) /* even in C99 this type is optional */
> #if defined(INTPTR_MAX) /* even in C99 this type is optional */
650a633,670
>
> /*
> @@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
> ** Change that if you do not want to use C locales. (Code using this
> ** macro must include header 'locale.h'.)
> */
> #if !defined(lua_getlocaledecpoint)
> #define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
> #endif
>
> /* }================================================================== */
>
>
> /*
> ** {==================================================================
> ** Language Variations
> ** =====================================================================
> */
>
> /*
> @@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
> ** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
> ** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
> ** coercion from strings to numbers.
> */
> /* #define LUA_NOCVTN2S */
> /* #define LUA_NOCVTS2N */
>
>
> /*
> @@ LUA_USE_APICHECK turns on several consistency checks on the C API.
> ** Define it as a help when debugging C code.
> */
> #if defined(LUA_USE_APICHECK)
> #include <assert.h>
> #define luai_apicheck(l,e) assert(e)
> #endif
>
674,676d693
< /* reserve some space for error handling */
< #define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
<
695,703d711
< @@ LUAI_MAXSHORTLEN is the maximum length for short strings, that is,
< ** strings that are internalized. (Cannot be smaller than reserved words
< ** or tags for metamethods, as these strings must be internalized;
< ** #("function") = 8, #("__newindex") = 10.)
< */
< #define LUAI_MAXSHORTLEN 40
<
<
< /*
705c713,716
< ** CHANGE it if it uses too much C-stack space.
> ** CHANGE it if it uses too much C-stack space. (For long double,
> ** 'string.format("%.99f", 1e4932)' needs ~5030 bytes, so a
> ** smaller buffer would force a memory allocation for each call to
> ** 'string.format'.)
707c718,722
< #define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
> #if defined(LUA_FLOAT_LONGDOUBLE)
> #define LUAL_BUFFERSIZE 8192
> #else
> #define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
> #endif
src/lutf8lib.c
2c2
< ** $Id: lutf8lib.c,v 1.13 2014/11/02 19:19:04 roberto Exp $
> ** $Id: lutf8lib.c,v 1.15 2015/03/28 19:16:55 roberto Exp $
13a14
> #include <limits.h>
40c41
< static unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};
> static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};
109,110c110
< n = (int)(pose - posi + 1);
< if (posi + n <= pose) /* (lua_Integer -> int) overflow? */
> if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */
111a112
> n = (int)(pose - posi) + 1;
237c238
< static struct luaL_Reg funcs[] = {
> static const luaL_Reg funcs[] = {
251c252
< lua_pushliteral(L, UTF8PATT);
> lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);
src/lvm.c
2c2
< ** $Id: lvm.c,v 2.232 2014/12/27 20:30:38 roberto Exp $
> ** $Id: lvm.c,v 2.245 2015/06/09 15:53:35 roberto Exp $
12c12
<
> #include <float.h>
13a14
> #include <math.h>
33,42d33
< /*
< ** You can define LUA_FLOORN2I if you want to convert floats to integers
< ** by flooring them (instead of raising an error if they are not
< ** integral values)
< */
< #if !defined(LUA_FLOORN2I)
< #define LUA_FLOORN2I 0
< #endif
<
<
46a38
>
48,49c40,42
< ** Similar to 'tonumber', but does not attempt to convert strings and
< ** ensure correct precision (no extra bits). Used in comparisons.
> ** 'l_intfitsf' checks whether a given integer can be converted to a
> ** float without rounding. Used in comparisons. Left undefined if
> ** all integers fit in a float precisely.
51,62c44,65
< static int tofloat (const TValue *obj, lua_Number *n) {
< if (ttisfloat(obj)) *n = fltvalue(obj);
< else if (ttisinteger(obj)) {
< volatile lua_Number x = cast_num(ivalue(obj)); /* avoid extra precision */
< *n = x;
< }
< else {
< *n = 0; /* to avoid warnings */
< return 0;
< }
< return 1;
< }
> #if !defined(l_intfitsf)
>
> /* number of bits in the mantissa of a float */
> #define NBM (l_mathlim(MANT_DIG))
>
> /*
> ** Check whether some integers may not fit in a float, that is, whether
> ** (maxinteger >> NBM) > 0 (that implies (1 << NBM) <= maxinteger).
> ** (The shifts are done in parts to avoid shifting by more than the size
> ** of an integer. In a worst case, NBM == 113 for long double and
> ** sizeof(integer) == 32.)
> */
> #if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \
> >> (NBM - (3 * (NBM / 4)))) > 0
>
> #define l_intfitsf(i) \
> (-((lua_Integer)1 << NBM) <= (i) && (i) <= ((lua_Integer)1 << NBM))
>
> #endif
>
> #endif
>
76c79
< luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) {
> luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {
91c94
< static int tointeger_aux (const TValue *obj, lua_Integer *p, int mode) {
> int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode) {
109c112
< luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) {
> luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {
118,125d120
< ** try to convert a value to an integer
< */
< int luaV_tointeger_ (const TValue *obj, lua_Integer *p) {
< return tointeger_aux(obj, p, LUA_FLOORN2I);
< }
<
<
< /*
143c138
< if (!tointeger_aux(obj, p, (step < 0 ? 2 : 1))) { /* not fit in integer? */
> if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) { /* not fit in integer? */
147c142
< if (n > 0) { /* if true, float is larger than max integer */
> if (luai_numlt(0, n)) { /* if true, float is larger than max integer */
242c237
< size_t ll = ls->len;
> size_t ll = tsslen(ls);
244c239
< size_t lr = rs->len;
> size_t lr = tsslen(rs);
263a259,348
> ** Check whether integer 'i' is less than float 'f'. If 'i' has an
> ** exact representation as a float ('l_intfitsf'), compare numbers as
> ** floats. Otherwise, if 'f' is outside the range for integers, result
> ** is trivial. Otherwise, compare them as integers. (When 'i' has no
> ** float representation, either 'f' is "far away" from 'i' or 'f' has
> ** no precision left for a fractional part; either way, how 'f' is
> ** truncated is irrelevant.) When 'f' is NaN, comparisons must result
> ** in false.
> */
> static int LTintfloat (lua_Integer i, lua_Number f) {
> #if defined(l_intfitsf)
> if (!l_intfitsf(i)) {
> if (f >= -cast_num(LUA_MININTEGER)) /* -minint == maxint + 1 */
> return 1; /* f >= maxint + 1 > i */
> else if (f > cast_num(LUA_MININTEGER)) /* minint < f <= maxint ? */
> return (i < cast(lua_Integer, f)); /* compare them as integers */
> else /* f <= minint <= i (or 'f' is NaN) --> not(i < f) */
> return 0;
> }
> #endif
> return luai_numlt(cast_num(i), f); /* compare them as floats */
> }
>
>
> /*
> ** Check whether integer 'i' is less than or equal to float 'f'.
> ** See comments on previous function.
> */
> static int LEintfloat (lua_Integer i, lua_Number f) {
> #if defined(l_intfitsf)
> if (!l_intfitsf(i)) {
> if (f >= -cast_num(LUA_MININTEGER)) /* -minint == maxint + 1 */
> return 1; /* f >= maxint + 1 > i */
> else if (f >= cast_num(LUA_MININTEGER)) /* minint <= f <= maxint ? */
> return (i <= cast(lua_Integer, f)); /* compare them as integers */
> else /* f < minint <= i (or 'f' is NaN) --> not(i <= f) */
> return 0;
> }
> #endif
> return luai_numle(cast_num(i), f); /* compare them as floats */
> }
>
>
> /*
> ** Return 'l < r', for numbers.
> */
> static int LTnum (const TValue *l, const TValue *r) {
> if (ttisinteger(l)) {
> lua_Integer li = ivalue(l);
> if (ttisinteger(r))
> return li < ivalue(r); /* both are integers */
> else /* 'l' is int and 'r' is float */
> return LTintfloat(li, fltvalue(r)); /* l < r ? */
> }
> else {
> lua_Number lf = fltvalue(l); /* 'l' must be float */
> if (ttisfloat(r))
> return luai_numlt(lf, fltvalue(r)); /* both are float */
> else if (luai_numisnan(lf)) /* 'r' is int and 'l' is float */
> return 0; /* NaN < i is always false */
> else /* without NaN, (l < r) <--> not(r <= l) */
> return !LEintfloat(ivalue(r), lf); /* not (r <= l) ? */
> }
> }
>
>
> /*
> ** Return 'l <= r', for numbers.
> */
> static int LEnum (const TValue *l, const TValue *r) {
> if (ttisinteger(l)) {
> lua_Integer li = ivalue(l);
> if (ttisinteger(r))
> return li <= ivalue(r); /* both are integers */
> else /* 'l' is int and 'r' is float */
> return LEintfloat(li, fltvalue(r)); /* l <= r ? */
> }
> else {
> lua_Number lf = fltvalue(l); /* 'l' must be float */
> if (ttisfloat(r))
> return luai_numle(lf, fltvalue(r)); /* both are float */
> else if (luai_numisnan(lf)) /* 'r' is int and 'l' is float */
> return 0; /* NaN <= i is always false */
> else /* without NaN, (l <= r) <--> not(r < l) */
> return !LTintfloat(ivalue(r), lf); /* not (r < l) ? */
> }
> }
>
>
> /*
268,272c353,354
< lua_Number nl, nr;
< if (ttisinteger(l) && ttisinteger(r)) /* both operands are integers? */
< return (ivalue(l) < ivalue(r));
< else if (tofloat(l, &nl) && tofloat(r, &nr)) /* both are numbers? */
< return luai_numlt(nl, nr);
> if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */
> return LTnum(l, r);
282c364,369
< ** Main operation less than or equal to; return 'l <= r'.
> ** Main operation less than or equal to; return 'l <= r'. If it needs
> ** a metamethod and there is no '__le', try '__lt', based on
> ** l <= r iff !(r < l) (assuming a total order). If the metamethod
> ** yields during this substitution, the continuation has to know
> ** about it (to negate the result of r<l); bit CIST_LEQ in the call
> ** status keeps that information.
286,290c373,374
< lua_Number nl, nr;
< if (ttisinteger(l) && ttisinteger(r)) /* both operands are integers? */
< return (ivalue(l) <= ivalue(r));
< else if (tofloat(l, &nl) && tofloat(r, &nr)) /* both are numbers? */
< return luai_numle(nl, nr);
> if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */
> return LEnum(l, r);
293c377
< else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* first try 'le' */
> else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* try 'le' */
295,297c379,386
< else if ((res = luaT_callorderTM(L, r, l, TM_LT)) < 0) /* else try 'lt' */
< luaG_ordererror(L, l, r);
< return !res;
> else { /* try 'lt': */
> L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
> res = luaT_callorderTM(L, r, l, TM_LT);
> L->ci->callstatus ^= CIST_LEQ; /* clear mark */
> if (res < 0)
> luaG_ordererror(L, l, r);
> return !res; /* result is negated */
> }
302c391
< ** Main operation for equality of Lua values; return 't1 == t2'.
> ** Main operation for equality of Lua values; return 't1 == t2'.
311,314c400,401
< lua_Number n1, n2; /* compare them as floats */
< lua_assert(ttisnumber(t1) && ttisnumber(t2));
< cast_void(tofloat(t1, &n1)); cast_void(tofloat(t2, &n2));
< return luai_numeq(n1, n2);
> lua_Integer i1, i2; /* compare them as integers */
> return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);
356a444,445
> #define isemptystr(o) (ttisshrstring(o) && tsvalue(o)->shrlen == 0)
>
368c457
< else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
> else if (isemptystr(top - 1)) /* second operand is empty? */
370c459
< else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
> else if (isemptystr(top - 2)) { /* first operand is an empty string? */
375c464
< size_t tl = tsvalue(top-1)->len;
> size_t tl = vslen(top - 1);
380c469
< size_t l = tsvalue(top-i-1)->len;
> size_t l = vslen(top - i - 1);
389c478
< size_t l = tsvalue(top-i)->len;
> size_t l = vslen(top - i);
406c495
< switch (ttnov(rb)) {
> switch (ttype(rb)) {
414,415c503,508
< case LUA_TSTRING: {
< setivalue(ra, tsvalue(rb)->len);
> case LUA_TSHRSTR: {
> setivalue(ra, tsvalue(rb)->shrlen);
> return;
> }
> case LUA_TLNGSTR: {
> setivalue(ra, tsvalue(rb)->u.lnglen);
451c544
< ** Integer modulus; return 'm % n'. (Assume that C '%' with
> ** Integer modulus; return 'm % n'. (Assume that C '%' with
556,560c649,653
< /* metamethod should not be called when operand is K */
< lua_assert(!ISK(GETARG_B(inst)));
< if (op == OP_LE && /* "<=" using "<" instead? */
< ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
< res = !res; /* invert result */
> if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */
> lua_assert(op == OP_LE);
> ci->callstatus ^= CIST_LEQ; /* clear mark */
> res = !res; /* negate result */
> }
610c703
< #if !defined luai_runtimecheck
> #if !defined(luai_runtimecheck)
746c839
< vmcase(OP_ADD) {
> vmcase(OP_ADD) {
931c1024
< rb = b + base;
> rb = base + b;
1034d1126
< if (b != 0) L->top = ra+b-1;
1036c1128
< b = luaD_poscall(L, ra);
> b = luaD_poscall(L, ra, (b != 0 ? b - 1 : L->top - ra));
1054c1146
< setivalue(ra, idx); /* update internal index... */
> chgivalue(ra, idx); /* update internal index... */
1065c1157
< setfltvalue(ra, idx); /* update internal index... */
> chgfltvalue(ra, idx); /* update internal index... */
src/lvm.h
2c2
< ** $Id: lvm.h,v 2.34 2014/08/01 17:24:02 roberto Exp $
> ** $Id: lvm.h,v 2.35 2015/02/20 14:27:53 roberto Exp $
29a30,39
> /*
> ** You can define LUA_FLOORN2I if you want to convert floats to integers
> ** by flooring them (instead of raising an error if they are not
> ** integral values)
> */
> #if !defined(LUA_FLOORN2I)
> #define LUA_FLOORN2I 0
> #endif
>
>
34c44
< (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i))
> (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))
45c55
< LUAI_FUNC int luaV_tointeger_ (const TValue *obj, lua_Integer *p);
> LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode);