Lua diffs-lua-5.4.0-work2-alpha-rc1


Makefile

39c39
< PLATS= aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
> PLATS= aix bsd c89 freebsd generic guess linux linux-readline macosx mingw posix solaris

112c112
< .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho
> .PHONY: all $(PLATS) clean test install uninstall local none dummy echo pc

README

2c2
< This is Lua 5.4.0 (work2), released on 18 Jun 2018.
> This is Lua 5.4.0 (alpha), released on 29 May 2019.

doc/contents.html

35c35
< Copyright &copy; 2018 Lua.org, PUC-Rio.
> Copyright &copy; 2019 Lua.org, PUC-Rio.

72a73
> <LI><A HREF="manual.html#3.3.8">3.3.8 &ndash; To-be-closed Variables</A>

109c110
< <LI><A HREF="manual.html#6">6 &ndash; Standard Libraries</A>
> <LI><A HREF="manual.html#6">6 &ndash; The Standard Libraries</A>

131,133c132,134
< <LI><A HREF="manual.html#8.1">8.1 &ndash; Changes in the Language</A>
< <LI><A HREF="manual.html#8.2">8.2 &ndash; Changes in the Libraries</A>
< <LI><A HREF="manual.html#8.3">8.3 &ndash; Changes in the API</A>
> <LI><A HREF="manual.html#8.1">8.1 &ndash; Incompatibilities in the Language</A>
> <LI><A HREF="manual.html#8.2">8.2 &ndash; Incompatibilities in the Libraries</A>
> <LI><A HREF="manual.html#8.3">8.3 &ndash; Incompatibilities in the API</A>

169a171
> <A HREF="manual.html#pdf-warn">warn</A><BR>

175a178
> <A HREF="manual.html#pdf-coroutine.kill">coroutine.kill</A><BR>

346a350
> <A HREF="manual.html#lua_WarnFunction">lua_WarnFunction</A><BR>

431a436
> <A HREF="manual.html#lua_resetthread">lua_resetthread</A><BR>

444a450
> <A HREF="manual.html#lua_setwarnf">lua_setwarnf</A><BR>

448a455
> <A HREF="manual.html#lua_toclose">lua_toclose</A><BR>

463a471
> <A HREF="manual.html#lua_warning">lua_warning</A><BR>

477a486
> <A HREF="manual.html#luaL_addgsub">luaL_addgsub</A><BR>

483a493,494
> <A HREF="manual.html#luaL_argexpected">luaL_argexpected</A><BR>
> <A HREF="manual.html#luaL_buffaddr">luaL_buffaddr</A><BR>

485a497
> <A HREF="manual.html#luaL_bufflen">luaL_bufflen</A><BR>

532a545
> <A HREF="manual.html#luaL_typeerror">luaL_typeerror</A><BR>

554d566
< <A HREF="manual.html#pdf-LUA_ERRGCMM">LUA_ERRGCMM</A><BR>

562a575
> <A HREF="manual.html#pdf-LUAL_BUFFERSIZE">LUAL_BUFFERSIZE</A><BR>

606d618
< <A HREF="manual.html#pdf-LUAL_BUFFERSIZE">LUAL_BUFFERSIZE</A><BR>

614c626
< Mon Jun 18 17:11:17 -03 2018
> Wed May 29 08:06:44 -03 2019

617c629
< Last change: revised for Lua 5.4.0 (work2)
> Last change: revised for Lua 5.4.0 (alpha)

doc/manual.html

22c22
< Copyright &copy; 2018 Lua.org, PUC-Rio.
> Copyright &copy; 2019 Lua.org, PUC-Rio.

38c38
< <!-- $Id: manual.of,v 1.175 2018/06/18 19:17:35 roberto Exp $ -->
> <!-- $Id: manual.of $ -->

59c59
< incremental garbage collection,
> a generational garbage collection,

137c137
< it usually represents the absence of a useful value.
> it often represents the absence of a useful value.

141,149d140
< The type <em>number</em> represents both
< integer numbers and real (floating-point) numbers.
< The type <em>string</em> represents immutable sequences of bytes.
< 
< Lua is 8-bit clean:
< strings can contain any 8-bit value,
< including embedded zeros ('<code>\0</code>').
< Lua is also encoding-agnostic;
< it makes no assumptions about the contents of a string.

153,161c144,146
< The type <em>number</em> uses two internal representations,
< or two subtypes,
< one called <em>integer</em> and the other called <em>float</em>.
< Lua has explicit rules about when each representation is used,
< but it also converts between them automatically as needed (see <a href="#3.4.3">&sect;3.4.3</a>).
< Therefore,
< the programmer may choose to mostly ignore the difference
< between integers and floats
< or to assume complete control over the representation of each number.
> The type <em>number</em> represents both
> integer numbers and real (floating-point) numbers,
> using two subtypes: <em>integer</em> and <em>float</em>.

171a157,176
> Lua has explicit rules about when each subtype is used,
> but it also converts between them automatically as needed (see <a href="#3.4.3">&sect;3.4.3</a>).
> Therefore,
> the programmer may choose to mostly ignore the difference
> between integers and floats
> or to assume complete control over the representation of each number.
> 
> 
> <p>
> The type <em>string</em> represents immutable sequences of bytes.
> 
> Lua is 8-bit clean:
> strings can contain any 8-bit value,
> including embedded zeros ('<code>\0</code>').
> Lua is also encoding-agnostic;
> it makes no assumptions about the contents of a string.
> The length of any string in Lua must fit in a Lua integer.
> 
> 
> <p>

193c198,199
< This guarantees the integrity of data owned by the host program.
> This guarantees the integrity of data owned by
> the host program and C&nbsp;libraries.

210c216
< undefined or unrepresentable numerical results, such as <code>0/0</code>.)
> undefined numerical results, such as <code>0/0</code>.)

213c219
< Any key with value <b>nil</b> is not considered part of the table.
> Any key associated to the value <b>nil</b> is not considered part of the table.

249,250c255,256
< any float with integral value used as a key
< is converted to its respective integer.
> any float used as a key that is equal to an integer
> is converted to that integer.

252,256c258
< the actual key inserted into the table will be the
< integer <code>2</code>.
< (On the other hand,
< 2 and "<code>2</code>" are different Lua values and therefore
< denote different table entries.)
> the actual key inserted into the table will be the integer <code>2</code>.

270c272
< of a given value (see <a href="#6.1">&sect;6.1</a>).
> of a given value (see <a href="#pdf-type"><code>type</code></a>).

279c281
< As will be discussed in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,
> As we will discuss further in <a href="#3.2">&sect;3.2</a> and <a href="#3.3.3">&sect;3.3.3</a>,

307c309,310
< (<a href="#pdf-_G"><code>_G</code></a> is never used internally.)
> (<a href="#pdf-_G"><code>_G</code></a> is never used internally,
> so changing its value will affect only your own code.)

316c319
< (and, therefore, they are also called <em>global variables</em>).
> and, therefore, they are also called <em>global variables</em>.

379a383,390
> <p>
> Lua also offers a system of <em>warnings</em> (see <a href="#pdf-warn"><code>warn</code></a>).
> Unlike errors, warnings do not interfere
> in any way with program execution.
> They typically only generate a message to the user,
> although this behavior can be adapted from C (see <a href="#lua_setwarnf"><code>lua_setwarnf</code></a>).
> 
> 

412,413d422
< So, to retrieve the metamethod for event <code>ev</code> in object <code>o</code>,
< Lua does the equivalent to the following code:

415,417d423
< <pre>
<      rawget(getmetatable(<em>o</em>) or {}, "__<em>ev</em>")
< </pre>

422,424c428,429
< You cannot change the metatable of other types from Lua code
< (except by using the debug library (<a href="#6.10">&sect;6.10</a>));
< you should use the C&nbsp;API for that.
> You cannot change the metatable of other types from Lua code,
> except by using the debug library (<a href="#6.10">&sect;6.10</a>).

428,429c433,434
< Tables and full userdata have individual metatables
< (although multiple tables and userdata can share their metatables).
> Tables and full userdata have individual metatables,
> although multiple tables and userdata can share their metatables.

465,466c470
< If any operand for an addition is not a number
< (nor a string coercible to a number),
> If any operand for an addition is not a number,

520c524
< nor a value coercible to an integer (see <a href="#3.4.3">&sect;3.4.3</a>).
> nor a float coercible to an integer (see <a href="#3.4.3">&sect;3.4.3</a>).

589,599c593
< Unlike other operations,
< the less-equal operation can use two different events.
< First, Lua looks for the <code>__le</code> metamethod in both operands,
< like in the less than operation.
< If it cannot find such a metamethod,
< then it will try the <code>__lt</code> metamethod,
< assuming that <code>a &lt;= b</code> is equivalent to <code>not (b &lt; a)</code>.
< As with the other comparison operators,
< the result is always a boolean.
< (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.)
> Behavior similar to the less than operation.

619,620c613,614
< (This indexing is regular, not raw,
< and therefore can trigger another metamethod.)
> This indexing is regular, not raw,
> and therefore can trigger another metamethod.

638,639c632,633
< (This assignment is regular, not raw,
< and therefore can trigger another metamethod.)
> This assignment is regular, not raw,
> and therefore can trigger another metamethod.

660c654
< (This is the only metamethod that allows multiple results.)
> This is the only metamethod that allows multiple results.

706c700
< Programs that waste a large proportion of its time
> However, programs that waste a large proportion of their time

715c709
< <a href="#lua_gc"><code>lua_gc</code></a> in C
> <a href="#lua_gc"><code>lua_gc</code></a> in&nbsp;C

718c712
< the collector directly (e.g., stop and restart it).
> the collector directly (e.g., to stop and restart it).

741c735
< Values smaller than 100 mean the collector will not wait to
> Values equal to or less than 100 mean the collector will not wait to

750c744
< controls the relative speed of the collector relative to
> controls the speed of the collector relative to

757c751
< You should not use values smaller than 100,
> You should not use values less than 100,

774c768
< which makes for steps of approximately 8&nbsp;Kbytes.
> which means steps of approximately 8&nbsp;Kbytes.

826c820,822
< These metamethods are also called <em>finalizers</em>.
> These metamethods, called <em>finalizers</em>,
> are called when the garbage collector detects that the
> corresponding table or userdata is unreachable.

828,830c824,826
< with external resource management
< (such as closing files, network or database connections,
< or freeing your own memory).
> with external resource management such as closing files,
> network or database connections,
> or freeing your own memory.

845c841
< When a marked object becomes garbage,
> When a marked object becomes unreachable,

852,855c848,849
< If it is a function,
< Lua calls it with the object as its single argument;
< if the metamethod is not a function,
< Lua simply ignores it.
> If it is present,
> Lua calls it with the object as its single argument.

860c854
< the finalizers for objects are called in
> the finalizers are called in

893a888,903
> <p>
> Finalizers cannot yield.
> Except for that, they can do anything,
> such as raise errors, create new objects,
> or even run the garbage collector.
> However, because they can run in unpredictable times,
> it is good practice to restrict each finalizer
> to the minimum necessary to properly release
> its associated resource.
> 
> 
> <p>
> Any error while running a finalizer generates a warning;
> the error is not propagated.
> 
> 

950,951c960,963
< they do not have an explicit construction,
< and therefore are not removed from weak tables.
> they do not have an explicit construction and
> their equality is by value;
> they behave more like values than like objects.
> Therefore, they are not removed from weak tables.

1018c1030,1033
< plus an error object.
> plus the error object.
> In this case, the coroutine does not unwind its stack,
> so that it is possible to inspect it after the error
> with the debug API.

1046,1047c1061,1064
< <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> does not catch errors;
< any error is propagated to the caller.
> the function created by <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a>
> propagates any error to the caller.
> In this case,
> the function also kills the coroutine (see <a href="#pdf-coroutine.kill"><code>coroutine.kill</code></a>).

1124,1126c1141,1146
< It ignores spaces (including new lines) and comments
< between lexical elements (tokens),
< except as delimiters between names and keywords.
> It ignores spaces and comments between lexical elements (tokens),
> except as delimiters between two tokens.
> In source code,
> Lua recognizes as spaces the standard ASCII white-space
> characters space, form feed, newline,
> carriage return, horizontal tab, and vertical tab.

1132,1133c1152,1153
< in Lua can be any string of letters,
< digits, and underscores,
> in Lua can be any string of Latin letters,
> Arabic-Indic digits, and underscores,

1215c1235
< (note the mandatory enclosing brackets),
> (with mandatory enclosing brackets),

1217a1238,1240
> This code point can be any value less than <em>2<sup>31</sup></em>.
> (Lua uses the original UTF-8 specification here,
> which is not restricted to valid Unicode code points.)

1241a1265,1266
> When the opening long bracket is immediately followed by a newline,
> the newline is not included in the string.

1245,1247d1269
< For convenience,
< when the opening long bracket is immediately followed by a newline,
< the newline is not included in the string.

1268c1290
< and the system file functions may have problems with
> and the system's file functions may have problems with

1271c1293
< non-text data as a quoted literal with
> binary data as a quoted literal with

1284a1307,1309
> 
> 
> <p>

1288,1289c1313,1318
< if its value fits in an integer,
< it denotes an integer.
> if its value fits in an integer or it is a hexadecimal constant,
> it denotes an integer;
> otherwise (that is, a decimal integer numeral that overflows),
> it denotes a float.
> (Hexadecimal integer numerals that overflow <em>wrap around</em>;
> they always denote an integer value.)

1331c1360
< Name denotes identifiers, as defined in <a href="#3.1">&sect;3.1</a>.
> Name denotes identifiers (see <a href="#3.1">&sect;3.1</a>).

1378c1407
< similar to those in Pascal or C.
> similar to those in other conventional languages.

1380c1409
< assignments, control structures, function calls,
> blocks, assignments, control structures, function calls,

1404c1433
< Function calls and assignments
> Both function calls and assignments

1413c1442
< The grammar could see it in two ways:
> The grammar could see this fragment in two ways:

1482c1511
< see program <code>luac</code> and function <a href="#pdf-string.dump"><code>string.dump</code></a> for details.
> see the program <code>luac</code> and the function <a href="#pdf-string.dump"><code>string.dump</code></a> for details.

1514c1543
< the list is extended with as many  <b>nil</b>'s as needed.
> the list is extended with <b>nil</b>'s.

1583c1612
< (In particular, the number 0 and the empty string also test true).
> In particular, the number 0 and the empty string also test true.

1609,1611c1638
< except
< inside nested blocks where a label with the same name is defined and
< inside nested functions.
> except inside nested functions.

1613a1641,1643
> A label should not be declared
> where a label with the same name is visible,
> even if this other label has been declared in an enclosing block.

1636c1666
< (which is an anonymous function).
> (which is handled as an anonymous function).

1648c1678
< If it is really necessary to <b>return</b> in the middle of a block,
> If it is necessary to <b>return</b> in the middle of a block,

1664a1695,1697
> 
> <h4>The numerical <b>for</b> loop</h4>
> 

1667c1700
< control variable runs through an arithmetic progression.
> control variable goes through an arithmetic progression.

1673,1676c1706,1707
< The <em>block</em> is repeated for <em>name</em> starting at the value of
< the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the
< third <em>exp</em>.
< More precisely, a <b>for</b> statement like
> The given identifier (Name) defines the control variable,
> which is local to the loop body (<em>block</em>).

1678,1697d1708
< <pre>
<      for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end
< </pre><p>
< is equivalent to the code:
< 
< <pre>
<      do
<        local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>)
<        if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end
<        <em>var</em> = <em>var</em> - <em>step</em>
<        while true do
<          <em>var</em> = <em>var</em> + <em>step</em>
<          if (<em>step</em> &gt;= 0 and <em>var</em> &gt; <em>limit</em>) or (<em>step</em> &lt; 0 and <em>var</em> &lt; <em>limit</em>) then
<            break
<          end
<          local v = <em>var</em>
<          <em>block</em>
<        end
<      end
< </pre>

1700c1711,1725
< Note the following:
> The loop starts by evaluating once the three control expressions;
> they must all result in numbers.
> Their values are called respectively
> the <em>initial value</em>, the <em>limit</em>, and the <em>step</em>.
> If the step is absent, it defaults to&nbsp;1.
> Then the loop body is repeated with the value of the control variable
> going through an arithmetic progression,
> starting at the initial value,
> with a common difference given by the step,
> until that value passes the limit.
> A negative step makes a decreasing sequence;
> a step equal to zero raises an error.
> If the initial value is already greater than the limit
> (or less than, if the step is negative),
> the body is not executed.

1702d1726
< <ul>

1704,1718c1728,1734
< <li>
< All three control expressions are evaluated only once,
< before the loop starts.
< They must all result in numbers.
< </li>
< 
< <li>
< <code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables.
< The names shown here are for explanatory purposes only.
< </li>
< 
< <li>
< If the third expression (the step) is absent,
< then a step of&nbsp;1 is used.
< </li>
> <p>
> If both the initial value and the step are integers,
> the loop is done with integers;
> in this case, the range of the control variable is clipped
> by the range of integers.
> Otherwise, the loop is done with floats.
> (Beware of floating-point accuracy in this case.)

1720,1722d1735
< <li>
< You can use <b>break</b> and <b>goto</b> to exit a <b>for</b> loop.
< </li>

1724,1725c1737,1739
< <li>
< The loop variable <code>v</code> is local to the loop body.
> <p>
> You should not change the value of the control variable
> during the loop.

1728d1741
< </li>

1730,1734d1742
< <li>
< The values in <em>var</em>, <em>limit</em>, and <em>step</em>
< can be integers or floats.
< All operations on them respect the usual rules in Lua.
< </li>

1736c1744,1747
< </ul>
> 
> 
> 
> <h4>The generic <b>for</b> loop</h4>

1752c1763
<      for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>block</em> end
>      for <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> in <em>explist</em> do <em>body</em> end

1754c1765
< is equivalent to the code:
> works as follows.

1756,1767d1766
< <pre>
<      do
<        local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em>
<        while true do
<          local <em>var_1</em>, &middot;&middot;&middot;, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>)
<          if <em>var_1</em> == nil then break end
<          <em>var</em> = <em>var_1</em>
<          <em>block</em>
<        end
<      end
< </pre><p>
< Note the following:

1769c1768,1770
< <ul>
> <p>
> The names <em>var_i</em> declare loop variables local to the loop body.
> The first of these variables is the <em>control variable</em>.

1771,1773c1772,1776
< <li>
< <code><em>explist</em></code> is evaluated only once.
< Its results are an <em>iterator</em> function,
> 
> <p>
> The loop starts by evaluating <em>explist</em>
> to produce four values:
> an <em>iterator function</em>,

1775,1776c1778,1779
< and an initial value for the first <em>iterator variable</em>.
< </li>
> an initial value for the control variable,
> and a <em>closing value</em>.

1778,1781d1780
< <li>
< <code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables.
< The names are here for explanatory purposes only.
< </li>

1783,1785c1782,1804
< <li>
< You can use <b>break</b> to exit a <b>for</b> loop.
< </li>
> <p>
> Then, at each iteration,
> Lua calls the iterator function with two arguments:
> the state and the control variable.
> The results from this call are then assigned to the loop variables,
> following the rules of multiple assignments (see <a href="#3.3.3">&sect;3.3.3</a>).
> If the control variable becomes <b>nil</b>,
> the loop terminates.
> Otherwise, the body is executed and the loop goes
> to the next iteration.
> 
> 
> <p>
> The closing value behaves like a
> to-be-closed variable (see <a href="#3.3.8">&sect;3.3.8</a>),
> which can be used to release resources when the loop ends.
> Otherwise, it does not interfere with the loop.
> 
> 
> <p>
> You should not change the value of the control variable
> during the loop.
> 

1787,1792d1805
< <li>
< The loop variables <code><em>var_i</em></code> are local to the loop;
< you cannot use their values after the <b>for</b> ends.
< If you need these values,
< then assign them to other variables before breaking or exiting the loop.
< </li>

1794d1806
< </ul>

1815c1827
< The declaration can include an initial assignment:
> The declaration can include an initialization:

1819c1831
< </pre><p>
> 	stat ::=  <b>local</b> &lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo; Name &lsquo;<b>=</b>&rsquo; exp </pre><p>

1822a1835,1842
> The second syntax declares a local with a given attribute,
> which is the name between the angle brackets.
> In this case, there must be an initialization.
> There are two possible attributes:
> <code>const</code>, which declares a constant variable,
> that is, a variable that cannot be assigned to
> after its initialization;
> and <code>toclose</code>, wich declares a to-be-closed variable (see <a href="#3.3.8">&sect;3.3.8</a>).

1836a1857,1912
> <h3>3.3.8 &ndash; <a name="3.3.8">To-be-closed Variables</a></h3>
> 
> <p>
> A local variable can be declared as a <em>to-be-closed</em> variable,
> using the identifier <code>toclose</code> as its attribute:
> 
> <pre>
> 	stat ::=  <b>local</b> &lsquo;<b>&lt;</b>&rsquo; <code>toclose</code> &lsquo;<b>&gt;</b>&rsquo; Name &lsquo;<b>=</b>&rsquo; exp </pre><p>
> A to-be-closed variable behaves like a constant local variable,
> except that its value is <em>closed</em> whenever the variable
> goes out of scope, including normal block termination,
> exiting its block by <b>break</b>/<b>goto</b>/<b>return</b>,
> or exiting by an error.
> 
> 
> <p>
> Here, to <em>close</em> a value means
> to call its <code>__close</code> metamethod.
> If the value is <b>nil</b>, it is ignored;
> otherwise,
> if it does not have a <code>__close</code> metamethod,
> an error is raised.
> When calling the metamethod,
> the value itself is passed as the first argument
> and the error object (if any) is passed as a second argument;
> if there was no error, the second argument is <b>nil</b>.
> 
> 
> <p>
> If several to-be-closed variables go out of scope at the same event,
> they are closed in the reverse order that they were declared.
> If there is any error while running a closing method,
> that error is handled like an error in the regular code
> where the variable was defined;
> in particular,
> the other pending closing methods will still be called.
> 
> 
> <p>
> If a coroutine yields inside a block and is never resumed again,
> the variables visible at that block will never go out of scope,
> and therefore they will not be closed.
> Similarly, if a coroutine ends with an error,
> it does not unwind its stack,
> so it does not close any variable.
> You should either use finalizers
> or call <a href="#pdf-coroutine.kill"><code>coroutine.kill</code></a> to close the variables in these cases.
> However, note that if the coroutine was created
> through <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a>,
> then its corresponding function will close all variables
> in case of errors.
> 
> 
> 
> 
> 

1948c2024
< the operation is performed following the usual rules
> the operation is performed following the machine's rules

1967c2043
< that is, the floor of the division of its operands.
> resulting in the floor of the division of its operands.

1981c2057,2058
< that is equal modulo <em>2<sup>64</sup></em> to the mathematical result.)
> that is equal modulo <em>2<sup>n</sup></em> to the mathematical result,
> where <em>n</em> is the number of bits of the integer type.)

2049,2051c2126,2127
< The string library uses metamethods that try to coerce
< strings to numbers in all arithmetic operations.
< Any string operator is converted to an integer or a float,
> Several places in Lua coerce strings to numbers when necessary.
> A string is converted to an integer or a float

2057a2134,2146
> If the string is not a valid numeral,
> the conversion fails.
> If necessary, the result of this first step is then converted
> to the required number subtype following the previous rules
> for conversions between floats and integers.
> 
> 
> <p>
> The string library uses metamethods that try to coerce
> strings to numbers in all arithmetic operations.
> If the conversion fails,
> the library calls the metamethod of the other operand
> (if present) or it raises an error.

2063,2065c2152,2153
< For complete control over how numbers are converted to strings,
< use the <code>format</code> function from the string library
< (see <a href="#pdf-string.format"><code>string.format</code></a>).
> To convert numbers to strings in any specific way,
> use the function <a href="#pdf-string.format"><code>string.format</code></a>.

2089c2177
< Strings are compared in the obvious way.
> Strings are equal if they have the same byte content.

2098c2186
< (a table, userdata, or thread),
> (a table, a userdata, or a thread),

2100,2101c2188,2189
< A closure is always equal to itself.
< Closures with any detectable difference
> A function is always equal to itself.
> Functions with any detectable difference

2103c2191
< Closures created at different times but with no detectable differences
> Functions created at different times but with no detectable differences

2105c2193
< (depending on internal cashing details).
> (depending on internal caching details).

2128,2129c2216,2217
< then they are compared according to their mathematical values
< (regardless of their subtypes).
> then they are compared according to their mathematical values,
> regardless of their subtypes.

2140,2141c2228,2229
< NaN is considered neither smaller than,
< nor equal to, nor greater than any value (including itself).
> the special value NaN is considered neither less than,
> nor equal to, nor greater than any value, including itself.

2185,2186c2273,2275
< If both operands are strings or numbers, then they are converted to
< strings according to the rules described in <a href="#3.4.3">&sect;3.4.3</a>.
> If both operands are strings or numbers,
> then the numbers are converted to strings
> in a non-specified format (see <a href="#3.4.3">&sect;3.4.3</a>).

2200,2202c2289,2291
< The length of a string is its number of bytes
< (that is, the usual meaning of string length when each
< character is one byte).
> The length of a string is its number of bytes.
> (That is the usual meaning of string length when each
> character is one byte.)

2225a2315
> (The <b>nil</b> at index 4 is called a <em>hole</em>.)

2227c2317,2318
< has three borders (0, 3, and 6),
> has three borders (0, 3, and 6) and three holes
> (at indices 1, 4, and 5),

2307c2398
< Finally, fields of the form <code>exp</code> are equivalent to
> Fields of the form <code>exp</code> are equivalent to

2309,2310c2400,2401
< starting with 1.
< Fields in the other formats do not affect this counting.
> starting with 1;
> fields in the other formats do not affect this counting.

2363,2364c2454,2456
< Otherwise, the prefixexp <code>__call</code> metamethod is called,
< having as first argument the value of prefixexp,
> Otherwise, if present,
> the prefixexp <code>__call</code> metamethod is called:
> its first argument is the value of prefixexp,

2375c2467
< can be used to call "methods".
> can be used to emulate methods.

2400,2401c2492,2493
< A call of the form <code>return <em>functioncall</em></code> is called
< a <em>tail call</em>.
> A call of the form <code>return <em>functioncall</em></code> not in the
> scope of a to-be-closed variable is called a <em>tail call</em>.

2411,2413c2503,2507
< where the <b>return</b> has one single function call as argument;
< this syntax makes the calling function return exactly
< the returns of the called function.
> where the <b>return</b> has one single function call as argument,
> and it is outside the scope of any to-be-closed variable.
> This syntax makes the calling function return exactly
> the returns of the called function,
> without any intervening action.

2418c2512
<      return 2 * f(x)
>      return 2 * f(x)      -- result multiplied by 2

2488c2582,2583
< all its function bodies are precompiled too.
> all its function bodies are precompiled too,
> but they are not created yet.

2491c2586
< This function instance (or <em>closure</em>)
> This function instance, or <em>closure</em>,

2559c2654
< This limit is guaranteed to be larger than 1000.
> This limit is guaranteed to be greater than 1000.

2564,2565c2659,2660
< is used for defining <em>methods</em>,
< that is, functions that have an implicit extra parameter <code>self</code>.
> is used to emulate <em>methods</em>,
> adding an implicit extra parameter <code>self</code> to the function.

2720,2721c2815,2816
< A positive index represents an absolute stack position
< (starting at&nbsp;1);
> A positive index represents an absolute stack position,
> starting at&nbsp;1 as the bottom of the stack;

2797c2892
< Indices to upvalues (see <a href="#4.4">&sect;4.4</a>) larger than the real number
> Indices to upvalues (see <a href="#4.4">&sect;4.4</a>) greater than the real number

2807c2902
< without the need to first check whether there is a third argument,
> without the need to check whether there is a third argument,

2848c2943,2944
< A C&nbsp;closure can also change the values of its corresponding upvalues.
> A C&nbsp;closure can also change the values
> of its corresponding upvalues.

2860c2956
< The registry table is always located at pseudo-index
> The registry table is always accessible at pseudo-index

2878c2974,2975
< Therefore, integer keys must not be used for other purposes.
> Therefore, integer keys in the registry
> must not be used for other purposes.

2908,2909c3005,3006
< When Lua faces any error
< (such as a memory allocation error or a type error)
> When Lua faces any error,
> such as a memory allocation error or a type error,

2918c3015,3016
< Inside a C&nbsp;function you can raise an error by calling <a href="#lua_error"><code>lua_error</code></a>.
> Inside a C&nbsp;function you can raise an error explicitly
> by calling <a href="#lua_error"><code>lua_error</code></a>.

2949c3047
< (e.g., a Lua parameter to the function,
> (e.g., a Lua-state argument to the function,

2957c3055
< in particular, the error object is at the top of the stack.
> in particular, the error object is on the top of the stack.

2993c3091
< (This can happen when the callee function is <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
> This can happen when the callee function is <a href="#lua_yieldk"><code>lua_yieldk</code></a>,

2995c3093
< and the function called by them yields.)
> and the function called by them yields.

3065c3163
< the final status of the call plus the context value (<code>ctx</code>) that
> the final status of the call and the context value (<code>ctx</code>) that

3067c3165
< (Lua does not use this context value;
> Lua does not use this context value;

3069c3167
< continuation function.)
> continuation function.

3123,3124c3221,3222
< by looking only at its arguments
< (e.g., they may depend on what is on the stack).
> by looking only at its arguments.
> (For instance, they may depend on what is on the stack.)

3128,3129c3226
< '<code>m</code>' means the function may raise out-of-memory errors
< and errors running a finalizer;
> '<code>m</code>' means the function may raise only out-of-memory errors;

3131,3133c3228,3230
< '<code>e</code>' means the function may raise any errors
< (because it can run arbitrary Lua code,
< either directly or through metamethods).
> '<code>e</code>' means the function can run arbitrary Lua code,
> either directly or through metamethods,
> and therefore may raise any errors.

3193c3290
< and return <code>NULL</code>.
> and then return <code>NULL</code>.

3199c3296
< The allocator returns <code>NULL</code>
> In particular, the allocator returns <code>NULL</code>

3235c3332
< with the value at the top being the second operand,
> with the value on the top being the second operand,

3293,3295c3390,3392
< All arguments and the function value are popped from the stack
< when the function is called.
< The function results are pushed onto the stack when the function returns.
> When the function returns,
> all arguments and the function value are popped
> and the function results are pushed onto the stack.

3375c3472
< and returns the number of results.
> and returns in C the number of results.

3412,3413c3509,3510
< Ensures that the stack has space for at least <code>n</code> extra slots
< (that is, that you can safely push up to <code>n</code> values into it).
> Ensures that the stack has space for at least <code>n</code> extra slots,
> that is, that you can safely push up to <code>n</code> values into it.

3416c3513
< to be larger than a fixed maximum size
> to be greater than a fixed maximum size

3434a3532,3534
> 
> 
> <p>

3479c3579
< pops them, and leaves the result at the top.
> pops them, and leaves the result on the top.

3515c3615
< This preallocation is useful for performance when you know in advance
> This preallocation may help performance when you know in advance

3568c3668
< using the value at the top of the stack as the error object.
> using the value on the top of the stack as the error object.

3578c3678
< <span class="apii">[-0, +0, <em>v</em>]</span>
> <span class="apii">[-0, +0, &ndash;]</span>

3638,3641d3737
< <p>
< This function may raise errors when calling finalizers.
< 
< 

3752c3848
< and <code>k</code> is the value at the top of the stack.
> and <code>k</code> is the value on the top of the stack.

4079,4084d4174
< <li><b><a href="#pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b>
< error while running a <code>__gc</code> metamethod.
< (This error has no relation with the chunk being loaded.
< It is generated by the garbage collector.)
< </li>
< 

4129,4130c4219,4220
< Creates a new thread running in a new, independent state.
< Returns <code>NULL</code> if it cannot create the thread or the state
> Creates a new independent state and returns its main thread.
> Returns <code>NULL</code> if it cannot create the state

4133c4223
< Lua does all memory allocation for this state
> Lua will do all memory allocation for this state

4181c4271
< with <code>nuvalue</code> associated Lua values (called <code>user values</code>)
> with <code>nuvalue</code> associated Lua values, called <code>user values</code>,

4200,4201c4290,4291
< and pushes a key&ndash;value pair from the table at the given index
< (the "next" pair after the given key).
> and pushes a key&ndash;value pair from the table at the given index,
> the "next" pair after the given key.

4203c4293
< then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing).
> then <a href="#lua_next"><code>lua_next</code></a> returns 0 and pushes nothing.

4207c4297
< A typical traversal looks like this:
> A typical table traversal looks like this:

4224c4314
< do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,
> avoid calling <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,

4261,4262c4351,4352
< Converts a Lua float to a Lua integer.
< This macro assumes that <code>n</code> has an integral value.
> Tries to convert a Lua float to a Lua integer;
> the float <code>n</code> must have an integral value.

4268,4269c4358
< correctly without this macro,
< due to roundings.)
> correctly without this macro, due to rounding.)

4309c4398
< this function will be called with the error object
> this handler will be called with the error object

4343,4349d4431
< <li><b><a name="pdf-LUA_ERRGCMM"><code>LUA_ERRGCMM</code></a>: </b>
< error while running a <code>__gc</code> metamethod.
< For such errors, Lua does not call the message handler
< (as this kind of error typically has no relation
< with the function being called).
< </li>
< 

4416,4420c4498,4503
< thus creating a C&nbsp;closure (see <a href="#4.4">&sect;4.4</a>);
< these values are then accessible to the function whenever it is called.
< To associate values with a C&nbsp;function,
< first these values must be pushed onto the stack
< (when there are multiple values, the first value is pushed first).
> the so called upvalues;
> these upvalues are then accessible to the function whenever it is called.
> This association is called a C&nbsp;closure (see <a href="#4.4">&sect;4.4</a>).
> To create a C&nbsp;closure,
> first the initial values for its upvalues must be pushed onto the stack.
> (When there are multiple upvalues, the first value is pushed first.)

4447a4531
> This function is equivalent to <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> with no upvalues.

4474c4558
< '<code>%p</code>' (inserts a pointer as a hexadecimal numeral),
> '<code>%p</code>' (inserts a pointer),

4537a4622
> (Lua may optimize this case.)

4550c4635
< Lua makes (or reuses) an internal copy of the given string,
> Lua will make or reuse an internal copy of the given string,

4593c4678
< Lua makes (or reuses) an internal copy of the given string,
> Lua will make or reuse an internal copy of the given string,

4654c4739
< (that is, without calling the <code>__eq</code> metamethod).
> (that is, equal without calling the <code>__eq</code> metamethod).

4721,4722c4806,4807
< for the userdata;
< for other values, it is&nbsp;0.
> for the userdata.
> For other values, this call returns&nbsp;0.

4747c4832
< and <code>v</code> is the value at the top of the stack.
> and <code>v</code> is the value on the top of the stack.

4767c4852
< and <code>v</code> is the value at the top of the stack.
> and <code>v</code> is the value on the top of the stack.

4786,4787c4871,4872
< Every time it needs another piece of the chunk,
< <a href="#lua_load"><code>lua_load</code></a> calls the reader,
> Every time <a href="#lua_load"><code>lua_load</code></a> needs another piece of the chunk,
> it calls the reader,

4844a4930,4946
> <hr><h3><a name="lua_resetthread"><code>lua_resetthread</code></a></h3><p>
> <span class="apii">[-0, +?, &ndash;]</span>
> <pre>int lua_resetthread (lua_State *L);</pre>
> 
> <p>
> Resets a thread, cleaning its call stack and closing all pending
> to-be-closed variables.
> Returns a status code:
> <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> for no errors in closing methods,
> or an error status otherwise.
> In case of error,
> leave the error object on the stack,
> 
> 
> 
> 
> 

4861c4963
< <code>nresults</code> is updated and
> <code>*nresults</code> is updated and

4863c4965
< the <code>nresults</code> values passed to <a href="#lua_yield"><code>lua_yield</code></a>
> the <code>*nresults</code> values passed to <a href="#lua_yield"><code>lua_yield</code></a>

4870,4872d4971
< 
< 
< <p>

4874,4876c4973
< the stack is not unwound,
< so you can use the debug API over it.
< The error object is on the top of the stack.
> the error object is on the top of the stack.

4880,4883c4977,4978
< To resume a coroutine,
< you remove all results from the last <a href="#lua_yield"><code>lua_yield</code></a>,
< put on its stack only the values to
< be passed as results from <code>yield</code>,
> To resume a coroutine, you clear its stack,
> push only the values to be passed as results from <code>yield</code>,

4935c5030
< and <code>v</code> is the value at the top of the stack.
> and <code>v</code> is the value on the top of the stack.

4966c5061
< and <code>v</code> is the value at the top of the stack.
> and <code>v</code> is the value on the top of the stack.

4977a5073,5086
> <hr><h3><a name="lua_setiuservalue"><code>lua_setiuservalue</code></a></h3><p>
> <span class="apii">[-1, +0, &ndash;]</span>
> <pre>int lua_setiuservalue (lua_State *L, int index, int n);</pre>
> 
> <p>
> Pops a value from the stack and sets it as
> the new <code>n</code>-th user value associated to the
> full userdata at the given index.
> Returns 0 if the userdata does not have that value.
> 
> 
> 
> 
> 

4997c5106
< <code>v</code> is the value at the top of the stack,
> <code>v</code> is the value on the top of the stack,

5017c5126
< If the new top is larger than the old one,
> If the new top is greater than the old one,

5025,5027c5134,5136
< <hr><h3><a name="lua_setiuservalue"><code>lua_setiuservalue</code></a></h3><p>
< <span class="apii">[-1, +0, &ndash;]</span>
< <pre>int lua_setiuservalue (lua_State *L, int index, int n);</pre>
> <hr><h3><a name="lua_setwarnf"><code>lua_setwarnf</code></a></h3><p>
> <span class="apii">[-0, +0, &ndash;]</span>
> <pre>void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud);</pre>

5030,5033c5139,5142
< Pops a value from the stack and sets it as
< the new <code>n</code>-th user value associated to the
< full userdata at the given index.
< Returns 0 if the userdata does not have that value.
> Sets the warning function to be used by Lua to emit warnings
> (see <a href="#lua_WarnFunction"><code>lua_WarnFunction</code></a>).
> The <code>ud</code> parameter sets the value <code>ud</code> passed to
> the warning function.

5068c5177
< The status can be 0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) for a normal thread,
> The status can be <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> for a normal thread,

5075c5184
< You can only call functions in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.
> You can call functions only in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.

5135a5245,5277
> <hr><h3><a name="lua_toclose"><code>lua_toclose</code></a></h3><p>
> <span class="apii">[-0, +0, <em>v</em>]</span>
> <pre>void lua_toclose (lua_State *L, int index);</pre>
> 
> <p>
> Marks the given index in the stack as a
> to-be-closed "variable" (see <a href="#3.3.8">&sect;3.3.8</a>).
> Like a to-be-closed variable in Lua,
> the value at that index in the stack will be closed
> when it goes out of scope.
> Here, in the context of a C function,
> to go out of scope means that the running function returns to Lua,
> there is an error,
> or the index is removed from the stack through
> <a href="#lua_settop"><code>lua_settop</code></a> or <a href="#lua_pop"><code>lua_pop</code></a>.
> An index marked as to-be-closed should not be removed from the stack
> by any other function in the API except <a href="#lua_settop"><code>lua_settop</code></a> or <a href="#lua_pop"><code>lua_pop</code></a>.
> 
> 
> <p>
> This function should not be called for an index
> that is equal to or below an already marked to-be-closed index.
> 
> 
> <p>
> This function can raise an out-of-memory error.
> In that case, the value in the given index is immediately closed,
> as if it was already marked.
> 
> 
> 
> 
> 

5241c5383
< The value can be a userdata, a table, a thread, or a function;
> The value can be a userdata, a table, a thread, a string, or a function;

5287c5429
< returns its pointer.
> returns its value (a pointer).

5300c5442
< or <code>LUA_TNONE</code> for a non-valid (but acceptable) index.
> or <code>LUA_TNONE</code> for a non-valid but acceptable index.

5346a5489
> <code>i</code> must be in the range <em>[1,256]</em>.

5362a5506,5534
> <hr><h3><a name="lua_WarnFunction"><code>lua_WarnFunction</code></a></h3>
> <pre>typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);</pre>
> 
> <p>
> The type of warning functions, called by Lua to emit warnings.
> The first parameter is an opaque pointer
> set by <a href="#lua_setwarnf"><code>lua_setwarnf</code></a>.
> The second parameter is the warning message.
> The third parameter is a boolean that
> indicates whether the message is
> to be continued by the message in the next call.
> 
> 
> 
> 
> 
> <hr><h3><a name="lua_warning"><code>lua_warning</code></a></h3><p>
> <span class="apii">[-0, +0, &ndash;]</span>
> <pre>void lua_warning (lua_State *L, const char *msg, int tocont);</pre>
> 
> <p>
> Emits a warning with the given message.
> A message in a call with <code>tocont</code> true should be
> continued in another call to this function.
> 
> 
> 
> 
> 

5371,5372c5543,5544
< Every time it produces another piece of chunk,
< <a href="#lua_dump"><code>lua_dump</code></a> calls the writer,
> Every time <a href="#lua_dump"><code>lua_dump</code></a> produces another piece of chunk,
> it calls the writer,

5375c5547
< and the <code>data</code> parameter supplied to <a href="#lua_dump"><code>lua_dump</code></a>.
> and the <code>ud</code> parameter supplied to <a href="#lua_dump"><code>lua_dump</code></a>.

5472c5644
< (what is called a <em>C-call boundary</em>,
> (what is called a <em>C-call boundary</em>),

5500a5673
>   size_t srclen;              /* (S) */

5521c5694
< call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.
> you must call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.

5530c5703
< the name of the chunk that created the function.
> the source of the chunk that created the function.

5540a5714,5717
> <li><b><code>srclen</code>: </b>
> The length of the string <code>source</code>.
> </li>
> 

5741c5918,5919
< This function returns 0 if given an invalid option in <code>what</code>.
> This function returns 0 to signal an invalid option in <code>what</code>;
> even then the valid options are handled correctly.

5773c5951
< to be inspected must be at the top of the stack.
> to be inspected must be on the top of the stack.

5803,5805c5981,5983
< When there are no errors, <a href="#lua_getstack"><code>lua_getstack</code></a> returns 1;
< when called with a level greater than the stack depth,
< it returns 0.
> When called with a level greater than the stack depth,
> <a href="#lua_getstack"><code>lua_getstack</code></a> returns 0;
> otherwise it returns 1.

5832,5837d6009
< <p>
< Upvalues have no particular order,
< as they are active through the whole function.
< They are numbered in an arbitrary order.
< 
< 

5918,5919d6089
< There is no standard way to access the values
< to be returned by the function.

5925c6095
< (This event only happens while Lua is executing a Lua function.)
> This event only happens while Lua is executing a Lua function.

5930c6100
< (This event only happens while Lua is executing a Lua function.)
> This event only happens while Lua is executing a Lua function.

5936c6106
< A hook is disabled by setting <code>mask</code> to zero.
> Hooks are disabled by setting <code>mask</code> to zero.

5948c6118
< It assigns the value at the top of the stack
> It assigns the value on the top of the stack

5960c6130
< Parameters <code>ar</code> and <code>n</code> are as in function <a href="#lua_getlocal"><code>lua_getlocal</code></a>.
> Parameters <code>ar</code> and <code>n</code> are as in the function <a href="#lua_getlocal"><code>lua_getlocal</code></a>.

5972c6142
< It assigns the value at the top of the stack
> It assigns the value on the top of the stack

5983c6153,6154
< Parameters <code>funcindex</code> and <code>n</code> are as in function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>.
> Parameters <code>funcindex</code> and <code>n</code> are as in
> the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>.

6007c6178,6179
< Parameters <code>funcindex</code> and <code>n</code> are as in function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>,
> Parameters <code>funcindex</code> and <code>n</code> are as in
> the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>,

6096a6269,6283
> <hr><h3><a name="luaL_addgsub"><code>luaL_addgsub</code></a></h3><p>
> <span class="apii">[-0, +0, <em>m</em>]</span>
> <pre>const void luaL_addgsub (luaL_Buffer *B, const char *s,
>                          const char *p, const char *r);</pre>
> 
> <p>
> Adds a copy of the string <code>s</code> to the buffer <code>B</code>,
> replacing any occurrence of the string <code>p</code>
> with the string <code>r</code>.
> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
> 
> 
> 
> 
> 

6142c6329
< Adds the value at the top of the stack
> Adds the value on the top of the stack

6190a6378,6393
> <hr><h3><a name="luaL_argexpected"><code>luaL_argexpected</code></a></h3><p>
> <span class="apii">[-0, +0, <em>v</em>]</span>
> <pre>void luaL_argexpected (lua_State *L,
>                        int cond,
>                        int arg,
>                        const char *tname);</pre>
> 
> <p>
> Checks whether <code>cond</code> is true.
> If it is not, raises an error about the type of the argument <code>arg</code>
> with a standard message (see <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>).
> 
> 
> 
> 
> 

6221c6424
< If you know beforehand the total size of the resulting string,
> If you know beforehand the maximum size of the resulting string,

6236c6439,6440
< copied into that space.
> copied into that space (which may be less than or
> equal to the preallocated size).

6253,6254c6457,6458
< After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a> the stack is back to its
< level when the buffer was initialized,
> After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a>,
> the stack is back to its level when the buffer was initialized,

6260a6465,6477
> <hr><h3><a name="luaL_buffaddr"><code>luaL_buffaddr</code></a></h3><p>
> <span class="apii">[-0, +0, &ndash;]</span>
> <pre>char *luaL_buffaddr (luaL_Buffer *B);</pre>
> 
> <p>
> Returns the address of the current contents of buffer <code>B</code>.
> Note that any addition to the buffer may invalidate this address.
> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
> 
> 
> 
> 
> 

6274a6492,6503
> <hr><h3><a name="luaL_bufflen"><code>luaL_bufflen</code></a></h3><p>
> <span class="apii">[-0, +0, &ndash;]</span>
> <pre>size_t luaL_bufflen (luaL_Buffer *B);</pre>
> 
> <p>
> Returns the length of the current contents of buffer <code>B</code>.
> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
> 
> 
> 
> 
> 

6302c6531
< this function returns false (without pushing any value on the stack).
> this function returns false without pushing any value on the stack.

6327c6556
< and returns this integer cast to a <a href="#lua_Integer"><code>lua_Integer</code></a>.
> and returns this integer.

6340c6569
< if <code>l</code> is not <code>NULL</code> fills <code>*l</code>
> if <code>l</code> is not <code>NULL</code> fills its referent

6358c6587
< and returns this number.
> and returns this number converted to a <code>lua_Number</code>.

6601,6602c6830,6831
< Creates a copy of string <code>s</code> by replacing
< any occurrence of the string <code>p</code>
> Creates a copy of string <code>s</code>,
> replacing any occurrence of the string <code>p</code>

6619c6848
< (This case only can happen through metamethods.)
> (This case can only happen through metamethods.)

6657c6886
< The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>.
> The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.

6689c6918
< The string <code>mode</code> works as in function <a href="#lua_load"><code>lua_load</code></a>.
> The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.

6735c6964
< the functions in list <code>l</code>.
> the functions in the list <code>l</code>.

6788c7017,7018
< In both cases pushes onto the stack the final value associated
> In both cases,
> the function pushes onto the stack the final value associated

6802,6805c7032,7034
< allocator based on the standard&nbsp;C <code>realloc</code> function
< and then sets a panic function (see <a href="#4.6">&sect;4.6</a>) that prints
< an error message to the standard error output in case of fatal
< errors.
> allocator based on the standard&nbsp;C allocation functions
> and then sets a warning function and a panic function (see <a href="#4.6">&sect;4.6</a>)
> that print messages to the standard error output.

6841c7070
< parameters.
> arguments.

6856c7085
< (or convertible to an integer),
> (or it is convertible to an integer),

6883c7112
< fills the position <code>*l</code> with the result's length.
> fills its referent with the result's length.

6903c7132
< returns this number.
> returns this number as a <code>lua_Number</code>.

6987c7216
< for the object at the top of the stack (and pops the object).
> for the object on the top of the stack (and pops the object).

6992c7221
< As long as you do not manually add integer keys into table <code>t</code>,
> As long as you do not manually add integer keys into the table <code>t</code>,

6994c7223
< You can retrieve an object referred by reference <code>r</code>
> You can retrieve an object referred by the reference <code>r</code>

6996c7225
< Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object.
> The function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference.

7000c7229
< If the object at the top of the stack is <b>nil</b>,
> If the object on the top of the stack is <b>nil</b>,

7034c7263
< calls function <code>openf</code> with string <code>modname</code> as an argument
> calls the function <code>openf</code> with the string <code>modname</code> as an argument

7041c7270
< also stores the module into global <code>modname</code>.
> also stores the module into the global <code>modname</code>.

7078c7307
< Sets the metatable of the object at the top of the stack
> Sets the metatable of the object on the top of the stack

7093,7094c7322,7323
< The standard representation for file handles,
< which is used by the standard I/O library.
> The standard representation for file handles
> used by the standard I/O library.

7108c7337
< Field <code>f</code> points to the corresponding C stream
> The field <code>f</code> points to the corresponding C stream

7110c7339
< Field <code>closef</code> points to a Lua function
> The field <code>closef</code> points to a Lua function

7114,7115c7343,7344
< must return either <b>true</b> (in case of success)
< or <b>nil</b> plus an error message (in case of error).
> must return either <b>true</b>, in case of success,
> or <b>nil</b> plus an error message, in case of error.

7167c7396
< If <code>msg</code> is not <code>NULL</code> it is appended
> If <code>msg</code> is not <code>NULL</code>, it is appended

7175a7405,7421
> <hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p>
> <span class="apii">[-0, +0, <em>v</em>]</span>
> <pre>const char *luaL_typeerror (lua_State *L,
>                                       int arg,
>                                       const char *tname);</pre>
> 
> <p>
> Raises a type error for the argument <code>arg</code>
> of the C&nbsp;function that called it,
> using a standard message;
> <code>tname</code> is a "name" for the expected type.
> This function never returns.
> 
> 
> 
> 
> 

7192c7438
< Releases reference <code>ref</code> from the table at index <code>t</code>
> Releases the reference <code>ref</code> from the table at index <code>t</code>

7233c7479
< <h1>6 &ndash; <a name="6">Standard Libraries</a></h1>
> <h1>6 &ndash; <a name="6">The Standard Libraries</a></h1>

7237c7483
< that are implemented directly through the C&nbsp;API.
> that are implemented in&nbsp;C through the C&nbsp;API.

7240c7486
< others provide access to "outside" services (e.g., I/O);
> others provide access to outside services (e.g., I/O);

7242c7488
< but are quite useful or have critical performance requirements that
> but that for different reasons

7298c7544
< <a name="pdf-luaopen_utf8"><code>luaopen_utf8</code></a> (for the UTF8 library),
> <a name="pdf-luaopen_utf8"><code>luaopen_utf8</code></a> (for the UTF-8 library),

7361,7362c7607
< gives the exact number of bytes in use by Lua
< (except for overflows).
> gives the exact number of bytes in use by Lua.

7387a7633
> A zero means to not change that value.

7394a7641
> A zero means to not change that value.

7402c7649,7652
< </ul>
> </ul><p>
> See <a href="#2.5">&sect;2.5</a> for more details about garbage collection
> and some of these options.
> 

7413c7663,7664
< to its caller (that is, <code>dofile</code> does not run in protected mode).
> to its caller.
> (That is, <code>dofile</code> does not run in protected mode.)

7422c7673
< Function <code>error</code> never returns.
> This function never returns.

7506,7511c7757
< If the resulting function has upvalues,
< the first upvalue is set to the value of <code>env</code>,
< if that parameter is given,
< or to the value of the global environment.
< Other upvalues are initialized with <b>nil</b>.
< (When you load a main chunk,
> When you load a main chunk,

7516c7762,7773
< the resulting function can have an arbitrary number of upvalues.)
> the resulting function can have an arbitrary number of upvalues,
> and there is no guarantee that its first upvalue will be
> the <code>_ENV</code> variable.
> (A non-main function may not even have an <code>_ENV</code> upvalue.)
> 
> 
> <p>
> Regardless, if the resulting function has any upvalues,
> its first upvalue is set to the value of <code>env</code>,
> if that parameter is given,
> or to the value of the global environment.
> Other upvalues are initialized with <b>nil</b>.

7567c7824
< <code>next</code> returns the next index of the table
> A call to <code>next</code> returns the next index of the table

7630c7887
< Calls function <code>f</code> with
> Calls the function <code>f</code> with

7639c7896
< In case of any error, <code>pcall</code> returns <b>false</b> plus the error message.
> In case of any error, <code>pcall</code> returns <b>false</b> plus the error object.

7648,7649c7905,7910
< using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert each argument to a string.
< <code>print</code> is not intended for formatted output,
> converting each argument to a string
> following the same rules of <a href="#pdf-tostring"><code>tostring</code></a>.
> 
> 
> <p>
> The function <code>print</code> is not intended for formatted output,

7722,7723d7982
< (To change the metatable of other types from Lua code,
< you must use the debug library (<a href="#6.10">&sect;6.10</a>).)

7733a7993,7997
> <p>
> To change the metatable of other types from Lua code,
> you must use the debug library (<a href="#6.10">&sect;6.10</a>).
> 
> 

7752c8016
< (The string may have leading and trailing spaces and a sign.)
> The string may have leading and trailing spaces and a sign.

7814a8079,8091
> <hr><h3><a name="pdf-warn"><code>warn (message [, tocont])</code></a></h3>
> 
> 
> <p>
> Emits a warning with the given message.
> A message in a call with <code>tocont</code> true should be
> continued in another call to this function.
> The default for <code>tocont</code> is false.
> 
> 
> 
> 
> <p>

7850c8127
< <hr><h3><a name="pdf-coroutine.isyieldable"><code>coroutine.isyieldable ()</code></a></h3>
> <hr><h3><a name="pdf-coroutine.isyieldable"><code>coroutine.isyieldable ([co])</code></a></h3>

7854c8131,8132
< Returns true when the running coroutine can yield.
> Returns true when the coroutine <code>co</code> can yield.
> The default for <code>co</code> is the running coroutine.

7858c8136
< A running coroutine is yieldable if it is not the main thread and
> A coroutine is yieldable if it is not the main thread and

7864a8143,8157
> <hr><h3><a name="pdf-coroutine.kill"><code>coroutine.kill (co)</code></a></h3>
> 
> 
> <p>
> Kills coroutine <code>co</code>,
> closing all its pending to-be-closed variables
> and putting the coroutine in a dead state.
> In case of error closing some variable,
> returns <b>false</b> plus the error object;
> otherwise returns <b>true</b>.
> 
> 
> 
> 
> <p>

7907c8200
< Returns the status of coroutine <code>co</code>, as a string:
> Returns the status of the coroutine <code>co</code>, as a string:

7925c8218
< Creates a new coroutine, with body <code>f</code>.
> Creates a new coroutine, with body <code>f</code>;

7928c8221
< Any arguments passed to the function behave as the
> Any arguments passed to this function behave as the

7930c8223
< Returns the same values returned by <code>resume</code>,
> The function returns the same values returned by <code>resume</code>,

7932c8225,8226
< In case of error, propagates the error.
> In case of error,
> the function kills the coroutine and propagates the error.

7958c8252
< Everything else is exported in a table <a name="pdf-package"><code>package</code></a>.
> Everything else is exported in the table <a name="pdf-package"><code>package</code></a>.

7970a8265,8266
> (The absence of a second result in this case
> signals that this call did not have to load the module.)

7976,7977c8272,8275
< <code>require</code> is guided by the <a href="#pdf-package.searchers"><code>package.searchers</code></a> sequence.
< By changing this sequence,
> <code>require</code> is guided by the table <a href="#pdf-package.searchers"><code>package.searchers</code></a>.
> Each item in this table is a search function,
> that searches for the module in a particular way.
> By changing this table,

7998,8000c8296,8303
< <code>modname</code> and an extra value dependent on how it got the loader.
< (If the loader came from a file,
< this extra value is the file name.)
> <code>modname</code> and an extra value,
> a <em>loader data</em>,
> also returned by the searcher.
> The loader data can be any value useful to the module;
> for the default searchers,
> it indicates where the loader was found.
> (For instance, if the loader came from a file,
> this extra value is the file path.)

8007a8311,8313
> Besides that value, <code>require</code> also returns as a second result
> the loader data returned by the searcher,
> which indicates how <code>require</code> found the module.

8143c8449
< Any "<code>;;</code>" in the value of the environment variable
> A "<code>;;</code>" in the value of the environment variable

8171c8477
< A table used by <a href="#pdf-require"><code>require</code></a> to control how to load modules.
> A table used by <a href="#pdf-require"><code>require</code></a> to control how to find modules.

8179,8182c8485,8492
< sole parameter.
< The function can return another function (the module <em>loader</em>)
< plus an extra value that will be passed to that loader,
< or a string explaining why it did not find that module
> sole argument.
> If the searcher finds the module,
> it returns another function, the module <em>loader</em>,
> plus an extra value, a <em>loader data</em>,
> that will be passed to that loader and
> returned as a second result by <a href="#pdf-require"><code>require</code></a>.
> If it cannot find the module,
> it returns a string explaining why

8245c8555
< the file name where the module was found,
> the file path where the module was found,

8247c8557,8563
< The first searcher returns no extra value.
> The first searcher always returns the string "<code>:preload:</code>".
> 
> 
> <p>
> Searchers should raise no errors and have no side effects in Lua.
> (They may have side effects in C,
> for instance by linking the application with a library.)

8372,8373c8688,8691
< those upvalues receive fresh instances containing <b>nil</b>.
< (You can use the debug library to serialize
> those upvalues receive fresh instances.
> (See the <a href="#pdf-load"><code>load</code></a> function for details about
> how these upvalues are initialized.
> You can use the debug library to serialize

8415c8733,8734
< following the description given in its first argument (which must be a string).
> following the description given in its first argument,
> which must be a string.

8417,8420c8736,8738
< The only differences are that the options/modifiers
< <code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, <code>n</code>,
< and <code>p</code> are not supported
< and that there is an extra option, <code>q</code>.
> The only differences are that the conversion specifiers and modifiers
> <code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, and <code>n</code> are not supported
> and that there is an extra specifier, <code>q</code>.

8424c8742
< The <code>q</code> option formats booleans, nil, numbers, and strings
> The specifier <code>q</code> formats booleans, nil, numbers, and strings

8443c8761,8763
< </pre>
> </pre><p>
> This specifier does not support modifiers (flags, width, length).
> 

8446c8766
< Options
> The conversion specifiers

8449c8769
< Options <code>c</code>, <code>d</code>,
> The specifiers <code>c</code>, <code>d</code>,

8453,8454c8773,8774
< options <code>A</code> and <code>a</code> (hexadecimal floats)
< do not support any modifier (flags, width, length).
> the specifiers <code>A</code> and <code>a</code> (hexadecimal floats)
> do not support modifiers.

8458c8778
< Option <code>s</code> expects a string;
> The specifier <code>s</code> expects a string;

8461,8462c8781,8792
< If the option has any modifier (flags, width, length),
< the string argument should not contain embedded zeros.
> If the specifier has any modifier,
> the corresponding string argument should not contain embedded zeros.
> 
> 
> <p>
> The specifier <code>p</code> formats the pointer
> returned by <a href="#lua_topointer"><code>lua_topointer</code></a>.
> That gives a unique string identifier for tables, userdata,
> threads, strings, and functions.
> For other values (numbers, nil, booleans),
> this specifier results in a string representing
> the pointer <code>NULL</code>.

8468c8798
< <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern)</code></a></h3>
> <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern [, init])</code></a></h3>

8474a8805,8807
> A third, optional numeric argument <code>init</code> specifies
> where to start the search;
> its default value is&nbsp;1 and can be negative.

8523,8525c8856,8858
< stands for the value of the <em>d</em>-th captured substring.
< The sequence <code>%0</code> stands for the whole match.
< The sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.
> stands for the value of the <em>d</em>-th captured substring;
> the sequence <code>%0</code> stands for the whole match;
> the sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.

8583a8917,8919
> 
> 
> <p>

8593a8930,8932
> 
> 
> <p>

8603a8943,8945
> 
> 
> <p>

8605c8947
< <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) in the string <code>s</code>.
> the <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) in the string <code>s</code>.

8624c8966
< packed (that is, serialized in binary form)
> serialized in binary form (packed)

8644a8987,8989
> 
> 
> <p>

8660a9006,9008
> 
> 
> <p>

8667a9016,9018
> 
> 
> <p>

8710a9062,9064
> 
> 
> <p>

8773,8774c9127
< can be preceded by a '<code>%</code>'
< when used to represent itself in a pattern.
> can be preceded by a '<code>%</code>' to represent itself in a pattern.

8839c9192
< which matches zero or more repetitions of characters in the class.
> which matches sequences of zero or more characters in the class.

8845c9198
< which matches one or more repetitions of characters in the class.
> which matches sequences of one or more characters in the class.

8851c9204
< which also matches zero or more repetitions of characters in the class.
> which also matches sequences of zero or more characters in the class.

8915c9268
< stored as the first capture (and therefore has number&nbsp;1);
> stored as the first capture, and therefore has number&nbsp;1;

8935c9288
< if it ends at least one byte after the previous match.
> if it ends at least one byte after the end of the previous match.

8942c9295
<      &gt; string.gsub("abc", "()a*()", print)
>      &gt; string.gsub("abc", "()a*()", print);

9007,9008c9360,9361
< each option corresponds to an argument (in <a href="#pdf-string.pack"><code>string.pack</code></a>)
< or a result (in <a href="#pdf-string.unpack"><code>string.unpack</code></a>).
> each option corresponds to an argument in <a href="#pdf-string.pack"><code>string.pack</code></a>
> or a result in <a href="#pdf-string.unpack"><code>string.unpack</code></a>.

9016a9370,9371
> For the unsigned options,
> Lua integers are treated as unsigned values too.

9026a9382,9388
> Native endianness assumes that the whole system is
> either big or little endian.
> The packing functions will not emulate correctly the behavior
> of mixed-endian formats.
> 
> 
> <p>

9039c9401
< (and ignored by <a href="#pdf-string.unpack"><code>string.unpack</code></a>).
> and ignored by <a href="#pdf-string.unpack"><code>string.unpack</code></a>.

9067a9430,9448
> Functions that create byte sequences
> accept all values up to <code>0x7FFFFFFF</code>,
> as defined in the original UTF-8 specification;
> that implies byte sequences of up to six bytes.
> 
> 
> <p>
> Functions that interpret byte sequences only accept
> valid sequences (well formed and not overlong).
> By default, they only accept byte sequences
> that result in valid Unicode code points,
> rejecting values greater than <code>10FFFF</code> and surrogates.
> A boolean argument <code>lax</code>, when available,
> lifts these checks,
> so that all values up to <code>0x7FFFFFFF</code> are accepted.
> (Not well formed and overlong sequences are still rejected.)
> 
> 
> <p>

9068a9450,9452
> 
> 
> <p>

9078c9462,9465
< The pattern (a string, not a function) "<code>[\0-\x7F\xC2-\xF4][\x80-\xBF]*</code>"
> 
> 
> <p>
> The pattern (a string, not a function) "<code>[\0-\x7F\xC2-\xFD][\x80-\xBF]*</code>"

9087c9474
< <hr><h3><a name="pdf-utf8.codes"><code>utf8.codes (s)</code></a></h3>
> <hr><h3><a name="pdf-utf8.codes"><code>utf8.codes (s [, lax])</code></a></h3>

9096c9483
< will iterate over all characters in string <code>s</code>,
> will iterate over all UTF-8 characters in string <code>s</code>,

9105,9106c9492,9496
< <hr><h3><a name="pdf-utf8.codepoint"><code>utf8.codepoint (s [, i [, j]])</code></a></h3>
< Returns the codepoints (as integers) from all characters in <code>s</code>
> <hr><h3><a name="pdf-utf8.codepoint"><code>utf8.codepoint (s [, i [, j [, lax]]])</code></a></h3>
> 
> 
> <p>
> Returns the code points (as integers) from all characters in <code>s</code>

9115c9505,9508
< <hr><h3><a name="pdf-utf8.len"><code>utf8.len (s [, i [, j]])</code></a></h3>
> <hr><h3><a name="pdf-utf8.len"><code>utf8.len (s [, i [, j [, lax]]])</code></a></h3>
> 
> 
> <p>

9126a9520,9522
> 
> 
> <p>

9194c9590
< of list <code>t</code>.
> of the list <code>t</code>.

9204c9600
< Moves elements from table <code>a1</code> to table <code>a2</code>,
> Moves elements from the table <code>a1</code> to the table <code>a2</code>,

9250c9646
< of list <code>l</code>.
> of the list <code>l</code>.

9260c9656
< Sorts list elements in a given order, <em>in-place</em>,
> Sorts the list elements in a given order, <em>in-place</em>,

9314,9315c9710,9711
< Rounding functions
< (<a href="#pdf-math.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a href="#pdf-math.modf"><code>math.modf</code></a>)
> the rounding functions
> <a href="#pdf-math.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a href="#pdf-math.modf"><code>math.modf</code></a>

9325c9721
< Returns the absolute value of <code>x</code>. (integer/float)
> Returns the maximum value between <code>x</code> and <code>-x</code>. (integer/float)

9357c9753
< but uses the signs of both parameters to find the
> but uses the signs of both arguments to find the

9359c9755
< (It also handles correctly the case of <code>x</code> being zero.)
> It also handles correctly the case of <code>x</code> being zero.

9375c9771
< Returns the smallest integral value larger than or equal to <code>x</code>.
> Returns the smallest integral value greater than or equal to <code>x</code>.

9416c9812
< Returns the largest integral value smaller than or equal to <code>x</code>.
> Returns the largest integral value less than or equal to <code>x</code>.

9438c9834
< a value larger than any other numeric value.
> a value greater than any other numeric value.

9461c9857
< according to the Lua operator <code>&lt;</code>. (integer/float)
> according to the Lua operator <code>&lt;</code>.

9479c9875
< according to the Lua operator <code>&lt;</code>. (integer/float)
> according to the Lua operator <code>&lt;</code>.

9540,9541c9936,9937
< Lua initializes its pseudo-random generator with
< a weak attempt for ``randomness'',
> Lua initializes its pseudo-random generator with the equivalent of
> a call to <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with no arguments,

9544,9547d9939
< To ensure a required level of randomness to the initial state
< (or contrarily, to have a deterministic sequence,
< for instance when debugging a program),
< you should call <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> explicitly.

9553c9945
< (For instance, there are no garanties that it is hard
> (For instance, there are no guarantees that it is hard

9561c9953
< <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed (x [, y])</code></a></h3>
> <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed ([x [, y]])</code></a></h3>

9565,9566c9957,9960
< Sets <code>x</code> and <code>y</code> as the "seed"
< for the pseudo-random generator:
> When called with at least one argument,
> the integer parameters <code>x</code> and <code>y</code> are
> joined into a 128-bit <em>seed</em> that
> is used to reinitialize the pseudo-random generator;

9570a9965,9974
> <p>
> When called with no arguments,
> Lua generates a seed with
> a weak attempt for randomness.
> To ensure a required level of randomness to the initial state
> (or contrarily, to have a deterministic sequence,
> for instance when debugging a program),
> you should call <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with explicit arguments.
> 
> 

9650c10054
< and all input/output operations are over these default files.
> and all input/output operations are done over these default files.

9662a10067,10072
> The metatable for file handles provides metamethods
> for <code>__gc</code> and <code>__close</code> that try
> to close the file when called.
> 
> 
> <p>

9671,9673c10081,10083
< all I/O functions return <b>nil</b> on failure
< (plus an error message as a second result and
< a system-dependent error code as a third result)
> all I/O functions return <b>nil</b> on failure,
> plus an error message as a second result and
> a system-dependent error code as a third result,

9712c10122
< When called without parameters,
> When called without arguments,

9732a10143,10149
> Besides the iterator function,
> <code>io.lines</code> returns three other values:
> two <b>nil</b> values as placeholders,
> plus the created file handle.
> Therefore, when used in a generic <b>for</b> loop,
> the file is closed also if the loop is interrupted by an
> error or a <b>break</b>.

9798c10215
< Starts program <code>prog</code> in a separated process and returns
> Starts the program <code>prog</code> in a separated process and returns

9922c10339
< When called without parameters,
> When called without arguments,

9939c10356,10357
< (e.g., an empty string, "<code>0x</code>", or "<code>3.4e-</code>"),
> (e.g., an empty string, "<code>0x</code>", or "<code>3.4e-</code>")
> or it is too long (more than 200 characters),

10034,10035c10452,10453
< For the last two cases, <code>size</code>
< specifies the size of the buffer, in bytes.
> For the last two cases,
> <code>size</code> is a hint for the size of the buffer, in bytes.

10116,10119c10534,10536
< When called without arguments,
< <code>date</code> returns a reasonable date and time representation that depends on
< the host system and on the current locale.
< (More specifically, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>.)
> If <code>format</code> is absent, it defaults to "<code>%c</code>",
> which gives a reasonable date and time representation
> using the current locale.

10405,10406c10822,10823
< and the current hook count
< (as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function).
> and the current hook count,
> as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function.

10425c10842
< If <code>f</code> is a number larger than the number of active functions,
> If <code>f</code> is a number greater than the number of active functions,

10462c10879
< but also parameters, temporaries, etc.
> but also parameters and temporary values.

10470,10471c10887,10888
< Negative indices refer to vararg parameters;
< -1 is the first vararg parameter.
> Negative indices refer to vararg arguments;
> -1 is the first vararg argument.

10547c10964
< Sets the given function as a hook.
> Sets the given function as the debug hook.

10571,10572c10988
< <code>"call"</code> (or <code>"tail call"</code>),
< <code>"return"</code>,
> <code>"call"</code>, <code>"tail call"</code>, <code>"return"</code>,

10578,10580c10994,10996
< the running function
< (level&nbsp;0 is the <code>getinfo</code> function,
< and level&nbsp;1 is the hook function).
> the running function.
> (Level&nbsp;0 is the <code>getinfo</code> function,
> and level&nbsp;1 is the hook function.)

10711c11127
< all standard libraries, including the debug library.
> all standard libraries.

10737c11153
< When called without option <code>-E</code>,
> When called without the option <code>-E</code>,

10747c11163
< When called with option <code>-E</code>,
> When called with the option <code>-E</code>,

10800c11216
< the script is called with parameters
> the script is called with arguments

10802,10803c11218,11219
< (Like all chunks in Lua,
< the script is compiled as a vararg function.)
> Like all chunks in Lua,
> the script is compiled as a vararg function.

10833a11250
> Warnings are simply printed in the standard error output.

10847,10848c11264
< the standalone interpreter skips
< the first line of a chunk if it starts with <code>#</code>.
> Lua skips the first line of a file chunk if it starts with <code>#</code>.

10856c11272
< (Of course,
> Of course,

10864c11280
< is a more portable solution.)
> is a more portable solution.

10872a11289,11291
> 
> 
> <p>

10876a11296,11302
> More often than not,
> compatibility issues arise when these compatibility options
> are removed.
> So, whenever you have the chance,
> you should try to test your code with a version of Lua compiled
> with all compatibility options turned off.
> That will ease transitions to newer versions of Lua.

10885c11311
< you should not assume that binaries are compatible between
> you should never assume that binaries are compatible between

10903c11329
< <h2>8.1 &ndash; <a name="8.1">Changes in the Language</a></h2>
> <h2>8.1 &ndash; <a name="8.1">Incompatibilities in the Language</a></h2>

10919a11346,11371
> <li>
> The use of the <code>__lt</code> metamethod to emulate <code>__le</code>
> has been removed.
> When needed, this metamethod must be explicitly defined.
> </li>
> 
> <li>
> The semantics of the numerical <b>for</b> loop
> over integers changed in some details.
> In particular, the control variable never wraps around.
> </li>
> 
> <li>
> A label for a <b>goto</b> cannot be declared where a label with the same
> name is visible, even if this other label is declared in an enclosing
> block.
> </li>
> 
> <li>
> When finalizing an object,
> Lua does not ignore <code>__gc</code> metamethods that are not functions.
> Any value will be called, if present.
> (Non-callable values will generate a warning,
> like any other error when calling a finalizer.)
> </li>
> 

10925c11377
< <h2>8.2 &ndash; <a name="8.2">Changes in the Libraries</a></h2>
> <h2>8.2 &ndash; <a name="8.2">Incompatibilities in the Libraries</a></h2>

10928a11381,11387
> The function <a href="#pdf-print"><code>print</code></a> does not call <a href="#pdf-tostring"><code>tostring</code></a>
> to format its arguments;
> instead, it has this functionality hardwired.
> You should use <code>__tostring</code> to modify how values are printed.
> </li>
> 
> <li>

10933a11393,11398
> <li>
> By default, the decoding functions in the <a href="#pdf-utf8"><code>utf8</code></a> library
> do not accept surrogates as valid code points.
> An extra parameter in these functions makes them more permissive.
> </li>
> 

10939c11404
< <h2>8.3 &ndash; <a name="8.3">Changes in the API</a></h2>
> <h2>8.3 &ndash; <a name="8.3">Incompatibilities in the API</a></h2>

10954,10955c11419,11422
< (For compatibility, the old names still work as macros assuming
< one single user value.)
> For compatibility, the old names still work as macros assuming
> one single user value.
> Note, however, that userdata with zero user values
> are more efficient memory-wise.

10962c11429
< (In older versions,
> (In previous versions,

10969c11436
< (The Lua core should work correctly with libraries using their
> The Lua core should work correctly with libraries using their

10972c11439,11445
< address space.)
> address space.
> </li>
> 
> <li>
> The constant <code>LUA_ERRGCMM</code> was removed.
> Errors in finalizers are never propagated;
> instead, they generate a warning.

11015c11488,11489
< 		 <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist] 
> 		 <b>local</b> namelist [&lsquo;<b>=</b>&rsquo; explist] | 
> 		 <b>local</b> &lsquo;<b>&lt;</b>&rsquo; Name &lsquo;<b>&gt;</b>&rsquo; Name &lsquo;<b>=</b>&rsquo; exp 

11073c11547
< Mon Jun 18 17:05:33 -03 2018
> Wed May 29 08:06:33 -03 2019

11076c11550
< Last change: revised for Lua 5.4.0 (work2)
> Last change: revised for Lua 5.4.0 (alpha)

doc/readme.html

113c113
< the top-level directory, which is named <TT>lua-5.4.0-work2</TT>.
> the top-level directory, which is named <TT>lua-5.4.0-alpha</TT>.

121c121
<    aix bsd c89 freebsd generic linux macosx mingw posix solaris
>    aix bsd c89 freebsd generic guess linux linux-readline macosx mingw posix solaris

123a124,127
>   If your platform is a common Unix-like platform,
>   just do "<KBD>make guess</KBD>".
>   The <TT>Makefile</TT> will guess your platform and build Lua for it.
> <P>

142c146
< If you're running Linux and get compilation errors,
> If you're running Linux and get compilation errors when building for <TT>linux-readline</TT>,

153c157
<   probably need the right permissions to install files, and so make need to do "<KBD>sudo make install</KBD>".
>   probably need the right permissions to install files, and so may need to do "<KBD>sudo make install</KBD>".

157c161
<   where xxx is your platform name.
>   where xxx is your platform name, including "guess".

267a272,273
> <LI> to-be-closed variables
> <LI> const variables

268a275,276
> <LI> new implementation for math.random
> <LI> warning system

270,271c278,284
< <LI> new implementation for <CODE>math.random</CODE>
< 
> <LI> new semantics for the integer 'for' loop
> <LI> optional 'init' argument to 'string.gmatch'
> <LI> new functions 'lua_resetthread' and 'coroutine.kill'
> <LI> coersions string->number moved to the string library
> <LI> allocation function allowed to fail when shrinking a memory block
> <LI> new format '%p' in 'string.format'
> <LI> utf8 library accepts codepoints up to 2^31

292c305
< Copyright &copy; 1994&ndash;2018 Lua.org, PUC-Rio.
> Copyright &copy; 1994&ndash;2019 Lua.org, PUC-Rio.

319c332
< Mon Jun 18 17:08:42 -03 2018
> Wed May 29 16:02:01 BRT 2019

322c335
< Last change: revised for Lua 5.4.0 (work2)
> Last change: revised for Lua 5.4.0 (alpha)

src/Makefile

29c29
< PLATS= aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
> PLATS= aix bsd c89 freebsd generic guess linux linux-readline macosx mingw posix solaris

88c88,92
< aix:
> guess:
> 	@echo Guessing `uname`
> 	@$(MAKE) `uname`
> 
> AIX aix:

100c104
< freebsd:
> FreeBSD NetBSD OpenBSD freebsd:

105c109
< linux:	linux-noreadline
> Linux linux:	linux-noreadline

113c117
< macosx:
> Darwin macos macosx:

125c129
< solaris:
> SunOS solaris:

152,153c156,157
< lfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \
<  lgc.h lstate.h ltm.h lzio.h lmem.h
> lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
>  llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h

185,186c189,190
< luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \
<  lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h
> luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h ldebug.h lstate.h \
>  lobject.h llimits.h ltm.h lzio.h lmem.h lopcodes.h lopnames.h lundump.h

src/lapi.c

2c2
< ** $Id: lapi.c,v 2.295 2018/06/18 12:08:10 roberto Exp $
> ** $Id: lapi.c $

41c41,45
< /* test for a valid index */
> /*
> ** Test for a valid index.
> ** '!ttisnil(o)' implies 'o != &G(L)->nilvalue', so it is not needed.
> ** However, it covers the most common cases in a faster way.
> */

171a176
>     StkId newtop = (func + 1) + idx;

173c178
<     while (L->top < (func + 1) + idx)
>     while (L->top < newtop)

175c180
<     L->top = (func + 1) + idx;
>     L->top = newtop;

180a186
>   luaF_close(L, L->top, LUA_OK);

411,412c417
< LUA_API void *lua_touserdata (lua_State *L, int idx) {
<   const TValue *o = index2value(L, idx);
> static void *touserdata (const TValue *o) {

420a426,431
> LUA_API void *lua_touserdata (lua_State *L, int idx) {
>   const TValue *o = index2value(L, idx);
>   return touserdata(o);
> }
> 
> 

426a438,444
> /*
> ** Returns a pointer to the internal representation of an object.
> ** Note that ANSI C does not allow the conversion of a pointer to
> ** function to a 'void*', so the conversion here goes through
> ** a 'size_t'. (As the returned pointer is only informative, this
> ** conversion should not be a problem.)
> */

430,432d447
<     case LUA_TTABLE: return hvalue(o);
<     case LUA_TLCL: return clLvalue(o);
<     case LUA_TCCL: return clCvalue(o);

434,437c449,456
<     case LUA_TTHREAD: return thvalue(o);
<     case LUA_TUSERDATA: return getudatamem(uvalue(o));
<     case LUA_TLIGHTUSERDATA: return pvalue(o);
<     default: return NULL;
>     case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA:
>       return touserdata(o);
>     default: {
>       if (iscollectable(o))
>         return gcvalue(o);
>       else
>         return NULL;
>     }

920,921c939,940
<   if (!(0 < n && n <= uvalue(o)->nuvalue))
<     res = 0;
>   if (!(cast_uint(n) - 1u < cast_uint(uvalue(o)->nuvalue)))
>     res = 0;  /* 'n' not in [1, uvalue(o)->nuvalue] */

953c972
<   if (k != NULL && L->nny == 0) {  /* need to prepare continuation? */
>   if (k != NULL && yieldable(L)) {  /* need to prepare continuation? */

1001c1020
<   if (k == NULL || L->nny > 0) {  /* no continuation or no yieldable? */
>   if (k == NULL || !yieldable(L)) {  /* no continuation or no yieldable? */

1138d1156
<       int oldmode = g->gckind;

1140a1159
>       res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;

1146d1164
<       res = (oldmode == KGC_GEN) ? LUA_GCGEN : LUA_GCINC;

1150d1167
<       int oldmode = g->gckind;

1153a1171
>       res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC;

1161d1178
<       res = (oldmode == KGC_GEN) ? LUA_GCGEN : LUA_GCINC;

1203a1221,1236
> LUA_API void lua_toclose (lua_State *L, int idx) {
>   int nresults;
>   StkId o;
>   lua_lock(L);
>   o = index2stack(L, idx);
>   nresults = L->ci->nresults;
>   api_check(L, L->openupval == NULL || uplevel(L->openupval) <= o,
>                "marked index below or equal new one");
>   luaF_newtbcupval(L, o);  /* create new to-be-closed upvalue */
>   if (!hastocloseCfunc(nresults))  /* function not marked yet? */
>     L->ci->nresults = codeNresults(nresults);  /* mark it */
>   lua_assert(hastocloseCfunc(L->ci->nresults));
>   lua_unlock(L);
> }
> 
> 

1247a1281,1296
> void lua_setwarnf (lua_State *L, lua_WarnFunction f, void *ud) {
>   lua_lock(L);
>   G(L)->ud_warn = ud;
>   G(L)->warnf = f;
>   lua_unlock(L);
> }
> 
> 
> void lua_warning (lua_State *L, const char *msg, int tocont) {
>   lua_lock(L);
>   luaE_warning(L, msg, tocont);
>   lua_unlock(L);
> }
> 
> 
> 

1267c1316,1317
<       if (!(1 <= n && n <= f->nupvalues)) return NULL;
>       if (!(cast_uint(n) - 1u < cast_uint(f->nupvalues)))
>         return NULL;  /* 'n' not in [1, f->nupvalues] */

1276c1326,1327
<       if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
>       if (!(cast_uint(n) - 1u  < cast_uint(p->sizeupvalues)))
>         return NULL;  /* 'n' not in [1, p->sizeupvalues] */

1280c1331
<       return (name == NULL) ? "(*no name)" : getstr(name);
>       return (name == NULL) ? "(no name)" : getstr(name);

src/lapi.h

2c2
< ** $Id: lapi.h,v 2.12 2017/11/07 13:25:26 roberto Exp $
> ** $Id: lapi.h $

18c18
<     { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
>     { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }

23a24,36
> /*
> ** To reduce the overhead of returning from C functions, the presence of
> ** to-be-closed variables in these functions is coded in the CallInfo's
> ** field 'nresults', in a way that functions with no to-be-closed variables
> ** with zero, one, or "all" wanted results have no overhead. Functions
> ** with other number of wanted results, as well as functions with
> ** variables to be closed, have an extra check.
> */
> 
> #define hastocloseCfunc(n)	((n) < LUA_MULTRET)
> 
> #define codeNresults(n)		(-(n) - 3)
> 

src/lauxlib.c

2c2
< ** $Id: lauxlib.c,v 1.295 2018/06/18 12:08:10 roberto Exp $
> ** $Id: lauxlib.c $

29a30,35
> #if !defined(MAX_SIZET)
> /* maximum value for size_t */
> #define MAX_SIZET	((size_t)(~(size_t)0))
> #endif
> 
> 

43,44c49,50
< ** search for 'objidx' in table at index -1.
< ** return 1 + string at top if find a good name.
> ** Search for 'objidx' in table at index -1. ('objidx' must be an
> ** absolute index.) Return 1 + string at top if it found a good name.

57,60c63,66
<         lua_remove(L, -2);  /* remove table (but keep name) */
<         lua_pushliteral(L, ".");
<         lua_insert(L, -2);  /* place '.' between the two names */
<         lua_concat(L, 3);
>         /* stack: lib_name, lib_table, field_name (top) */
>         lua_pushliteral(L, ".");  /* place '.' between the two names */
>         lua_replace(L, -3);  /* (in the slot ocupied by table) */
>         lua_concat(L, 3);  /* lib_name.field_name */

83,84c89,90
<     lua_copy(L, -1, top + 1);  /* move name to proper place */
<     lua_pop(L, 2);  /* remove pushed values */
>     lua_copy(L, -1, top + 1);  /* copy name to proper place */
>     lua_settop(L, top + 1);  /* remove table "loaded" an name copy */

126a133
>   luaL_Buffer b;

128d134
<   int top = lua_gettop(L);

130,134c136,142
<   int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;
<   if (msg)
<     lua_pushfstring(L, "%s\n", msg);
<   luaL_checkstack(L, 10, NULL);
<   lua_pushliteral(L, "stack traceback:");
>   int limit2show = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1;
>   luaL_buffinit(L, &b);
>   if (msg) {
>     luaL_addstring(&b, msg);
>     luaL_addchar(&b, '\n');
>   }
>   luaL_addstring(&b, "stack traceback:");

136,138c144,148
<     if (n1-- == 0) {  /* too many levels? */
<       lua_pushliteral(L, "\n\t...");  /* add a '...' */
<       level = last - LEVELS2 + 1;  /* and skip to last ones */
>     if (limit2show-- == 0) {  /* too many levels? */
>       int n = last - level - LEVELS2 + 1;  /* number of levels to skip */
>       lua_pushfstring(L, "\n\t...\t(skipping %d levels)", n);
>       luaL_addvalue(&b);  /* add warning about skip */
>       level += n;  /* and skip to last levels */

142,145c152,156
<       lua_pushfstring(L, "\n\t%s:", ar.short_src);
<       if (ar.currentline > 0)
<         lua_pushfstring(L, "%d:", ar.currentline);
<       lua_pushliteral(L, " in ");
>       if (ar.currentline <= 0)
>         lua_pushfstring(L, "\n\t%s: in ", ar.short_src);
>       else
>         lua_pushfstring(L, "\n\t%s:%d: in ", ar.short_src, ar.currentline);
>       luaL_addvalue(&b);

146a158
>       luaL_addvalue(&b);

148,149c160
<         lua_pushliteral(L, "\n\t(...tail calls...)");
<       lua_concat(L, lua_gettop(L) - top);
>         luaL_addstring(&b, "\n\t(...tail calls...)");

152c163
<   lua_concat(L, lua_gettop(L) - top);
>   luaL_pushresult(&b);

182c193
< static int typeerror (lua_State *L, int arg, const char *tname) {
> int luaL_typeerror (lua_State *L, int arg, const char *tname) {

197c208
<   typeerror(L, arg, lua_typename(L, tag));
>   luaL_typeerror(L, arg, lua_typename(L, tag));

292a304
> 

335c347
<   if (p == NULL) typeerror(L, ud, tname);
>   luaL_argexpected(L, p != NULL, ud, tname);

466,467c478
<   if (temp == NULL && newsize > 0) {  /* allocation error? */
<     resizebox(L, idx, 0);  /* free buffer */
>   if (temp == NULL && newsize > 0)  /* allocation error? */

469d479
<   }

482c492,499
< static void *newbox (lua_State *L, size_t newsize) {
> static const luaL_Reg boxmt[] = {  /* box metamethods */
>   {"__gc", boxgc},
>   {"__close", boxgc},
>   {NULL, NULL}
> };
> 
> 
> static void newbox (lua_State *L) {

486,489c503,504
<   if (luaL_newmetatable(L, "_UBOX*")) {  /* creating metatable? */
<     lua_pushcfunction(L, boxgc);
<     lua_setfield(L, -2, "__gc");  /* metatable.__gc = boxgc */
<   }
>   if (luaL_newmetatable(L, "_UBOX*"))  /* creating metatable? */
>     luaL_setfuncs(L, boxmt, 0);  /* set its metamethods */

491d505
<   return resizebox(L, -1, newsize);

503c517,518
< ** returns a pointer to a free area with at least 'sz' bytes
> ** Compute new size for buffer 'B', enough to accommodate extra 'sz'
> ** bytes.

505,507c520,539
< LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
<   lua_State *L = B->L;
<   if (B->size - B->n < sz) {  /* not enough space? */
> static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
>   size_t newsize = B->size * 2;  /* double buffer size */
>   if (MAX_SIZET - sz < B->n)  /* overflow in (B->n + sz)? */
>     return luaL_error(B->L, "buffer too large");
>   if (newsize < B->n + sz)  /* double is not big enough? */
>     newsize = B->n + sz;
>   return newsize;
> }
> 
> 
> /*
> ** Returns a pointer to a free area with at least 'sz' bytes in buffer
> ** 'B'. 'boxidx' is the relative position in the stack where the
> ** buffer's box is or should be.
> */
> static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) {
>   if (B->size - B->n >= sz)  /* enough space? */
>     return B->b + B->n;
>   else {
>     lua_State *L = B->L;

509,513c541
<     size_t newsize = B->size * 2;  /* double buffer size */
<     if (newsize - B->n < sz)  /* not big enough? */
<       newsize = B->n + sz;
<     if (newsize < B->n || newsize - B->n < sz)
<       luaL_error(L, "buffer too large");
>     size_t newsize = newbuffsize(B, sz);

515,518c543,551
<     if (buffonstack(B))
<       newbuff = (char *)resizebox(L, -1, newsize);
<     else {  /* no buffer yet */
<       newbuff = (char *)newbox(L, newsize);
>     if (buffonstack(B))  /* buffer already has a box? */
>       newbuff = (char *)resizebox(L, boxidx, newsize);  /* resize it */
>     else {  /* no box yet */
>       lua_pushnil(L);  /* reserve slot for final result */
>       newbox(L);  /* create a new box */
>       /* move box (and slot) to its intended position */
>       lua_rotate(L, boxidx - 1, 2);
>       lua_toclose(L, boxidx);
>       newbuff = (char *)resizebox(L, boxidx, newsize);

522a556
>     return newbuff + B->n;

524c558,564
<   return &B->b[B->n];
> }
> 
> /*
> ** returns a pointer to a free area with at least 'sz' bytes
> */
> LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
>   return prepbuffsize(B, sz, -1);

530c570
<     char *b = luaL_prepbuffsize(B, l);
>     char *b = prepbuffsize(B, l, -1);

546,547c586,587
<     resizebox(L, -2, 0);  /* delete old buffer */
<     lua_remove(L, -2);  /* remove its header from the stack */
>     lua_copy(L, -1, -3);  /* move string to reserved slot */
>     lua_pop(L, 2);  /* pop string and box (closing the box) */

557a598,606
> /*
> ** 'luaL_addvalue' is the only function in the Buffer system where the
> ** box (if existent) is not on the top of the stack. So, instead of
> ** calling 'luaL_addlstring', it replicates the code using -2 as the
> ** last argument to 'prepbuffsize', signaling that the box is (or will
> ** be) bellow the string being added to the buffer. (Box creation can
> ** trigger an emergency GC, so we should not remove the string from the
> ** stack before we have the space guaranteed.)
> */

560,565c609,614
<   size_t l;
<   const char *s = lua_tolstring(L, -1, &l);
<   if (buffonstack(B))
<     lua_insert(L, -2);  /* put value below buffer */
<   luaL_addlstring(B, s, l);
<   lua_remove(L, (buffonstack(B)) ? -2 : -1);  /* remove value */
>   size_t len;
>   const char *s = lua_tolstring(L, -1, &len);
>   char *b = prepbuffsize(B, len, -2);
>   memcpy(b, s, len * sizeof(char));
>   luaL_addsize(B, len);
>   lua_pop(L, 1);  /* pop string */

579c628
<   return luaL_prepbuffsize(B, sz);
>   return prepbuffsize(B, sz, -1);

857,859c906,912
<     for (i = 0; i < nup; i++)  /* copy upvalues to the top */
<       lua_pushvalue(L, -nup);
<     lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */
>     if (l->func == NULL)  /* place holder? */
>       lua_pushboolean(L, 0);
>     else {
>       for (i = 0; i < nup; i++)  /* copy upvalues to the top */
>         lua_pushvalue(L, -nup);
>       lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */
>     }

910,911c963,964
< LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
<                                                                const char *r) {
> LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
>                                      const char *p, const char *r) {

914,915d966
<   luaL_Buffer b;
<   luaL_buffinit(L, &b);

917,918c968,969
<     luaL_addlstring(&b, s, wild - s);  /* push prefix */
<     luaL_addstring(&b, r);  /* push replacement in place of pattern */
>     luaL_addlstring(b, s, wild - s);  /* push prefix */
>     luaL_addstring(b, r);  /* push replacement in place of pattern */

921c972,980
<   luaL_addstring(&b, s);  /* push last suffix */
>   luaL_addstring(b, s);  /* push last suffix */
> }
> 
> 
> LUALIB_API const char *luaL_gsub (lua_State *L, const char *s,
>                                   const char *p, const char *r) {
>   luaL_Buffer b;
>   luaL_buffinit(L, &b);
>   luaL_addgsub(&b, s, p, r);

944a1004,1018
> /*
> ** Emit a warning. '*previoustocont' signals whether previous message
> ** was to be continued by the current one.
> */
> static void warnf (void *ud, const char *message, int tocont) {
>   int *previoustocont = (int *)ud;
>   if (!*previoustocont)  /* previous message was the last? */
>     lua_writestringerror("%s", "Lua warning: ");  /* start a new warning */
>   lua_writestringerror("%s", message);  /* write message */
>   if (!tocont)  /* is this the last part? */
>     lua_writestringerror("%s", "\n");  /* finish message with end-of-line */
>   *previoustocont = tocont;
> }
> 
> 

947c1021,1028
<   if (L) lua_atpanic(L, &panic);
>   if (L) {
>     int *previoustocont;  /* space for warning state */
>     lua_atpanic(L, &panic);
>     previoustocont = (int *)lua_newuserdatauv(L, sizeof(int), 0);
>     luaL_ref(L, LUA_REGISTRYINDEX);  /* make sure it won't be collected */
>     *previoustocont = 0;  /* next message starts a new warning */
>     lua_setwarnf(L, warnf, previoustocont);
>   }

src/lauxlib.h

2c2
< ** $Id: lauxlib.h,v 1.134 2018/02/27 18:47:32 roberto Exp $
> ** $Id: lauxlib.h $

21a22,23
> typedef struct luaL_Buffer luaL_Buffer;
> 

50a53
> LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname);

79a83
> 

100,101c104,107
< LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
<                                                   const char *r);
> LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
>                                      const char *p, const char *r);
> LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
>                                     const char *p, const char *r);

127a134,137
> 
> #define luaL_argexpected(L,cond,arg,tname)	\
> 		((void)((cond) || luaL_typeerror(L, (arg), (tname))))
> 

152c162
< typedef struct luaL_Buffer {
> struct luaL_Buffer {

161c171,175
< } luaL_Buffer;
> };
> 
> 
> #define luaL_bufflen(bf)	((bf)->n)
> #define luaL_buffaddr(bf)	((bf)->b)

src/lbaselib.c

2c2
< ** $Id: lbaselib.c,v 1.323 2018/03/07 15:55:38 roberto Exp $
> ** $Id: lbaselib.c $

27,29c27
<   lua_getglobal(L, "tostring");
<   for (i=1; i<=n; i++) {
<     const char *s;
>   for (i = 1; i <= n; i++) {  /* for each argument */

31,38c29,32
<     lua_pushvalue(L, -1);  /* function to be called */
<     lua_pushvalue(L, i);   /* value to print */
<     lua_call(L, 1, 1);
<     s = lua_tolstring(L, -1, &l);  /* get result */
<     if (s == NULL)
<       return luaL_error(L, "'tostring' must return a string to 'print'");
<     if (i>1) lua_writestring("\t", 1);
<     lua_writestring(s, l);
>     const char *s = luaL_tolstring(L, i, &l);  /* convert it to string */
>     if (i > 1)  /* not the first element? */
>       lua_writestring("\t", 1);  /* add a tab before it */
>     lua_writestring(s, l);  /* print it */

45a40,46
> static int luaB_warn (lua_State *L) {
>   const char *msg = luaL_checkstring(L, 1);
>   lua_warning(L, msg, lua_toboolean(L, 2));
>   return 0;
> }
> 
> 

71d71
<     luaL_checkany(L, 1);

81a82
>       luaL_checkany(L, 1);  /* (but there must be some parameter) */

128,129c129
<   luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
<                     "nil or table expected");
>   luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");

148,149c148,149
<   luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
<                    "table or string expected");
>   luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
>                       "table or string");

485a486
>   {"warn", luaB_warn},

src/lcode.c

2c2
< ** $Id: lcode.c,v 2.161 2018/04/04 14:23:41 roberto Exp $
> ** $Id: lcode.c $

182,183c182,183
< static int condjump (FuncState *fs, OpCode op, int A, int B, int k) {
<   luaK_codeABCk(fs, op, A, B, 0, k);
> static int condjump (FuncState *fs, OpCode op, int A, int B, int C, int k) {
>   luaK_codeABCk(fs, op, A, B, C, k);

279,282c279,280
< ** Correct a jump list to jump to 'target'. If 'hasclose' is true,
< ** 'target' contains an OP_CLOSE instruction (see first assert).
< ** Only the jumps with ('m' == true) need that close; other jumps
< ** avoid it jumping to the next instruction.
> ** MAXimum number of successive Instructions WiTHout ABSolute line
> ** information.

284,311d281
< void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) {
<   lua_assert(!hasclose || GET_OPCODE(fs->f->code[target]) == OP_CLOSE);
<   while (list != NO_JUMP) {
<     int next = getjump(fs, list);
<     lua_assert(!GETARG_m(fs->f->code[list]) || hasclose);
<     patchtestreg(fs, list, NO_REG);  /* do not generate values */
<     if (!hasclose || GETARG_m(fs->f->code[list]))
<       fixjump(fs, list, target);
<     else  /* there is a CLOSE instruction but jump does not need it */
<       fixjump(fs, list, target + 1);  /* avoid CLOSE instruction */
<     list = next;
<   }
< }
< 
< 
< /*
< ** Mark (using the 'm' arg) all jumps in 'list' to close upvalues. Mark
< ** will instruct 'luaK_patchgoto' to make these jumps go to OP_CLOSE
< ** instructions.
< */
< void luaK_patchclose (FuncState *fs, int list) {
<   for (; list != NO_JUMP; list = getjump(fs, list)) {
<     lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP);
<     SETARG_m(fs->f->code[list], 1);
<   }
< }
< 
< 

315a286,290
> 
> /* limit for difference between lines in relative line info. */
> #define LIMLINEDIFF	0x80
> 
> 

323c298
< static void savelineinfo (FuncState *fs, Proto *f, int pc, int line) {
> static void savelineinfo (FuncState *fs, Proto *f, int line) {

325c300,301
<   if (abs(linedif) >= 0x80 || fs->iwthabs++ > MAXIWTHABS) {
>   int pc = fs->pc - 1;  /* last instruction coded */
>   if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ > MAXIWTHABS) {

330c306
<     linedif = ABSLINEINFO;  /* signal there is absolute information */
>     linedif = ABSLINEINFO;  /* signal that there is absolute information */

340a317,347
> ** Remove line information from the last instruction.
> ** If line information for that instruction is absolute, set 'iwthabs'
> ** above its max to force the new (replacing) instruction to have
> ** absolute line info, too.
> */
> static void removelastlineinfo (FuncState *fs) {
>   Proto *f = fs->f;
>   int pc = fs->pc - 1;  /* last instruction coded */
>   if (f->lineinfo[pc] != ABSLINEINFO) {  /* relative line info? */
>     fs->previousline -= f->lineinfo[pc];  /* last line saved */
>     fs->iwthabs--;
>   }
>   else {  /* absolute line information */
>     fs->nabslineinfo--;  /* remove it */
>     lua_assert(f->abslineinfo[fs->nabslineinfo].pc = pc);
>     fs->iwthabs = MAXIWTHABS + 1;  /* force next line info to be absolute */
>   }
> }
> 
> 
> /*
> ** Remove the last instruction created, correcting line information
> ** accordingly.
> */
> static void removelastinstruction (FuncState *fs) {
>   removelastlineinfo(fs);
>   fs->pc--;
> }
> 
> 
> /*

349,351c356,358
<   f->code[fs->pc] = i;
<   savelineinfo(fs, f, fs->pc, fs->ls->lastline);
<   return fs->pc++;
>   f->code[fs->pc++] = i;
>   savelineinfo(fs, f, fs->ls->lastline);
>   return fs->pc - 1;  /* index of new instruction */

367,370d373
< #define codeABsC(fs,o,a,b,c,k)	luaK_codeABCk(fs,o,a,b,((c) + OFFSET_sC),k)
< 
< 
< 

677a681
>       e->u.info = e->u.var.idx;

682c686
<       e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.info, 0);
>       e->u.info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->u.var.idx, 0);

799c803
< ** jump ** lists) is in register 'reg'.
> ** jump lists) is in register 'reg'.

814,815c818,820
<       p_f = code_loadbool(fs, reg, 0, 1);
<       p_t = code_loadbool(fs, reg, 1, 0);
>       p_f = code_loadbool(fs, reg, 0, 1);  /* load false and skip next i. */
>       p_t = code_loadbool(fs, reg, 1, 0);  /* load true */
>       /* jump around these booleans if 'e' is not a test */

880a886,912
> ** Try to make 'e' a K expression with an index in the range of R/K
> ** indices. Return true iff succeeded.
> */
> static int luaK_exp2K (FuncState *fs, expdesc *e) {
>   if (!hasjumps(e)) {
>     int info;
>     switch (e->k) {  /* move constants to 'k' */
>       case VTRUE: info = boolK(fs, 1); break;
>       case VFALSE: info = boolK(fs, 0); break;
>       case VNIL: info = nilK(fs); break;
>       case VKINT: info = luaK_intK(fs, e->u.ival); break;
>       case VKFLT: info = luaK_numberK(fs, e->u.nval); break;
>       case VK: info = e->u.info; break;
>       default: return 0;  /* not a constant */
>     }
>     if (info <= MAXINDEXRK) {  /* does constant fit in 'argC'? */
>       e->k = VK;  /* make expression a 'K' expression */
>       e->u.info = info;
>       return 1;
>     }
>   }
>   /* else, expression doesn't fit; leave it unchanged */
>   return 0;
> }
> 
> 
> /*

884c916
< ** Returns 1 if expression is K, 0 otherwise.
> ** Returns 1 iff expression is K.

887,900c919,923
<   luaK_exp2val(fs, e);
<   switch (e->k) {  /* move constants to 'k' */
<     case VTRUE: e->u.info = boolK(fs, 1); goto vk;
<     case VFALSE: e->u.info = boolK(fs, 0); goto vk;
<     case VNIL: e->u.info = nilK(fs); goto vk;
<     case VKINT: e->u.info = luaK_intK(fs, e->u.ival); goto vk;
<     case VKFLT: e->u.info = luaK_numberK(fs, e->u.nval); goto vk;
<     case VK:
<      vk:
<       e->k = VK;
<       if (e->u.info <= MAXINDEXRK)  /* constant fits in 'argC'? */
<         return 1;
<       else break;
<     default: break;
>   if (luaK_exp2K(fs, e))
>     return 1;
>   else {  /* not a constant in the right range: put it in a register */
>     luaK_exp2anyreg(fs, e);
>     return 0;

902,904d924
<   /* not a constant in the right range: put it in a register */
<   luaK_exp2anyreg(fs, e);
<   return 0;

922c942
<       exp2reg(fs, ex, var->u.info);  /* compute 'ex' into proper place */
>       exp2reg(fs, ex, var->u.var.idx);  /* compute 'ex' into proper place */

927c947
<       luaK_codeABC(fs, OP_SETUPVAL, e, var->u.info, 0);
>       luaK_codeABC(fs, OP_SETUPVAL, e, var->u.var.idx, 0);

989,990c1009,1010
<       fs->pc--;  /* remove previous OP_NOT */
<       return condjump(fs, OP_TEST, GETARG_B(ie), 0, !cond);
>       removelastinstruction(fs);  /* remove previous OP_NOT */
>       return condjump(fs, OP_TEST, GETARG_B(ie), 0, 0, !cond);

996c1016
<   return condjump(fs, OP_TESTSET, NO_REG, e->u.info, cond);
>   return condjump(fs, OP_TESTSET, NO_REG, e->u.info, 0, cond);

1124c1144
< ** proper range to fit in register sC
> ** proper range to fit in a register (sB or sC).

1126c1146
< static int isSCnumber (expdesc *e, lua_Integer *i) {
> static int isSCnumber (expdesc *e, lua_Integer *i, int *isfloat) {

1130a1151,1152
>   else
>     *isfloat = 1;

1147c1169,1170
<   lua_assert(!hasjumps(t) && (vkisinreg(t->k) || t->k == VUPVAL));
>   lua_assert(!hasjumps(t) &&
>              (t->k == VLOCAL || t->k == VNONRELOC || t->k == VUPVAL));

1150d1172
<   t->u.ind.t = t->u.info;  /* register or upvalue index */

1151a1174
>     t->u.ind.t = t->u.var.idx;  /* upvalue index */

1155,1162d1177
<   else if (isKstr(fs, k)) {
<     t->u.ind.idx = k->u.info;  /* literal string */
<     t->k = VINDEXSTR;
<   }
<   else if (isCint(k)) {
<     t->u.ind.idx = cast_int(k->u.ival);  /* integer constant in proper range */
<     t->k = VINDEXI;
<   }

1164,1165c1179,1192
<     t->u.ind.idx = luaK_exp2anyreg(fs, k);  /* register */
<     t->k = VINDEXED;
>     /* register index of the table */
>     t->u.ind.t = (t->k == VLOCAL) ? t->u.var.idx: t->u.info;
>     if (isKstr(fs, k)) {
>       t->u.ind.idx = k->u.info;  /* literal string */
>       t->k = VINDEXSTR;
>     }
>     else if (isCint(k)) {
>       t->u.ind.idx = cast_int(k->u.ival);  /* int. constant in proper range */
>       t->k = VINDEXI;
>     }
>     else {
>       t->u.ind.idx = luaK_exp2anyreg(fs, k);  /* register */
>       t->k = VINDEXED;
>     }

1227a1255,1263
> /*
> ** Emit code for binary expressions that "produce values"
> ** (everything but logical operators 'and'/'or' and comparison
> ** operators).
> ** Expression to produce final result will be encoded in 'e1'.
> ** Because 'luaK_exp2anyreg' can free registers, its calls must be
> ** in "stack order" (that is, first on 'e2', which may have more
> ** recent registers to be released).
> */

1229c1265,1267
<                              int pc, int line) {
>                              OpCode op, int v2, int k, int line) {
>   int v1 = luaK_exp2anyreg(fs, e1);
>   int pc = luaK_codeABCk(fs, op, 0, v1, v2, k);

1238,1244c1276,1277
< ** Emit code for binary expressions that "produce values"
< ** (everything but logical operators 'and'/'or' and comparison
< ** operators).
< ** Expression to produce final result will be encoded in 'e1'.
< ** Because 'luaK_exp2anyreg' can free registers, its calls must be
< ** in "stack order" (that is, first on 'e2', which may have more
< ** recent registers to be released).
> ** Emit code for binary expressions that "produce values" over
> ** two registers.

1249,1251c1282
<   int v1 = luaK_exp2anyreg(fs, e1);
<   int pc = luaK_codeABC(fs, op, 0, v1, v2);  /* generate opcode */
<   finishbinexpval(fs, e1, e2, pc, line);
>   finishbinexpval(fs, e1, e2, op, v2, 0, line);

1260,1263c1291,1297
<   int v2 = cast_int(e2->u.ival);  /* immediate operand */
<   int v1 = luaK_exp2anyreg(fs, e1);
<   int pc = codeABsC(fs, op, 0, v1, v2, k);  /* generate opcode */
<   finishbinexpval(fs, e1, e2, pc, line);
>   int v2 = cast_int(e2->u.ival) + OFFSET_sC;  /* immediate operand */
>   finishbinexpval(fs, e1, e2, op, v2, k, line);
> }
> 
> 
> static void swapexps (expdesc *e1, expdesc *e2) {
>   expdesc temp = *e1; *e1 = *e2; *e2 = temp;  /* swap 'e1' and 'e2' */

1270c1304
< ** operands.
> ** operands or K operands.

1274,1276c1308
<   if (!isSCint(e2))
<     codebinexpval(fs, op, e1, e2, line);  /* use standard operators */
<   else  /* use immediate operators */
>   if (isSCint(e2))  /* immediate operand? */

1278,1282c1310,1319
< }
< 
< 
< static void swapexps (expdesc *e1, expdesc *e2) {
<   expdesc temp = *e1; *e1 = *e2; *e2 = temp;  /* swap 'e1' and 'e2' */
>   else if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) {  /* K operand? */
>     int v2 = e2->u.info;  /* K index */
>     op = cast(OpCode, op - OP_ADD + OP_ADDK);
>     finishbinexpval(fs, e1, e2, op, v2, flip, line);
>   }
>   else {  /* 'e2' is neither an immediate nor a K operand */
>     if (flip)
>       swapexps(e1, e2);  /* back to original order */
>     codebinexpval(fs, op, e1, e2, line);  /* use standard operators */
>   }

1288c1325,1326
< ** constant, change order of operands to use immediate operator.
> ** numeric constant, change order of operands to try to use an
> ** immediate or K operator.

1293,1294c1331,1332
<   if (isSCint(e1)) {
<     swapexps(e1, e2);
>   if (tonumeral(e1, NULL)) {  /* is first operand a numeric constant? */
>     swapexps(e1, e2);  /* change order */

1308c1346
<   int v1, v2, pc;
>   int v2;

1319d1356
<   v1 = luaK_exp2anyreg(fs, e1);

1323,1324c1360
<   pc = luaK_codeABCk(fs, op, 0, v1, v2, inv);
<   finishbinexpval(fs, e1, e2, pc, line);
>   finishbinexpval(fs, e1, e2, op, v2, inv, line);

1348,1351c1384,1385
< ** Emit code for order comparisons.
< ** When the first operand A is an integral value in the proper range,
< ** change (A < B) to (B > A) and (A <= B) to (B >= A) so that
< ** it can use an immediate operand.
> ** Emit code for order comparisons. When using an immediate operand,
> ** 'isfloat' tells whether the original value was a float.

1356c1390,1391
<   if (isSCnumber(e2, &im)) {
>   int isfloat = 0;
>   if (isSCnumber(e2, &im, &isfloat)) {

1362c1397
<   else if (isSCnumber(e1, &im)) {
>   else if (isSCnumber(e1, &im, &isfloat)) {

1373c1408
<   e1->u.info = condjump(fs, op, r1, r2, 1);
>   e1->u.info = condjump(fs, op, r1, r2, isfloat, 1);

1384a1420
>   int isfloat = 0;  /* not needed here, but kept for symmetry */

1391c1427
<   if (isSCnumber(e2, &im)) {
>   if (isSCnumber(e2, &im, &isfloat)) {

1404c1440
<   e1->u.info = condjump(fs, op, r1, r2, (opr == OPR_EQ));
>   e1->u.info = condjump(fs, op, r1, r2, isfloat, (opr == OPR_EQ));

1465c1501,1502
<       if (!isSCnumber(v, &dummy))
>       int dummy2;
>       if (!isSCnumber(v, &dummy, &dummy2))

1575,1579c1612,1613
< ** Change line information associated with current position. If that
< ** information is absolute, just change it and correct 'previousline'.
< ** Otherwise, restore 'previousline' to its value before saving the
< ** current position and than saves the line information again, with the
< ** new line.
> ** Change line information associated with current position, by removing
> ** previous info and adding it again with new line.

1582,1591c1616,1617
<   Proto *f = fs->f;
<   if (f->lineinfo[fs->pc - 1] == ABSLINEINFO) {
<     lua_assert(f->abslineinfo[fs->nabslineinfo - 1].pc == fs->pc - 1);
<     f->abslineinfo[fs->nabslineinfo - 1].line = line;
<     fs->previousline = line;
<   }
<   else {
<     fs->previousline -= f->lineinfo[fs->pc - 1];  /* undo previous info. */
<     savelineinfo(fs, f, fs->pc - 1, line);  /* redo it */
<   }
>   removelastlineinfo(fs);
>   savelineinfo(fs, fs->f, line);

1646c1672
<         if (p->sizep == 0 && !p->is_vararg)
>         if (!(fs->needclose || p->is_vararg))

1652c1678
<         if (p->sizep > 0 || p->is_vararg) {
>         if (fs->needclose || p->is_vararg) {

src/lcode.h

2c2
< ** $Id: lcode.h,v 1.73 2018/04/04 14:23:41 roberto Exp $
> ** $Id: lcode.h $

81,82d80
< LUAI_FUNC void luaK_patchgoto (FuncState *fs, int list, int target,
<                                int hasclose);

84d81
< LUAI_FUNC void luaK_patchclose (FuncState *fs, int list);

src/lcorolib.c

2c2
< ** $Id: lcorolib.c,v 1.11 2017/11/02 11:28:56 roberto Exp $
> ** $Id: lcorolib.c $

23c23
<   luaL_argcheck(L, co, 1, "thread expected");
>   luaL_argexpected(L, co, 1, "thread");

27a28,31
> /*
> ** Resumes a coroutine. Returns the number of results for non-error
> ** cases or -1 for errors.
> */

34,37d37
<   if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
<     lua_pushliteral(L, "cannot resume dead coroutine");
<     return -1;  /* error flag */
<   }

76a77,82
>     int stat = lua_status(co);
>     if (stat != LUA_OK && stat != LUA_YIELD) {
>       stat = lua_resetthread(co);  /* close variables in case of errors */
>       if (stat != LUA_OK)  /* error closing variables? */
>         lua_xmove(co, L, 1);  /* get new error object */
>     }

78c84
<       luaL_where(L, 1);  /* add extra info */
>       luaL_where(L, 1);  /* add extra info, if available */

110,112c116,126
< static int luaB_costatus (lua_State *L) {
<   lua_State *co = getco(L);
<   if (L == co) lua_pushliteral(L, "running");
> #define COS_RUN		0
> #define COS_DEAD	1
> #define COS_YIELD	2
> #define COS_NORM	3
> 
> 
> static const char *statname[] = {"running", "dead", "suspended", "normal"};
> 
> 
> static int auxstatus (lua_State *L, lua_State *co) {
>   if (L == co) return COS_RUN;

116,117c130
<         lua_pushliteral(L, "suspended");
<         break;
>         return COS_YIELD;

120,121c133,134
<         if (lua_getstack(co, 0, &ar) > 0)  /* does it have frames? */
<           lua_pushliteral(L, "normal");  /* it is running */
>         if (lua_getstack(co, 0, &ar))  /* does it have frames? */
>           return COS_NORM;  /* it is running */

123c136
<             lua_pushliteral(L, "dead");
>             return COS_DEAD;

125,126c138
<           lua_pushliteral(L, "suspended");  /* initial state */
<         break;
>           return COS_YIELD;  /* initial state */

129,130c141
<         lua_pushliteral(L, "dead");
<         break;
>         return COS_DEAD;

132a144,149
> }
> 
> 
> static int luaB_costatus (lua_State *L) {
>   lua_State *co = getco(L);
>   lua_pushstring(L, statname[auxstatus(L, co)]);

138c155,156
<   lua_pushboolean(L, lua_isyieldable(L));
>   lua_State *co = lua_isnone(L, 1) ? L : getco(L);
>   lua_pushboolean(L, lua_isyieldable(co));

149a168,189
> static int luaB_kill (lua_State *L) {
>   lua_State *co = getco(L);
>   int status = auxstatus(L, co);
>   switch (status) {
>     case COS_DEAD: case COS_YIELD: {
>       status = lua_resetthread(co);
>       if (status == LUA_OK) {
>         lua_pushboolean(L, 1);
>         return 1;
>       }
>       else {
>         lua_pushboolean(L, 0);
>         lua_xmove(co, L, 1);  /* copy error message */
>         return 2;
>       }
>     }
>     default:  /* normal or running coroutine */
>       return luaL_error(L, "cannot kill a %s coroutine", statname[status]);
>   }
> }
> 
> 

157a198
>   {"kill", luaB_kill},

src/lctype.c

2c2
< ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $
> ** $Id: lctype.c $

src/lctype.h

2c2
< ** $Id: lctype.h,v 1.13 2018/06/18 12:51:05 roberto Exp $
> ** $Id: lctype.h $

src/ldblib.c

2c2
< ** $Id: ldblib.c,v 1.155 2018/03/16 15:33:34 roberto Exp $
> ** $Id: ldblib.c $

58,59c58
<   luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
<                     "nil or table expected");
>   luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");

171c170,171
<     settabss(L, "source", ar.source);
>     lua_pushlstring(L, ar.source, ar.srclen);
>     lua_setfield(L, -2, "source");

src/ldebug.c

2c2
< ** $Id: ldebug.c,v 2.158 2018/06/08 19:06:59 roberto Exp $
> ** $Id: ldebug.c $

195c195
<       return "(*vararg)";  /* generic name for any vararg */
>       return "(vararg)";  /* generic name for any vararg */

202,203c202
< static const char *findlocal (lua_State *L, CallInfo *ci, int n,
<                               StkId *pos) {
> const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {

214,215c213,216
<     if (limit - base >= n && n > 0)  /* is 'n' inside 'ci' stack? */
<       name = "(*temporary)";  /* generic name for any valid slot */
>     if (limit - base >= n && n > 0) {  /* is 'n' inside 'ci' stack? */
>       /* generic name for any valid slot */
>       name = isLua(ci) ? "(temporary)" : "(C temporary)";
>     }

219c220,221
<   *pos = base + (n - 1);
>   if (pos)
>     *pos = base + (n - 1);

235c237
<     name = findlocal(L, ar->i_ci, n, &pos);
>     name = luaG_findlocal(L, ar->i_ci, n, &pos);

250c252
<   name = findlocal(L, ar->i_ci, n, &pos);
>   name = luaG_findlocal(L, ar->i_ci, n, &pos);

262a265
>     ar->srclen = LL("=[C]");

269c272,279
<     ar->source = p->source ? getstr(p->source) : "=?";
>     if (p->source) {
>       ar->source = getstr(p->source);
>       ar->srclen = tsslen(p->source);
>     }
>     else {
>       ar->source = "=?";
>       ar->srclen = LL("=?");
>     }

274c284
<   luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
>   luaO_chunkid(ar->short_src, ar->source, ar->srclen);

613,614c623
<     case OP_POWI: case OP_DIVI: case OP_IDIVI:
<     case OP_BANDK: case OP_BORK: case OP_BXORK: {
>     case OP_POWI: case OP_DIVI: case OP_IDIVI: {

618a628,634
>     case OP_ADDK: case OP_SUBK: case OP_MULK: case OP_MODK:
>     case OP_POWK: case OP_DIVK: case OP_IDIVK:
>     case OP_BANDK: case OP_BORK: case OP_BXORK: {
>       int offset = GET_OPCODE(i) - OP_ADDK;  /* ORDER OP */
>       tm = cast(TMS, offset + TM_ADD);  /* ORDER TM */
>       break;
>     }

698a715,720
> l_noret luaG_forerror (lua_State *L, const TValue *o, const char *what) {
>   luaG_runerror(L, "bad 'for' %s (number expected, got %s)",
>                    what, luaT_objtypename(L, o));
> }
> 
> 

739c761
<     luaO_chunkid(buff, getstr(src), LUA_IDSIZE);
>     luaO_chunkid(buff, getstr(src), tsslen(src));

src/ldebug.h

2c2
< ** $Id: ldebug.h,v 2.18 2018/06/08 19:06:59 roberto Exp $
> ** $Id: ldebug.h $

24a25,26
> LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n,
>                                                     StkId *pos);

26a29,30
> LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o,
>                                                const char *what);

src/ldo.c

2c2
< ** $Id: ldo.c,v 2.202 2018/05/30 14:25:52 roberto Exp $
> ** $Id: ldo.c $

91c91
< static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
> void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {

94,95c94
<       TString *memerrmsg = luaS_newliteral(L, MEMERRMSG);
<       setsvalue2s(L, oldtop, memerrmsg); /* reuse preregistered msg. */
>       setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */

101a101,104
>     case CLOSEPROTECT: {
>       setnilvalue(s2v(oldtop));  /* no error message */
>       break;
>     }

117a121
>     errcode = luaF_close(L, L->stack, errcode);  /* close all upvalues */

125c129
<         seterrorobj(L, errcode, L->top);  /* assume EXTRA_STACK */
>         luaD_seterrorobj(L, errcode, L->top);  /* assume EXTRA_STACK */

138c142
<   unsigned short oldnCcalls = L->nCcalls - L->nci;
>   l_uint32 oldnCcalls = L->nCcalls - L->nci;

139a144
>   lua_assert(L->nCcalls >= L->nci);

368a374,375
>   StkId firstresult;
>   int i;

372c379
<       break;
>       return;

379c386
<       break;
>       return;

382,391d388
<       /* FALLTHROUGH */
<     default: {  /* multiple results */
<       StkId firstresult = L->top - nres;  /* index of first result */
<       int i;
<       /* move all results to correct place */
<       for (i = 0; i < nres && i < wanted; i++)
<         setobjs2s(L, res + i, firstresult + i);
<       for (; i < wanted; i++)  /* complete wanted number of results */
<         setnilvalue(s2v(res + i));
<       L->top = res + wanted;  /* top points after the last result */

393c390,399
<     }
>     default:  /* multiple results (or to-be-closed variables) */
>       if (hastocloseCfunc(wanted)) {  /* to-be-closed variables? */
>         ptrdiff_t savedres = savestack(L, res);
>         luaF_close(L, res, LUA_OK);  /* may change the stack */
>         res = restorestack(L, savedres);
>         wanted = codeNresults(wanted);  /* correct value */
>         if (wanted == LUA_MULTRET)
>           wanted = nres;
>       }
>       break;

394a401,407
>   firstresult = L->top - nres;  /* index of first result */
>   /* move all results to correct place */
>   for (i = 0; i < nres && i < wanted; i++)
>     setobjs2s(L, res + i, firstresult + i);
>   for (; i < wanted; i++)  /* complete wanted number of results */
>     setnilvalue(s2v(res + i));
>   L->top = res + wanted;  /* top points after the last result */

504c517,520
< ** Similar to 'luaD_call', but does not allow yields during the call
> ** Similar to 'luaD_call', but does not allow yields during the call.
> ** If there is a stack overflow, freeing all CI structures will
> ** force the subsequent call to invoke 'luaE_extendCI', which then
> ** will raise any errors.

507c523,525
<   L->nny++;
>   incXCcalls(L);
>   if (getCcalls(L) >= LUAI_MAXCSTACK)  /* possible stack overflow? */
>     luaE_freeCI(L);

509c527
<   L->nny--;
>   decXCcalls(L);

521c539
<   lua_assert(ci->u.c.k != NULL && L->nny == 0);
>   lua_assert(ci->u.c.k != NULL && yieldable(L));

587,588c605,607
<   luaF_close(L, oldtop);
<   seterrorobj(L, status, oldtop);
>   luaF_close(L, oldtop, status);  /* may change the stack */
>   oldtop = restorestack(L, ci->u2.funcidx);
>   luaD_seterrorobj(L, status, oldtop);

591d609
<   L->nny = 0;  /* should be zero to be yieldable */

644d661
< 

648d664
<   unsigned short oldnny = L->nny;  /* save "number of non-yieldable" calls */

652a669,670
>     else if (L->top - (L->ci->func + 1) == nargs)  /* no function? */
>       return resume_error(L, "cannot resume dead coroutine", nargs);

654c672
<   else if (L->status != LUA_YIELD)
>   else if (L->status != LUA_YIELD)  /* ended with errors? */

656,657c674,678
<   L->nCcalls = (from) ? from->nCcalls + 1 : 1;
<   if (L->nCcalls >= LUAI_MAXCCALLS)
>   if (from == NULL)
>     L->nCcalls = 1;
>   else  /* correct 'nCcalls' for this thread */
>     L->nCcalls = getCcalls(from) - from->nci + L->nci + CSTACKCF;
>   if (L->nCcalls >= LUAI_MAXCSTACK)

660d680
<   L->nny = 0;  /* allow yields */

663,675c683,693
<   if (unlikely(status == -1))  /* error calling 'lua_resume'? */
<     status = LUA_ERRRUN;
<   else {  /* continue running after recoverable errors */
<     while (errorstatus(status) && recover(L, status)) {
<       /* unroll continuation */
<       status = luaD_rawrunprotected(L, unroll, &status);
<     }
<     if (unlikely(errorstatus(status))) {  /* unrecoverable error? */
<       L->status = cast_byte(status);  /* mark thread as 'dead' */
<       seterrorobj(L, status, L->top);  /* push error message */
<       L->ci->top = L->top;
<     }
<     else lua_assert(status == L->status);  /* normal end or yield */
>    /* continue running after recoverable errors */
>   while (errorstatus(status) && recover(L, status)) {
>     /* unroll continuation */
>     status = luaD_rawrunprotected(L, unroll, &status);
>   }
>   if (likely(!errorstatus(status)))
>     lua_assert(status == L->status);  /* normal end or yield */
>   else {  /* unrecoverable error */
>     L->status = cast_byte(status);  /* mark thread as 'dead' */
>     luaD_seterrorobj(L, status, L->top);  /* push error message */
>     L->ci->top = L->top;

679,680d696
<   L->nny = oldnny;  /* restore 'nny' */
<   L->nCcalls--;

687c703
<   return (L->nny == 0);
>   return yieldable(L);

697c713
<   if (unlikely(L->nny > 0)) {
>   if (unlikely(!yieldable(L))) {

720a737,741
> /*
> ** Call the C function 'func' in protected mode, restoring basic
> ** thread information ('allowhook', etc.) and in particular
> ** its stack level in case of errors.
> */

726d746
<   unsigned short old_nny = L->nny;

732,733d751
<     luaF_close(L, oldtop);  /* close possible pending closures */
<     seterrorobj(L, status, oldtop);

736c754,756
<     L->nny = old_nny;
>     status = luaF_close(L, oldtop, status);
>     oldtop = restorestack(L, old_top);  /* previous call may change stack */
>     luaD_seterrorobj(L, status, oldtop);

787c807
<   L->nny++;  /* cannot yield during parsing */
>   incnny(L);  /* cannot yield during parsing */

798c818
<   L->nny--;
>   decnny(L);

src/ldo.h

2c2
< ** $Id: ldo.h,v 2.44 2018/05/22 12:02:36 roberto Exp $
> ** $Id: ldo.h $

52a53
> LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);

src/ldump.c

2c2
< ** $Id: ldump.c,v 2.41 2018/02/26 14:16:05 roberto Exp $
> ** $Id: ldump.c $

201c201
<   DumpByte(LUAC_VERSION, D);
>   DumpInt(LUAC_VERSION, D);

204,205d203
<   DumpByte(sizeof(int), D);
<   DumpByte(sizeof(size_t), D);

src/lfunc.c

2c2
< ** $Id: lfunc.c,v 2.51 2017/06/29 15:06:44 roberto Exp $
> ** $Id: lfunc.c $

16a17,18
> #include "ldebug.h"
> #include "ldo.h"

41a44
> 

57a61,86
> /*
> ** Create a new upvalue with the given tag at the given level,
> ** and link it to the list of open upvalues of 'L' after entry 'prev'.
> **/
> static UpVal *newupval (lua_State *L, int tag, StkId level, UpVal **prev) {
>   GCObject *o = luaC_newobj(L, tag, sizeof(UpVal));
>   UpVal *uv = gco2upv(o);
>   UpVal *next = *prev;
>   uv->v = s2v(level);  /* current value lives in the stack */
>   uv->u.open.next = next;  /* link it to list of open upvalues */
>   uv->u.open.previous = prev;
>   if (next)
>     next->u.open.previous = &uv->u.open.next;
>   *prev = uv;
>   if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */
>     L->twups = G(L)->twups;  /* link it to the list */
>     G(L)->twups = L;
>   }
>   return uv;
> }
> 
> 
> /*
> ** Find and reuse, or create if it does not exist, a regular upvalue
> ** at the given level.
> */

60d88
<   GCObject *o;

62d89
<   UpVal *uv;

64c91
<   while ((p = *pp) != NULL && uplevel(p) >= level) {
>   while ((p = *pp) != NULL && uplevel(p) >= level) {  /* search for it */

69,80c96,184
<   /* not found: create a new upvalue between 'pp' and 'p' */
<   o = luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal));
<   uv = gco2upv(o);
<   uv->u.open.next = p;  /* link it to list of open upvalues */
<   uv->u.open.previous = pp;
<   if (p)
<     p->u.open.previous = &uv->u.open.next;
<   *pp = uv;
<   uv->v = s2v(level);  /* current value lives in the stack */
<   if (!isintwups(L)) {  /* thread not in list of threads with upvalues? */
<     L->twups = G(L)->twups;  /* link it to the list */
<     G(L)->twups = L;
>   /* not found: create a new upvalue after 'pp' */
>   return newupval(L, LUA_TUPVAL, level, pp);
> }
> 
> 
> static void callclose (lua_State *L, void *ud) {
>   UNUSED(ud);
>   luaD_callnoyield(L, L->top - 3, 0);
> }
> 
> 
> /*
> ** Prepare closing method plus its arguments for object 'obj' with
> ** error message 'err'. (This function assumes EXTRA_STACK.)
> */
> static int prepclosingmethod (lua_State *L, TValue *obj, TValue *err) {
>   StkId top = L->top;
>   const TValue *tm = luaT_gettmbyobj(L, obj, TM_CLOSE);
>   if (ttisnil(tm))  /* no metamethod? */
>     return 0;  /* nothing to call */
>   setobj2s(L, top, tm);  /* will call metamethod... */
>   setobj2s(L, top + 1, obj);  /* with 'self' as the 1st argument */
>   setobj2s(L, top + 2, err);  /* and error msg. as 2nd argument */
>   L->top = top + 3;  /* add function and arguments */
>   return 1;
> }
> 
> 
> /*
> ** Prepare and call a closing method. If status is OK, code is still
> ** inside the original protected call, and so any error will be handled
> ** there. Otherwise, a previous error already activated original
> ** protected call, and so the call to the closing method must be
> ** protected here. (A status = CLOSEPROTECT behaves like a previous
> ** error, to also run the closing method in protected mode).
> ** If status is OK, the call to the closing method will be pushed
> ** at the top of the stack. Otherwise, values are pushed after
> ** the 'level' of the upvalue being closed, as everything after
> ** that won't be used again.
> */
> static int callclosemth (lua_State *L, TValue *uv, StkId level, int status) {
>   if (likely(status == LUA_OK)) {
>     if (prepclosingmethod(L, uv, &G(L)->nilvalue))  /* something to call? */
>       callclose(L, NULL);  /* call closing method */
>     else if (!ttisnil(uv)) {  /* non-closable non-nil value? */
>       int idx = cast_int(level - L->ci->func);
>       const char *vname = luaG_findlocal(L, L->ci, idx, NULL);
>       if (vname == NULL) vname = "?";
>       luaG_runerror(L, "attempt to close non-closable variable '%s'", vname);
>     }
>   }
>   else {  /* there was an error */
>     /* save error message and set stack top to 'level + 1' */
>     luaD_seterrorobj(L, status, level);
>     if (prepclosingmethod(L, uv, s2v(level))) {  /* something to call? */
>       int newstatus = luaD_pcall(L, callclose, NULL, savestack(L, level), 0);
>       if (newstatus != LUA_OK)  /* another error when closing? */
>         status = newstatus;  /* this will be the new error */
>     }
>     /* else no metamethod; ignore this case and keep original error */
>   }
>   return status;
> }
> 
> 
> /*
> ** Try to create a to-be-closed upvalue
> ** (can raise a memory-allocation error)
> */
> static void trynewtbcupval (lua_State *L, void *ud) {
>   StkId level = cast(StkId, ud);
>   lua_assert(L->openupval == NULL || uplevel(L->openupval) < level);
>   newupval(L, LUA_TUPVALTBC, level, &L->openupval);
> }
> 
> 
> /*
> ** Create a to-be-closed upvalue. If there is a memory error
> ** when creating the upvalue, the closing method must be called here,
> ** as there is no upvalue to call it later.
> */
> void luaF_newtbcupval (lua_State *L, StkId level) {
>   int status = luaD_rawrunprotected(L, trynewtbcupval, level);
>   if (unlikely(status != LUA_OK)) {  /* memory error creating upvalue? */
>     lua_assert(status == LUA_ERRMEM);
>     luaD_seterrorobj(L, LUA_ERRMEM, level + 1);  /* save error message */
>     if (prepclosingmethod(L, s2v(level), s2v(level + 1)))
>       callclose(L, NULL);  /* call closing method */
>     luaD_throw(L, LUA_ERRMEM);  /* throw memory error */

82d185
<   return uv;

94c197
< void luaF_close (lua_State *L, StkId level) {
> int luaF_close (lua_State *L, StkId level, int status) {

96,97c199,200
<   while (L->openupval != NULL &&
<         (uv = L->openupval, uplevel(uv) >= level)) {
>   while ((uv = L->openupval) != NULL && uplevel(uv) >= level) {
>     StkId upl = uplevel(uv);

104a208,213
>     if (uv->tt == LUA_TUPVALTBC && status != NOCLOSINGMETH) {
>       /* must run closing method */
>       ptrdiff_t levelrel = savestack(L, level);
>       status = callclosemth(L, uv->v, upl, status);  /* may change the stack */
>       level = restorestack(L, levelrel);
>     }

105a215
>   return status;

117,118d226
<   f->cache = NULL;
<   f->cachemiss = 0;

src/lfunc.h

2c2
< ** $Id: lfunc.h,v 2.20 2018/02/25 13:40:00 roberto Exp $
> ** $Id: lfunc.h $

44a45,55
> /*
> ** Special "status" for 'luaF_close'
> */
> 
> /* close upvalues without running their closing methods */
> #define NOCLOSINGMETH	(-1)
> 
> /* close upvalues running all closing methods in protected mode */
> #define CLOSEPROTECT	(-2)
> 
> 

50c61,62
< LUAI_FUNC void luaF_close (lua_State *L, StkId level);
> LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
> LUAI_FUNC int luaF_close (lua_State *L, StkId level, int status);

src/lgc.c

2c2
< ** $Id: lgc.c,v 2.254 2018/06/15 14:14:20 roberto Exp $
> ** $Id: lgc.c $

14a15
> 

102a104
> static void entersweep (lua_State *L);

183,185c185,191
< ** being pointed by a black object. (If in sweep phase, clear the black
< ** object to white [sweep it] to avoid other barrier calls for this
< ** same object.)
> ** 'v' being pointed by the black object 'o'. (If in sweep phase, clear
> ** the black object to white [sweep it] to avoid other barrier calls for
> ** this same object.) In the generational mode, 'v' must also become
> ** old, if 'o' is old; however, it cannot be changed directly to OLD,
> ** because it may still point to non-old objects. So, it is marked as
> ** OLD0. In the next cycle it will become OLD1, and in the next it
> ** will finally become OLD (regular old).

214c220
<   black2gray(o);  /* make table gray (again) */
>   black2gray(o);  /* make object gray (again) */

219,238d224
< /*
< ** Barrier for prototype's cache of closures.  For an 'old1'
< ** object, making it gray stops it from being visited by 'markold',
< ** so it is linked in the 'grayagain' list to ensure it will be
< ** visited. Otherwise, it goes to 'protogray', as only its 'cache' field
< ** needs to be revisited.  (A prototype to be in this barrier must be
< ** already finished, so its other fields cannot change and do not need
< ** to be revisited.)
< */
< LUAI_FUNC void luaC_protobarrier_ (lua_State *L, Proto *p) {
<   global_State *g = G(L);
<   lua_assert(g->gckind != KGC_GEN || isold(p));
<   if (getage(p) == G_OLD1)  /* still need to be visited? */
<     linkgclist(p, g->grayagain);  /* link it in 'grayagain' */
<   else
<     linkgclist(p, g->protogray);  /* link it in 'protogray' */
<   black2gray(p);  /* make prototype gray (to avoid other barriers) */
< }
< 
< 

290c276,277
<     case LUA_TUPVAL: {
>     case LUA_TUPVAL:
>     case LUA_TUPVALTBC: {

375c362
<   g->weak = g->allweak = g->ephemeron = g->protogray = NULL;
>   g->weak = g->allweak = g->ephemeron = NULL;

517,537c504,511
< /*
< ** Check the cache of a prototype, to keep invariants. If the
< ** cache is white, clear it. (A cache should not prevent the
< ** collection of its reference.) Otherwise, if in generational
< ** mode, check the generational invariant. If the cache is old,
< ** everything is ok. If the prototype is 'old0', everything
< ** is ok too. (It will naturally be visited again.) If the
< ** prototype is older than 'old0', then its cache (which is new)
< ** must be visited again in the next collection, so the prototype
< ** goes to the 'protogray' list. (If the prototype has a cache,
< ** it is already immutable and does not need other barriers;
< ** then, it can become gray without problems for its other fields.)
< */
< static void checkprotocache (global_State *g, Proto *p) {
<   if (p->cache) {
<     if (iswhite(p->cache))
<       p->cache = NULL;  /* allow cache to be collected */
<     else if (g->gckind == KGC_GEN && !isold(p->cache) && getage(p) >= G_OLD1) {
<       linkgclist(p, g->protogray);  /* link it in 'protogray' */
<       black2gray(p);  /* make prototype gray */
<     }
> static int traverseudata (global_State *g, Udata *u) {
>   int i;
>   markobjectN(g, u->metatable);  /* mark its metatable */
>   for (i = 0; i < u->nuvalue; i++)
>     markvalue(g, &u->uv[i].uv);
>   if (g->gckind == KGC_GEN) {
>     linkgclist(u, g->grayagain);  /* keep it in some gray list */
>     black2gray(u);

539c513
<   p->cachemiss = 0;  /* restart counting */
>   return 1 + u->nuvalue;

550d523
<   checkprotocache(g, f);

591a565
>   UpVal *uv;

598a573,576
>   for (uv = th->openupval; uv != NULL; uv = uv->u.open.next) {
>     if (uv->tt == LUA_TUPVALTBC)  /* to be closed? */
>       markobject(g, uv);  /* cannot be collected */
>   }

615,623d592
< static int traverseudata (global_State *g, Udata *u) {
<   int i;
<   markobjectN(g, u->metatable);  /* mark its metatable */
<   for (i = 0; i < u->nuvalue; i++)
<     markvalue(g, &u->uv[i].uv);
<   return 1 + u->nuvalue;
< }
< 
< 

683,695d651
< static void clearprotolist (global_State *g) {
<   GCObject *p = g->protogray;
<   g->protogray = NULL;
<   while (p != NULL) {
<     Proto *pp = gco2p(p);
<     GCObject *next = pp->gclist;
<     lua_assert(isgray(pp) && (pp->cache != NULL || pp->cachemiss >= MAXMISS));
<     gray2black(pp);
<     checkprotocache(g, pp);
<     p = next;
<   }
< }
< 

752a709
>     case LUA_TUPVALTBC:

871c828
< static void GCTM (lua_State *L, int propagateerrors) {
> static void GCTM (lua_State *L) {

878c835
<   if (tm != NULL && ttisfunction(tm)) {  /* is there a finalizer? */
>   if (!notm(tm)) {  /* is there a finalizer? */

892,900c849,855
<     if (status != LUA_OK && propagateerrors) {  /* error while running __gc? */
<       if (status == LUA_ERRRUN) {  /* is there an error object? */
<         const char *msg = (ttisstring(s2v(L->top - 1)))
<                             ? svalue(s2v(L->top - 1))
<                             : "no message";
<         luaO_pushfstring(L, "error in __gc metamethod (%s)", msg);
<         status = LUA_ERRGCMM;  /* error in __gc metamethod */
<       }
<       luaD_throw(L, status);  /* re-throw error */
>     if (status != LUA_OK) {  /* error while running __gc? */
>       const char *msg = (ttisstring(s2v(L->top - 1)))
>                         ? svalue(s2v(L->top - 1))
>                         : "error object is not a string";
>       luaE_warning(L, "error in __gc metamethod (", 1);
>       luaE_warning(L, msg, 1);
>       luaE_warning(L, ")", 0);

913c868
<     GCTM(L, 1);  /* call one finalizer */
>     GCTM(L);  /* call one finalizer */

921c876
< static void callallpendingfinalizers (lua_State *L, int propagateerrors) {
> static void callallpendingfinalizers (lua_State *L) {

924c879
<     GCTM(L, propagateerrors);
>     GCTM(L);

1006a962,963
> static void setpause (global_State *g);
> 

1081,1083c1038,1040
< ** Correct a list of gray objects. Because this correction is
< ** done after sweeping, young objects can be white and still
< ** be in the list. They are only removed.
> ** Correct a list of gray objects.
> ** Because this correction is done after sweeping, young objects might
> ** be turned white and still be in the list. They are only removed.

1100,1101c1057,1058
<         else {
<           if (!iswhite(curr)) {
>         else {  /* not touched in this cycle */
>           if (!iswhite(curr)) {  /* not white? */

1103,1104c1060,1061
<             if (getage(curr) == G_TOUCHED2)
<               changeage(curr, G_TOUCHED2, G_OLD);
>             if (getage(curr) == G_TOUCHED2)  /* advance from G_TOUCHED2... */
>               changeage(curr, G_TOUCHED2, G_OLD);  /* ... to G_OLD */

1106a1064
>           /* else, object is white: just remove it from this list */

1142c1100
< ** Mark 'old1' objects when starting a new young collection.
> ** Mark 'OLD1' objects when starting a new young collection.

1168c1126
<     callallpendingfinalizers(L, 1);
>     callallpendingfinalizers(L);

1173,1175c1131,1133
< ** Does a young collection. First, mark 'old1' objects.  (Only survival
< ** and "recent old" lists can contain 'old1' objects. New lists cannot
< ** contain 'old1' objects, at most 'old0' objects that were already
> ** Does a young collection. First, mark 'OLD1' objects.  (Only survival
> ** and "recent old" lists can contain 'OLD1' objects. New lists cannot
> ** contain 'OLD1' objects, at most 'OLD0' objects that were already

1208,1216c1166
< /*
< ** Enter generational mode. Must go until the end of an atomic cycle
< ** to ensure that all threads are in the gray list. Then, turn all
< ** objects into old and finishes the collection.
< */
< static void entergen (lua_State *L, global_State *g) {
<   luaC_runtilstate(L, bitmask(GCSpause));  /* prepare to start a new cycle */
<   luaC_runtilstate(L, bitmask(GCSpropagate));  /* start new cycle */
<   atomic(L);
> static void atomic2gen (lua_State *L, global_State *g) {

1228a1179
>   g->lastatomic = 0;

1234a1186,1200
> ** Enter generational mode. Must go until the end of an atomic cycle
> ** to ensure that all threads and weak tables are in the gray lists.
> ** Then, turn all objects into old and finishes the collection.
> */
> static lu_mem entergen (lua_State *L, global_State *g) {
>   lu_mem numobjs;
>   luaC_runtilstate(L, bitmask(GCSpause));  /* prepare to start a new cycle */
>   luaC_runtilstate(L, bitmask(GCSpropagate));  /* start new cycle */
>   numobjs = atomic(L);  /* propagates all and then do the atomic stuff */
>   atomic2gen(L, g);
>   return numobjs;
> }
> 
> 
> /*

1237c1203
< ** and go to pause state.
> ** and go to the pause state.

1246a1213
>   g->lastatomic = 0;

1260a1228
>   g->lastatomic = 0;

1267c1235
< static void fullgen (lua_State *L, global_State *g) {
> static lu_mem fullgen (lua_State *L, global_State *g) {

1269c1237,1246
<   entergen(L, g);
>   return entergen(L, g);
> }
> 
> 
> /*
> ** Set debt for the next minor collection, which will happen when
> ** memory grows 'genminormul'%.
> */
> static void setminordebt (global_State *g) {
>   luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));

1274,1277c1251,1307
< ** Does a generational "step". If memory grows 'genmajormul'% larger
< ** than last major collection (kept in 'g->GCestimate'), does a major
< ** collection. Otherwise, does a minor collection and set debt to make
< ** another collection when memory grows 'genminormul'% larger.
> ** Does a major collection after last collection was a "bad collection".
> **
> ** When the program is building a big struture, it allocates lots of
> ** memory but generates very little garbage. In those scenarios,
> ** the generational mode just wastes time doing small collections, and
> ** major collections are frequently what we call a "bad collection", a
> ** collection that frees too few objects. To avoid the cost of switching
> ** between generational mode and the incremental mode needed for full
> ** (major) collections, the collector tries to stay in incremental mode
> ** after a bad collection, and to switch back to generational mode only
> ** after a "good" collection (one that traverses less than 9/8 objects
> ** of the previous one).
> ** The collector must choose whether to stay in incremental mode or to
> ** switch back to generational mode before sweeping. At this point, it
> ** does not know the real memory in use, so it cannot use memory to
> ** decide whether to return to generational mode. Instead, it uses the
> ** number of objects traversed (returned by 'atomic') as a proxy. The
> ** field 'g->lastatomic' keeps this count from the last collection.
> ** ('g->lastatomic != 0' also means that the last collection was bad.)
> */
> static void stepgenfull (lua_State *L, global_State *g) {
>   lu_mem newatomic;  /* count of traversed objects */
>   lu_mem lastatomic = g->lastatomic;  /* count from last collection */
>   if (g->gckind == KGC_GEN)  /* still in generational mode? */
>     enterinc(g);  /* enter incremental mode */
>   luaC_runtilstate(L, bitmask(GCSpropagate));  /* start new cycle */
>   newatomic = atomic(L);  /* mark everybody */
>   if (newatomic < lastatomic + (lastatomic >> 3)) {  /* good collection? */
>     atomic2gen(L, g);  /* return to generational mode */
>     setminordebt(g);
>   }
>   else {  /* another bad collection; stay in incremental mode */
>     g->GCestimate = gettotalbytes(g);  /* first estimate */;
>     entersweep(L);
>     luaC_runtilstate(L, bitmask(GCSpause));  /* finish collection */
>     setpause(g);
>     g->lastatomic = newatomic;
>   }
> }
> 
> 
> /*
> ** Does a generational "step".
> ** Usually, this means doing a minor collection and setting the debt to
> ** make another collection when memory grows 'genminormul'% larger.
> **
> ** However, there are exceptions.  If memory grows 'genmajormul'%
> ** larger than it was at the end of the last major collection (kept
> ** in 'g->GCestimate'), the function does a major collection. At the
> ** end, it checks whether the major collection was able to free a
> ** decent amount of memory (at least half the growth in memory since
> ** previous major collection). If so, the collector keeps its state,
> ** and the next collection will probably be minor again. Otherwise,
> ** we have what we call a "bad collection". In that case, set the field
> ** 'g->lastatomic' to signal that fact, so that the next collection will
> ** go to 'stepgenfull'.
> **

1279c1309
< ** in that case, always do a minor collection.
> ** in that case, do a minor collection.

1282,1287c1312,1313
<   lu_mem majorbase = g->GCestimate;
<   int majormul = getgcparam(g->genmajormul);
<   if (g->GCdebt > 0 &&
<       gettotalbytes(g) > (majorbase / 100) * (100 + majormul)) {
<     fullgen(L, g);
<   }
>   if (g->lastatomic != 0)  /* last collection was a bad one? */
>     stepgenfull(L, g);  /* do a full step */

1289,1293c1315,1333
<     lu_mem mem;
<     youngcollection(L, g);
<     mem = gettotalbytes(g);
<     luaE_setdebt(g, -(cast(l_mem, (mem / 100)) * g->genminormul));
<     g->GCestimate = majorbase;  /* preserve base value */
>     lu_mem majorbase = g->GCestimate;  /* memory after last major collection */
>     lu_mem majorinc = (majorbase / 100) * getgcparam(g->genmajormul);
>     if (g->GCdebt > 0 && gettotalbytes(g) > majorbase + majorinc) {
>       lu_mem numobjs = fullgen(L, g);  /* do a major collection */
>       if (gettotalbytes(g) < majorbase + (majorinc / 2)) {
>         /* collected at least half of memory growth since last major
>            collection; keep doing minor collections */
>         setminordebt(g);
>       }
>       else {  /* bad collection */
>         g->lastatomic = numobjs;  /* signal that last collection was bad */
>         setpause(g);  /* do a long wait for next (major) collection */
>       }
>     }
>     else {  /* regular case; do a minor collection */
>       youngcollection(L, g);
>       setminordebt(g);
>       g->GCestimate = majorbase;  /* preserve base value */
>     }

1294a1335
>   lua_assert(isdecGCmodegen(g));

1364c1405
<   callallpendingfinalizers(L, 0);
>   callallpendingfinalizers(L);

1384a1426
>   work += propagateall(g);  /* empties 'gray' list */

1408d1449
<   clearprotolist(g);

1449,1450c1490
<       lu_mem work = propagateall(g);  /* make sure gray list is empty */
<       work += atomic(L);  /* work is what was traversed by 'atomic' */
>       lu_mem work = atomic(L);  /* work is what was traversed by 'atomic' */

1526,1528c1566
<     if (g->gckind == KGC_INC)
<       incstep(L, g);
<     else
>     if(isdecGCmodegen(g))

1529a1568,1569
>     else
>       incstep(L, g);

src/lgc.h

2c2
< ** $Id: lgc.h,v 2.103 2018/06/11 14:19:50 roberto Exp $
> ** $Id: lgc.h $

126c126
< #define LUAI_GCPAUSE    200     /* 200% */
> #define LUAI_GCPAUSE    200

130c130
< ** larger than 1000 in a 'lu_byte'.
> ** up to 1023 in a 'lu_byte'.

141a142,148
> ** Check whether the declared GC mode is generational. While in
> ** generational mode, the collector can go temporarily to incremental
> ** mode to improve performance. This is signaled by 'g->lastatomic != 0'.
> */
> #define isdecGCmodegen(g)	(g->gckind == KGC_GEN || g->lastatomic != 0)
> 
> /*

167,169d173
< #define luaC_protobarrier(L,p,o) \
< 	(isblack(p) ? luaC_protobarrier_(L,p) : cast_void(0))
< 

178d181
< LUAI_FUNC void luaC_protobarrier_ (lua_State *L, Proto *p);

src/linit.c

2c2
< ** $Id: linit.c,v 1.41 2018/02/27 18:47:32 roberto Exp $
> ** $Id: linit.c $

src/liolib.c

2c2
< ** $Id: liolib.c,v 2.156 2018/03/02 18:25:00 roberto Exp $
> ** $Id: liolib.c $

42c42
<          (*mode != '+' || (++mode, 1)) &&  /* skip if char is '+' */
>          (*mode != '+' || ((void)(++mode), 1)) &&  /* skip if char is '+' */

71c71
< 	  ((void)((void)c, m), \
> 	  ((void)c, (void)m, \

135a136
> 

338a340,348
> /*
> ** Auxiliar function to create the iteration function for 'lines'.
> ** The iteration function is a closure over 'io_readline', with
> ** the following upvalues:
> ** 1) The file being read (first value in the stack)
> ** 2) the number of arguments to read
> ** 3) a boolean, true iff file has to be closed when finished ('toclose')
> ** *) a variable number of format arguments (rest of the stack)
> */

341a352
>   lua_pushvalue(L, 1);  /* file */

344c355
<   lua_rotate(L, 2, 2);  /* move 'n' and 'toclose' to their positions */
>   lua_rotate(L, 2, 3);  /* move the three values to their positions */

355a367,371
> /*
> ** Return an iteration function for 'io.lines'. If file has to be
> ** closed, also returns the file itself as a second result (to be
> ** closed as the state at the exit of a generic for).
> */

371,372c387,395
<   aux_lines(L, toclose);
<   return 1;
>   aux_lines(L, toclose);  /* push iteration function */
>   if (toclose) {
>     lua_pushnil(L);  /* state */
>     lua_pushnil(L);  /* control */
>     lua_pushvalue(L, 1);  /* file is the to-be-closed variable (4th result) */
>     return 4;
>   }
>   else
>     return 1;

438c461
< ** correct and to convert it to a Lua number
> ** correct and to convert it to a Lua number.

484c507
<   int c = '\0';
>   int c;

486,487c509,510
<   while (c != EOF && c != '\n') {  /* repeat until end of line */
<     char *buff = luaL_prepbuffer(&b);  /* preallocate buffer */
>   do {  /* may need to read several chunks to get whole line */
>     char *buff = luaL_prepbuffer(&b);  /* preallocate buffer space */

491c514
<       buff[i++] = c;
>       buff[i++] = c;  /* read up to end of line or buffer limit */

494c517
<   }
>   } while (c != EOF && c != '\n');  /* repeat until end of line */

588a612,614
> /*
> ** Iteration function for 'lines'.
> */

609,610c635,636
<       lua_settop(L, 0);
<       lua_pushvalue(L, lua_upvalueindex(1));
>       lua_settop(L, 0);  /* clear stack */
>       lua_pushvalue(L, lua_upvalueindex(1));  /* push file at index 1 */

727a754
>   {"__close", f_gc},

src/ljumptab.h

0a1,7
> /*
> ** $Id: ljumptab.h $
> ** Jump Table for the Lua interpreter
> ** See Copyright Notice in lua.h
> */
> 
> 

12c19
< static void *disptab[] = {
> static void *disptab[NUM_OPCODES] = {

46a54,60
> &&L_OP_ADDK,
> &&L_OP_SUBK,
> &&L_OP_MULK,
> &&L_OP_MODK,
> &&L_OP_POWK,
> &&L_OP_DIVK,
> &&L_OP_IDIVK,

69a84
> &&L_OP_TBC,

87,88d101
< &&L_OP_FORLOOP1,
< &&L_OP_FORPREP1,

90a104
> &&L_OP_TFORPREP,

96c110
< &&L_OP_PREPVARARG,
> &&L_OP_VARARGPREP,

src/llex.c

2c2
< ** $Id: llex.c,v 2.102 2018/04/04 14:23:41 roberto Exp $
> ** $Id: llex.c $

85c85,88
<     return luaO_pushfstring(ls->L, "'%c'", token);
>     if (lisprint(token))
>       return luaO_pushfstring(ls->L, "'%c'", token);
>     else  /* control character */
>       return luaO_pushfstring(ls->L, "'<\\%d>'", token);

230a234,235
>   if (lislalnum(ls->current))  /* is numeral touching an alpha num? */
>     save_and_next(ls);  /* force an error */

247,249c252,254
< ** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return
< ** its number of '='s; otherwise, return a negative number (-1 iff there
< ** are no '='s after initial bracket)
> ** reads a sequence '[=*[' or ']=*]', leaving the last bracket.
> ** If sequence is well formed, return its number of '='s + 2; otherwise,
> ** return 1 if there is no '='s or 0 otherwise (an unfinished '[==...').

251,252c256,257
< static int skip_sep (LexState *ls) {
<   int count = 0;
> static size_t skip_sep (LexState *ls) {
>   size_t count = 0;

260c265,267
<   return (ls->current == s) ? count : (-count) - 1;
>   return (ls->current == s) ? count + 2
>          : (count == 0) ? 1
>          : 0;

264c271
< static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
> static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {

298,299c305,306
<     seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + (2 + sep),
<                                      luaZ_bufflen(ls->buff) - 2*(2 + sep));
>     seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
>                                      luaZ_bufflen(ls->buff) - 2 * sep);

334a342
>     esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");

336d343
<     esccheck(ls, r <= 0x10FFFF, "UTF-8 value too large");

447c454
<           int sep = skip_sep(ls);
>           size_t sep = skip_sep(ls);

449c456
<           if (sep >= 0) {
>           if (sep >= 2) {

461,462c468,469
<         int sep = skip_sep(ls);
<         if (sep >= 0) {
>         size_t sep = skip_sep(ls);
>         if (sep >= 2) {

466c473
<         else if (sep != -1)  /* '[=...' missing second bracket */
>         else if (sep == 0)  /* '[=...' missing second bracket? */

src/llex.h

2c2
< ** $Id: llex.h,v 1.82 2018/04/04 14:23:41 roberto Exp $
> ** $Id: llex.h $

src/llimits.h

2c2
< ** $Id: llimits.h,v 1.151 2018/06/15 14:13:45 roberto Exp $
> ** $Id: llimits.h $

16a17
> 

25c26
< #elif LUAI_BITSINT >= 32	/* }{ */
> #elif LUAI_IS32INT	/* }{ */

42c43
< /* maximum size visible for Lua (must be representable in a lua_Integer */
> /* maximum size visible for Lua (must be representable in a lua_Integer) */

67a69,72
> /* number of chars of a literal string without the ending \0 */
> #define LL(x)   (sizeof(x)/sizeof(char) - 1)
> 
> 

172,182d176
< ** maximum depth for nested C calls and syntactical nested non-terminals
< ** in a program. (Value must fit in an unsigned short int. It must also
< ** be compatible with the size of the C stack.)
< */
< #if !defined(LUAI_MAXCCALLS)
< #define LUAI_MAXCCALLS		2200
< #endif
< 
< 
< 
< /*

186,187c180,181
< #if LUAI_BITSINT >= 32
< typedef unsigned int Instruction;
> #if LUAI_IS32INT
> typedef unsigned int l_uint32;

189c183
< typedef unsigned long Instruction;
> typedef unsigned long l_uint32;

191a186,187
> typedef l_uint32 Instruction;
> 

296,300c292,300
< ** 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.
> ** modulo: defined as 'a - floor(a/b)*b'; the direct computation
> ** using this definition has several problems with rounding errors,
> ** so it is better to use 'fmod'. '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: non-integer result is equivalent to
> ** a non-zero remainder 'm'; negative result is equivalent to 'a' and
> ** 'b' with different signs, or 'm' and 'b' with different signs
> ** (as the result 'm' of 'fmod' has the same sign of 'a').

304c304,305
<   { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }
>   { (void)L; (m) = l_mathop(fmod)(a,b); \
>     if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); }

320a322,323
> #define luai_numgt(a,b)         ((a)>(b))
> #define luai_numge(a,b)         ((a)>=(b))

src/lmathlib.c

2c2
< ** $Id: lmathlib.c,v 1.135 2018/06/14 18:47:22 roberto Exp $
> ** $Id: lmathlib.c $

269c269
< #if (LONG_MAX >> 31 >> 31) >= 1
> #if (ULONG_MAX >> 31 >> 31) >= 3

279c279
< #elif (LUA_MAXINTEGER >> 31 >> 31) >= 1
> #elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3

304c304
<   return (x << n) | (trim64(x) >> (64 - n)); 
>   return (x << n) | (trim64(x) >> (64 - n));

326c326,327
< ** interval [0,1).
> ** interval [0,1), getting the higher FIG bits from the
> ** random unsigned integer and converting that to a float.

328,330c329,334
< #define maskFIG		(~(~(Rand64)1 << (FIGS - 1)))  /* use FIGS bits */
< #define shiftFIG  \
< 	(l_mathop(0.5) / ((Rand64)1 << (FIGS - 1)))  /* 2^(-FIGS) */
> 
> /* must throw out the extra (64 - FIGS) bits */
> #define shift64_FIG  	(64 - FIGS)
> 
> /* to scale to [0, 1), multiply by scaleFIG = 2^(-FIGS) */
> #define scaleFIG	(l_mathop(0.5) / ((Rand64)1 << (FIGS - 1)))

333c337
<   return (lua_Number)(x & maskFIG) * shiftFIG;
>   return (lua_Number)(trim64(x) >> shift64_FIG) * scaleFIG;

346c350
< #if (INT_MAX >> 30) >= 1
> #if LUAI_IS32INT

451a456
> 

454,456c459,469
< #define maskHI		0  /* do not need bits from higher half */
< #define maskLOW		(~(~UONE << (FIGS - 1)))  /* use FIGS bits */
< #define shiftFIG	(l_mathop(0.5) / (UONE << (FIGS - 1)))  /* 2^(-FIGS) */
> /* 2^(-FIGS) */
> #define scaleFIG       (l_mathop(0.5) / (UONE << (FIGS - 1)))
> 
> /*
> ** get up to 32 bits from higher half, shifting right to
> ** throw out the extra bits.
> */
> static lua_Number I2d (Rand64 x) {
>   lua_Number h = (lua_Number)(trim32(x.h) >> (32 - FIGS));
>   return h * scaleFIG;
> }

462,463c475,477
< /* use FIGS - 32 bits from higher half */
< #define maskHI		(~(~UONE << (FIGS - 33)))
> /* 2^(-FIGS) = 1.0 / 2^30 / 2^3 / 2^(FIGS-33) */
> #define scaleFIG  \
> 	((lua_Number)1.0 / (UONE << 30) / 8.0 / (UONE << (FIGS - 33)))

465,469c479,483
< /* use 32 bits from lower half */
< #define maskLOW		(~(~UONE << 31))
< 
< /* 2^(-FIGS) == (1 / 2^33) / 2^(FIGS-33) */
< #define shiftFIG  ((lua_Number)(1.0 / 8589934592.0) / (UONE << (FIGS - 33)))
> /*
> ** use FIGS - 32 bits from lower half, throwing out the other
> ** (32 - (FIGS - 32)) = (64 - FIGS) bits
> */
> #define shiftLOW	(64 - FIGS)

471c485,488
< #endif
> /*
> ** higher 32 bits go after those (FIGS - 32) bits: shiftHI = 2^(FIGS - 32)
> */
> #define shiftHI		((lua_Number)(UONE << (FIGS - 33)) * 2.0)

473d489
< #define twoto32		l_mathop(4294967296.0)  /* 2^32 */

476,478c492,494
<   lua_Number h = (lua_Number)(x.h & maskHI);
<   lua_Number l = (lua_Number)(x.l & maskLOW);
<   return (h * twoto32 + l) * shiftFIG;
>   lua_Number h = (lua_Number)trim32(x.h) * shiftHI;
>   lua_Number l = (lua_Number)(trim32(x.l) >> shiftLOW);
>   return (h + l) * scaleFIG;

480a497,498
> #endif
> 

523c541
< #if (LUA_MAXINTEGER >> 30 >> 1) > 0
> #if (LUA_MAXUNSIGNED >> 31) >= 3

581a600,611
> /*
> ** Set a "random" seed. To get some randomness, use the current time
> ** and the address of 'L' (in case the machine does address space layout
> ** randomization).
> */
> static void randseed (lua_State *L, RanState *state) {
>   lua_Unsigned seed1 = (lua_Unsigned)time(NULL);
>   lua_Unsigned seed2 = (lua_Unsigned)(size_t)L;
>   setseed(state->s, seed1, seed2);
> }
> 
> 

584,586c614,620
<   lua_Integer n1 = luaL_checkinteger(L, 1);
<   lua_Integer n2 = luaL_optinteger(L, 2, 0);
<   setseed(state->s, n1, n2);
>   if (lua_isnone(L, 1))
>     randseed(L, state);
>   else {
>     lua_Integer n1 = luaL_checkinteger(L, 1);
>     lua_Integer n2 = luaL_optinteger(L, 2, 0);
>     setseed(state->s, n1, n2);
>   }

600,602d633
< ** To give some "randomness" to the initial seed, use the current time
< ** and the address of 'L' (in case the machine does address space layout
< ** randomization).

606,608c637
<   lua_Unsigned seed1 = (lua_Unsigned)time(NULL); 
<   lua_Unsigned seed2 = (lua_Unsigned)(size_t)L; 
<   setseed(state->s, seed1, seed2);
>   randseed(L, state);  /* initialize with a "random" seed */

src/lmem.c

2c2
< ** $Id: lmem.c,v 1.98 2018/06/18 12:08:10 roberto Exp $
> ** $Id: lmem.c $

111c111
<   lua_assert((block == 0) == (block == NULL));
>   lua_assert((osize == 0) == (block == NULL));

src/lmem.h

2c2
< ** $Id: lmem.h,v 1.47 2018/01/28 15:13:26 roberto Exp $
> ** $Id: lmem.h $

src/loadlib.c

2c2
< ** $Id: loadlib.c,v 1.132 2018/02/27 18:47:32 roberto Exp $
> ** $Id: loadlib.c $

292a293
>   const char *dftmark;

294,295c295,296
<   const char *path = getenv(nver);  /* use versioned name */
<   if (path == NULL)  /* no environment variable? */
>   const char *path = getenv(nver);  /* try versioned name */
>   if (path == NULL)  /* no versioned environment variable? */

299,304c300,315
<   else {
<     /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
<     path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
<                               LUA_PATH_SEP AUXMARK LUA_PATH_SEP);
<     luaL_gsub(L, path, AUXMARK, dft);
<     lua_remove(L, -2); /* remove result from 1st 'gsub' */
>   else if ((dftmark = strstr(path, LUA_PATH_SEP LUA_PATH_SEP)) == NULL)
>     lua_pushstring(L, path);  /* nothing to change */
>   else {  /* path contains a ";;": insert default path in its place */
>     size_t len = strlen(path);
>     luaL_Buffer b;
>     luaL_buffinit(L, &b);
>     if (path < dftmark) {  /* is there a prefix before ';;'? */
>       luaL_addlstring(&b, path, dftmark - path);  /* add it */
>       luaL_addchar(&b, *LUA_PATH_SEP);
>     }
>     luaL_addstring(&b, dft);  /* add default */
>     if (dftmark < path + len - 2) {  /* is there a sufix after ';;'? */
>       luaL_addchar(&b, *LUA_PATH_SEP);
>       luaL_addlstring(&b, dftmark + 2, (path + len - 2) - dftmark);
>     }
>     luaL_pushresult(&b);

308c319
<   lua_pop(L, 1);  /* pop versioned variable name */
>   lua_pop(L, 1);  /* pop versioned variable name ('nver') */

424,431c435,470
< static const char *pushnexttemplate (lua_State *L, const char *path) {
<   const char *l;
<   while (*path == *LUA_PATH_SEP) path++;  /* skip separators */
<   if (*path == '\0') return NULL;  /* no more templates */
<   l = strchr(path, *LUA_PATH_SEP);  /* find next separator */
<   if (l == NULL) l = path + strlen(path);
<   lua_pushlstring(L, path, l - path);  /* template */
<   return l;
> /*
> ** Get the next name in '*path' = 'name1;name2;name3;...', changing
> ** the ending ';' to '\0' to create a zero-terminated string. Return
> ** NULL when list ends.
> */
> static const char *getnextfilename (char **path, char *end) {
>   char *sep;
>   char *name = *path;
>   if (name == end)
>     return NULL;  /* no more names */
>   else if (*name == '\0') {  /* from previous iteration? */
>     *name = *LUA_PATH_SEP;  /* restore separator */
>     name++;  /* skip it */
>   }
>   sep = strchr(name, *LUA_PATH_SEP);  /* find next separator */
>   if (sep == NULL)  /* separator not found? */
>     sep = end;  /* name goes until the end */
>   *sep = '\0';  /* finish file name */
>   *path = sep;  /* will start next search from here */
>   return name;
> }
> 
> 
> /*
> ** Given a path such as ";blabla.so;blublu.so", pushes the string
> **
> ** 	no file 'blabla.so'
> **	no file 'blublu.so'
> */
> static void pusherrornotfound (lua_State *L, const char *path) {
>   luaL_Buffer b;
>   luaL_buffinit(L, &b);
>   luaL_addstring(&b, "\n\tno file '");
>   luaL_addgsub(&b, path, LUA_PATH_SEP, "'\n\tno file '");
>   luaL_addstring(&b, "'");
>   luaL_pushresult(&b);

439,440c478,483
<   luaL_Buffer msg;  /* to build error message */
<   if (*sep != '\0')  /* non-empty separator? */
>   luaL_Buffer buff;
>   char *pathname;  /* path with name inserted */
>   char *endpathname;  /* its end */
>   const char *filename;
>   /* separator is non-empty and appears in 'name'? */
>   if (*sep != '\0' && strchr(name, *sep) != NULL)

442,446c485,491
<   luaL_buffinit(L, &msg);
<   while ((path = pushnexttemplate(L, path)) != NULL) {
<     const char *filename = luaL_gsub(L, lua_tostring(L, -1),
<                                      LUA_PATH_MARK, name);
<     lua_remove(L, -2);  /* remove path template */
>   luaL_buffinit(L, &buff);
>   /* add path to the buffer, replacing marks ('?') with the file name */
>   luaL_addgsub(&buff, path, LUA_PATH_MARK, name);
>   luaL_addchar(&buff, '\0');
>   pathname = luaL_buffaddr(&buff);  /* writable list of file names */
>   endpathname = pathname + luaL_bufflen(&buff) - 1;
>   while ((filename = getnextfilename(&pathname, endpathname)) != NULL) {

448,451c493
<       return filename;  /* return that file name */
<     lua_pushfstring(L, "\n\tno file '%s'", filename);
<     lua_remove(L, -2);  /* remove file name */
<     luaL_addvalue(&msg);  /* concatenate error msg. entry */
>       return lua_pushstring(L, filename);  /* save and return name */

453c495,496
<   luaL_pushresult(&msg);  /* create error message */
>   luaL_pushresult(&buff);  /* push path to create error message */
>   pusherrornotfound(L, lua_tostring(L, -1));  /* create error message */

563c606
<   if (lua_getfield(L, -1, name) == LUA_TNIL)  /* not found? */
>   if (lua_getfield(L, -1, name) == LUA_TNIL) {  /* not found? */

565c608,613
<   return 1;
>     return 1;
>   }
>   else {
>     lua_pushliteral(L, ":preload:");
>     return 2;
>   }

607,608c655,658
<   lua_pushstring(L, name);  /* pass name as argument to module loader */
<   lua_insert(L, -2);  /* name is 1st argument (before search data) */
>   lua_rotate(L, -2, 1);  /* function <-> loader data */
>   lua_pushvalue(L, 1);  /* name is 1st argument to module loader */
>   lua_pushvalue(L, -3);  /* loader data is 2nd argument */
>   /* stack: ...; loader data; loader function; mod. name; loader data */

609a660
>   /* stack: ...; loader data; result from loader */

611a663,664
>   else
>     lua_pop(L, 1);  /* pop nil */

614c667
<     lua_pushvalue(L, -1);  /* extra copy to be returned */
>     lua_copy(L, -1, -2);  /* replace loader result */

617c670,671
<   return 1;
>   lua_rotate(L, -2, 1);  /* loader data <-> module result  */
>   return 2;  /* return module result and loader data */

src/lobject.c

2c2
< ** $Id: lobject.c,v 2.126 2018/06/01 17:40:38 roberto Exp $
> ** $Id: lobject.c $

86c86
<     case LUA_OPIDIV: return luaV_div(L, v1, v2);
>     case LUA_OPIDIV: return luaV_idiv(L, v1, v2);

109,113c109
<     case LUA_OPMOD: {
<       lua_Number m;
<       luai_nummod(L, v1, v2, m);
<       return m;
<     }
>     case LUA_OPMOD: return luaV_modf(L, v1, v2);

350c346
<   lua_assert(x <= 0x10FFFF);
>   lua_assert(x <= 0x7FFFFFFFu);

371c367
< ** Convert a number object to a string
> ** Convert a number object to a string, adding it to a buffer

373,374c369
< void luaO_tostring (lua_State *L, TValue *obj) {
<   char buff[MAXNUMBER2STR];
> static size_t tostringbuff (TValue *obj, char *buff) {

378c373
<     len = lua_integer2str(buff, sizeof(buff), ivalue(obj));
>     len = lua_integer2str(buff, MAXNUMBER2STR, ivalue(obj));

380c375
<     len = lua_number2str(buff, sizeof(buff), fltvalue(obj));
>     len = lua_number2str(buff, MAXNUMBER2STR, fltvalue(obj));

385a381,390
>   return len;
> }
> 
> 
> /*
> ** Convert a number object to a Lua string, replacing the value at 'obj'
> */
> void luaO_tostring (lua_State *L, TValue *obj) {
>   char buff[MAXNUMBER2STR];
>   size_t len = tostringbuff(obj, buff);

390c395,420
< static void pushstr (lua_State *L, const char *str, size_t l) {
> 
> 
> /*
> ** {==================================================================
> ** 'luaO_pushvfstring'
> ** ===================================================================
> */
> 
> /* size for buffer space used by 'luaO_pushvfstring' */
> #define BUFVFS		400
> 
> /* buffer used by 'luaO_pushvfstring' */
> typedef struct BuffFS {
>   lua_State *L;
>   int pushed;  /* number of string pieces already on the stack */
>   int blen;  /* length of partial string in 'space' */
>   char space[BUFVFS];  /* holds last part of the result */
> } BuffFS;
> 
> 
> /*
> ** Push given string to the stack, as part of the buffer. If the stack
> ** is almost full, join all partial strings in the stack into one.
> */
> static void pushstr (BuffFS *buff, const char *str, size_t l) {
>   lua_State *L = buff->L;

392c422,427
<   L->top++;
>   L->top++;  /* may use one extra slot */
>   buff->pushed++;
>   if (buff->pushed > 1 && L->top + 1 >= L->stack_last) {
>     luaV_concat(L, buff->pushed);  /* join all partial results into one */
>     buff->pushed = 1;
>   }

397c432,483
< ** this function handles only '%d', '%c', '%f', '%p', and '%s'
> ** empty the buffer space into the stack
> */
> static void clearbuff (BuffFS *buff) {
>   pushstr(buff, buff->space, buff->blen);  /* push buffer contents */
>   buff->blen = 0;  /* space now is empty */
> }
> 
> 
> /*
> ** Get a space of size 'sz' in the buffer. If buffer has not enough
> ** space, empty it. 'sz' must fit in an empty space.
> */
> static char *getbuff (BuffFS *buff, size_t sz) {
>   lua_assert(buff->blen <= BUFVFS); lua_assert(sz <= BUFVFS);
>   if (sz > BUFVFS - cast_sizet(buff->blen))  /* string does not fit? */
>     clearbuff(buff);
>   return buff->space + buff->blen;
> }
> 
> 
> #define addsize(b,sz)	((b)->blen += (sz))
> 
> 
> /*
> ** Add 'str' to the buffer. If string is larger than the buffer space,
> ** push the string directly to the stack.
> */
> static void addstr2buff (BuffFS *buff, const char *str, size_t slen) {
>   if (slen <= BUFVFS) {  /* does string fit into buffer? */
>     char *bf = getbuff(buff, slen);
>     memcpy(bf, str, slen);  /* add string to buffer */
>     addsize(buff, slen);
>   }
>   else {  /* string larger than buffer */
>     clearbuff(buff);  /* string comes after buffer's content */
>     pushstr(buff, str, slen);  /* push string */
>   }
> }
> 
> 
> /*
> ** Add a number to the buffer.
> */
> static void addnum2buff (BuffFS *buff, TValue *num) {
>   char *numbuff = getbuff(buff, MAXNUMBER2STR);
>   size_t len = tostringbuff(num, numbuff);  /* format number into 'numbuff' */
>   addsize(buff, len);
> }
> 
> 
> /*
> ** this function handles only '%d', '%c', '%f', '%p', '%s', and '%%'

401,402c487,490
<   int n = 0;  /* number of strings in the stack to concatenate */
<   const char *e;  /* points to next conversion specifier */
>   BuffFS buff;  /* holds last part of the result */
>   const char *e;  /* points to next '%' */
>   buff.pushed = buff.blen = 0;
>   buff.L = L;

404,405c492,493
<     pushstr(L, fmt, e - fmt);  /* string up to conversion specifier */
<     switch (*(e+1)) {
>     addstr2buff(&buff, fmt, e - fmt);  /* add 'fmt' up to '%' */
>     switch (*(e + 1)) {  /* conversion specifier */

409c497
<         pushstr(L, s, strlen(s));
>         addstr2buff(&buff, s, strlen(s));

413,417c501,502
<         char buff = cast_char(va_arg(argp, int));
<         if (lisprint(cast_uchar(buff)))
<           pushstr(L, &buff, 1);
<         else  /* non-printable character; print its code */
<           luaO_pushfstring(L, "<\\%d>", cast_uchar(buff));
>         char c = cast_uchar(va_arg(argp, int));
>         addstr2buff(&buff, &c, sizeof(char));

421,422c506,509
<         setivalue(s2v(L->top), va_arg(argp, int));
<         goto top2str;
>         TValue num;
>         setivalue(&num, va_arg(argp, int));
>         addnum2buff(&buff, &num);
>         break;

425,426c512,515
<         setivalue(s2v(L->top), cast(lua_Integer, va_arg(argp, l_uacInt)));
<         goto top2str;
>         TValue num;
>         setivalue(&num, cast(lua_Integer, va_arg(argp, l_uacInt)));
>         addnum2buff(&buff, &num);
>         break;

429,432c518,520
<         setfltvalue(s2v(L->top), cast_num(va_arg(argp, l_uacNumber)));
<       top2str:  /* convert the top element to a string */
<         L->top++;
<         luaO_tostring(L, s2v(L->top - 1));
>         TValue num;
>         setfltvalue(&num, cast_num(va_arg(argp, l_uacNumber)));
>         addnum2buff(&buff, &num);

436c524,525
<         char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */
>         const int sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */
>         char *bf = getbuff(&buff, sz);

438,439c527,528
<         int l = lua_pointer2str(buff, sizeof(buff), p);
<         pushstr(L, buff, l);
>         int len = lua_pointer2str(bf, sz, p);
>         addsize(&buff, len);

442,445c531,534
<       case 'U': {  /* an 'int' as a UTF-8 sequence */
<         char buff[UTF8BUFFSZ];
<         int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long)));
<         pushstr(L, buff + UTF8BUFFSZ - l, l);
>       case 'U': {  /* a 'long' as a UTF-8 sequence */
>         char bf[UTF8BUFFSZ];
>         int len = luaO_utf8esc(bf, va_arg(argp, long));
>         addstr2buff(&buff, bf + UTF8BUFFSZ - len, len);

449c538
<         pushstr(L, "%", 1);
>         addstr2buff(&buff, "%", 1);

457,462c546
<     n += 2;
<     if (L->top + 2 > L->stack_last) {  /* no free stack space? */
<       luaV_concat(L, n);
<       n = 1;
<     }
<     fmt = e + 2;
>     fmt = e + 2;  /* skip '%' and the specifier */

464,465c548,551
<   pushstr(L, fmt, strlen(fmt));
<   if (n > 0) luaV_concat(L, n + 1);
>   addstr2buff(&buff, fmt, strlen(fmt));  /* rest of 'fmt' */
>   clearbuff(&buff);  /* empty buffer into the stack */
>   if (buff.pushed > 1)
>     luaV_concat(L, buff.pushed);  /* join all partial results */

478a565
> /* }================================================================== */

480,481d566
< /* number of chars of a literal string without the ending \0 */
< #define LL(x)	(sizeof(x)/sizeof(char) - 1)

489,490c574,575
< void luaO_chunkid (char *out, const char *source, size_t bufflen) {
<   size_t l = strlen(source);
> void luaO_chunkid (char *out, const char *source, size_t srclen) {
>   size_t bufflen = LUA_IDSIZE;  /* free space in buffer */

492,493c577,578
<     if (l <= bufflen)  /* small enough? */
<       memcpy(out, source + 1, l * sizeof(char));
>     if (srclen <= bufflen)  /* small enough? */
>       memcpy(out, source + 1, srclen * sizeof(char));

500,501c585,586
<     if (l <= bufflen)  /* small enough? */
<       memcpy(out, source + 1, l * sizeof(char));
>     if (srclen <= bufflen)  /* small enough? */
>       memcpy(out, source + 1, srclen * sizeof(char));

505c590
<       memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
>       memcpy(out, source + 1 + srclen - bufflen, bufflen * sizeof(char));

512,513c597,598
<     if (l < bufflen && nl == NULL) {  /* small one-line source? */
<       addstr(out, source, l);  /* keep it */
>     if (srclen < bufflen && nl == NULL) {  /* small one-line source? */
>       addstr(out, source, srclen);  /* keep it */

516,518c601,603
<       if (nl != NULL) l = nl - source;  /* stop at first newline */
<       if (l > bufflen) l = bufflen;
<       addstr(out, source, l);
>       if (nl != NULL) srclen = nl - source;  /* stop at first newline */
>       if (srclen > bufflen) srclen = bufflen;
>       addstr(out, source, srclen);

src/lobject.h

2c2
< ** $Id: lobject.h,v 2.146 2018/06/15 19:31:22 roberto Exp $
> ** $Id: lobject.h $

353,360d352
< /*
< ** Ensures that address after this type is always fully aligned.
< */
< typedef union UTString {
<   LUAI_MAXALIGN;  /* ensures maximum alignment for strings */
<   TString tsv;
< } UTString;
< 

367c359
<   check_exp(sizeof((ts)->extra), cast_charp((ts)) + sizeof(UTString))
>   check_exp(sizeof((ts)->extra), cast_charp((ts)) + sizeof(TString))

508d499
<   lu_byte cachemiss;  /* count for successive misses for 'cache' field */

519d509
<   struct LClosure *cache;  /* last-created closure with this prototype */

590a581,584
> /* variant for "To Be Closed" upvalues */
> #define LUA_TUPVALTBC	(LUA_TUPVAL | (1 << 4))
> 
> 

756c750
< LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
> LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen);

src/lopcodes.c

2c2
< ** $Id: lopcodes.c,v 1.82 2018/04/19 15:42:41 roberto Exp $
> ** $Id: lopcodes.c $

20,105d19
< #if defined(LUAI_DEFOPNAMES)
< 
< LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
<   "MOVE",
<   "LOADI",
<   "LOADF",
<   "LOADK",
<   "LOADKX",
<   "LOADBOOL",
<   "LOADNIL",
<   "GETUPVAL",
<   "SETUPVAL",
<   "GETTABUP",
<   "GETTABLE",
<   "GETI",
<   "GETFIELD",
<   "SETTABUP",
<   "SETTABLE",
<   "SETI",
<   "SETFIELD",
<   "NEWTABLE",
<   "SELF",
<   "ADDI",
<   "SUBI",
<   "MULI",
<   "MODI",
<   "POWI",
<   "DIVI",
<   "IDIVI",
<   "BANDK",
<   "BORK",
<   "BXORK",
<   "SHRI",
<   "SHLI",
<   "ADD",
<   "SUB",
<   "MUL",
<   "MOD",
<   "POW",
<   "DIV",
<   "IDIV",
<   "BAND",
<   "BOR",
<   "BXOR",
<   "SHL",
<   "SHR",
<   "UNM",
<   "BNOT",
<   "NOT",
<   "LEN",
<   "CONCAT",
<   "CLOSE",
<   "JMP",
<   "EQ",
<   "LT",
<   "LE",
<   "EQK",
<   "EQI",
<   "LTI",
<   "LEI",
<   "GTI",
<   "GEI",
<   "TEST",
<   "TESTSET",
<   "CALL",
<   "TAILCALL",
<   "RETURN",
<   "RETURN0",
<   "RETURN1",
<   "FORLOOP1",
<   "FORPREP1",
<   "FORLOOP",
<   "FORPREP",
<   "TFORCALL",
<   "TFORLOOP",
<   "SETLIST",
<   "CLOSURE",
<   "VARARG",
<   "PREPVARARG",
<   "EXTRAARG",
<   NULL
< };
< 
< #endif
< 
< 

133a48,54
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_ADDK */
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_SUBK */
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_MULK */
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_MODK */
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_POWK */
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_DIVK */
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_IDIVK */

156a78
>  ,opmode(0, 0, 0, 0, iABC)		/* OP_TBC */

174,175d95
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_FORLOOP1 */
<  ,opmode(0, 0, 0, 1, iABx)		/* OP_FORPREP1 */

177a98
>  ,opmode(0, 0, 0, 0, iABx)		/* OP_TFORPREP */

183c104
<  ,opmode(0, 0, 0, 1, iABC)		/* OP_PREPVARARG */
>  ,opmode(0, 0, 0, 1, iABC)		/* OP_VARARGPREP */

src/lopcodes.h

2c2
< ** $Id: lopcodes.h,v 1.193 2018/06/18 12:51:05 roberto Exp $
> ** $Id: lopcodes.h $

24c24
< isJ                          sJ(24)                   |m|   Op(7)     |
> isJ                          sJ(25)                     |   Op(7)     |

43c43
< #define SIZE_sJ		(SIZE_Bx + SIZE_A - 1)
> #define SIZE_sJ		(SIZE_Bx + SIZE_A)

58,59c58,59
< #define POS_m		POS_A
< #define POS_sJ		(POS_A + 1)
> #define POS_sJ		POS_A
> 

63,64c63,64
< ** we use (signed) int to manipulate most arguments,
< ** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
> ** we use (signed) 'int' to manipulate most arguments,
> ** so they must fit in ints.

66c66,71
< #if SIZE_Bx < LUAI_BITSINT-1
> 
> /* Check whether type 'int' has at least 'b' bits ('b' < 32) */
> #define L_INTHASBITS(b)		((UINT_MAX >> ((b) - 1)) >= 1)
> 
> 
> #if L_INTHASBITS(SIZE_Bx)

75c80
< #if SIZE_Ax < LUAI_BITSINT-1
> #if L_INTHASBITS(SIZE_Ax)

81c86
< #if SIZE_sJ < LUAI_BITSINT-1
> #if L_INTHASBITS(SIZE_sJ)

94d98
< #define MAXARG_Cx	((1<<(SIZE_C + 1))-1)

147,148d150
< #define GETARG_m(i)	check_exp(checkopm(i, isJ), getarg(i, POS_m, 1))
< #define SETARG_m(i,m)	setarg(i, m, POS_m, 1)

226a229,236
> OP_ADDK,/*	A B C	R(A) := R(B) + K(C)				*/
> OP_SUBK,/*	A B C	R(A) := R(B) - K(C)				*/
> OP_MULK,/*	A B C	R(A) := R(B) * K(C)				*/
> OP_MODK,/*	A B C	R(A) := R(B) % K(C)				*/
> OP_POWK,/*	A B C	R(A) := R(B) ^ K(C)				*/
> OP_DIVK,/*	A B C	R(A) := R(B) / K(C)				*/
> OP_IDIVK,/*	A B C	R(A) := R(B) // K(C)				*/
> 

231,232c241,242
< OP_SHRI,/*	A B C	R(A) := R(B) >> C				*/
< OP_SHLI,/*	A B C	R(A) := C << R(B)				*/
> OP_SHRI,/*	A B sC	R(A) := R(B) >> C				*/
> OP_SHLI,/*	A B sC	R(A) := C << R(B)				*/

240a251
> 

245a257
> 

253a266
> OP_TBC,/*	A	mark variable A "to be closed"			*/

267c280
< OP_TESTSET,/*	A B	if (not R(B) == k) then R(A) := R(B) else pc++	*/
> OP_TESTSET,/*	A B	if (not R(B) == k) then pc++ else R(A) := R(B)	*/

276,279d288
< OP_FORLOOP1,/*	A Bx	R(A)++;
< 			if R(A) <= R(A+1) then { pc-=Bx; R(A+3)=R(A) }	*/
< OP_FORPREP1,/*	A Bx	R(A)--; pc+=Bx					*/
< 

284,285c293,295
< OP_TFORCALL,/*	A C	R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));	*/
< OP_TFORLOOP,/*	A Bx	if R(A+1) ~= nil then { R(A)=R(A+1); pc -= Bx }	*/
> OP_TFORPREP,/*	A Bx	create upvalue for R(A + 3); pc+=Bx		*/
> OP_TFORCALL,/*	A C	R(A+4), ... ,R(A+3+C) := R(A)(R(A+1), R(A+2));	*/
> OP_TFORLOOP,/*	A Bx	if R(A+2) ~= nil then { R(A)=R(A+2); pc -= Bx }	*/

293c303
< OP_PREPVARARG,/*A 	(adjust vararg parameters)			*/
> OP_VARARGPREP,/*A 	(adjust vararg parameters)			*/

299c309
< #define NUM_OPCODES	(cast_int(OP_EXTRAARG) + 1)
> #define NUM_OPCODES	((int)(OP_EXTRAARG) + 1)

305,307c315,317
<   (*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is
<   set to last_result+1, so next open instruction (OP_CALL, OP_RETURN*,
<   OP_SETLIST) may use 'top'.
>   (*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then
>   'top' is set to last_result+1, so next open instruction (OP_CALL,
>   OP_RETURN*, OP_SETLIST) may use 'top'.

329a340,342
>   (*) In comparisons with an immediate operand, C signals whether the
>   original operand was a float.
> 

361,363d373
< LUAI_DDEC(const char *const luaP_opnames[NUM_OPCODES+1];)  /* opcode names */
< 
< 

src/lopnames.h

0a1,101
> /*
> ** $Id: lopnames.h $
> ** Opcode names
> ** See Copyright Notice in lua.h
> */
> 
> #if !defined(lopnames_h)
> #define lopnames_h
> 
> /* ORDER OP */
> 
> static const char *const opnames[] = {
>   "MOVE",
>   "LOADI",
>   "LOADF",
>   "LOADK",
>   "LOADKX",
>   "LOADBOOL",
>   "LOADNIL",
>   "GETUPVAL",
>   "SETUPVAL",
>   "GETTABUP",
>   "GETTABLE",
>   "GETI",
>   "GETFIELD",
>   "SETTABUP",
>   "SETTABLE",
>   "SETI",
>   "SETFIELD",
>   "NEWTABLE",
>   "SELF",
>   "ADDI",
>   "SUBI",
>   "MULI",
>   "MODI",
>   "POWI",
>   "DIVI",
>   "IDIVI",
>   "ADDK",
>   "SUBK",
>   "MULK",
>   "MODK",
>   "POWK",
>   "DIVK",
>   "IDIVK",
>   "BANDK",
>   "BORK",
>   "BXORK",
>   "SHRI",
>   "SHLI",
>   "ADD",
>   "SUB",
>   "MUL",
>   "MOD",
>   "POW",
>   "DIV",
>   "IDIV",
>   "BAND",
>   "BOR",
>   "BXOR",
>   "SHL",
>   "SHR",
>   "UNM",
>   "BNOT",
>   "NOT",
>   "LEN",
>   "CONCAT",
>   "CLOSE",
>   "TBC",
>   "JMP",
>   "EQ",
>   "LT",
>   "LE",
>   "EQK",
>   "EQI",
>   "LTI",
>   "LEI",
>   "GTI",
>   "GEI",
>   "TEST",
>   "TESTSET",
>   "CALL",
>   "TAILCALL",
>   "RETURN",
>   "RETURN0",
>   "RETURN1",
>   "FORLOOP",
>   "FORPREP",
>   "TFORPREP",
>   "TFORCALL",
>   "TFORLOOP",
>   "SETLIST",
>   "CLOSURE",
>   "VARARG",
>   "VARARGPREP",
>   "EXTRAARG",
>   NULL
> };
> 
> #endif
> 

src/loslib.c

2c2
< ** $Id: loslib.c,v 1.66 2017/03/14 12:40:44 roberto Exp $
> ** $Id: loslib.c $

13d12
< #include <errno.h>

src/lparser.c

2c2
< ** $Id: lparser.c,v 2.181 2018/06/18 17:57:20 roberto Exp $
> ** $Id: lparser.c $

12a13
> #include <limits.h>

52,53d52
<   int brks;  /* list of break jumps in this block */
<   lu_byte brkcls;  /* true if some 'break' needs to close upvalues */

56a56
>   lu_byte insidetbc;  /* true if inside the scope of a to-be-closed var. */

91a92,94
> /*
> ** Test whether next token is 'c'; if so, skip it.
> */

100a104,106
> /*
> ** Check that next token is 'c'.
> */

106a113,115
> /*
> ** Check that next token is 'c' and skip it.
> */

116c125,129
< 
> /*
> ** Check that next token is 'what' and skip it. In case of error,
> ** raise an error that the expected 'what' should match a 'who'
> ** in line 'where' (if that is not the current line).
> */

118,120c131,133
<   if (!testnext(ls, what)) {
<     if (where == ls->linenumber)
<       error_expected(ls, what);
>   if (unlikely(!testnext(ls, what))) {
>     if (where == ls->linenumber)  /* all in the same line? */
>       error_expected(ls, what);  /* do not need a complex message */

145a159,165
> static void init_var (expdesc *e, expkind k, int i) {
>   e->f = e->t = NO_JUMP;
>   e->k = k;
>   e->u.var.idx = i;
> }
> 
> 

151c171
< static void checkname (LexState *ls, expdesc *e) {
> static void codename (LexState *ls, expdesc *e) {

155a176,179
> /*
> ** Register a new local variable in the active 'Proto' (for debug
> ** information).
> */

170c194,197
< static void new_localvar (LexState *ls, TString *name) {
> /*
> ** Create a new local variable with the given 'name'.
> */
> static Vardesc *new_localvar (LexState *ls, TString *name) {

172a200
>   Vardesc *var;

178c206,210
<   dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
>   var = &dyd->actvar.arr[dyd->actvar.n++];
>   var->idx = cast(short, reg);
>   var->name = name;
>   var->ro = 0;
>   return var;

180a213,214
> #define new_localvarliteral(ls,v) \
>     new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));

182,184d215
< static void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {
<   new_localvar(ls, luaX_newstring(ls, name, sz));
< }

186,187d216
< #define new_localvarliteral(ls,v) \
< 	new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)

188a218,224
> /*
> ** Return the "variable description" (Vardesc) of a given
> ** variable
> */
> static Vardesc *getlocalvardesc (FuncState *fs, int i) {
>   return &fs->ls->dyd->actvar.arr[fs->firstlocal + i];
> }

189a226,228
> /*
> ** Get the debug-information entry for current variable 'i'.
> */

191c230
<   int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;
>   int idx = getlocalvardesc(fs, i)->idx;

196a236,276
> /*
> ** Return the "variable description" (Vardesc) of a given
> ** variable or upvalue
> */
> static Vardesc *getvardesc (FuncState *fs, expdesc *e) {
>   if (e->k == VLOCAL)
>     return getlocalvardesc(fs, e->u.var.idx);
>   else if (e->k != VUPVAL)
>     return NULL;  /* not a local variable */
>   else {  /* upvalue: must go up all levels up to the original local */
>     int idx = e->u.var.idx;
>     for (;;) {
>       Upvaldesc *up = &fs->f->upvalues[idx];
>       fs = fs->prev;  /* must look at the previous level */
>       idx = up->idx;  /* at this index */
>       if (fs == NULL) {  /* no more levels? (can happen only with _ENV) */
>         lua_assert(strcmp(getstr(up->name), LUA_ENV) == 0);
>         return NULL;
>       }
>       else if (up->instack)  /* got to the original level? */
>         return getlocalvardesc(fs, idx);
>       /* else repeat for previous level */
>     }
>   }
> }
> 
> 
> static void check_readonly (LexState *ls, expdesc *e) {
>   Vardesc *vardesc = getvardesc(ls->fs, e);
>   if (vardesc && vardesc->ro) {  /* is variable local and const? */
>     const char *msg = luaO_pushfstring(ls->L,
>        "attempt to assign to const variable '%s'", getstr(vardesc->name));
>     luaK_semerror(ls, msg);  /* error */
>   }
> }
> 
> 
> /*
> ** Start the scope for the last 'nvars' created variables.
> ** (debug info.)
> */

205a286,289
> /*
> ** Close the scope for all variables up to level 'tolevel'.
> ** (debug info.)
> */

212a297,300
> /*
> ** Search the upvalues of the function 'fs' for one
> ** with the given 'name'.
> */

232c320
<   f->upvalues[fs->nups].idx = cast_byte(v->u.info);
>   f->upvalues[fs->nups].idx = cast_byte(v->u.var.idx);

238a327,330
> /*
> ** Look for an active local variable with the name 'n' in the
> ** function 'fs'.
> */

250,251c342,343
<   Mark block where variable at given level was defined
<   (to emit close instructions later).
> ** Mark block where variable at given level was defined
> ** (to emit close instructions later).

257a350
>   fs->needclose = 1;

262,263c355,357
<   Find variable with given name 'n'. If it is an upvalue, add this
<   upvalue into all intermediate functions.
> ** Find a variable with the given name 'n'. If it is an upvalue, add
> ** this upvalue into all intermediate functions. If it is a global, set
> ** 'var' as 'void' as a flag.

271c365
<       init_exp(var, VLOCAL, v);  /* variable is local */
>       init_var(var, VLOCAL, v);  /* variable is local */

284c378
<       init_exp(var, VUPVAL, idx);  /* new or old upvalue */
>       init_var(var, VUPVAL, idx);  /* new or old upvalue */

289a384,387
> /*
> ** Find a variable with the given name 'n', handling global variables
> ** too.
> */

303a402,405
> /*
> ** Adjust the number of results from an expression list 'e' with 'nexps'
> ** expressions to 'nvars' values.
> */

306,309c408,412
<   int extra = nvars - nexps;
<   if (hasmultret(e->k)) {
<     extra++;  /* includes call itself */
<     if (extra < 0) extra = 0;
>   int needed = nvars - nexps;  /* extra values needed */
>   if (hasmultret(e->k)) {  /* last expression has multiple returns? */
>     int extra = needed + 1;  /* discount last expression itself */
>     if (extra < 0)
>       extra = 0;

311d413
<     if (extra > 1) luaK_reserveregs(fs, extra-1);

314,319c416,419
<     if (e->k != VVOID) luaK_exp2nextreg(fs, e);  /* close last expression */
<     if (extra > 0) {
<       int reg = fs->freereg;
<       luaK_reserveregs(fs, extra);
<       luaK_nil(fs, reg, extra);
<     }
>     if (e->k != VVOID)  /* at least one expression? */
>       luaK_exp2nextreg(fs, e);  /* close last expression */
>     if (needed > 0)  /* missing values? */
>       luaK_nil(fs, fs->freereg, needed);  /* complete with nils */

321,322c421,424
<   if (nexps > nvars)
<     ls->fs->freereg -= nexps - nvars;  /* remove extra values */
>   if (needed > 0)
>     luaK_reserveregs(fs, needed);  /* registers for extra values */
>   else  /* adding 'needed' is actually a subtraction */
>     fs->freereg += needed;  /* remove extra values */

326c428,433
< #define enterlevel(ls)	luaE_incCcalls((ls)->L)
> /*
> ** Macros to limit the maximum recursion depth while parsing
> */
> #define enterlevel(ls)	luaE_enterCcall((ls)->L)
> 
> #define leavelevel(ls)	luaE_exitCcall((ls)->L)

329c436,445
< #define leavelevel(ls)	((ls)->L->nCcalls--)
> /*
> ** Generates an error that a goto jumps into the scope of some
> ** local variable.
> */
> static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {
>   const char *varname = getstr(getlocvar(ls->fs, gt->nactvar)->varname);
>   const char *msg = "<goto %s> at line %d jumps into the scope of local '%s'";
>   msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line, varname);
>   luaK_semerror(ls, msg);  /* raise the error */
> }

332c448,453
< static void closegoto (LexState *ls, int g, Labeldesc *label) {
> /*
> ** Solves the goto at index 'g' to given 'label' and removes it
> ** from the list of pending goto's.
> ** If it jumps into the scope of some variable, raises an error.
> */
> static void solvegoto (LexState *ls, int g, Labeldesc *label) {

334,336c455,456
<   FuncState *fs = ls->fs;
<   Labellist *gl = &ls->dyd->gt;
<   Labeldesc *gt = &gl->arr[g];
>   Labellist *gl = &ls->dyd->gt;  /* list of goto's */
>   Labeldesc *gt = &gl->arr[g];  /* goto to be resolved */

338,347c458,461
<   if (gt->nactvar < label->nactvar) {
<     TString *vname = getlocvar(fs, gt->nactvar)->varname;
<     const char *msg = luaO_pushfstring(ls->L,
<       "<goto %s> at line %d jumps into the scope of local '%s'",
<       getstr(gt->name), gt->line, getstr(vname));
<     luaK_semerror(ls, msg);
<   }
<   luaK_patchgoto(fs, gt->pc, label->pc, 1);
<   /* remove goto from pending list */
<   for (i = g; i < gl->n - 1; i++)
>   if (unlikely(gt->nactvar < label->nactvar))  /* enter some scope? */
>     jumpscopeerror(ls, gt);
>   luaK_patchlist(ls->fs, gt->pc, label->pc);
>   for (i = g; i < gl->n - 1; i++)  /* remove goto from pending list */

354c468
< ** try to close a goto with existing labels; this solves backward jumps
> ** Search for an active label with the given name.

356c470
< static int solvelabel (LexState *ls, int g) {
> static Labeldesc *findlabel (LexState *ls, TString *name) {

358d471
<   BlockCnt *bl = ls->fs->bl;

360,362c473,474
<   Labeldesc *gt = &dyd->gt.arr[g];
<   /* check labels in current block for a match */
<   for (i = bl->firstlabel; i < dyd->label.n; i++) {
>   /* check labels in current function for a match */
>   for (i = ls->fs->firstlabel; i < dyd->label.n; i++) {

364,370c476,477
<     if (eqstr(lb->name, gt->name)) {  /* correct label? */
<       if (gt->nactvar > lb->nactvar &&
<           (bl->upval || dyd->label.n > bl->firstlabel))
<         luaK_patchclose(ls->fs, gt->pc);
<       closegoto(ls, g, lb);  /* close it */
<       return 1;
<     }
>     if (eqstr(lb->name, name))  /* correct label? */
>       return lb;

372c479
<   return 0;  /* label not found; cannot close goto */
>   return NULL;  /* label not found */

375a483,485
> /*
> ** Adds a new label/goto in the corresponding list.
> */

383a494
>   l->arr[n].close = 0;

389a501,505
> static int newgotoentry (LexState *ls, TString *name, int line, int pc) {
>   return newlabelentry(ls, &ls->dyd->gt, name, line, pc);
> }
> 
> 

391,392c507,509
< ** check whether new label 'lb' matches any pending gotos in current
< ** block; solves forward jumps
> ** Solves forward jumps. Check whether new label 'lb' matches any
> ** pending gotos in current block and solves them. Return true
> ** if any of the goto's need to close upvalues.

394c511
< static void solvegotos (LexState *ls, Labeldesc *lb) {
> static int solvegotos (LexState *ls, Labeldesc *lb) {

396a514
>   int needsclose = 0;

398,399c516,519
<     if (eqstr(gl->arr[i].name, lb->name))
<       closegoto(ls, i, lb);  /* will remove 'i' from the list */
>     if (eqstr(gl->arr[i].name, lb->name)) {
>       needsclose |= gl->arr[i].close;
>       solvegoto(ls, i, lb);  /* will remove 'i' from the list */
>     }

402a523,547
>   return needsclose;
> }
> 
> 
> /*
> ** Create a new label with the given 'name' at the given 'line'.
> ** 'last' tells whether label is the last non-op statement in its
> ** block. Solves all pending goto's to this new label and adds
> ** a close instruction if necessary.
> ** Returns true iff it added a close instruction.
> */
> static int createlabel (LexState *ls, TString *name, int line,
>                         int last) {
>   FuncState *fs = ls->fs;
>   Labellist *ll = &ls->dyd->label;
>   int l = newlabelentry(ls, ll, name, line, luaK_getlabel(fs));
>   if (last) {  /* label is last no-op statement in the block? */
>     /* assume that locals are already out of scope */
>     ll->arr[l].nactvar = fs->bl->nactvar;
>   }
>   if (solvegotos(ls, &ll->arr[l])) {  /* need close? */
>     luaK_codeABC(fs, OP_CLOSE, fs->nactvar, 0, 0);
>     return 1;
>   }
>   return 0;

407,411c552
< ** export pending gotos to outer level, to check them against
< ** outer labels; if the block being exited has upvalues, and
< ** the goto exits the scope of any variable (which can be the
< ** upvalue), close those variables being exited. Also export
< ** break list.
> ** Adjust pending gotos to outer level of a block.

414c555
<   int i = bl->firstgoto;
>   int i;

416,418c557,558
<   /* correct pending gotos to current block and try to close it
<      with visible labels */
<   while (i < gl->n) {  /* for each pending goto */
>   /* correct pending gotos to current block */
>   for (i = bl->firstgoto; i < gl->n; i++) {  /* for each pending goto */

421,422d560
<       if (bl->upval)  /* variable may be an upvalue? */
<         luaK_patchclose(fs, gt->pc);  /* jump will need a close */

423a562
>       gt->close |= bl->upval;  /* jump may need a close */

425,435c564
<     if (!solvelabel(fs->ls, i))
<       i++;  /* move to next one */
<     /* else, 'solvelabel' removed current goto from the list
<        and 'i' now points to next one */
<   }
<   /* handles break list */
<   if (bl->upval)  /* exiting the scope of an upvalue? */
<     luaK_patchclose(fs, bl->brks);  /* breaks will need OP_CLOSE */
<   /* move breaks to outer block */
<   luaK_concat(fs, &bl->previous->brks, bl->brks);
<   bl->previous->brkcls |= bl->brkcls;
>   }

444,445d572
<   bl->brks = NO_JUMP;
<   bl->brkcls = 0;

446a574
>   bl->insidetbc = (fs->bl != NULL && fs->bl->insidetbc);

454,467d581
< ** Fix all breaks in block 'bl' to jump to the end of the block.
< */
< static void fixbreaks (FuncState *fs, BlockCnt *bl) {
<   int target = fs->pc;
<   if (bl->brkcls)  /* does the block need to close upvalues? */
<     luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
<   luaK_patchgoto(fs, bl->brks, target, bl->brkcls);
<   bl->brks = NO_JUMP;  /* no more breaks to fix */
<   bl->brkcls = 0;  /* no more need to close upvalues */
<   lua_assert(!bl->upval);  /* loop body cannot have local variables */
< }
< 
< 
< /*

471,472c585,593
<   const char *msg = "no visible label '%s' for <goto> at line %d";
<   msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
>   const char *msg;
>   if (eqstr(gt->name, luaS_newliteral(ls->L, "break"))) {
>     msg = "break outside loop at line %d";
>     msg = luaO_pushfstring(ls->L, msg, gt->line);
>   }
>   else {
>     msg = "no visible label '%s' for <goto> at line %d";
>     msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
>   }

480,484c601,604
<   if (bl->upval && bl->brks != NO_JUMP)  /* breaks in upvalue scopes? */
<     bl->brkcls = 1;  /* these breaks must close the upvalues */
<   if (bl->isloop)
<     fixbreaks(fs, bl);  /* fix pending breaks */
<   if (bl->previous && bl->upval)
>   int hasclose = 0;
>   if (bl->isloop)  /* fix pending breaks? */
>     hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0);
>   if (!hasclose && bl->previous && bl->upval)

494d613
<     lua_assert(bl->brks == NO_JUMP);  /* no pending breaks */

549a669
>   fs->needclose = 0;

550a671
>   fs->firstlabel = ls->dyd->label.n;

562c683
<   luaK_ret(fs, 0, 0);  /* final return */
>   luaK_ret(fs, fs->nactvar, 0);  /* final return */

619c740
<   checkname(ls, &key);
>   codename(ls, &key);

656c777
<     checkname(ls, &key);
>     codename(ls, &key);

757c878
<   luaK_codeABC(fs, OP_PREPVARARG, nparams, 0, 0);
>   luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0);

925c1046
<         checkname(ls, &key);
>         codename(ls, &key);

1034a1156,1158
> /*
> ** Priority table for binary operators.
> */

1063c1187
<   if (uop != OPR_NOUNOPR) {
>   if (uop != OPR_NOUNOPR) {  /* prefix (unary) operator? */

1065c1189
<     luaX_next(ls);
>     luaX_next(ls);  /* skip operator */

1076c1200
<     luaX_next(ls);
>     luaX_next(ls);  /* skip operator */

1136c1260
<         if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) {
>         if (v->k == VUPVAL && lh->v.u.ind.t == v->u.var.idx) {

1143c1267
<         if (v->k == VLOCAL && lh->v.u.ind.t == v->u.info) {
>         if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.idx) {

1149c1273
<             lh->v.u.ind.idx == v->u.info) {
>             lh->v.u.ind.idx == v->u.var.idx) {

1159c1283
<     luaK_codeABC(fs, op, extra, v->u.info, 0);
>     luaK_codeABC(fs, op, extra, v->u.var.idx, 0);

1164,1165c1288,1295
< 
< static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
> /*
> ** Parse and compile a mulitple assignment. The first "variable"
> ** (a 'suffixedexp') was already read by the caller.
> **
> ** assignment -> suffixedexp restassign
> ** restassign -> ',' suffixedexp restassign | '=' explist
> */
> static void restassign (LexState *ls, struct LHS_assign *lh, int nvars) {

1168c1298,1299
<   if (testnext(ls, ',')) {  /* assignment -> ',' suffixedexp assignment */
>   check_readonly(ls, &lh->v);
>   if (testnext(ls, ',')) {  /* restassign -> ',' suffixedexp restassign */

1174,1176c1305,1307
<     luaE_incCcalls(ls->L);  /* control recursion depth */
<     assignment(ls, &nv, nvars+1);
<     ls->L->nCcalls--;
>     enterlevel(ls);  /* control recursion depth */
>     restassign(ls, &nv, nvars+1);
>     leavelevel(ls);

1178c1309
<   else {  /* assignment -> '=' explist */
>   else {  /* restassign -> '=' explist */

1205c1336,1337
< static void gotostat (LexState *ls, int pc) {
> static void gotostat (LexState *ls) {
>   FuncState *fs = ls->fs;

1207,1210c1339,1350
<   int g;
<   luaX_next(ls);  /* skip 'goto' */
<   g = newlabelentry(ls, &ls->dyd->gt, str_checkname(ls), line, pc);
<   solvelabel(ls, g);  /* close it if label already defined */
>   TString *name = str_checkname(ls);  /* label's name */
>   Labeldesc *lb = findlabel(ls, name);
>   if (lb == NULL)  /* no label? */
>     /* forward jump; will be resolved when the label is declared */
>     newgotoentry(ls, name, line, luaK_jump(fs));
>   else {  /* found a label */
>     /* backward jump; will be resolved here */
>     if (fs->nactvar > lb->nactvar)  /* leaving the scope of some variable? */
>       luaK_codeABC(fs, OP_CLOSE, lb->nactvar, 0, 0);
>     /* create jump and link it to the label */
>     luaK_patchlist(fs, luaK_jump(fs), lb->pc);
>   }

1214,1216c1354,1358
< static void breakstat (LexState *ls, int pc) {
<   FuncState *fs = ls->fs;
<   BlockCnt *bl = fs->bl;
> /*
> ** Break statement. Semantically equivalent to "goto break".
> */
> static void breakstat (LexState *ls) {
>   int line = ls->linenumber;

1218,1221c1360
<   while (bl && !bl->isloop) { bl = bl->previous; }
<   if (!bl)
<     luaX_syntaxerror(ls, "no loop to break");
<   luaK_concat(fs, &fs->bl->brks, pc);
>   newgotoentry(ls, luaS_newliteral(ls->L, "break"), line, luaK_jump(ls->fs));

1225,1234c1364,1372
< /* check for repeated labels on the same block */
< static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {
<   int i;
<   for (i = fs->bl->firstlabel; i < ll->n; i++) {
<     if (eqstr(label, ll->arr[i].name)) {
<       const char *msg = luaO_pushfstring(fs->ls->L,
<                           "label '%s' already defined on line %d",
<                           getstr(label), ll->arr[i].line);
<       luaK_semerror(fs->ls, msg);
<     }
> /*
> ** Check whether there is already a label with the given 'name'.
> */
> static void checkrepeated (LexState *ls, TString *name) {
>   Labeldesc *lb = findlabel(ls, name);
>   if (unlikely(lb != NULL)) {  /* already defined? */
>     const char *msg = "label '%s' already defined on line %d";
>     msg = luaO_pushfstring(ls->L, msg, getstr(name), lb->line);
>     luaK_semerror(ls, msg);  /* error */

1239,1246c1377
< /* skip no-op statements */
< static void skipnoopstat (LexState *ls) {
<   while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
<     statement(ls);
< }
< 
< 
< static void labelstat (LexState *ls, TString *label, int line) {
> static void labelstat (LexState *ls, TString *name, int line) {

1248,1251d1378
<   FuncState *fs = ls->fs;
<   Labellist *ll = &ls->dyd->label;
<   int l;  /* index of new label being created */
<   checkrepeated(fs, ll, label);  /* check for repeated labels */

1253,1261c1380,1383
<   /* create new entry for this label */
<   l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));
<   luaK_codeABC(fs, OP_CLOSE, fs->nactvar, 0, 0);
<   skipnoopstat(ls);  /* skip other no-op statements */
<   if (block_follow(ls, 0)) {  /* label is last no-op statement in the block? */
<     /* assume that locals are already out of scope */
<     ll->arr[l].nactvar = fs->bl->nactvar;
<   }
<   solvegotos(ls, &ll->arr[l]);
>   while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
>     statement(ls);  /* skip other no-op statements */
>   checkrepeated(ls, name);  /* check for repeated labels */
>   createlabel(ls, name, line, block_follow(ls, 0));

1296,1297d1417
<   if (bl2.upval)  /* upvalues? */
<     luaK_patchclose(fs, condexit);

1313,1314c1433
< ** stack slot. Return true if expression is a constant integer and,
< ** if 'i' is not-zero, its value is equal to 'i'.
> ** stack slot.

1317c1436
< static int exp1 (LexState *ls, int i) {
> static void exp1 (LexState *ls) {

1319d1437
<   int res;

1321d1438
<   res = luaK_isKint(&e) && (i == 0 || i == e.u.ival);

1324d1440
<   return res;

1338c1454
<   if (offset > MAXARG_Bx)
>   if (unlikely(offset > MAXARG_Bx))

1345,1347c1461
< ** Generate code for a 'for' loop. 'kind' can be zero (a common for
< ** loop), one (a basic for loop, with integer values and increment of
< ** 1), or two (a generic for loop).
> ** Generate code for a 'for' loop.

1349c1463
< static void forbody (LexState *ls, int base, int line, int nvars, int kind) {
> static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {

1350a1465,1466
>   static OpCode forprep[2] = {OP_FORPREP, OP_TFORPREP};
>   static OpCode forloop[2] = {OP_FORLOOP, OP_TFORLOOP};

1354d1469
<   adjustlocalvars(ls, 3);  /* control variables */

1356,1358c1471
<   prep = (kind == 0) ? luaK_codeABx(fs, OP_FORPREP, base, 0)
<        : (kind == 1) ? luaK_codeABx(fs, OP_FORPREP1, base, 0)
<        : luaK_jump(fs);
>   prep = luaK_codeABx(fs, forprep[isgen], base, 0);

1364,1365c1477,1478
<   if (kind == 2) {  /* generic for? */
<     luaK_patchtohere(fs, prep);
>   fixforjump(fs, prep, luaK_getlabel(fs), 0);
>   if (isgen) {  /* generic for? */

1368,1373c1481
<     endfor = luaK_codeABx(fs, OP_TFORLOOP, base + 2, 0);
<   }
<   else {
<     fixforjump(fs, prep, luaK_getlabel(fs), 0);
<     endfor = (kind == 0) ? luaK_codeABx(fs, OP_FORLOOP, base, 0)
<                          : luaK_codeABx(fs, OP_FORLOOP1, base, 0);
>     base += 2;  /* base for 'OP_TFORLOOP' (skips function and state) */

1374a1483
>   endfor = luaK_codeABx(fs, forloop[isgen], base, 0);

1384d1492
<   int basicfor = 1;  /* true if it is a "basic" 'for' (integer + 1) */

1390,1391c1498
<   if (!exp1(ls, 0))  /* initial value not an integer? */
<     basicfor = 0;  /* not a basic 'for' */
>   exp1(ls);  /* initial value */

1393,1397c1500,1502
<   exp1(ls, 0);  /* limit */
<   if (testnext(ls, ',')) {
<     if (!exp1(ls, 1))  /* optional step not 1? */
<       basicfor = 0;  /* not a basic 'for' */
<   }
>   exp1(ls);  /* limit */
>   if (testnext(ls, ','))
>     exp1(ls);  /* optional step */

1402c1507,1508
<   forbody(ls, base, line, 1, basicfor);
>   adjustlocalvars(ls, 3);  /* control variables */
>   forbody(ls, base, line, 1, 0);

1410c1516
<   int nvars = 4;  /* gen, state, control, plus at least one declared var */
>   int nvars = 5;  /* gen, state, control, toclose, 'indexname' */

1415a1522
>   markupval(fs, fs->nactvar);  /* state may create an upvalue */

1416a1524
>   new_localvarliteral(ls, "(for toclose)");

1425c1533,1534
<   adjust_assign(ls, 3, explist(ls, &e), &e);
>   adjust_assign(ls, 4, explist(ls, &e), &e);
>   adjustlocalvars(ls, 4);  /* control variables */

1427c1536
<   forbody(ls, base, line, nvars - 3, 2);
>   forbody(ls, base, line, nvars - 4, 1);

1448a1558,1589
> /*
> ** Check whether next instruction is a single jump (a 'break', a 'goto'
> ** to a forward label, or a 'goto' to a backward label with no variable
> ** to close). If so, set the name of the 'label' it is jumping to
> ** ("break" for a 'break') or to where it is jumping to ('target') and
> ** return true. If not a single jump, leave input unchanged, to be
> ** handled as a regular statement.
> */
> static int issinglejump (LexState *ls, TString **label, int *target) {
>   if (testnext(ls, TK_BREAK)) {  /* a break? */
>     *label = luaS_newliteral(ls->L, "break");
>     return 1;
>   }
>   else if (ls->t.token != TK_GOTO || luaX_lookahead(ls) != TK_NAME)
>     return 0;  /* not a valid goto */
>   else {
>     TString *lname = ls->lookahead.seminfo.ts;  /* label's id */
>     Labeldesc *lb = findlabel(ls, lname);
>     if (lb) {  /* a backward jump? */
>       if (ls->fs->nactvar > lb->nactvar)  /* needs to close variables? */
>         return 0;  /* not a single jump; cannot optimize */
>       *target = lb->pc;
>     }
>     else  /* jump forward */
>       *label = lname;
>     luaX_next(ls);  /* skip goto */
>     luaX_next(ls);  /* skip name */
>     return 1;
>   }
> }
> 
> 

1451a1593
>   int line;

1452a1595,1596
>   TString *jlb = NULL;
>   int target = NO_JUMP;

1458c1602,1603
<   if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
>   line = ls->linenumber;
>   if (issinglejump(ls, &jlb, &target)) {  /* 'if x then goto' ? */

1461,1464c1606,1609
<     if (ls->t.token == TK_GOTO)
<       gotostat(ls, v.t);  /* handle goto */
<     else
<       breakstat(ls, v.t);  /* handle break */
>     if (jlb != NULL)  /* forward jump? */
>       newgotoentry(ls, jlb, line, v.t);  /* will be resolved later */
>     else  /* backward jump */
>       luaK_patchlist(fs, v.t, target);  /* jump directly to 'target' */

1466c1611
<     if (block_follow(ls, 0)) {  /* 'goto'/'break' is the entire block? */
>     if (block_follow(ls, 0)) {  /* jump is the entire block? */

1473c1618
<   else {  /* regular case (not goto/break) */
>   else {  /* regular case (not a jump) */

1512c1657
< static void localstat (LexState *ls) {
> static void commonlocalstat (LexState *ls) {

1531a1677,1713
> static void tocloselocalstat (LexState *ls, Vardesc *var) {
>   FuncState *fs = ls->fs;
>   var->ro = 1;  /* to-be-closed variables are always read-only */
>   markupval(fs, fs->nactvar);
>   fs->bl->insidetbc = 1;  /* in the scope of a to-be-closed variable */
>   luaK_codeABC(fs, OP_TBC, fs->nactvar - 1, 0, 0);
> }
> 
> 
> static void attriblocalstat (LexState *ls) {
>   Vardesc *var;
>   TString *attr = str_checkname(ls);
>   testnext(ls, '>');
>   var = new_localvar(ls, str_checkname(ls));
>   checknext(ls, '=');
>   exp1(ls);
>   adjustlocalvars(ls, 1);
>   if (strcmp(getstr(attr), "const") == 0)
>     var->ro = 1;  /* set variable as read-only */
>   else if (strcmp(getstr(attr), "toclose") == 0)
>     tocloselocalstat(ls, var);
>   else
>     luaK_semerror(ls,
>       luaO_pushfstring(ls->L, "unknown attribute '%s'", getstr(attr)));
> }
> 
> 
> static void localstat (LexState *ls) {
>   /* stat -> LOCAL NAME {',' NAME} ['=' explist]
>            | LOCAL *toclose NAME '=' exp */
>   if (testnext(ls, '<'))
>     attriblocalstat(ls);
>   else
>     commonlocalstat(ls);
> }
> 
> 

1565c1747
<     assignment(ls, &v, 1);
>     restassign(ls, &v, 1);

1579c1761,1762
<   int first, nret;  /* registers with returned values */
>   int nret;  /* number of values being returned */
>   int first = fs->nactvar;  /* first slot to be returned */

1581c1764
<     first = nret = 0;  /* return no values */
>     nret = 0;  /* return no values */

1586c1769
<       if (e.k == VCALL && nret == 1) {  /* tail call? */
>       if (e.k == VCALL && nret == 1 && !fs->bl->insidetbc) {  /* tail call? */

1590d1772
<       first = fs->nactvar;

1595,1598c1777,1779
<         first = luaK_exp2anyreg(fs, &e);
<       else {
<         luaK_exp2nextreg(fs, &e);  /* values must go to the stack */
<         first = fs->nactvar;  /* return all active values */
>         first = luaK_exp2anyreg(fs, &e);  /* can use original slot */
>       else {  /* values must go to the top of the stack */
>         luaK_exp2nextreg(fs, &e);

1661c1842
<       breakstat(ls, luaK_jump(ls->fs));
>       breakstat(ls);

1665c1846,1847
<       gotostat(ls, luaK_jump(ls->fs));
>       luaX_next(ls);  /* skip 'goto' */
>       gotostat(ls);

1691c1873
<   init_exp(&v, VLOCAL, 0);  /* create and... */
>   init_var(&v, VLOCAL, 0);  /* create and... */

src/lparser.h

2c2
< ** $Id: lparser.h,v 1.82 2018/04/04 14:23:41 roberto Exp $
> ** $Id: lparser.h $

36,37c36,37
<   VLOCAL,  /* local variable; info = local register */
<   VUPVAL,  /* upvalue variable; info = index of upvalue in 'upvalues' */
>   VLOCAL,  /* local variable; var.idx = local register */
>   VUPVAL,  /* upvalue variable; var.idx = index of upvalue in 'upvalues' */

61c61
< #define vkisinreg(k)	((k) == VNONRELOC || (k) == VLOCAL)
> 

72a73,75
>     struct {  /* for local variables and upvalues */
>       lu_byte idx;  /* index of the variable */
>     } var;

79c82
< /* description of active local variable */
> /* description of an active local variable */

81c84,86
<   short idx;  /* variable index in stack */
>   TString *name;
>   short idx;  /* index of the variable in the Proto's 'locvars' array */
>   lu_byte ro;  /* true if variable is 'const' */

90a96
>   lu_byte close;  /* goto that escapes upvalues */

130a137
>   int firstlabel;  /* index of first label (in 'dyd->label->arr') */

135a143
>   lu_byte needclose;  /* function needs to close upvalues when returning */

src/lprefix.h

2c2
< ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $
> ** $Id: lprefix.h $

src/lstate.c

2c2
< ** $Id: lstate.c,v 2.155 2018/06/18 12:08:10 roberto Exp $
> ** $Id: lstate.c $

102,112c102,129
< ** overflow while handling stack overflow). If 'nCalls' is larger than
< ** LUAI_MAXCCALLS (which means it is handling a "regular" overflow) but
< ** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to
< ** allow overflow handling to work)
< */
< void luaE_incCcalls (lua_State *L) {
<   if (++L->nCcalls >= LUAI_MAXCCALLS) {
<     if (L->nCcalls == LUAI_MAXCCALLS)
<       luaG_runerror(L, "C stack overflow");
<     else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3)))
<       luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */
> ** overflow while handling stack overflow).
> ** If 'nCcalls' is larger than LUAI_MAXCSTACK but smaller than
> ** LUAI_MAXCSTACK + CSTACKCF (plus 2 to avoid by-one errors), it means
> ** it has just entered the "overflow zone", so the function raises an
> ** overflow error.
> ** If 'nCcalls' is larger than LUAI_MAXCSTACK + CSTACKCF + 2
> ** (which means it is already handling an overflow) but smaller than
> ** 9/8 of LUAI_MAXCSTACK, does not report an error (to allow message
> ** handling to work).
> ** Otherwise, report a stack overflow while handling a stack overflow
> ** (probably caused by a repeating error in the message handling
> ** function).
> */
> void luaE_enterCcall (lua_State *L) {
>   int ncalls = getCcalls(L);
>   L->nCcalls++;
>   if (ncalls >= LUAI_MAXCSTACK) {  /* possible overflow? */
>     luaE_freeCI(L);  /* release unused CIs */
>     ncalls = getCcalls(L);  /* update call count */
>     if (ncalls >= LUAI_MAXCSTACK) {  /* still overflow? */
>       if (ncalls <= LUAI_MAXCSTACK + CSTACKCF + 2) {
>         /* no error before increments; raise the error now */
>         L->nCcalls += (CSTACKCF + 4);  /* avoid raising it again */
>         luaG_runerror(L, "C stack overflow");
>       }
>       else if (ncalls >= (LUAI_MAXCSTACK + (LUAI_MAXCSTACK >> 3)))
>         luaD_throw(L, LUA_ERRERR);  /* error while handling stack error */
>     }

119c136,137
<   luaE_incCcalls(L);
>   lua_assert(L->ci->next == NULL);
>   luaE_enterCcall(L);

138c156
<   L->nCcalls -= L->nci;  /* to subtract removed elements from 'nCcalls' */
>   L->nCcalls -= L->nci;  /* subtract removed elements from 'nCcalls' */

144c162
<   L->nCcalls += L->nci;  /* to subtract removed elements from 'nCcalls' */
>   L->nCcalls += L->nci;  /* adjust result */

154c172
<   L->nCcalls -= L->nci;  /* to subtract removed elements from 'nCcalls' */
>   L->nCcalls -= L->nci;  /* subtract removed elements from 'nCcalls' */

163c181
<   L->nCcalls += L->nci;  /* to subtract removed elements from 'nCcalls' */
>   L->nCcalls += L->nci;  /* adjust result */

180a199,200
>   ci->u.c.k = NULL;
>   ci->nresults = 0;

218c238,239
< ** ('ttisnil(&g->nilvalue)'' flags that the state was completely build)
> ** ('g->nilvalue' being a nil value flags that the state was completely
> ** build.)

253d273
<   L->nny = 1;

261c281
<   luaF_close(L, L->stack);  /* close all upvalues for this thread */
>   luaF_close(L, L->stack, CLOSEPROTECT);  /* close all upvalues */

304c324
<   luaF_close(L1, L1->stack);  /* close all upvalues for this thread */
>   luaF_close(L1, L1->stack, NOCLOSINGMETH);  /* close all upvalues */

311a332,354
> int lua_resetthread (lua_State *L) {
>   CallInfo *ci;
>   int status;
>   lua_lock(L);
>   ci = &L->base_ci;
>   status = luaF_close(L, L->stack, CLOSEPROTECT);
>   setnilvalue(s2v(L->stack));  /* 'function' entry for basic 'ci' */
>   if (status != CLOSEPROTECT)  /* real errors? */
>     luaD_seterrorobj(L, status, L->stack + 1);
>   else {
>     status = LUA_OK;
>     L->top = L->stack + 1;
>   }
>   ci->callstatus = CIST_C;
>   ci->func = L->stack;
>   ci->top = L->top + LUA_MINSTACK;
>   L->ci = ci;
>   L->status = status;
>   lua_unlock(L);
>   return status;
> }
> 
> 

327a371,372
>   g->warnf = NULL;
>   g->ud_warn = NULL;

343c388
<   g->weak = g->ephemeron = g->allweak = g->protogray = NULL;
>   g->weak = g->ephemeron = g->allweak = NULL;

346a392
>   g->lastatomic = 0;

369a416,422
> void luaE_warning (lua_State *L, const char *msg, int tocont) {
>   lua_WarnFunction wf = G(L)->warnf;
>   if (wf != NULL)
>     wf(G(L)->ud_warn, msg, tocont);
> }
> 
> 

src/lstate.h

2c2
< ** $Id: lstate.h,v 2.160 2018/06/18 12:08:10 roberto Exp $
> ** $Id: lstate.h $

18d17
< 

29a29,44
> ** For the generational collector, some of these lists have marks for
> ** generations. Each mark points to the first element in the list for
> ** that particular generation; that generation goes until the next mark.
> **
> ** 'allgc' -> 'survival': new objects;
> ** 'survival' -> 'old': objects that survived one collection;
> ** 'old' -> 'reallyold': objects that became old in last collection;
> ** 'reallyold' -> NULL: objects old for more than one cycle.
> **
> ** 'finobj' -> 'finobjsur': new objects marked for finalization;
> ** 'finobjsur' -> 'finobjold': survived   """";
> ** 'finobjold' -> 'finobjrold': just old  """";
> ** 'finobjrold' -> NULL: really old       """".
> */
> 
> /*

46,47c61,62
< ** There is also a list 'protogray' for prototypes that need to have
< ** their caches cleared.
> */
> 

48a64,83
> 
> /*
> ** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of
> ** how many "C calls" it can do in the C stack, to avoid C-stack overflow.
> ** This count is very rough approximation; it considers only recursive
> ** functions inside the interpreter, as non-recursive calls can be
> ** considered using a fixed (although unknown) amount of stack space.
> **
> ** The count itself has two parts: the lower part is the count itself;
> ** the higher part counts the number of non-yieldable calls in the stack.
> **
> ** Because calls to external C functions can use of unkown amount
> ** of space (e.g., functions using an auxiliary buffer), calls
> ** to these functions add more than one to the count.
> **
> ** The proper count also includes the number of CallInfo structures
> ** allocated by Lua, as a kind of "potential" calls. So, when Lua
> ** calls a function (and "consumes" one CallInfo), it needs neither to
> ** increment nor to check 'nCcalls', as its use of C stack is already
> ** accounted for.

50a86,111
> /* number of "C stack slots" used by an external C function */
> #define CSTACKCF	10
> 
> /* true if this thread does not have non-yieldable calls in the stack */
> #define yieldable(L)		(((L)->nCcalls & 0xffff0000) == 0)
> 
> /* real number of C calls */
> #define getCcalls(L)	((L)->nCcalls & 0xffff)
> 
> 
> /* Increment the number of non-yieldable calls */
> #define incnny(L)	((L)->nCcalls += 0x10000)
> 
> /* Decrement the number of non-yieldable calls */
> #define decnny(L)	((L)->nCcalls -= 0x10000)
> 
> /* Increment the number of non-yieldable calls and nCcalls */
> #define incXCcalls(L)	((L)->nCcalls += 0x10000 + CSTACKCF)
> 
> /* Decrement the number of non-yieldable calls and nCcalls */
> #define decXCcalls(L)	((L)->nCcalls -= 0x10000 + CSTACKCF)
> 
> 
> 
> 
> 

125,127c186,190
< #define CIST_LEQ	(1<<6)  /* using __lt for __le */
< #define CIST_FIN	(1<<7)  /* call is running a finalizer */
< #define CIST_TRAN	(1<<8)	/* 'ci' has transfer information */
> #define CIST_FIN	(1<<6)  /* call is running a finalizer */
> #define CIST_TRAN	(1<<7)	/* 'ci' has transfer information */
> #if defined(LUA_COMPAT_LT_LE)
> #define CIST_LEQ	(1<<8)  /* using __lt for __le */
> #endif

148a212
>   lu_mem lastatomic;  /* see function 'genstep' in file 'lgc.c' */

171d234
<   GCObject *protogray;  /* list of prototypes with "new" caches */

187a251,252
>   lua_WarnFunction warnf;  /* warning function */
>   void *ud_warn;         /* auxiliary data to 'warnf' */

196d260
<   unsigned short nci;  /* number of items in 'ci' list */

197a262,263
>   lu_byte allowhook;
>   unsigned short nci;  /* number of items in 'ci' list */

210a277
>   l_uint32 nCcalls;  /* number of allowed nested C calls - 'nci' */

214,215d280
<   unsigned short nny;  /* number of non-yieldable calls in stack */
<   unsigned short nCcalls;  /* number of nested C calls */

217d281
<   lu_byte allowhook;

252c316,317
< #define gco2upv(o)  check_exp((o)->tt == LUA_TUPVAL, &((cast_u(o))->upv))
> #define gco2upv(o)  \
> 	check_exp(novariant((o)->tt) == LUA_TUPVAL, &((cast_u(o))->upv))

270c335,337
< LUAI_FUNC void luaE_incCcalls (lua_State *L);
> LUAI_FUNC void luaE_enterCcall (lua_State *L);
> LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
> 

271a339
> #define luaE_exitCcall(L)	((L)->nCcalls--)

src/lstring.c

2c2
< ** $Id: lstring.c,v 2.66 2018/05/30 14:25:52 roberto Exp $
> ** $Id: lstring.c $

src/lstring.h

2c2
< ** $Id: lstring.h,v 1.64 2018/02/20 16:52:50 roberto Exp $
> ** $Id: lstring.h $

22c22
< #define sizelstring(l)  (sizeof(union UTString) + ((l) + 1) * sizeof(char))
> #define sizelstring(l)  (sizeof(TString) + ((l) + 1) * sizeof(char))

src/lstrlib.c

2c2
< ** $Id: lstrlib.c,v 1.263 2018/05/25 13:39:32 roberto Exp $
> ** $Id: lstrlib.c $

63,67c63,96
< /* translate a relative string position: negative means back from end */
< static lua_Integer posrelat (lua_Integer pos, size_t len) {
<   if (pos >= 0) return pos;
<   else if (0u - (size_t)pos > len) return 0;
<   else return (lua_Integer)len + pos + 1;
> /*
> ** translate a relative initial string position
> ** (negative means back from end): clip result to [1, inf).
> ** The length of any string in Lua must fit in a lua_Integer,
> ** so there are no overflows in the casts.
> ** The inverted comparison avoids a possible overflow
> ** computing '-pos'.
> */
> static size_t posrelatI (lua_Integer pos, size_t len) {
>   if (pos > 0)
>     return (size_t)pos;
>   else if (pos == 0)
>     return 1;
>   else if (pos < -(lua_Integer)len)  /* inverted comparison */
>     return 1;  /* clip to 1 */
>   else return len + (size_t)pos + 1;
> }
> 
> 
> /*
> ** Gets an optional ending string position from argument 'arg',
> ** with default value 'def'.
> ** Negative means back from end: clip result to [0, len]
> */
> static size_t getendpos (lua_State *L, int arg, lua_Integer def,
>                          size_t len) {
>   lua_Integer pos = luaL_optinteger(L, arg, def);
>   if (pos > (lua_Integer)len)
>     return len;
>   else if (pos >= 0)
>     return (size_t)pos;
>   else if (pos < -(lua_Integer)len)
>     return 0;
>   else return len + (size_t)pos + 1;

74,77c103,104
<   lua_Integer start = posrelat(luaL_checkinteger(L, 2), l);
<   lua_Integer end = posrelat(luaL_optinteger(L, 3, -1), l);
<   if (start < 1) start = 1;
<   if (end > (lua_Integer)l) end = l;
>   size_t start = posrelatI(luaL_checkinteger(L, 2), l);
>   size_t end = getendpos(L, 3, -1, l);

79c106
<     lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1);
>     lua_pushlstring(L, s + start - 1, (end - start) + 1);

152,153c179,181
<   lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), l);
<   lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), l);
>   lua_Integer pi = luaL_optinteger(L, 2, 1);
>   size_t posi = posrelatI(pi, l);
>   size_t pose = getendpos(L, 3, pi, l);

155,156d182
<   if (posi < 1) posi = 1;
<   if (pose > (lua_Integer)l) pose = l;

158c184
<   if (pose - posi >= INT_MAX)  /* arithmetic overflow? */
>   if (pose - posi >= (size_t)INT_MAX)  /* arithmetic overflow? */

174,175c200,201
<     lua_Integer c = luaL_checkinteger(L, i);
<     luaL_argcheck(L, uchar(c) == c, i, "value out of range");
>     lua_Unsigned c = (lua_Unsigned)luaL_checkinteger(L, i);
>     luaL_argcheck(L, c <= (lua_Unsigned)UCHAR_MAX, i, "value out of range");

637,638c663,671
< static void push_onecapture (MatchState *ms, int i, const char *s,
<                                                     const char *e) {
> /*
> ** get information about the i-th capture. If there are no captures
> ** and 'i==0', return information about the whole match, which
> ** is the range 's'..'e'. If the capture is a string, return
> ** its length and put its address in '*cap'. If it is an integer
> ** (a position), push it on the stack and return CAP_POSITION.
> */
> static size_t get_onecapture (MatchState *ms, int i, const char *s,
>                               const char *e, const char **cap) {

640,642c673
<     if (i == 0)  /* ms->level == 0, too */
<       lua_pushlstring(ms->L, s, e - s);  /* add whole match */
<     else
>     if (i != 0)

643a675,676
>     *cap = s;
>     return e - s;

646,648c679,683
<     ptrdiff_t l = ms->capture[i].len;
<     if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
<     if (l == CAP_POSITION)
>     ptrdiff_t capl = ms->capture[i].len;
>     *cap = ms->capture[i].init;
>     if (capl == CAP_UNFINISHED)
>       luaL_error(ms->L, "unfinished capture");
>     else if (capl == CAP_POSITION)

650,651c685
<     else
<       lua_pushlstring(ms->L, ms->capture[i].init, l);
>     return capl;

655a690,702
> /*
> ** Push the i-th capture on the stack.
> */
> static void push_onecapture (MatchState *ms, int i, const char *s,
>                                                     const char *e) {
>   const char *cap;
>   ptrdiff_t l = get_onecapture(ms, i, s, e, &cap);
>   if (l != CAP_POSITION)
>     lua_pushlstring(ms->L, cap, l);
>   /* else position was already pushed */
> }
> 
> 

698,700c745,746
<   lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);
<   if (init < 1) init = 1;
<   else if (init > (lua_Integer)ls + 1) {  /* start after string's end? */
>   size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1;
>   if (init > ls) {  /* start after string's end? */

707c753
<     const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
>     const char *s2 = lmemfind(s + init, ls - init, p, lp);

716c762
<     const char *s1 = s + init - 1;
>     const char *s1 = s + init;

779a826
>   size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1;

781c828
<   lua_settop(L, 2);  /* keep them on closure to avoid being collected */
>   lua_settop(L, 2);  /* keep strings on closure to avoid being collected */

782a830,831
>   if (init > ls)  /* start after string's end? */
>     init = ls + 1;  /* avoid overflows in 's + init' */

784c833
<   gm->src = s; gm->p = p; gm->lastmatch = NULL;
>   gm->src = s + init; gm->p = p; gm->lastmatch = NULL;

792c841
<   size_t l, i;
>   size_t l;

795,812c844,858
<   for (i = 0; i < l; i++) {
<     if (news[i] != L_ESC)
<       luaL_addchar(b, news[i]);
<     else {
<       i++;  /* skip ESC */
<       if (!isdigit(uchar(news[i]))) {
<         if (news[i] != L_ESC)
<           luaL_error(L, "invalid use of '%c' in replacement string", L_ESC);
<         luaL_addchar(b, news[i]);
<       }
<       else if (news[i] == '0')
<           luaL_addlstring(b, s, e - s);
<       else {
<         push_onecapture(ms, news[i] - '1', s, e);
<         luaL_tolstring(L, -1, NULL);  /* if number, convert it to string */
<         lua_remove(L, -2);  /* remove original value */
<         luaL_addvalue(b);  /* add capture to accumulated result */
<       }
>   const char *p;
>   while ((p = (char *)memchr(news, L_ESC, l)) != NULL) {
>     luaL_addlstring(b, news, p - news);
>     p++;  /* skip ESC */
>     if (*p == L_ESC)  /* '%%' */
>       luaL_addchar(b, *p);
>     else if (*p == '0')  /* '%0' */
>         luaL_addlstring(b, s, e - s);
>     else if (isdigit(uchar(*p))) {  /* '%n' */
>       const char *cap;
>       ptrdiff_t resl = get_onecapture(ms, *p - '1', s, e, &cap);
>       if (resl == CAP_POSITION)
>         luaL_addvalue(b);  /* add position to accumulated result */
>       else
>         luaL_addlstring(b, cap, resl);

813a860,863
>     else
>       luaL_error(L, "invalid use of '%c' in replacement string", L_ESC);
>     l -= p + 1 - news;
>     news = p + 1;

814a865
>   luaL_addlstring(b, news, l);

818,819c869,875
< static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
<                                        const char *e, int tr) {
> /*
> ** Add the replacement value to the string buffer 'b'.
> ** Return true if the original string was changed. (Function calls and
> ** table indexing resulting in nil or false do not change the subject.)
> */
> static int add_value (MatchState *ms, luaL_Buffer *b, const char *s,
>                                       const char *e, int tr) {

822c878
<     case LUA_TFUNCTION: {
>     case LUA_TFUNCTION: {  /* call the function */

824,826c880,882
<       lua_pushvalue(L, 3);
<       n = push_captures(ms, s, e);
<       lua_call(L, n, 1);
>       lua_pushvalue(L, 3);  /* push the function */
>       n = push_captures(ms, s, e);  /* all captures as arguments */
>       lua_call(L, n, 1);  /* call it */

829,830c885,886
<     case LUA_TTABLE: {
<       push_onecapture(ms, 0, s, e);
>     case LUA_TTABLE: {  /* index the table */
>       push_onecapture(ms, 0, s, e);  /* first capture is the index */

835,836c891,892
<       add_s(ms, b, s, e);
<       return;
>       add_s(ms, b, s, e);  /* add value to the buffer */
>       return 1;  /* something changed */

840,841c896,898
<     lua_pop(L, 1);
<     lua_pushlstring(L, s, e - s);  /* keep original text */
>     lua_pop(L, 1);  /* remove value */
>     luaL_addlstring(b, s, e - s);  /* keep original text */
>     return 0;  /* no changes */

844,845c901,906
<     luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
<   luaL_addvalue(b);  /* add result to accumulator */
>     return luaL_error(L, "invalid replacement value (a %s)",
>                          luaL_typename(L, -1));
>   else {
>     luaL_addvalue(b);  /* add result to accumulator */
>     return 1;  /* something changed */
>   }

857a919
>   int changed = 0;  /* change flag */

860c922
<   luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
>   luaL_argexpected(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||

862c924
<                       "string/function/table expected");
>                       "string/function/table");

873c935
<       add_value(&ms, &b, src, e, tr);  /* add replacement to buffer */
>       changed = add_value(&ms, &b, src, e, tr) | changed;

881,882c943,948
<   luaL_addlstring(&b, src, ms.src_end-src);
<   luaL_pushresult(&b);
>   if (!changed)  /* no changes? */
>     lua_pushvalue(L, 1);  /* return original string */
>   else {  /* something changed */
>     luaL_addlstring(&b, src, ms.src_end-src);
>     luaL_pushresult(&b);  /* create and return new string */
>   }

975c1041
< ** Maximum size of each formatted item. This maximum size is produced
> ** Maximum size for items formatted with '%f'. This size is produced

978,979c1044,1055
< ** is maximum exponent + 1). (99+3+1 then rounded to 120 for "extra
< ** expenses", such as locale-dependent stuff)
> ** is maximum exponent + 1). (99+3+1, adding some extra, 110)
> */
> #define MAX_ITEMF	(110 + l_mathlim(MAX_10_EXP))
> 
> 
> /*
> ** All formats except '%f' do not need that large limit.  The other
> ** float formats use exponents, so that they fit in the 99 limit for
> ** significant digits; 's' for large strings and 'q' add items directly
> ** to the buffer; all integer formats also fit in the 99 limit.  The
> ** worst case are floats: they may need 99 significant digits, plus
> ** '0x', '-', '.', 'e+XXXX', and '\0'. Adding some extra, 120.

981c1057
< #define MAX_ITEM        (120 + l_mathlim(MAX_10_EXP))
> #define MAX_ITEM	120

1131c1207,1208
<       char *buff = luaL_prepbuffsize(&b, MAX_ITEM);  /* to put formatted item */
>       int maxitem = MAX_ITEM;
>       char *buff = luaL_prepbuffsize(&b, maxitem);  /* to put formatted item */

1134c1211
<         luaL_argerror(L, arg, "no value");
>         return luaL_argerror(L, arg, "no value");

1138c1215
<           nb = l_sprintf(buff, MAX_ITEM, form, (int)luaL_checkinteger(L, arg));
>           nb = l_sprintf(buff, maxitem, form, (int)luaL_checkinteger(L, arg));

1145c1222
<           nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACINT)n);
>           nb = l_sprintf(buff, maxitem, form, (LUAI_UACINT)n);

1150c1227
<           nb = lua_number2strx(L, buff, MAX_ITEM, form,
>           nb = lua_number2strx(L, buff, maxitem, form,

1155a1233,1237
>           if (*(strfrmt - 1) == 'f' && l_mathop(fabs)(n) >= 1e100) {
>             /* 'n' needs more than 99 digits */
>             maxitem = MAX_ITEMF;  /* extra space for '%f' */
>             buff = luaL_prepbuffsize(&b, maxitem);
>           }

1157c1239,1244
<           nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n);
>           nb = l_sprintf(buff, maxitem, form, (LUAI_UACNUMBER)n);
>           break;
>         }
>         case 'p': {
>           const void *p = lua_topointer(L, arg);
>           nb = l_sprintf(buff, maxitem, form, p);

1160a1248,1249
>           if (form[2] != '\0')  /* modifiers? */
>             return luaL_error(L, "specifier '%%q' cannot have modifiers");

1176c1265
<               nb = l_sprintf(buff, MAX_ITEM, form, s);
>               nb = l_sprintf(buff, maxitem, form, s);

1183,1184c1272
<           return luaL_error(L, "invalid option '%%%c' to 'format'",
<                                *(strfrmt - 1));
>           return luaL_error(L, "invalid conversion '%s' to 'format'", form);

1187c1275
<       lua_assert(nb < MAX_ITEM);
>       lua_assert(nb < maxitem);

1576c1664
<   size_t pos = (size_t)posrelat(luaL_optinteger(L, 3, 1), ld) - 1;
>   size_t pos = posrelatI(luaL_optinteger(L, 3, 1), ld) - 1;

src/ltable.c

2c2
< ** $Id: ltable.c,v 2.140 2018/06/15 14:18:40 roberto Exp $
> ** $Id: ltable.c $

51,52c51,52
< ** between 2^MAXABITS and the maximum size such that, measured in bytes,
< ** it fits in a 'size_t'.
> ** between 2^MAXABITS and the maximum size that, measured in bytes,
> ** fits in a 'size_t'.

217,218c217,218
< #if (INT_MAX >> 30 >> 1) > 0
<     size |= (size >> 32);  /* int has more than 32 bits */
> #if (UINT_MAX >> 30) > 3
>     size |= (size >> 32);  /* unsigned int has more than 32 bits */

272c272
<   if (0 < k && l_castS2U(k) <= MAXASIZE)
>   if (l_castS2U(k) - 1u < MAXASIZE)  /* 'k' in [1, MAXASIZE]? */

289c289
<   if (i != 0 && i <= asize)  /* is 'key' inside array part? */
>   if (i - 1u < asize)  /* is 'key' inside array part? */

681c681
<   if (l_castS2U(key) - 1u < t->alimit)  /* (1 <= key && key <= t->alimit)? */
>   if (l_castS2U(key) - 1u < t->alimit)  /* 'key' in [1, t->alimit]? */

src/ltable.h

2c2
< ** $Id: ltable.h,v 2.28 2018/06/15 14:14:20 roberto Exp $
> ** $Id: ltable.h $

src/ltablib.c

2c2
< ** $Id: ltablib.c,v 1.97 2018/04/04 14:23:41 roberto Exp $
> ** $Id: ltablib.c $

72c72,74
<       luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds");
>       /* check whether 'pos' is in [1, e] */
>       luaL_argcheck(L, (lua_Unsigned)pos - 1u < (lua_Unsigned)e, 2,
>                        "position out of bounds");

92c94,96
<     luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds");
>     /* check whether 'pos' is in [1, size + 1] */
>     luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 1,
>                      "position out of bounds");

298c302
<     while (lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {
>     while ((void)lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) {

src/ltm.c

2c2
< ** $Id: ltm.c,v 2.70 2018/06/15 19:31:22 roberto Exp $
> ** $Id: ltm.c $

46c46
<     "__concat", "__call"
>     "__concat", "__call", "__close"

179c179
< void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2,
> void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,

190a191
> #if defined(LUA_COMPAT_LT_LE)

199a201
> #endif

206c208
<                        int inv, TMS event) {
>                        int inv, int isfloat, TMS event) {

208c210,214
<   setivalue(&aux, v2);
>   if (isfloat) {
>     setfltvalue(&aux, cast_num(v2));
>   }
>   else
>     setivalue(&aux, v2);

src/ltm.h

2c2
< ** $Id: ltm.h,v 2.39 2018/06/18 12:51:05 roberto Exp $
> ** $Id: ltm.h $

42a43
>   TM_CLOSE,

79c80
< LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2,
> LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,

84c85
<                                  int inv, TMS event);
>                                  int inv, int isfloat, TMS event);

src/lua.c

2c2
< ** $Id: lua.c,v 1.235 2018/03/16 14:23:08 roberto Exp $
> ** $Id: lua.c $

386,387c386
< #define lua_initreadline(L)  \
< 	((void)L, rl_readline_name="lua", rl_inhibit_completion=1)
> #define lua_initreadline(L)	((void)L, rl_readline_name="lua")

src/lua.h

2c2
< ** $Id: lua.h,v 1.347 2018/06/18 12:08:10 roberto Exp $
> ** $Id: lua.h $

21d20
< #define LUA_VERSION_NUM		504

23a23,25
> #define LUA_VERSION_NUM			504
> #define LUA_VERSION_RELEASE_NUM		(LUA_VERSION_NUM * 100 + 0)
> 

26c28
< #define LUA_COPYRIGHT	LUA_RELEASE "  Copyright (C) 1994-2018 Lua.org, PUC-Rio"
> #define LUA_COPYRIGHT	LUA_RELEASE "  Copyright (C) 1994-2019 Lua.org, PUC-Rio"

52,53c54
< #define LUA_ERRGCMM	5
< #define LUA_ERRERR	6
> #define LUA_ERRERR	5

126a128,134
> /*
> ** Type for warning functions
> */
> typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);
> 
> 
> 

147a156
> LUA_API int        (lua_resetthread) (lua_State *L);

299a309,315
> ** Warning-related functions
> */
> LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud);
> LUA_API void (lua_warning)  (lua_State *L, const char *msg, int tocont);
> 
> 
> /*

333a350,351
> LUA_API void  (lua_toclose) (lua_State *L, int idx);
> 

453a472
>   size_t srclen;	/* (S) */

472c491
< * Copyright (C) 1994-2018 Lua.org, PUC-Rio.
> * Copyright (C) 1994-2019 Lua.org, PUC-Rio.

src/luac.c

20a21
> #include "ldebug.h"

21a23,24
> #include "lopcodes.h"
> #include "lopnames.h"

212,222d214
< #include <ctype.h>
< #include <stdio.h>
< 
< #define luac_c
< #define LUA_CORE
< #define LUAI_DEFOPNAMES
< 
< #include "ldebug.h"
< #include "lobject.h"
< #include "lopcodes.c"
< 

225d216
< #define getfuncline(f,pc) luaG_getfuncline((Proto *)f,pc)

241c232
<    	printf("\\\\");
> 	printf("\\\\");

244c235
<    	printf("\\a");
> 	printf("\\a");

247c238
<    	printf("\\b");
> 	printf("\\b");

250c241
<    	printf("\\f");
> 	printf("\\f");

253c244
<    	printf("\\n");
> 	printf("\\n");

256c247
<    	printf("\\r");
> 	printf("\\r");

259c250
<    	printf("\\t");
> 	printf("\\t");

262c253
<    	printf("\\v");
> 	printf("\\v");

271a263,290
> static void PrintType(const Proto* f, int i)
> {
>  const TValue* o=&f->k[i];
>  switch (ttypetag(o))
>  {
>   case LUA_TNIL:
>   	printf("N");
> 	break;
>   case LUA_TBOOLEAN:
>   	printf("B");
> 	break;
>   case LUA_TNUMFLT:
>   	printf("F");
> 	break;
>   case LUA_TNUMINT:
>   	printf("I");
> 	break;
>   case LUA_TSHRSTR:
>   case LUA_TLNGSTR:
>   	printf("S");
> 	break;
>   default:				/* cannot happen */
> 	printf("?%d",ttypetag(o));
> 	break;
>  }
>  printf("\t");
> }
> 

299c318
< 	printf("? type=%d",ttypetag(o));
> 	printf("?%d",ttypetag(o));

321c340
<   int line=getfuncline(f,pc);
>   int line=luaG_getfuncline(f,pc);

324c343
<   printf("%-9s\t",luaP_opnames[o]);
>   printf("%-9s\t",opnames[o]);

420a440,467
>    case OP_ADDK:
> 	printf("%d %d %d",a,b,c);
> 	printf("\t; "); PrintConstant(f,c);
> 	break;
>    case OP_SUBK:
> 	printf("%d %d %d",a,b,c);
> 	printf("\t; "); PrintConstant(f,c);
> 	break;
>    case OP_MULK:
> 	printf("%d %d %d",a,b,c);
> 	printf("\t; "); PrintConstant(f,c);
> 	break;
>    case OP_MODK:
> 	printf("%d %d %d",a,b,c);
> 	printf("\t; "); PrintConstant(f,c);
> 	break;
>    case OP_POWK:
> 	printf("%d %d %d",a,b,c);
> 	printf("\t; "); PrintConstant(f,c);
> 	break;
>    case OP_DIVK:
> 	printf("%d %d %d",a,b,c);
> 	printf("\t; "); PrintConstant(f,c);
> 	break;
>    case OP_IDIVK:
> 	printf("%d %d %d",a,b,c);
> 	printf("\t; "); PrintConstant(f,c);
> 	break;

423c470
< 	printf("\t; "); PrintConstant(f,c); 
> 	printf("\t; "); PrintConstant(f,c);

427c474
< 	printf("\t; "); PrintConstant(f,c); 
> 	printf("\t; "); PrintConstant(f,c);

431c478
< 	printf("\t; "); PrintConstant(f,c); 
> 	printf("\t; "); PrintConstant(f,c);

492a540,542
>    case OP_TBC:
> 	printf("%d",a);
> 	break;

534,535c584,585
<    	if (b==0) printf("all in "); else printf("%d in ",b-1);
<    	if (c==0) printf("all out"); else printf("%d out",c-1);
> 	if (b==0) printf("all in "); else printf("%d in ",b-1);
> 	if (c==0) printf("all out"); else printf("%d out",c-1);

544c594
<    	if (b==0) printf("all out"); else printf("%d out",b-1);
> 	if (b==0) printf("all out"); else printf("%d out",b-1);

551c601
<    case OP_FORLOOP1:
>    case OP_FORLOOP:

555c605
<    case OP_FORPREP1:
>    case OP_FORPREP:

559,563c609
<    case OP_FORLOOP:
< 	printf("%d %d",a,bx);
< 	printf("\t; to %d",pc-bx+2);
< 	break;
<    case OP_FORPREP:
>    case OP_TFORPREP:

584c630
<    	if (c==0) printf("all out"); else printf("%d out",c-1);
> 	if (c==0) printf("all out"); else printf("%d out",c-1);

586c632
<    case OP_PREPVARARG:
>    case OP_VARARGPREP:

592a639,641
>    //default: printf("not handled"); break;
> 	//printf("%d %d %d",a,b,c);
> 	//break;

598,630d646
< static void riPrintCode(const Proto* p)
< {
<  const Instruction* code=p->code;
<  int pc,n=p->sizecode;
<  for (pc=0; pc<n; pc++)
<  {
<   Instruction i = code[pc];
<   OpCode o = GET_OPCODE(i);
<   const char *name = luaP_opnames[o];
<   int line = luaG_getfuncline(p, pc);
<   printf("(%4d) %4d - ", line, pc);
<   switch (getOpMode(o)) {
<     case iABC:
<       printf("%-12s%4d %4d %4d%s", name,
<               GETARG_A(i), GETARG_B(i), GETARG_C(i),
<               GETARG_k(i) ? " (k)" : "");
<       break;
<     case iABx:
<       printf("%-12s%4d %4d", name, GETARG_A(i), GETARG_Bx(i));
<       break;
<     case iAsBx:
<       printf("%-12s%4d %4d", name, GETARG_A(i), GETARG_sBx(i));
<       break;
<     case iAx:
<       printf("%-12s%4d", name, GETARG_Ax(i));
<       break;
<     case isJ:
<       printf("%-12s%4d (%1d)", name, GETARG_sJ(i), !!GETARG_m(i));
<       break;
<   }
<  printf("\n");
<  }
< }

662c678,679
<   printf("\t%d\t",i+1);
>   printf("\t%d\t",i);
>   PrintType(f,i);

686d702
<  riPrintCode(f);

src/luaconf.h

2c2
< ** $Id: luaconf.h,v 1.270 2018/06/18 12:51:05 roberto Exp $
> ** $Id: luaconf.h $

16a17,26
> ** General Configuration File for Lua
> **
> ** Some definitions here can be changed externally, through the
> ** compiler (e.g., with '-D' options). Those are protected by
> ** '#if !defined' guards. However, several other definitions should
> ** be changed directly here, either because they affect the Lua
> ** ABI (by making the changes here, you ensure that all software
> ** connected to Lua, such as C libraries, will be compiled with the
> ** same configuration); or because they are seldom changed.
> **

25,26c35
< ** particular platform, for instance compiling it with 32-bit numbers or
< ** restricting it to C89.
> ** particular platform, for instance restricting it to C89.

31,34c40,47
< @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
< ** can also define LUA_32BITS in the make file, but changing here you
< ** ensure that all software connected to Lua will be compiled with the
< ** same configuration.
> @@ LUAI_MAXCSTACK defines the maximum depth for nested calls and
> ** also limits the maximum depth of other recursive algorithms in
> ** the implementation, such as syntactic analysis. A value too
> ** large may allow the interpreter to crash (C-stack overflow).
> ** The default value seems ok for regular machines, but may be
> ** too high for restricted hardware.
> ** The test file 'cstack.lua' may help finding a good limit.
> ** (It will crash with a limit too high.)

36c49,51
< /* #define LUA_32BITS */
> #if !defined(LUAI_MAXCSTACK)
> #define LUAI_MAXCSTACK		2200
> #endif

74,76c89
< @@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
< ** C89 ('long' and 'double'); Windows always has '__int64', so it does
< ** not need to use this case.
> @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.

78,80c91,93
< #if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
< #define LUA_C89_NUMBERS
< #endif
> #define LUAI_IS32INT	((UINT_MAX >> 30) >= 3)
> 
> /* }================================================================== */

85c98,100
< @@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.
> ** {==================================================================
> ** Configuration for Number types.
> ** ===================================================================

87,92c102,115
< /* avoid undefined shifts */
< #if ((INT_MAX >> 15) >> 15) >= 1
< #define LUAI_BITSINT	32
< #else
< /* 'int' always must have at least 16 bits */
< #define LUAI_BITSINT	16
> 
> /*
> @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
> */
> /* #define LUA_32BITS */
> 
> 
> /*
> @@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
> ** C89 ('long' and 'double'); Windows always has '__int64', so it does
> ** not need to use this case.
> */
> #if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
> #define LUA_C89_NUMBERS

99,100c122,123
< ** Lua should work fine with any mix of these options (if supported
< ** by your C compiler). The usual configurations are 64-bit integers
> ** Lua should work fine with any mix of these options supported
> ** by your C compiler. The usual configurations are 64-bit integers

120c143
< #if LUAI_BITSINT >= 32  /* use 'int' if big enough */
> #if LUAI_IS32INT  /* use 'int' if big enough */

152d174
< 

179a202
> 

188a212,213
> 
> #if !defined(LUA_PATH_DEFAULT)

193a219,221
> #endif
> 
> #if !defined(LUA_CPATH_DEFAULT)

197a226
> #endif

203a233,234
> 
> #if !defined(LUA_PATH_DEFAULT)

207a239,241
> #endif
> 
> #if !defined(LUA_CPATH_DEFAULT)

209a244,245
> #endif
> 

217a254,255
> #if !defined(LUA_DIRSEP)
> 

223a262,263
> #endif
> 

258,260c298
< ** More often than not the libs go together with the core;
< ** Functions from the auxiliary library must be exported,
< ** but opening functions do not.
> ** More often than not the libs go together with the core.

263c301
< #define LUAMOD_API	LUAI_FUNC
> #define LUAMOD_API	LUA_API

282c320
< #define LUAI_FUNC	__attribute__((visibility("hidden"))) extern
> #define LUAI_FUNC	__attribute__((visibility("internal"))) extern

300c338
< @@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.2.
> @@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3.

309,310c347,348
< ** (These functions were already officially removed in 5.3, but
< ** nevertheless they are available by default there.)
> ** (These functions were already officially removed in 5.3;
> ** nevertheless they are still available here.)

317a356,357
> ** (These macros were also officially removed in 5.3, but they are still
> ** available here.)

321d360
< #endif				/* } */

322a362,366
> /*
> @@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
> ** using '__lt'.
> */
> #define LUA_COMPAT_LT_LE

328a373,374
> ** (Once more, these macros were officially removed in 5.3, but they are
> ** still available here.)

336a383,384
> #endif				/* } */
> 

360c408
< @@ lua_str2number converts a decimal numeric string to a number.
> @@ lua_str2number converts a decimal numeral to a number.

474d521
< #define LUA_MAXUNSIGNED		(~(lua_Unsigned)0)

488a536,537
> #define LUA_MAXUNSIGNED		UINT_MAX
> 

496a546,547
> #define LUA_MAXUNSIGNED		ULONG_MAX
> 

508a560,561
> #define LUA_MAXUNSIGNED		ULLONG_MAX
> 

517a571,572
> #define LUA_MAXUNSIGNED		_UI64_MAX
> 

552c607
< @@ lua_strx2number converts a hexadecimal numeric string to a number.
> @@ lua_strx2number converts a hexadecimal numeral to a number.

570c625
< @@ lua_number2strx converts a float to a hexadecimal numeric string.
> @@ lua_number2strx converts a float to a hexadecimal numeral.

616c671
< ** macro must include header 'locale.h'.)
> ** macro must include the header 'locale.h'.)

657c712
< ** Lua). You probably do not want/need to change them.
> ** Lua).

668c723
< #if LUAI_BITSINT >= 32
> #if LUAI_IS32INT

693,696d747
< ** CHANGE it if it uses too much C-stack space. (For long double,
< ** 'string.format("%.99f", -1e4932)' needs 5034 bytes, so a
< ** smaller buffer would force a memory allocation for each call to
< ** 'string.format'.)

698,702c749,750
< #if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE
< #define LUAL_BUFFERSIZE		8192
< #else
< #define LUAL_BUFFERSIZE   ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
< #endif
> #define LUAL_BUFFERSIZE   ((int)(16 * sizeof(void*) * sizeof(lua_Number)))
> 

src/lualib.h

2c2
< ** $Id: lualib.h,v 1.46 2018/02/27 18:47:32 roberto Exp $
> ** $Id: lualib.h $

src/lundump.c

2c2
< ** $Id: lundump.c,v 2.50 2018/06/01 16:45:58 roberto Exp $
> ** $Id: lundump.c $

12a13
> #include <limits.h>

40c41
<   luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why);
>   luaO_pushfstring(S->L, "%s: bad binary format (%s)", S->name, why);

53c54
<     error(S, "truncated");
>     error(S, "truncated chunk");

63c64
<     error(S, "truncated");
>     error(S, "truncated chunk");

68c69
< static size_t LoadSize (LoadState *S) {
> static size_t LoadUnsigned (LoadState *S, size_t limit) {

70a72
>   limit >>= 7;

72a75,76
>     if (x >= limit)
>       error(S, "integer overflow");

78a83,87
> static size_t LoadSize (LoadState *S) {
>   return LoadUnsigned(S, ~(size_t)0);
> }
> 
> 

80c89
<   return cast_int(LoadSize(S));
>   return cast_int(LoadUnsigned(S, INT_MAX));

258c267
<     error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname));
>     error(S, luaO_pushfstring(S->L, "%s size mismatch", tname));

265,267c274,277
<   checkliteral(S, LUA_SIGNATURE + 1, "not a");  /* 1st char already checked */
<   if (LoadByte(S) != LUAC_VERSION)
<     error(S, "version mismatch in");
>   /* skip 1st char (already read and checked) */
>   checkliteral(S, &LUA_SIGNATURE[1], "not a binary chunk");
>   if (LoadInt(S) != LUAC_VERSION)
>     error(S, "version mismatch");

269,272c279,280
<     error(S, "format mismatch in");
<   checkliteral(S, LUAC_DATA, "corrupted");
<   checksize(S, int);
<   checksize(S, size_t);
>     error(S, "format mismatch");
>   checkliteral(S, LUAC_DATA, "corrupted chunk");

277c285
<     error(S, "endianness mismatch in");
>     error(S, "integer format mismatch");

279c287
<     error(S, "float format mismatch in");
>     error(S, "float format mismatch");

src/lundump.h

2c2
< ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $
> ** $Id: lundump.h $

21,22c21
< #define MYINT(s)	(s[0]-'0')
< #define LUAC_VERSION	(MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))
> #define LUAC_VERSION	LUA_VERSION_NUM

src/lutf8lib.c

2c2
< ** $Id: lutf8lib.c,v 1.17 2017/03/14 12:40:44 roberto Exp $
> ** $Id: lutf8lib.c $

23c23,36
< #define MAXUNICODE	0x10FFFF
> 
> #define MAXUNICODE	0x10FFFFu
> 
> #define MAXUTF		0x7FFFFFFFu
> 
> /*
> ** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits.
> */
> #if (UINT_MAX >> 30) >= 1
> typedef	unsigned int utfint;
> #else
> typedef unsigned long utfint;
> #endif
> 

38c51,55
< ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.
> ** Decode one UTF-8 sequence, returning NULL if byte sequence is
> ** invalid.  The array 'limits' stores the minimum value for each
> ** sequence length, to check for overlong representations. Its first
> ** entry forces an error for non-ascii bytes with no continuation
> ** bytes (count == 0).

40,44c57,61
< static const char *utf8_decode (const char *o, int *val) {
<   static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};
<   const unsigned char *s = (const unsigned char *)o;
<   unsigned int c = s[0];
<   unsigned int res = 0;  /* final result */
> static const char *utf8_decode (const char *s, utfint *val, int strict) {
>   static const utfint limits[] =
>         {~(utfint)0, 0x80, 0x800, 0x10000u, 0x200000u, 0x4000000u};
>   unsigned int c = (unsigned char)s[0];
>   utfint res = 0;  /* final result */

49,50c66,67
<     while (c & 0x40) {  /* still have continuation bytes? */
<       int cc = s[++count];  /* read next byte */
>     for (; c & 0x40; c <<= 1) {  /* while it needs continuation bytes... */
>       unsigned int cc = (unsigned char)s[++count];  /* read next byte */

54d70
<       c <<= 1;  /* to test next bit */

56,57c72,73
<     res |= ((c & 0x7F) << (count * 5));  /* add first byte */
<     if (count > 3 || res > MAXUNICODE || res <= limits[count])
>     res |= ((utfint)(c & 0x7F) << (count * 5));  /* add first byte */
>     if (count > 5 || res > MAXUTF || res < limits[count])

60a77,81
>   if (strict) {
>     /* check for invalid code points; too large or surrogates */
>     if (res > MAXUNICODE || (0xD800u <= res && res <= 0xDFFFu))
>       return NULL;
>   }

62c83
<   return (const char *)s + 1;  /* +1 to include first byte */
>   return s + 1;  /* +1 to include first byte */

67,69c88,90
< ** utf8len(s [, i [, j]]) --> number of characters that start in the
< ** range [i,j], or nil + current position if 's' is not well formed in
< ** that interval
> ** utf8len(s [, i [, j [, lax]]]) --> number of characters that
> ** start in the range [i,j], or nil + current position if 's' is not
> ** well formed in that interval

72,73c93,94
<   int n = 0;
<   size_t len;
>   lua_Integer n = 0;  /* counter for the number of characters */
>   size_t len;  /* string length in bytes */

76a98
>   int lax = lua_toboolean(L, 4);

82c104
<     const char *s1 = utf8_decode(s + posi, NULL);
>     const char *s1 = utf8_decode(s + posi, NULL, !lax);

97,98c119,120
< ** codepoint(s, [i, [j]])  -> returns codepoints for all characters
< ** that start in the range [i,j]
> ** codepoint(s, [i, [j [, lax]]]) -> returns codepoints for all
> ** characters that start in the range [i,j]

104a127
>   int lax = lua_toboolean(L, 4);

112c135
<   n = (int)(pose -  posi) + 1;
>   n = (int)(pose -  posi) + 1;  /* upper bound for number of returns */

114,115c137,138
<   n = 0;
<   se = s + pose;
>   n = 0;  /* count the number of returns */
>   se = s + pose;  /* string end */

117,118c140,141
<     int code;
<     s = utf8_decode(s, &code);
>     utfint code;
>     s = utf8_decode(s, &code, !lax);

129,130c152,153
<   lua_Integer code = luaL_checkinteger(L, arg);
<   luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range");
>   lua_Unsigned code = (lua_Unsigned)luaL_checkinteger(L, arg);
>   luaL_argcheck(L, code <= MAXUTF, arg, "value out of range");

201c224
< static int iter_aux (lua_State *L) {
> static int iter_aux (lua_State *L, int strict) {

214,216c237,239
<     int code;
<     const char *next = utf8_decode(s + n, &code);
<     if (next == NULL || iscont(next))
>     utfint code;
>     const char *next = utf8_decode(s + n, &code, strict);
>     if (next == NULL)

224a248,256
> static int iter_auxstrict (lua_State *L) {
>   return iter_aux(L, 1);
> }
> 
> static int iter_auxlax (lua_State *L) {
>   return iter_aux(L, 0);
> }
> 
> 

225a258
>   int lax = lua_toboolean(L, 2);

227c260
<   lua_pushcfunction(L, iter_aux);
>   lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict);

235c268
< #define UTF8PATT	"[\0-\x7F\xC2-\xF4][\x80-\xBF]*"
> #define UTF8PATT	"[\0-\x7F\xC2-\xFD][\x80-\xBF]*"

src/lvm.c

2c2
< ** $Id: lvm.c,v 2.359 2018/06/18 17:58:21 roberto Exp $
> ** $Id: lvm.c $

151c151
< ** of the loop.  (The following explanation assumes a non-negative step;
> ** of the loop.  (The following explanation assumes a positive step;

152a153
> ** Return true if the loop must not run.

154,168c155,167
< ** rounding down, that is it.
< ** Otherwise, check whether the limit can be converted to a float.  If
< ** the number is too large, it is OK to set the limit as LUA_MAXINTEGER,
< ** which means no limit.  If the number is too negative, the loop
< ** should not run, because any initial integer value is larger than the
< ** limit. So, it sets the limit to LUA_MININTEGER. 'stopnow' corrects
< ** the extreme case when the initial value is LUA_MININTEGER, in which
< ** case the LUA_MININTEGER limit would still run the loop once.
< */
< static int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,
<                      int *stopnow) {
<   *stopnow = 0;  /* usually, let loops run */
<   if (ttisinteger(obj))
<     *p = ivalue(obj);
<   else if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) {
> ** rounding down, that is the limit.
> ** Otherwise, check whether the limit can be converted to a float. If
> ** the float is too large, clip it to LUA_MAXINTEGER.  If the float
> ** is too negative, the loop should not run, because any initial
> ** integer value is greater than such limit; so, it returns true to
> ** signal that.
> ** (For this latter case, no integer limit would be correct; even a
> ** limit of LUA_MININTEGER would run the loop once for an initial
> ** value equal to LUA_MININTEGER.)
> */
> static int forlimit (lua_State *L, lua_Integer init, const TValue *lim,
>                                    lua_Integer *p, lua_Integer step) {
>   if (!luaV_tointeger(lim, p, (step < 0 ? 2 : 1))) {

170,179c169,179
<     lua_Number n;  /* try to convert to float */
<     if (!tonumber(obj, &n)) /* cannot convert to float? */
<       return 0;  /* not a number */
<     if (luai_numlt(0, n)) {  /* if true, float is larger than max integer */
<       *p = LUA_MAXINTEGER;
<       if (step < 0) *stopnow = 1;
<     }
<     else {  /* float is less than min integer */
<       *p = LUA_MININTEGER;
<       if (step >= 0) *stopnow = 1;
>     lua_Number flim;  /* try to convert to float */
>     if (!tonumber(lim, &flim)) /* cannot convert to float? */
>       luaG_forerror(L, lim, "limit");
>     /* else 'flim' is a float out of integer bounds */
>     if (luai_numlt(0, flim)) {  /* if it is positive, it is too large */
>       if (step < 0) return 1;  /* initial value must be less than it */
>       *p = LUA_MAXINTEGER;  /* truncate */
>     }
>     else {  /* it is less than min integer */
>       if (step > 0) return 1;  /* initial value must be greater than it */
>       *p = LUA_MININTEGER;  /* truncate */

182c182
<   return 1;
>   return (step > 0 ? init > *p : init < *p);  /* not to run? */

586c586
< ** Main operation 'ra' = #rb'.
> ** Main operation 'ra = #rb'.

623,625c623,625
< lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) {
<   if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */
<     if (unlikely(n == 0))
> lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {
>   if (unlikely(l_castS2U(n) + 1u <= 1u)) {  /* special cases: -1 or 0 */
>     if (n == 0)

641c641
< ** about luaV_div.)
> ** about luaV_idiv.)

644,645c644,645
<   if (l_castS2U(n) + 1u <= 1u) {  /* special cases: -1 or 0 */
<     if (unlikely(n == 0))
>   if (unlikely(l_castS2U(n) + 1u <= 1u)) {  /* special cases: -1 or 0 */
>     if (n == 0)

651c651
<     if (r != 0 && (m ^ n) < 0)  /* 'm/n' would be non-integer negative? */
>     if (r != 0 && (r ^ n) < 0)  /* 'm/n' would be non-integer negative? */

657a658,667
> /*
> ** Float modulus
> */
> lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
>   lua_Number r;
>   luai_nummod(L, m, n, r);
>   return r;
> }
> 
> 

677,698d686
< ** check whether cached closure in prototype 'p' may be reused, that is,
< ** whether there is a cached closure with the same upvalues needed by
< ** new closure to be created.
< */
< static LClosure *getcached (Proto *p, UpVal **encup, StkId base) {
<   LClosure *c = p->cache;
<   if (c != NULL) {  /* is there a cached closure? */
<     int nup = p->sizeupvalues;
<     Upvaldesc *uv = p->upvalues;
<     int i;
<     for (i = 0; i < nup; i++) {  /* check whether it has right upvalues */
<       TValue *v = uv[i].instack ? s2v(base + uv[i].idx) : encup[uv[i].idx]->v;
<       if (c->upvals[i]->v != v)
<         return NULL;  /* wrong upvalue; cannot reuse closure */
<     }
<     p->cachemiss = 0;  /* got a hit */
<   }
<   return c;  /* return cached closure (or NULL if no cached closure) */
< }
< 
< 
< /*

700c688
< ** its upvalues. ???
> ** its upvalues.

717,723d704
<   if (p->cachemiss >= MAXMISS)  /* too many missings? */
<     p->cache = NULL;  /* give up cache */
<   else {
<     p->cache = ncl;  /* save it on cache for reuse */
<     luaC_protobarrier(L, p, ncl);
<     p->cachemiss++;
<   }

756a738
> #if defined(LUA_COMPAT_LT_LE)

760a743
> #endif

777,779c760,764
<     case OP_TFORCALL: case OP_CALL: case OP_TAILCALL:
<     case OP_SETTABUP: case OP_SETTABLE:
<     case OP_SETI: case OP_SETFIELD:
>     default: {
>       /* only these other opcodes can yield */
>       lua_assert(op == OP_TFORCALL || op == OP_CALL ||
>            op == OP_TAILCALL || op == OP_SETTABUP || op == OP_SETTABLE ||
>            op == OP_SETI || op == OP_SETFIELD);

781c766
<     default: lua_assert(0);
>     }

790c775
< ** Function 'luaV_execute': main interpreter loop
> ** Macros for arithmetic/bitwise/comparison opcodes in 'luaV_execute'

793a779,962
> #define l_addi(L,a,b)	intop(+, a, b)
> #define l_subi(L,a,b)	intop(-, a, b)
> #define l_muli(L,a,b)	intop(*, a, b)
> #define l_band(L,a,b)	intop(&, a, b)
> #define l_bor(L,a,b)	intop(|, a, b)
> #define l_bxor(L,a,b)	intop(^, a, b)
> 
> #define l_lti(a,b)	(a < b)
> #define l_lei(a,b)	(a <= b)
> #define l_gti(a,b)	(a > b)
> #define l_gei(a,b)	(a >= b)
> 
> 
> /*
> ** Auxiliary macro for arithmetic operations over floats and others
> ** with immediate operand. 'fop' is the float operation; 'tm' is the
> ** corresponding metamethod; 'flip' is true if operands were flipped.
> */
> #define op_arithfI_aux(L,v1,imm,fop,tm,flip) {  \
>   lua_Number nb;  \
>   if (tonumberns(v1, nb)) {  \
>     setfltvalue(s2v(ra), fop(L, nb, cast_num(imm)));  \
>   }  \
>   else  \
>     Protect(luaT_trybiniTM(L, v1, imm, flip, ra, tm)); }
> 
> 
> /*
> ** Arithmetic operations over floats and others with immediate operand.
> */
> #define op_arithfI(L,fop,tm) {  \
>   TValue *v1 = vRB(i);  \
>   int imm = GETARG_sC(i);  \
>   op_arithfI_aux(L, v1, imm, fop, tm, 0); }
> 
> /*
> ** Arithmetic operations with immediate operands. 'iop' is the integer
> ** operation.
> */
> #define op_arithI(L,iop,fop,tm,flip) {  \
>   TValue *v1 = vRB(i);  \
>   int imm = GETARG_sC(i);  \
>   if (ttisinteger(v1)) {  \
>     setivalue(s2v(ra), iop(L, ivalue(v1), imm));  \
>   }  \
>   else op_arithfI_aux(L, v1, imm, fop, tm, flip); }
> 
> 
> /*
> ** Auxiliary function for arithmetic operations over floats and others
> ** with two register operands.
> */
> #define op_arithf_aux(L,v1,v2,fop,tm) {  \
>   lua_Number n1; lua_Number n2;  \
>   if (tonumberns(v1, n1) && tonumberns(v2, n2)) {  \
>     setfltvalue(s2v(ra), fop(L, n1, n2));  \
>   }  \
>   else  \
>     Protect(luaT_trybinTM(L, v1, v2, ra, tm)); }
> 
> 
> /*
> ** Arithmetic operations over floats and others with register operands.
> */
> #define op_arithf(L,fop,tm) {  \
>   TValue *v1 = vRB(i);  \
>   TValue *v2 = vRC(i);  \
>   op_arithf_aux(L, v1, v2, fop, tm); }
> 
> 
> /*
> ** Arithmetic operations with register operands.
> */
> #define op_arith(L,iop,fop,tm) {  \
>   TValue *v1 = vRB(i);  \
>   TValue *v2 = vRC(i);  \
>   if (ttisinteger(v1) && ttisinteger(v2)) {  \
>     lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2);  \
>     setivalue(s2v(ra), iop(L, i1, i2));  \
>   }  \
>   else op_arithf_aux(L, v1, v2, fop, tm); }
> 
> 
> /*
> ** Arithmetic operations with K operands.
> */
> #define op_arithK(L,iop,fop,tm,flip) {  \
>   TValue *v1 = vRB(i);  \
>   TValue *v2 = KC(i);  \
>   if (ttisinteger(v1) && ttisinteger(v2)) {  \
>     lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2);  \
>     setivalue(s2v(ra), iop(L, i1, i2));  \
>   }  \
>   else { \
>     lua_Number n1; lua_Number n2;  \
>     if (tonumberns(v1, n1) && tonumberns(v2, n2)) {  \
>       setfltvalue(s2v(ra), fop(L, n1, n2));  \
>     }  \
>     else  \
>       Protect(luaT_trybinassocTM(L, v1, v2, ra, flip, tm)); } }
> 
> 
> /*
> ** Arithmetic operations with K operands for floats.
> */
> #define op_arithfK(L,fop,tm) {  \
>   TValue *v1 = vRB(i);  \
>   TValue *v2 = KC(i);  \
>   lua_Number n1; lua_Number n2;  \
>   if (tonumberns(v1, n1) && tonumberns(v2, n2)) {  \
>     setfltvalue(s2v(ra), fop(L, n1, n2));  \
>   }  \
>   else  \
>     Protect(luaT_trybinTM(L, v1, v2, ra, tm)); }
> 
> 
> /*
> ** Bitwise operations with constant operand.
> */
> #define op_bitwiseK(L,op,tm) {  \
>   TValue *v1 = vRB(i);  \
>   TValue *v2 = KC(i);  \
>   lua_Integer i1;  \
>   lua_Integer i2 = ivalue(v2);  \
>   if (tointegerns(v1, &i1)) {  \
>     setivalue(s2v(ra), op(L, i1, i2));  \
>   }  \
>   else  \
>     Protect(luaT_trybiniTM(L, v1, i2, TESTARG_k(i), ra, tm)); }
> 
> 
> /*
> ** Bitwise operations with register operands.
> */
> #define op_bitwise(L,op,tm) {  \
>   TValue *v1 = vRB(i);  \
>   TValue *v2 = vRC(i);  \
>   lua_Integer i1; lua_Integer i2;  \
>   if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) {  \
>     setivalue(s2v(ra), op(L, i1, i2));  \
>   }  \
>   else  \
>     Protect(luaT_trybinTM(L, v1, v2, ra, tm)); }
> 
> 
> /*
> ** Order operations with register operands.
> */
> #define op_order(L,opi,opf,other) {  \
>         int cond;  \
>         TValue *rb = vRB(i);  \
>         if (ttisinteger(s2v(ra)) && ttisinteger(rb))  \
>           cond = opi(ivalue(s2v(ra)), ivalue(rb));  \
>         else if (ttisnumber(s2v(ra)) && ttisnumber(rb))  \
>           cond = opf(s2v(ra), rb);  \
>         else  \
>           Protect(cond = other(L, s2v(ra), rb));  \
>         docondjump(); }
> 
> 
> /*
> ** Order operations with immediate operand.
> */
> #define op_orderI(L,opi,opf,inv,tm) {  \
>         int cond;  \
>         int im = GETARG_sB(i);  \
>         if (ttisinteger(s2v(ra)))  \
>           cond = opi(ivalue(s2v(ra)), im);  \
>         else if (ttisfloat(s2v(ra)))  \
>           cond = opf(fltvalue(s2v(ra)), cast_num(im));  \
>         else {  \
>           int isf = GETARG_C(i);  \
>           Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm));  \
>         }  \
>         docondjump(); }
> 
> /* }================================================================== */
> 
> 
> /*
> ** {==================================================================
> ** Function 'luaV_execute': main interpreter loop
> ** ===================================================================
> */

815a985,987
> #define updatestack(ci) { if (trap) { updatebase(ci); ra = RA(i); } }
> 
> 

857c1029,1031
< ** Protect code that will finish the loop (returns).
> ** Protect code that will finish the loop (returns) or can only raise
> ** errors. (That is, it will not return to the interpreter main loop
> ** after changing the stack or hooks.)

899c1073
<       trap = 0;  /* hooks will start after PREPVARARG instruction */
>       trap = 0;  /* hooks will start after VARARGPREP instruction */

907d1080
<     int cond;  /* flag for conditional jumps */

1094,1104c1267
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Number nb;
<         if (ttisinteger(rb)) {
<           setivalue(s2v(ra), intop(+, ivalue(rb), ic));
<         }
<         else if (tonumberns(rb, nb)) {
<           setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic)));
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_ADD));
>         op_arithI(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i));

1108,1118c1271
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Number nb;
<         if (ttisinteger(rb)) {
<           setivalue(s2v(ra), intop(-, ivalue(rb), ic));
<         }
<         else if (tonumberns(rb, nb)) {
<           setfltvalue(s2v(ra), luai_numsub(L, nb, cast_num(ic)));
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_SUB));
>         op_arithI(L, l_subi, luai_numsub, TM_SUB, 0);

1122,1132c1275
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Number nb;
<         if (ttisinteger(rb)) {
<           setivalue(s2v(ra), intop(*, ivalue(rb), ic));
<         }
<         else if (tonumberns(rb, nb)) {
<           setfltvalue(s2v(ra), luai_nummul(L, nb, cast_num(ic)));
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_MUL));
>         op_arithI(L, l_muli, luai_nummul, TM_MUL, GETARG_k(i));

1136,1149c1279
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Number nb;
<         if (ttisinteger(rb)) {
<           setivalue(s2v(ra), luaV_mod(L, ivalue(rb), ic));
<         }
<         else if (tonumberns(rb, nb)) {
<           lua_Number m;
<           lua_Number nc = cast_num(ic);
<           luai_nummod(L, nb, nc, m);
<           setfltvalue(s2v(ra), m);
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_MOD));
>         op_arithI(L, luaV_mod, luaV_modf, TM_MOD, 0);

1153,1161c1283
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Number nb;
<         if (tonumberns(rb, nb)) {
<           lua_Number nc = cast_num(ic);
<           setfltvalue(s2v(ra), luai_numpow(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_POW));
>         op_arithfI(L, luai_numpow, TM_POW);

1165,1173c1287
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Number nb;
<         if (tonumberns(rb, nb)) {
<           lua_Number nc = cast_num(ic);
<           setfltvalue(s2v(ra), luai_numdiv(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_DIV));
>         op_arithfI(L, luai_numdiv, TM_DIV);

1177,1188c1291,1319
<         TValue *rb = vRB(i);
<         int ic = GETARG_sC(i);
<         lua_Number nb;
<         if (ttisinteger(rb)) {
<           setivalue(s2v(ra), luaV_div(L, ivalue(rb), ic));
<         }
<         else if (tonumberns(rb, nb)) {
<           lua_Number nc = cast_num(ic);
<           setfltvalue(s2v(ra), luai_numdiv(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_IDIV));
>         op_arithI(L, luaV_idiv, luai_numidiv, TM_IDIV, 0);
>         vmbreak;
>       }
>       vmcase(OP_ADDK) {
>         op_arithK(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i));
>         vmbreak;
>       }
>       vmcase(OP_SUBK) {
>         op_arithK(L, l_subi, luai_numsub, TM_SUB, 0);
>         vmbreak;
>       }
>       vmcase(OP_MULK) {
>         op_arithK(L, l_muli, luai_nummul, TM_MUL, GETARG_k(i));
>         vmbreak;
>       }
>       vmcase(OP_MODK) {
>         op_arithK(L, luaV_mod, luaV_modf, TM_MOD, 0);
>         vmbreak;
>       }
>       vmcase(OP_POWK) {
>         op_arithfK(L, luai_numpow, TM_POW);
>         vmbreak;
>       }
>       vmcase(OP_DIVK) {
>         op_arithfK(L, luai_numdiv, TM_DIV);
>         vmbreak;
>       }
>       vmcase(OP_IDIVK) {
>         op_arithK(L, luaV_idiv, luai_numidiv, TM_IDIV, 0);

1192,1203c1323
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Number nb; lua_Number nc;
<         if (ttisinteger(rb) && ttisinteger(rc)) {
<           lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
<           setivalue(s2v(ra), intop(+, ib, ic));
<         }
<         else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
<           setfltvalue(s2v(ra), luai_numadd(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD));
>         op_arith(L, l_addi, luai_numadd, TM_ADD);

1207,1218c1327
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Number nb; lua_Number nc;
<         if (ttisinteger(rb) && ttisinteger(rc)) {
<           lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
<           setivalue(s2v(ra), intop(-, ib, ic));
<         }
<         else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
<           setfltvalue(s2v(ra), luai_numsub(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB));
>         op_arith(L, l_subi, luai_numsub, TM_SUB);

1222,1233c1331,1339
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Number nb; lua_Number nc;
<         if (ttisinteger(rb) && ttisinteger(rc)) {
<           lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
<           setivalue(s2v(ra), intop(*, ib, ic));
<         }
<         else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
<           setfltvalue(s2v(ra), luai_nummul(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL));
>         op_arith(L, l_muli, luai_nummul, TM_MUL);
>         vmbreak;
>       }
>       vmcase(OP_MOD) {
>         op_arith(L, luaV_mod, luaV_modf, TM_MOD);
>         vmbreak;
>       }
>       vmcase(OP_POW) {
>         op_arithf(L, luai_numpow, TM_POW);

1237,1244c1343,1347
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Number nb; lua_Number nc;
<         if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
<           setfltvalue(s2v(ra), luai_numdiv(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV));
>         op_arithf(L, luai_numdiv, TM_DIV);
>         vmbreak;
>       }
>       vmcase(OP_IDIV) {  /* floor division */
>         op_arith(L, luaV_idiv, luai_numidiv, TM_IDIV);

1248,1255c1351
<         TValue *p1 = vRB(i);
<         TValue *p2 = KC(i);
<         lua_Integer i1;
<         if (tointegerns(p1, &i1)) {
<           setivalue(s2v(ra), intop(&, i1, ivalue(p2)));
<         }
<         else
<           Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BAND));
>         op_bitwiseK(L, l_band, TM_BAND);

1259,1266c1355
<         TValue *p1 = vRB(i);
<         TValue *p2 = KC(i);
<         lua_Integer i1;
<         if (tointegerns(p1, &i1)) {
<           setivalue(s2v(ra), intop(|, i1, ivalue(p2)));
<         }
<         else
<           Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BOR));
>         op_bitwiseK(L, l_bor, TM_BOR);

1270,1277c1359
<         TValue *p1 = vRB(i);
<         TValue *p2 = KC(i);
<         lua_Integer i1;
<         if (tointegerns(p1, &i1)) {
<           setivalue(s2v(ra), intop(^, i1, ivalue(p2)));
<         }
<         else
<           Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BXOR));
>         op_bitwiseK(L, l_bxor, TM_BXOR);

1281,1288c1363
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Integer ib; lua_Integer ic;
<         if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
<           setivalue(s2v(ra), intop(&, ib, ic));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND));
>         op_bitwise(L, l_band, TM_BAND);

1292,1299c1367
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Integer ib; lua_Integer ic;
<         if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
<           setivalue(s2v(ra), intop(|, ib, ic));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR));
>         op_bitwise(L, l_bor, TM_BOR);

1303,1310c1371
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Integer ib; lua_Integer ic;
<         if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
<           setivalue(s2v(ra), intop(^, ib, ic));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR));
>         op_bitwise(L, l_bxor, TM_BXOR);

1340,1350d1400
<       vmcase(OP_SHL) {
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Integer ib; lua_Integer ic;
<         if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
<           setivalue(s2v(ra), luaV_shiftl(ib, ic));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL));
<         vmbreak;
<       }

1362,1394c1412
<       vmcase(OP_MOD) {
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Number nb; lua_Number nc;
<         if (ttisinteger(rb) && ttisinteger(rc)) {
<           lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
<           setivalue(s2v(ra), luaV_mod(L, ib, ic));
<         }
<         else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
<           lua_Number m;
<           luai_nummod(L, nb, nc, m);
<           setfltvalue(s2v(ra), m);
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD));
<         vmbreak;
<       }
<       vmcase(OP_IDIV) {  /* floor division */
<         TValue *rb = vRB(i);
<         TValue *rc = vRC(i);
<         lua_Number nb; lua_Number nc;
<         if (ttisinteger(rb) && ttisinteger(rc)) {
<           lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
<           setivalue(s2v(ra), luaV_div(L, ib, ic));
<         }
<         else if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
<           setfltvalue(s2v(ra), luai_numidiv(L, nb, nc));
<         }
<         else
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV));
<         vmbreak;
<       }
<       vmcase(OP_POW) {
>       vmcase(OP_SHL) {

1397,1399c1415,1417
<         lua_Number nb; lua_Number nc;
<         if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
<           setfltvalue(s2v(ra), luai_numpow(L, nb, nc));
>         lua_Integer ib; lua_Integer ic;
>         if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) {
>           setivalue(s2v(ra), luaV_shiftl(ib, ic));

1402c1420
<           Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW));
>           Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL));

1447c1465,1471
<         luaF_close(L, ra);
>         L->top = ra + 1;  /* everything is free after this slot */
>         Protect(luaF_close(L, ra, LUA_OK));
>         vmbreak;
>       }
>       vmcase(OP_TBC) {
>         /* create new to-be-closed upvalue */
>         halfProtect(luaF_newtbcupval(L, ra));

1454a1479
>         int cond;

1461,1468c1486
<         TValue *rb = vRB(i);
<         if (ttisinteger(s2v(ra)) && ttisinteger(rb))
<           cond = (ivalue(s2v(ra)) < ivalue(rb));
<         else if (ttisnumber(s2v(ra)) && ttisnumber(rb))
<           cond = LTnum(s2v(ra), rb);
<         else
<           Protect(cond = lessthanothers(L, s2v(ra), rb));
<         docondjump();
>         op_order(L, l_lti, LTnum, lessthanothers);

1472,1479c1490
<         TValue *rb = vRB(i);
<         if (ttisinteger(s2v(ra)) && ttisinteger(rb))
<           cond = (ivalue(s2v(ra)) <= ivalue(rb));
<         else if (ttisnumber(s2v(ra)) && ttisnumber(rb))
<           cond = LEnum(s2v(ra), rb);
<         else
<           Protect(cond = lessequalothers(L, s2v(ra), rb));
<         docondjump();
>         op_order(L, l_lei, LEnum, lessequalothers);

1485c1496
<         cond = luaV_equalobj(NULL, s2v(ra), rb);
>         int cond = luaV_equalobj(NULL, s2v(ra), rb);

1489a1501
>         int cond;

1501,1508c1513
<         int im = GETARG_sB(i);
<         if (ttisinteger(s2v(ra)))
<           cond = (ivalue(s2v(ra)) < im);
<         else if (ttisfloat(s2v(ra)))
<           cond = luai_numlt(fltvalue(s2v(ra)), cast_num(im));
<         else
<           Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 0, TM_LT));
<         docondjump();
>         op_orderI(L, l_lti, luai_numlt, 0, TM_LT);

1512,1519c1517
<         int im = GETARG_sB(i);
<         if (ttisinteger(s2v(ra)))
<           cond = (ivalue(s2v(ra)) <= im);
<         else if (ttisfloat(s2v(ra)))
<           cond = luai_numle(fltvalue(s2v(ra)), cast_num(im));
<         else
<           Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 0, TM_LE));
<         docondjump();
>         op_orderI(L, l_lei, luai_numle, 0, TM_LE);

1523,1530c1521
<         int im = GETARG_sB(i);
<         if (ttisinteger(s2v(ra)))
<           cond = (im < ivalue(s2v(ra)));
<         else if (ttisfloat(s2v(ra)))
<           cond = luai_numlt(cast_num(im), fltvalue(s2v(ra)));
<         else
<           Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 1, TM_LT));
<         docondjump();
>         op_orderI(L, l_gti, luai_numgt, 1, TM_LT);

1534,1541c1525
<         int im = GETARG_sB(i);
<         if (ttisinteger(s2v(ra)))
<           cond = (im <= ivalue(s2v(ra)));
<         else if (ttisfloat(s2v(ra)))
<           cond = luai_numle(cast_num(im), fltvalue(s2v(ra)));
<         else
<           Protect(cond = luaT_callorderiTM(L, s2v(ra), im, 1, TM_LE));
<         docondjump();
>         op_orderI(L, l_gei, luai_numge, 1, TM_LE);

1545c1529
<         cond = !l_isfalse(s2v(ra));
>         int cond = !l_isfalse(s2v(ra));

1575c1559
<         savepc(ci);
>         savepc(ci);  /* some calls here can raise errors */

1580c1564,1566
<           luaF_close(L, base);  /* close upvalues from current call */
>           /* close upvalues from current call; the compiler ensures
>              that there are no to-be-closed variables here */
>           luaF_close(L, base, NOCLOSINGMETH);

1589,1592c1575
<           if (trap) {  /* stack may have been relocated */
<             updatebase(ci);
<             ra = RA(i);
<           }
>           updatestack(ci);  /* stack may have been relocated */

1609a1593
>         savepc(ci);

1614c1598
<           luaF_close(L, base);  /* there may be open upvalues */
>           luaF_close(L, base, LUA_OK);  /* there may be open upvalues */

1616c1600
<         halfProtect(luaD_poscall(L, ci, n));
>         luaD_poscall(L, ci, n);

1624c1608
<         else {
>         else {  /* do the 'poscall' here */

1638c1622
<         else {
>         else {  /* do the 'poscall' here */

1652,1677d1635
<       vmcase(OP_FORLOOP1) {
<         lua_Integer idx = intop(+, ivalue(s2v(ra)), 1); /* increment index */
<         lua_Integer limit = ivalue(s2v(ra + 1));
<         if (idx <= limit) {
<           pc -= GETARG_Bx(i);  /* jump back */
<           chgivalue(s2v(ra), idx);  /* update internal index... */
<           setivalue(s2v(ra + 3), idx);  /* ...and external index */
<         }
<         updatetrap(ci);
<         vmbreak;
<       }
<       vmcase(OP_FORPREP1) {
<         TValue *init = s2v(ra);
<         TValue *plimit = s2v(ra + 1);
<         lua_Integer ilimit, initv;
<         int stopnow;
<         if (unlikely(!forlimit(plimit, &ilimit, 1, &stopnow))) {
<             savestate(L, ci);  /* for the error message */
<             luaG_runerror(L, "'for' limit must be a number");
<         }
<         initv = (stopnow ? 0 : ivalue(init));
<         setivalue(plimit, ilimit);
<         setivalue(init, intop(-, initv, 1));
<         pc += GETARG_Bx(i);
<         vmbreak;
<       }

1679,1683c1637,1645
<         if (ttisinteger(s2v(ra))) {  /* integer loop? */
<           lua_Integer step = ivalue(s2v(ra + 2));
<           lua_Integer idx = intop(+, ivalue(s2v(ra)), step); /* new index */
<           lua_Integer limit = ivalue(s2v(ra + 1));
<           if ((0 < step) ? (idx <= limit) : (limit <= idx)) {
>         if (ttisinteger(s2v(ra + 2))) {  /* integer loop? */
>           lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1)));
>           if (count > 0) {  /* still more iterations? */
>             lua_Integer step = ivalue(s2v(ra + 2));
>             lua_Integer idx = ivalue(s2v(ra));  /* internal index */
>             chgivalue(s2v(ra + 1), count - 1);  /* update counter */
>             idx = intop(+, idx, step);  /* add step to index */
>             chgivalue(s2v(ra), idx);  /* update internal index */
>             setivalue(s2v(ra + 3), idx);  /* and control variable */

1685,1686d1646
<             chgivalue(s2v(ra), idx);  /* update internal index... */
<             setivalue(s2v(ra + 3), idx);  /* ...and external index */

1693c1653
<           idx = luai_numadd(L, idx, step);  /* inc. index */
>           idx = luai_numadd(L, idx, step);  /* increment index */

1695a1656,1657
>             chgfltvalue(s2v(ra), idx);  /* update internal index */
>             setfltvalue(s2v(ra + 3), idx);  /* and control variable */

1697,1698d1658
<             chgfltvalue(s2v(ra), idx);  /* update internal index... */
<             setfltvalue(s2v(ra + 3), idx);  /* ...and external index */

1701c1661
<         updatetrap(ci);
>         updatetrap(ci);  /* allows a signal to break the loop */

1705c1665
<         TValue *init = s2v(ra);
>         TValue *pinit = s2v(ra);

1708,1715c1668,1693
<         lua_Integer ilimit;
<         int stopnow;
<         if (ttisinteger(init) && ttisinteger(pstep) &&
<             forlimit(plimit, &ilimit, ivalue(pstep), &stopnow)) {
<           /* all values are integer */
<           lua_Integer initv = (stopnow ? 0 : ivalue(init));
<           setivalue(plimit, ilimit);
<           setivalue(init, intop(-, initv, ivalue(pstep)));
>         savestate(L, ci);  /* in case of errors */
>         if (ttisinteger(pinit) && ttisinteger(pstep)) { /* integer loop? */
>           lua_Integer init = ivalue(pinit);
>           lua_Integer step = ivalue(pstep);
>           lua_Integer limit;
>           if (step == 0)
>             luaG_runerror(L, "'for' step is zero");
>           setivalue(s2v(ra + 3), init);  /* control variable */
>           if (forlimit(L, init, plimit, &limit, step))
>             pc += GETARG_Bx(i) + 1;  /* skip the loop */
>           else {  /* prepare loop counter */
>             lua_Unsigned count;
>             if (step > 0) {  /* ascending loop? */
>               count = l_castS2U(limit) - l_castS2U(init);
>               if (step != 1)  /* avoid division in the too common case */
>                 count /= l_castS2U(step);
>             }
>             else {  /* step < 0; descending loop */
>               count = l_castS2U(init) - l_castS2U(limit);
>               /* 'step+1' avoids negating 'mininteger' */
>               count /= l_castS2U(-(step + 1)) + 1u;
>             }
>             /* store the counter in place of the limit (which won't be
>                needed anymore */
>             setivalue(plimit, l_castU2S(count));
>           }

1718,1728c1696,1714
<           lua_Number ninit; lua_Number nlimit; lua_Number nstep;
<           savestate(L, ci);  /* in case of errors */
<           if (unlikely(!tonumber(plimit, &nlimit)))
<             luaG_runerror(L, "'for' limit must be a number");
<           setfltvalue(plimit, nlimit);
<           if (unlikely(!tonumber(pstep, &nstep)))
<             luaG_runerror(L, "'for' step must be a number");
<           setfltvalue(pstep, nstep);
<           if (unlikely(!tonumber(init, &ninit)))
<             luaG_runerror(L, "'for' initial value must be a number");
<           setfltvalue(init, luai_numsub(L, ninit, nstep));
>           lua_Number init; lua_Number limit; lua_Number step;
>           if (unlikely(!tonumber(plimit, &limit)))
>             luaG_forerror(L, plimit, "limit");
>           if (unlikely(!tonumber(pstep, &step)))
>             luaG_forerror(L, pstep, "step");
>           if (unlikely(!tonumber(pinit, &init)))
>             luaG_forerror(L, pinit, "initial value");
>           if (step == 0)
>             luaG_runerror(L, "'for' step is zero");
>           if (luai_numlt(0, step) ? luai_numlt(limit, init)
>                                    : luai_numlt(init, limit))
>             pc += GETARG_Bx(i) + 1;  /* skip the loop */
>           else {
>             /* make sure internal values are all float */
>             setfltvalue(plimit, limit);
>             setfltvalue(pstep, step);
>             setfltvalue(s2v(ra), init);  /* internal index */
>             setfltvalue(s2v(ra + 3), init);  /* control variable */
>           }

1730d1715
<         pc += GETARG_Bx(i);

1732a1718,1727
>       vmcase(OP_TFORPREP) {
>         if (!ttisnil(s2v(ra + 3))) {  /* is 'toclose' not nil? */
>           /* create to-be-closed upvalue for it */
>           halfProtect(luaF_newtbcupval(L, ra + 3));
>         }
>         pc += GETARG_Bx(i);
>         i = *(pc++);  /* go to next instruction */
>         lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i));
>         goto l_tforcall;
>       }

1734,1741c1729,1739
<         StkId cb = ra + 3;  /* call base */
<         setobjs2s(L, cb+2, ra+2);
<         setobjs2s(L, cb+1, ra+1);
<         setobjs2s(L, cb, ra);
<         L->top = cb + 3;  /* func. + 2 args (state and index) */
<         Protect(luaD_call(L, cb, GETARG_C(i)));
<         if (trap)  /* keep 'base' correct for next instruction */
<           updatebase(ci);
>        l_tforcall:
>         /* 'ra' has the iterator function, 'ra + 1' has the state,
>            'ra + 2' has the control variable, and 'ra + 3' has the
>            to-be-closed variable. The call will use the stack after
>            these values (starting at 'ra + 4')
>         */
>         /* push function, state, and control variable */
>         memcpy(ra + 4, ra, 3 * sizeof(*ra));
>         L->top = ra + 4 + 3;
>         Protect(luaD_call(L, ra + 4, GETARG_C(i)));  /* do the call */
>         updatestack(ci);  /* stack may have changed */

1743,1744c1741,1742
<         ra = RA(i);  /* get its 'ra' */
<         lua_assert(GET_OPCODE(i) == OP_TFORLOOP);
>         ra += 2;  /* adjust for next instruction */
>         lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));

1749,1750c1747,1748
<         if (!ttisnil(s2v(ra + 1))) {  /* continue loop? */
<           setobjs2s(L, ra, ra + 1);  /* save control variable */
>         if (!ttisnil(s2v(ra + 2))) {  /* continue loop? */
>           setobjs2s(L, ra, ra + 2);  /* save control variable */

1781,1787c1779
<         LClosure *ncl = getcached(p, cl->upvals, base);  /* cached closure */
<         if (ncl == NULL) {  /* no match? */
<           savestate(L, ci);  /* in case of allocation errors */
<           pushclosure(L, p, cl->upvals, base, ra);  /* create a new one */
<         }
<         else
<           setclLvalue2s(L, ra, ncl);  /* push cashed closure */
>         halfProtect(pushclosure(L, p, cl->upvals, base, ra));

1796c1788
<       vmcase(OP_PREPVARARG) {
>       vmcase(OP_VARARGPREP) {

src/lvm.h

2c2
< ** $Id: lvm.h,v 2.52 2018/06/15 14:14:20 roberto Exp $
> ** $Id: lvm.h $

117c117
< LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);
> LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y);

118a119
> LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y);

src/lzio.c

2c2
< ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $
> ** $Id: lzio.c $

src/lzio.h

2c2
< ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $
> ** $Id: lzio.h $