Lua diffs-lua-5.4.4-lua-5.4.5


Makefile

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

49c49
< R= $V.4
> R= $V.5

README

2c2
< This is Lua 5.4.4, released on 13 Jan 2022.
> This is Lua 5.4.5, released on 18 Apr 2023.

doc/contents.html

35c35
< Copyright &copy; 2020&ndash;2022 Lua.org, PUC-Rio.
> Copyright &copy; 2020&ndash;2023 Lua.org, PUC-Rio.

87a88,89
> <LI><A HREF="manual.html#3.4.12">3.4.12 &ndash; Lists of expressions, multiple results, and adjustment<A>
> 

616c618
< <A HREF="manual.html#pdf-LUAL_BUFFERSIZE">LUAL_BUFFERSIZE</A><BR>
> <A HREF="manual.html#pdf-LUA_LOADED_TABLE">LUA_LOADED_TABLE</A><BR>

643a646
> <A HREF="manual.html#pdf-LUA_PRELOAD_TABLE">LUA_PRELOAD_TABLE</A><BR>

659a663
> <A HREF="manual.html#pdf-LUAL_BUFFERSIZE">LUAL_BUFFERSIZE</A><BR>

667c671
< Thu Jan 13 11:32:22 UTC 2022
> Sat Apr  1 17:57:05 UTC 2023

670c674
< Last change: revised for Lua 5.4.4
> Last change: revised for Lua 5.4.5

doc/lua.1

1,2c1,2
< .\" $Id: lua.man,v 1.14 2020/05/21 19:31:21 lhf Exp $
< .TH LUA 1 "$Date: 2020/05/21 19:31:21 $"
> .\" $Id: lua.man,v 1.14 2022/09/23 09:06:36 lhf Exp $
> .TH LUA 1 "$Date: 2022/09/23 09:06:36 $"

89c89
< .BI \-l " name"
> .BI \-l " mod"

91c91
< .I name
> .I mod

93c93,99
< .IR name .
> .IR mod .
> .TP
> .BI \-l " g=mod"
> require library
> .I mod
> into global
> .IR g .

doc/manual.html

22c22
< Copyright &copy; 2020&ndash;2022 Lua.org, PUC-Rio.
> Copyright &copy; 2020&ndash;2023 Lua.org, PUC-Rio.

66c66
< the common subset of Standard&nbsp;C and C++.
> the common subset of standard&nbsp;C and C++.

1382c1382,1384
< marked by a letter '<code>p</code>' or '<code>P</code>'.
> marked by a letter '<code>p</code>' or '<code>P</code>' and written in decimal.
> (For instance, <code>0x1.fp10</code> denotes 1984,
> which is <em>0x1f / 16</em> multiplied by <em>2<sup>10</sup></em>.)

1624,1632c1626
< the list of variables.
< If there are more values than needed,
< the excess values are thrown away.
< If there are fewer values than needed,
< the list is extended with <b>nil</b>'s.
< If the list of expressions ends with a function call,
< then all values returned by that call enter the list of values,
< before the adjustment
< (except when the call is enclosed in parentheses; see <a href="#3.4">&sect;3.4</a>).
> the list of variables (see <a href="#3.4.12">&sect;3.4.12</a>).

1638c1632
< Lua ensures all reads get the value of the variable
> Lua ensures that all reads get the value of the variable

1742,1746d1735
< Labels and empty statements are called <em>void statements</em>,
< as they perform no actions.
< 
< 
< <p>

2062c2051
< directly inside a vararg function;
> directly inside a variadic function;

2077,2122d2065
< <p>
< Both function calls and vararg expressions can result in multiple values.
< If a function call is used as a statement (see <a href="#3.3.6">&sect;3.3.6</a>),
< then its return list is adjusted to zero elements,
< thus discarding all returned values.
< If an expression is used as the last (or the only) element
< of a list of expressions,
< then no adjustment is made
< (unless the expression is enclosed in parentheses).
< In all other contexts,
< Lua adjusts the result list to one element,
< either discarding all values except the first one
< or adding a single <b>nil</b> if there are no values.
< 
< 
< <p>
< Here are some examples:
< 
< <pre>
<      f()                -- adjusted to 0 results
<      g(f(), x)          -- f() is adjusted to 1 result
<      g(x, f())          -- g gets x plus all results from f()
<      a,b,c = f(), x     -- f() is adjusted to 1 result (c gets nil)
<      a,b = ...          -- a gets the first vararg argument, b gets
<                         -- the second (both a and b can get nil if there
<                         -- is no corresponding vararg argument)
<      
<      a,b,c = x, f()     -- f() is adjusted to 2 results
<      a,b,c = f()        -- f() is adjusted to 3 results
<      return f()         -- returns all results from f()
<      return ...         -- returns all received vararg arguments
<      return x,y,f()     -- returns x, y, and all results from f()
<      {f()}              -- creates a list with all results from f()
<      {...}              -- creates a list with all vararg arguments
<      {f(), nil}         -- f() is adjusted to 1 result
< </pre>
< 
< <p>
< Any expression enclosed in parentheses always results in only one value.
< Thus,
< <code>(f(x,y,z))</code> is always a single value,
< even if <code>f</code> returns several values.
< (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>
< or <b>nil</b> if <code>f</code> does not return any values.)
< 
< 

2255,2256c2198,2200
< Nonetheless, it is always a good practice not to rely on these
< implicit coercions, as they are not always applied;
> It is always a good practice not to rely on the
> implicit coercions from strings to numbers,
> as they are not always applied;

2561c2505
< and the expression is a function call or a vararg expression,
> and the expression is a multires expression,

2563c2507
< (see <a href="#3.4.10">&sect;3.4.10</a>).
> (see <a href="#3.4.12">&sect;3.4.12</a>).

2627c2571
< in a tail call,
> In a tail call,

2730,2731c2674,2675
< the length of its list of parameters,
< unless the function is a <em>vararg function</em>,
> the length of its list of parameters (see <a href="#3.4.12">&sect;3.4.12</a>),
> unless the function is a <em>variadic function</em>,

2734c2678
< A vararg function does not adjust its argument list;
> A variadic function does not adjust its argument list;

2739,2745c2683
< similar to a function with multiple results.
< If a vararg expression is used inside another expression
< or in the middle of a list of expressions,
< then its return list is adjusted to one element.
< If the expression is used as the last element of a list of expressions,
< then no adjustment is made
< (unless that last expression is enclosed in parentheses).
> similar to a function with multiple results (see <a href="#3.4.12">&sect;3.4.12</a>).

2805a2744,2859
> <h3>3.4.12 &ndash; <a name="3.4.12">Lists of expressions, multiple results,
> and adjustment</a></h3>
> 
> <p>
> Both function calls and vararg expressions can result in multiple values.
> These expressions are called <em>multires expressions</em>.
> 
> 
> <p>
> When a multires expression is used as the last element
> of a list of expressions,
> all results from the expression are added to the
> list of values produced by the list of expressions.
> Note that a single expression
> in a place that expects a list of expressions
> is the last expression in that (singleton) list.
> 
> 
> <p>
> These are the places where Lua expects a list of expressions:
> 
> <ul>
> 
> <li>A <b>return</b> statement,
> for instance <code>return e1, e2, e3</code> (see <a href="#3.3.4">&sect;3.3.4</a>).</li>
> 
> <li>A table constructor,
> for instance <code>{e1, e2, e3}</code> (see <a href="#3.4.9">&sect;3.4.9</a>).</li>
> 
> <li>The arguments of a function call,
> for instance <code>foo(e1, e2, e3)</code> (see <a href="#3.4.10">&sect;3.4.10</a>).</li>
> 
> <li>A multiple assignment,
> for instance <code>a , b, c = e1, e2, e3</code> (see <a href="#3.3.3">&sect;3.3.3</a>).</li>
> 
> <li>A local declaration,
> for instance <code>local a , b, c = e1, e2, e3</code> (see <a href="#3.3.7">&sect;3.3.7</a>).</li>
> 
> <li>The initial values in a generic <b>for</b> loop,
> for instance <code>for k in e1, e2, e3 do ... end</code> (see <a href="#3.3.5">&sect;3.3.5</a>).</li>
> 
> </ul><p>
> In the last four cases,
> the list of values from the list of expressions
> must be <em>adjusted</em> to a specific length:
> the number of parameters in a call to a non-variadic function
> (see <a href="#3.4.11">&sect;3.4.11</a>),
> the number of variables in a multiple assignment or
> a local declaration,
> and exactly four values for a generic <b>for</b> loop.
> The <em>adjustment</em> follows these rules:
> If there are more values than needed,
> the extra values are thrown away;
> if there are fewer values than needed,
> the list is extended with <b>nil</b>'s.
> When the list of expressions ends with a multires expression,
> all results from that expression enter the list of values
> before the adjustment.
> 
> 
> <p>
> When a multires expression is used
> in a list of expressions without being the last element,
> or in a place where the syntax expects a single expression,
> Lua adjusts the result list of that expression to one element.
> As a particular case,
> the syntax expects a single expression inside a parenthesized expression;
> therefore, adding parentheses around a multires expression
> forces it to produce exactly one result.
> 
> 
> <p>
> We seldom need to use a vararg expression in a place
> where the syntax expects a single expression.
> (Usually it is simpler to add a regular parameter before
> the variadic part and use that parameter.)
> When there is such a need,
> we recommend assigning the vararg expression
> to a single variable and using that variable
> in its place.
> 
> 
> <p>
> Here are some examples of uses of mutlres expressions.
> In all cases, when the construction needs
> "the n-th result" and there is no such result,
> it uses a <b>nil</b>.
> 
> <pre>
>      print(x, f())      -- prints x and all results from f().
>      print(x, (f()))    -- prints x and the first result from f().
>      print(f(), x)      -- prints the first result from f() and x.
>      print(1 + f())     -- prints 1 added to the first result from f().
>      local x = ...      -- x gets the first vararg argument.
>      x,y = ...          -- x gets the first vararg argument,
>                         -- y gets the second vararg argument.
>      x,y,z = w, f()     -- x gets w, y gets the first result from f(),
>                         -- z gets the second result from f().
>      x,y,z = f()        -- x gets the first result from f(),
>                         -- y gets the second result from f(),
>                         -- z gets the third result from f().
>      x,y,z = f(), g()   -- x gets the first result from f(),
>                         -- y gets the first result from g(),
>                         -- z gets the second result from g().
>      x,y,z = (f())      -- x gets the first result from f(), y and z get nil.
>      return f()         -- returns all results from f().
>      return x, ...      -- returns x and all received vararg arguments.
>      return x,y,f()     -- returns x, y, and all results from f().
>      {f()}              -- creates a list with all results from f().
>      {...}              -- creates a list with all vararg arguments.
>      {f(), 5}           -- creates a list with the first result from f() and 5.
> </pre>
> 
> 
> 
> 

2815a2870
> (<em>Void statements</em> are labels and empty statements.)

3074c3129
< The API guarantees that any pointer to a string in a stack index
> the API guarantees that any pointer to a string in a stack index

3540c3595
< Note that Standard&nbsp;C ensures
> Note that ISO&nbsp;C ensures

3788,3789c3843
< (Exceptionally, this function was introduced in release 5.4.3.
< It is not present in previous 5.4 releases.)
> (This function was introduced in release&nbsp;5.4.3.)

4545c4599
< 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&nbsp;0 and pushes nothing.

4987a5042
> The value at <code>index</code> must be a table.

5053a5109
> The value at <code>index</code> must be a table.

5166c5222
< <pre>int lua_resetthread (lua_State *L);</pre>
> <pre>int lua_resetthread (lua_State *L, lua_State *from);</pre>

5179a5236,5242
> <p>
> The parameter <code>from</code> represents the coroutine that is resetting <code>L</code>.
> If there is no such coroutine,
> this parameter can be <code>NULL</code>.
> (This parameter was introduced in release&nbsp;5.4.5.)
> 
> 

6036c6099
< true if the function is a vararg function
> true if the function is a variadic function

6776c6839
< Removes <code>n</code> bytes from the the buffer <code>B</code>
> Removes <code>n</code> bytes from the buffer <code>B</code>

6971,6972c7034,7035
< It returns <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if there are no errors,
< or an error code in case of errors (see <a href="#4.4.1">&sect;4.4.1</a>).
> It returns&nbsp;0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) if there are no errors,
> or 1 in case of errors.

6989,6990c7052,7053
< It returns <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if there are no errors,
< or an error code in case of errors (see <a href="#4.4.1">&sect;4.4.1</a>).
> It returns&nbsp;0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) if there are no errors,
> or 1 in case of errors.

7297c7360
< allocator based on the standard&nbsp;C allocation functions
> allocator based on the ISO&nbsp;C allocation functions

7688,7690c7751
< <pre>const char *luaL_typeerror (lua_State *L,
<                                       int arg,
<                                       const char *tname);</pre>
> <pre>int luaL_typeerror (lua_State *L, int arg, const char *tname);</pre>

8710a8772,8773
> The real table is stored in the C registry (see <a href="#4.3">&sect;4.3</a>),
> indexed by the key <a name="pdf-LUA_LOADED_TABLE"><code>LUA_LOADED_TABLE</code></a>, a string.

8748c8811
< This function is not supported by Standard&nbsp;C.
> This functionality is not supported by ISO&nbsp;C.

8801a8865,8866
> The real table is stored in the C registry (see <a href="#4.3">&sect;4.3</a>),
> indexed by the key <a name="pdf-LUA_PRELOAD_TABLE"><code>LUA_PRELOAD_TABLE</code></a>, a string.

9314c9379
< Returns the size of a string resulting from <a href="#pdf-string.pack"><code>string.pack</code></a>
> Returns the length of a string resulting from <a href="#pdf-string.pack"><code>string.pack</code></a>

10094c10159
< 
>  

10096c10161
< but uses the signs of both arguments to find the
> using the signs of both arguments to find the

10956c11021
< closes the Lua state before exiting.
> the function closes the Lua state before exiting (see <a href="#lua_close"><code>lua_close</code></a>).

11505a11571,11572
> <li><b><code>-l <em>g=mod</em></code>: </b> "require" <em>mod</em> and assign the
>   result to global <em>g</em>;</li>

11511a11579,11582
> (The form <code>-l <em>g=mod</em></code> was introduced in release&nbsp;5.4.4.)
> 
> 
> <p>

11585c11656
< the script is compiled as a vararg function.
> the script is compiled as a variadic function.

11952c12023
< Thu Jan 13 11:33:16 UTC 2022
> Tue Apr 18 12:51:25 UTC 2023

11955c12026
< Last change: revised for Lua 5.4.4
> Last change: revised for Lua 5.4.5

doc/readme.html

101,103d100
< Try also
< <A HREF="http://luadist.org/">LuaDist</A>,
< a multi-platform distribution of Lua that includes batteries.

113c110
< the top-level directory, which is named <TT>lua-5.4.4</TT>.
> the top-level directory, which is named <TT>lua-5.4.5</TT>.

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

306c303
< Copyright &copy; 1994&ndash;2022 Lua.org, PUC-Rio.
> Copyright &copy; 1994&ndash;2023 Lua.org, PUC-Rio.

333c330
< Mon Jan  3 09:54:18 UTC 2022
> Mon Mar 27 21:22:06 UTC 2023

336c333
< Last change: revised for Lua 5.4.4
> Last change: revised for Lua 5.4.5

src/Makefile

33c33
< PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
> PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris

118a119,121
> 
> ios:
> 	$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_IOS"

src/lapi.c

63,65c63,65
<     StkId o = ci->func + idx;
<     api_check(L, idx <= L->ci->top - (ci->func + 1), "unacceptable index");
<     if (o >= L->top) return &G(L)->nilvalue;
>     StkId o = ci->func.p + idx;
>     api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index");
>     if (o >= L->top.p) return &G(L)->nilvalue;

69,70c69,71
<     api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
<     return s2v(L->top + idx);
>     api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
>                  "invalid index");
>     return s2v(L->top.p + idx);

77,78c78,79
<     if (ttisCclosure(s2v(ci->func))) {  /* C closure? */
<       CClosure *func = clCvalue(s2v(ci->func));
>     if (ttisCclosure(s2v(ci->func.p))) {  /* C closure? */
>       CClosure *func = clCvalue(s2v(ci->func.p));

83c84
<       api_check(L, ttislcf(s2v(ci->func)), "caller not a C function");
>       api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function");

97,98c98,99
<     StkId o = ci->func + idx;
<     api_check(L, o < L->top, "invalid index");
>     StkId o = ci->func.p + idx;
>     api_check(L, o < L->top.p, "invalid index");

102c103,104
<     api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index");
>     api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
>                  "invalid index");

104c106
<     return L->top + idx;
>     return L->top.p + idx;

115c117
<   if (L->stack_last - L->top > n)  /* stack large enough? */
>   if (L->stack_last.p - L->top.p > n)  /* stack large enough? */

117,125c119,122
<   else {  /* no; need to grow stack */
<     int inuse = cast_int(L->top - L->stack) + EXTRA_STACK;
<     if (inuse > LUAI_MAXSTACK - n)  /* can grow without overflow? */
<       res = 0;  /* no */
<     else  /* try to grow stack */
<       res = luaD_growstack(L, n, 0);
<   }
<   if (res && ci->top < L->top + n)
<     ci->top = L->top + n;  /* adjust frame top */
>   else  /* need to grow stack */
>     res = luaD_growstack(L, n, 0);
>   if (res && ci->top.p < L->top.p + n)
>     ci->top.p = L->top.p + n;  /* adjust frame top */

137,138c134,135
<   api_check(from, to->ci->top - to->top >= n, "stack overflow");
<   from->top -= n;
>   api_check(from, to->ci->top.p - to->top.p >= n, "stack overflow");
>   from->top.p -= n;

140,141c137,138
<     setobjs2s(to, to->top, from->top + i);
<     to->top++;  /* stack already checked by previous 'api_check' */
>     setobjs2s(to, to->top.p, from->top.p + i);
>     to->top.p++;  /* stack already checked by previous 'api_check' */

175c172
<          : cast_int(L->top - L->ci->func) + idx;
>          : cast_int(L->top.p - L->ci->func.p) + idx;

180c177
<   return cast_int(L->top - (L->ci->func + 1));
>   return cast_int(L->top.p - (L->ci->func.p + 1));

190c187
<   func = ci->func;
>   func = ci->func.p;

192,193c189,190
<     api_check(L, idx <= ci->top - (func + 1), "new top too large");
<     diff = ((func + 1) + idx) - L->top;
>     api_check(L, idx <= ci->top.p - (func + 1), "new top too large");
>     diff = ((func + 1) + idx) - L->top.p;

195c192
<       setnilvalue(s2v(L->top++));  /* clear new slots */
>       setnilvalue(s2v(L->top.p++));  /* clear new slots */

198c195
<     api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
>     api_check(L, -(idx+1) <= (L->top.p - (func + 1)), "invalid new top");

201,203c198,200
<   api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot");
<   newtop = L->top + diff;
<   if (diff < 0 && L->tbclist >= newtop) {
>   api_check(L, L->tbclist.p < L->top.p, "previous pop of an unclosed slot");
>   newtop = L->top.p + diff;
>   if (diff < 0 && L->tbclist.p >= newtop) {

205c202
<     luaF_close(L, newtop, CLOSEKTOP, 0);
>     newtop = luaF_close(L, newtop, CLOSEKTOP, 0);

207c204
<   L->top = newtop;  /* correct top only after closing any upvalue */
>   L->top.p = newtop;  /* correct top only after closing any upvalue */

216c213
<   api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level,
>   api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist.p == level,

218,219c215
<   luaF_close(L, level, CLOSEKTOP, 0);
<   level = index2stack(L, idx);  /* stack may be moved */
>   level = luaF_close(L, level, CLOSEKTOP, 0);

248c244
<   t = L->top - 1;  /* end of stack segment being rotated */
>   t = L->top.p - 1;  /* end of stack segment being rotated */

267c263
<     luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr);
>     luaC_barrier(L, clCvalue(s2v(L->ci->func.p)), fr);

276c272
<   setobj2s(L, L->top, index2value(L, idx));
>   setobj2s(L, L->top.p, index2value(L, idx));

345c341
<     setobjs2s(L, L->top, L->top - 1);
>     setobjs2s(L, L->top.p, L->top.p - 1);

349,350c345,346
<   luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2);
<   L->top--;  /* remove second operand */
>   luaO_arith(L, op, s2v(L->top.p - 2), s2v(L->top.p - 1), L->top.p - 2);
>   L->top.p--;  /* remove second operand */

376c372
<   size_t sz = luaO_str2num(s, s2v(L->top));
>   size_t sz = luaO_str2num(s, s2v(L->top.p));

503c499
<   setnilvalue(s2v(L->top));
>   setnilvalue(s2v(L->top.p));

511c507
<   setfltvalue(s2v(L->top), n);
>   setfltvalue(s2v(L->top.p), n);

519c515
<   setivalue(s2v(L->top), n);
>   setivalue(s2v(L->top.p), n);

534c530
<   setsvalue2s(L, L->top, ts);
>   setsvalue2s(L, L->top.p, ts);

545c541
<     setnilvalue(s2v(L->top));
>     setnilvalue(s2v(L->top.p));

549c545
<     setsvalue2s(L, L->top, ts);
>     setsvalue2s(L, L->top.p, ts);

586c582
<     setfvalue(s2v(L->top), fn);
>     setfvalue(s2v(L->top.p), fn);

595c591
<     L->top -= n;
>     L->top.p -= n;

597c593
<       setobj2n(L, &cl->upvalue[n], s2v(L->top + n));
>       setobj2n(L, &cl->upvalue[n], s2v(L->top.p + n));

601c597
<     setclCvalue(L, s2v(L->top), cl);
>     setclCvalue(L, s2v(L->top.p), cl);

612c608
<     setbtvalue(s2v(L->top));
>     setbtvalue(s2v(L->top.p));

614c610
<     setbfvalue(s2v(L->top));
>     setbfvalue(s2v(L->top.p));

622c618
<   setpvalue(s2v(L->top), p);
>   setpvalue(s2v(L->top.p), p);

630c626
<   setthvalue(L, s2v(L->top), L);
>   setthvalue(L, s2v(L->top.p), L);

647c643
<     setobj2s(L, L->top, slot);
>     setobj2s(L, L->top.p, slot);

651c647
<     setsvalue2s(L, L->top, str);
>     setsvalue2s(L, L->top.p, str);

653c649
<     luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);
>     luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);

656c652
<   return ttype(s2v(L->top - 1));
>   return ttype(s2v(L->top.p - 1));

683,684c679,680
<   if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) {
<     setobj2s(L, L->top - 1, slot);
>   if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) {
>     setobj2s(L, L->top.p - 1, slot);

687c683
<     luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot);
>     luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);

689c685
<   return ttype(s2v(L->top - 1));
>   return ttype(s2v(L->top.p - 1));

705c701
<     setobj2s(L, L->top, slot);
>     setobj2s(L, L->top.p, slot);

710c706
<     luaV_finishget(L, t, &aux, L->top, slot);
>     luaV_finishget(L, t, &aux, L->top.p, slot);

714c710
<   return ttype(s2v(L->top - 1));
>   return ttype(s2v(L->top.p - 1));

720c716
<     setnilvalue(s2v(L->top));
>     setnilvalue(s2v(L->top.p));

722c718
<     setobj2s(L, L->top, val);
>     setobj2s(L, L->top.p, val);

725c721
<   return ttype(s2v(L->top - 1));
>   return ttype(s2v(L->top.p - 1));

742,743c738,739
<   val = luaH_get(t, s2v(L->top - 1));
<   L->top--;  /* remove key */
>   val = luaH_get(t, s2v(L->top.p - 1));
>   L->top.p--;  /* remove key */

770c766
<   sethvalue2s(L, L->top, t);
>   sethvalue2s(L, L->top.p, t);

797c793
<     sethvalue2s(L, L->top, mt);
>     sethvalue2s(L, L->top.p, mt);

813c809
<     setnilvalue(s2v(L->top));
>     setnilvalue(s2v(L->top.p));

817,818c813,814
<     setobj2s(L, L->top, &uvalue(o)->uv[n - 1].uv);
<     t = ttype(s2v(L->top));
>     setobj2s(L, L->top.p, &uvalue(o)->uv[n - 1].uv);
>     t = ttype(s2v(L->top.p));

838,839c834,835
<     luaV_finishfastset(L, t, slot, s2v(L->top - 1));
<     L->top--;  /* pop value */
>     luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
>     L->top.p--;  /* pop value */

842c838
<     setsvalue2s(L, L->top, str);  /* push 'str' (to make it a TValue) */
>     setsvalue2s(L, L->top.p, str);  /* push 'str' (to make it a TValue) */

844,845c840,841
<     luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot);
<     L->top -= 2;  /* pop value and key */
>     luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot);
>     L->top.p -= 2;  /* pop value and key */

865,866c861,862
<   if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) {
<     luaV_finishfastset(L, t, slot, s2v(L->top - 1));
>   if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) {
>     luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));

869,870c865,866
<     luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot);
<   L->top -= 2;  /* pop index and value */
>     luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot);
>   L->top.p -= 2;  /* pop index and value */

888c884
<     luaV_finishfastset(L, t, slot, s2v(L->top - 1));
>     luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));

893c889
<     luaV_finishset(L, t, &aux, s2v(L->top - 1), slot);
>     luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot);

895c891
<   L->top--;  /* pop value */
>   L->top.p--;  /* pop value */

905c901
<   luaH_set(L, t, key, s2v(L->top - 1));
>   luaH_set(L, t, key, s2v(L->top.p - 1));

907,908c903,904
<   luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
<   L->top -= n;
>   luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1));
>   L->top.p -= n;

914c910
<   aux_rawset(L, idx, s2v(L->top - 2), 2);
>   aux_rawset(L, idx, s2v(L->top.p - 2), 2);

930,932c926,928
<   luaH_setint(L, t, n, s2v(L->top - 1));
<   luaC_barrierback(L, obj2gco(t), s2v(L->top - 1));
<   L->top--;
>   luaH_setint(L, t, n, s2v(L->top.p - 1));
>   luaC_barrierback(L, obj2gco(t), s2v(L->top.p - 1));
>   L->top.p--;

943c939
<   if (ttisnil(s2v(L->top - 1)))
>   if (ttisnil(s2v(L->top.p - 1)))

946,947c942,943
<     api_check(L, ttistable(s2v(L->top - 1)), "table expected");
<     mt = hvalue(s2v(L->top - 1));
>     api_check(L, ttistable(s2v(L->top.p - 1)), "table expected");
>     mt = hvalue(s2v(L->top.p - 1));

971c967
<   L->top--;
>   L->top.p--;

987,988c983,984
<     setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top - 1));
<     luaC_barrierback(L, gcvalue(o), s2v(L->top - 1));
>     setobj(L, &uvalue(o)->uv[n - 1].uv, s2v(L->top.p - 1));
>     luaC_barrierback(L, gcvalue(o), s2v(L->top.p - 1));

991c987
<   L->top--;
>   L->top.p--;

1003c999,1000
<      api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \
>      api_check(L, (nr) == LUA_MULTRET \
>                || (L->ci->top.p - L->top.p >= (nr) - (na)), \

1016c1013
<   func = L->top - (nargs+1);
>   func = L->top.p - (nargs+1);

1064c1061
<   c.func = L->top - (nargs+1);  /* function to be called */
>   c.func = L->top.p - (nargs+1);  /* function to be called */

1099c1096
<     LClosure *f = clLvalue(s2v(L->top - 1));  /* get newly created function */
>     LClosure *f = clLvalue(s2v(L->top.p - 1));  /* get new function */

1104c1101
<       setobj(L, f->upvals[0]->v, gt);
>       setobj(L, f->upvals[0]->v.p, gt);

1118c1115
<   o = s2v(L->top - 1);
>   o = s2v(L->top.p - 1);

1244c1241
<   errobj = s2v(L->top - 1);
>   errobj = s2v(L->top.p - 1);

1262c1259
<   more = luaH_next(L, t, L->top - 1);
>   more = luaH_next(L, t, L->top.p - 1);

1267c1264
<     L->top -= 1;  /* remove key */
>     L->top.p -= 1;  /* remove key */

1279c1276
<   api_check(L, L->tbclist < o, "given index below or equal a marked one");
>   api_check(L, L->tbclist.p < o, "given index below or equal a marked one");

1294c1291
<     setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));  /* push empty string */
>     setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0));  /* push empty string */

1306c1303
<   luaV_objlen(L, L->top, t);
>   luaV_objlen(L, L->top.p, t);

1351c1348
<   setuvalue(L, s2v(L->top), u);
>   setuvalue(L, s2v(L->top.p), u);

1377c1374
<       *val = f->upvals[n-1]->v;
>       *val = f->upvals[n-1]->v.p;

1393c1390
<     setobj2s(L, L->top, val);
>     setobj2s(L, L->top.p, val);

1411,1412c1408,1409
<     L->top--;
<     setobj(L, val, s2v(L->top));
>     L->top.p--;
>     setobj(L, val, s2v(L->top.p));

src/lapi.h

15,17c15,18
< /* Increments 'L->top', checking for stack overflows */
< #define api_incr_top(L)   {L->top++; api_check(L, L->top <= L->ci->top, \
< 				"stack overflow");}
> /* Increments 'L->top.p', checking for stack overflows */
> #define api_incr_top(L)	{L->top.p++; \
> 			 api_check(L, L->top.p <= L->ci->top.p, \
> 					"stack overflow");}

23c24
< ** increases its stack space ('L->ci->top').
> ** increases its stack space ('L->ci->top.p').

26c27,28
<     { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
>     { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
> 	L->ci->top.p = L->top.p; }

30,31c32,34
< #define api_checknelems(L,n)	api_check(L, (n) < (L->top - L->ci->func), \
< 				  "not enough elements in the stack")
> #define api_checknelems(L,n) \
> 	api_check(L, (n) < (L->top.p - L->ci->func.p), \
> 			  "not enough elements in the stack")

src/lauxlib.c

529c529,530
< ** bytes.
> ** bytes. (The test for "not big enough" also gets the case when the
> ** computation of 'newsize' overflows.)

532c533
<   size_t newsize = B->size * 2;  /* double buffer size */
>   size_t newsize = (B->size / 2) * 3;  /* buffer size * 1.5 */

535c536
<   if (newsize < B->n + sz)  /* double is not big enough? */
>   if (newsize < B->n + sz)  /* not big enough? */

614c615
< ** be) bellow the string being added to the buffer. (Box creation can
> ** be) below the string being added to the buffer. (Box creation can

742,752c743,754
< static int skipBOM (LoadF *lf) {
<   const char *p = "\xEF\xBB\xBF";  /* UTF-8 BOM mark */
<   int c;
<   lf->n = 0;
<   do {
<     c = getc(lf->f);
<     if (c == EOF || c != *(const unsigned char *)p++) return c;
<     lf->buff[lf->n++] = c;  /* to be read by the parser */
<   } while (*p != '\0');
<   lf->n = 0;  /* prefix matched; discard it */
<   return getc(lf->f);  /* return next character */
> /*
> ** Skip an optional BOM at the start of a stream. If there is an
> ** incomplete BOM (the first character is correct but the rest is
> ** not), returns the first character anyway to force an error
> ** (as no chunk can start with 0xEF).
> */
> static int skipBOM (FILE *f) {
>   int c = getc(f);  /* read first character */
>   if (c == 0xEF && getc(f) == 0xBB && getc(f) == 0xBF)  /* correct BOM? */
>     return getc(f);  /* ignore BOM and return next char */
>   else  /* no (valid) BOM */
>     return c;  /* return first character */

763,764c765,766
< static int skipcomment (LoadF *lf, int *cp) {
<   int c = *cp = skipBOM(lf);
> static int skipcomment (FILE *f, int *cp) {
>   int c = *cp = skipBOM(f);

767c769
<       c = getc(lf->f);
>       c = getc(f);

769c771
<     *cp = getc(lf->f);  /* skip end-of-line, if present */
>     *cp = getc(f);  /* next character after comment, if present */

791,796c793,802
<   if (skipcomment(&lf, &c))  /* read initial portion */
<     lf.buff[lf.n++] = '\n';  /* add line to correct line numbers */
<   if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */
<     lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
<     if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
<     skipcomment(&lf, &c);  /* re-read initial portion */
>   lf.n = 0;
>   if (skipcomment(lf.f, &c))  /* read initial portion */
>     lf.buff[lf.n++] = '\n';  /* add newline to correct line numbers */
>   if (c == LUA_SIGNATURE[0]) {  /* binary file? */
>     lf.n = 0;  /* remove possible newline */
>     if (filename) {  /* "real" file? */
>       lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
>       if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
>       skipcomment(lf.f, &c);  /* re-read initial portion */
>     }

src/lcode.c

1354a1355,1383
> ** Convert a BinOpr to an OpCode  (ORDER OPR - ORDER OP)
> */
> l_sinline OpCode binopr2op (BinOpr opr, BinOpr baser, OpCode base) {
>   lua_assert(baser <= opr &&
>             ((baser == OPR_ADD && opr <= OPR_SHR) ||
>              (baser == OPR_LT && opr <= OPR_LE)));
>   return cast(OpCode, (cast_int(opr) - cast_int(baser)) + cast_int(base));
> }
> 
> 
> /*
> ** Convert a UnOpr to an OpCode  (ORDER OPR - ORDER OP)
> */
> l_sinline OpCode unopr2op (UnOpr opr) {
>   return cast(OpCode, (cast_int(opr) - cast_int(OPR_MINUS)) +
>                                        cast_int(OP_UNM));
> }
> 
> 
> /*
> ** Convert a BinOpr to a tag method  (ORDER OPR - ORDER TM)
> */
> l_sinline TMS binopr2TM (BinOpr opr) {
>   lua_assert(OPR_ADD <= opr && opr <= OPR_SHR);
>   return cast(TMS, (cast_int(opr) - cast_int(OPR_ADD)) + cast_int(TM_ADD));
> }
> 
> 
> /*

1392c1421
< static void codebinexpval (FuncState *fs, OpCode op,
> static void codebinexpval (FuncState *fs, BinOpr opr,

1394c1423,1427
<   int v2 = luaK_exp2anyreg(fs, e2);  /* both operands are in registers */
>   OpCode op = binopr2op(opr, OPR_ADD, OP_ADD);
>   int v2 = luaK_exp2anyreg(fs, e2);  /* make sure 'e2' is in a register */
>   /* 'e1' must be already in a register or it is a constant */
>   lua_assert((VNIL <= e1->k && e1->k <= VKSTR) ||
>              e1->k == VNONRELOC || e1->k == VRELOC);

1396,1397c1429
<   finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN,
<                   cast(TMS, (op - OP_ADD) + TM_ADD));
>   finishbinexpval(fs, e1, e2, op, v2, 0, line, OP_MMBIN, binopr2TM(opr));

1412a1445,1456
> /*
> ** Code binary operators with K operand.
> */
> static void codebinK (FuncState *fs, BinOpr opr,
>                       expdesc *e1, expdesc *e2, int flip, int line) {
>   TMS event = binopr2TM(opr);
>   int v2 = e2->u.info;  /* K index */
>   OpCode op = binopr2op(opr, OPR_ADD, OP_ADDK);
>   finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
> }
> 
> 

1440a1485,1495
> ** Code binary operators with no constant operand.
> */
> static void codebinNoK (FuncState *fs, BinOpr opr,
>                         expdesc *e1, expdesc *e2, int flip, int line) {
>   if (flip)
>     swapexps(e1, e2);  /* back to original order */
>   codebinexpval(fs, opr, e1, e2, line);  /* use standard operators */
> }
> 
> 
> /*

1446,1457c1501,1504
<   TMS event = cast(TMS, opr + TM_ADD);
<   if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) {  /* K operand? */
<     int v2 = e2->u.info;  /* K index */
<     OpCode op = cast(OpCode, opr + OP_ADDK);
<     finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event);
<   }
<   else {  /* 'e2' is neither an immediate nor a K operand */
<     OpCode op = cast(OpCode, opr + OP_ADD);
<     if (flip)
<       swapexps(e1, e2);  /* back to original order */
<     codebinexpval(fs, op, e1, e2, line);  /* use standard operators */
<   }
>   if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2))  /* K operand? */
>     codebinK(fs, opr, e1, e2, flip, line);
>   else  /* 'e2' is neither an immediate nor a K operand */
>     codebinNoK(fs, opr, e1, e2, flip, line);

1474c1521
<     codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD);
>     codebini(fs, OP_ADDI, e1, e2, flip, line, TM_ADD);

1481c1528
< ** Code bitwise operations; they are all associative, so the function
> ** Code bitwise operations; they are all commutative, so the function

1487,1489c1534
<   int v2;
<   OpCode op;
<   if (e1->k == VKINT && luaK_exp2RK(fs, e1)) {
>   if (e1->k == VKINT) {

1493,1502c1538,1541
<   else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) {  /* no constants? */
<     op = cast(OpCode, opr + OP_ADD);
<     codebinexpval(fs, op, e1, e2, line);  /* all-register opcodes */
<     return;
<   }
<   v2 = e2->u.info;  /* index in K array */
<   op = cast(OpCode, opr + OP_ADDK);
<   lua_assert(ttisinteger(&fs->f->k[v2]));
<   finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK,
<                   cast(TMS, opr + TM_ADD));
>   if (e2->k == VKINT && luaK_exp2K(fs, e2))  /* K operand? */
>     codebinK(fs, opr, e1, e2, flip, line);
>   else  /* no constants */
>     codebinNoK(fs, opr, e1, e2, flip, line);

1510c1549
< static void codeorder (FuncState *fs, OpCode op, expdesc *e1, expdesc *e2) {
> static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {

1513a1553
>   OpCode op;

1518c1558
<     op = cast(OpCode, (op - OP_LT) + OP_LTI);
>     op = binopr2op(opr, OPR_LT, OP_LTI);

1524c1564
<     op = (op == OP_LT) ? OP_GTI : OP_GEI;
>     op = binopr2op(opr, OPR_LT, OP_GTI);

1528a1569
>     op = binopr2op(opr, OPR_LT, OP_LT);

1554c1595
<   else if (luaK_exp2RK(fs, e2)) {  /* 1st expression is constant? */
>   else if (luaK_exp2RK(fs, e2)) {  /* 2nd expression is constant? */

1571c1612
< void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
> void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) {

1574c1615
<   switch (op) {
>   switch (opr) {

1576c1617
<       if (constfolding(fs, op + LUA_OPUNM, e, &ef))
>       if (constfolding(fs, opr + LUA_OPUNM, e, &ef))

1580c1621
<       codeunexpval(fs, cast(OpCode, op + OP_UNM), e, line);
>       codeunexpval(fs, unopr2op(opr), e, line);

1614c1655,1656
<       /* else keep numeral, which may be folded with 2nd operand */
>       /* else keep numeral, which may be folded or used as an immediate
>          operand */

1709c1751
<        codebinexpval(fs, OP_SHL, e1, e2, line);
>        codebinexpval(fs, opr, e1, e2, line);

1716c1758
<         codebinexpval(fs, OP_SHR, e1, e2, line);
>         codebinexpval(fs, opr, e1, e2, line);

1723,1727d1764
<     case OPR_LT: case OPR_LE: {
<       OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
<       codeorder(fs, op, e1, e2);
<       break;
<     }

1730d1766
<       OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);

1732c1768,1771
<       codeorder(fs, op, e1, e2);
>       opr = cast(BinOpr, (opr - OPR_GT) + OPR_LT);
>     }  /* FALLTHROUGH */
>     case OPR_LT: case OPR_LE: {
>       codeorder(fs, opr, e1, e2);

src/lcorolib.c

79c79
<       stat = lua_resetthread(co);  /* close its tbc variables */
>       stat = lua_resetthread(co, L);  /* close its tbc variables */

175c175
<       status = lua_resetthread(co);
>       status = lua_resetthread(co, L);

src/ldebug.c

185c185
<   if (clLvalue(s2v(ci->func))->p->is_vararg) {
>   if (clLvalue(s2v(ci->func.p))->p->is_vararg) {

188c188
<       *pos = ci->func - nextra - (n + 1);
>       *pos = ci->func.p - nextra - (n + 1);

197c197
<   StkId base = ci->func + 1;
>   StkId base = ci->func.p + 1;

206c206
<     StkId limit = (ci == L->ci) ? L->top : ci->next->func;
>     StkId limit = (ci == L->ci) ? L->top.p : ci->next->func.p;

224c224
<     if (!isLfunction(s2v(L->top - 1)))  /* not a Lua function? */
>     if (!isLfunction(s2v(L->top.p - 1)))  /* not a Lua function? */

227c227
<       name = luaF_getlocalname(clLvalue(s2v(L->top - 1))->p, n, 0);
>       name = luaF_getlocalname(clLvalue(s2v(L->top.p - 1))->p, n, 0);

233c233
<       setobjs2s(L, L->top, pos);
>       setobjs2s(L, L->top.p, pos);

248,249c248,249
<     setobjs2s(L, pos, L->top - 1);
<     L->top--;  /* pop value */
>     setobjs2s(L, pos, L->top.p - 1);
>     L->top.p--;  /* pop value */

292c292
<     setnilvalue(s2v(L->top));
>     setnilvalue(s2v(L->top.p));

301c301
<     sethvalue2s(L, L->top, t);  /* push it on stack */
>     sethvalue2s(L, L->top.p, t);  /* push it on stack */

391c391
<     func = s2v(L->top - 1);
>     func = s2v(L->top.p - 1);

394c394
<     L->top--;  /* pop function */
>     L->top.p--;  /* pop function */

398c398
<     func = s2v(ci->func);
>     func = s2v(ci->func.p);

404c404
<     setobj2s(L, L->top, func);
>     setobj2s(L, L->top.p, func);

659,668c659,669
< ** Check whether pointer 'o' points to some value in the stack
< ** frame of the current function. Because 'o' may not point to a
< ** value in this stack, we cannot compare it with the region
< ** boundaries (undefined behaviour in ISO C).
< */
< static int isinstack (CallInfo *ci, const TValue *o) {
<   StkId pos;
<   for (pos = ci->func + 1; pos < ci->top; pos++) {
<     if (o == s2v(pos))
<       return 1;
> ** Check whether pointer 'o' points to some value in the stack frame of
> ** the current function and, if so, returns its index.  Because 'o' may
> ** not point to a value in this stack, we cannot compare it with the
> ** region boundaries (undefined behavior in ISO C).
> */
> static int instack (CallInfo *ci, const TValue *o) {
>   int pos;
>   StkId base = ci->func.p + 1;
>   for (pos = 0; base + pos < ci->top.p; pos++) {
>     if (o == s2v(base + pos))
>       return pos;

670c671
<   return 0;  /* not found */
>   return -1;  /* not found */

684c685
<     if (c->upvals[i]->v == o) {
>     if (c->upvals[i]->v.p == o) {

711,713c712,716
<     if (!kind && isinstack(ci, o))  /* no? try a register */
<       kind = getobjname(ci_func(ci)->p, currentpc(ci),
<                         cast_int(cast(StkId, o) - (ci->func + 1)), &name);
>     if (!kind) {  /* not an upvalue? */
>       int reg = instack(ci, o);  /* try a register */
>       if (reg >= 0)  /* is 'o' a register? */
>         kind = getobjname(ci_func(ci)->p, currentpc(ci), reg, &name);
>     }

810,813c813,816
<     setobjs2s(L, L->top, L->top - 1);  /* move argument */
<     setobjs2s(L, L->top - 1, errfunc);  /* push function */
<     L->top++;  /* assume EXTRA_STACK */
<     luaD_callnoyield(L, L->top - 2, 1);  /* call it */
>     setobjs2s(L, L->top.p, L->top.p - 1);  /* move argument */
>     setobjs2s(L, L->top.p - 1, errfunc);  /* push function */
>     L->top.p++;  /* assume EXTRA_STACK */
>     luaD_callnoyield(L, L->top.p - 2, 1);  /* call it */

827c830
<   if (isLua(ci))  /* if Lua function, add source:line information */
>   if (isLua(ci)) {  /* if Lua function, add source:line information */

828a832,834
>     setobjs2s(L, L->top.p - 2, L->top.p - 1);  /* remove 'msg' */
>     L->top.p--;
>   }

845c851
<     int delta = 0;  /* line diference */
>     int delta = 0;  /* line difference */

872c878
< ** 'L->top' before calling anything that can run the GC.
> ** 'L->top.p' before calling anything that can run the GC.

895c901
<     L->top = ci->top;  /* correct top */
>     L->top.p = ci->top.p;  /* correct top */

src/ldebug.h

18c18
< #define ci_func(ci)		(clLvalue(s2v((ci)->func)))
> #define ci_func(ci)		(clLvalue(s2v((ci)->func.p)))

src/ldo.c

107c107
<       setobjs2s(L, oldtop, L->top - 1);  /* error message on current top */
>       setobjs2s(L, oldtop, L->top.p - 1);  /* error message on current top */

111c111
<   L->top = oldtop + 1;
>   L->top.p = oldtop + 1;

124c124
<       setobjs2s(L, g->mainthread->top++, L->top - 1);  /* copy error obj. */
>       setobjs2s(L, g->mainthread->top.p++, L->top.p - 1);  /* copy error obj. */

160c160,182
< static void correctstack (lua_State *L, StkId oldstack, StkId newstack) {
> 
> 
> /*
> ** Change all pointers to the stack into offsets.
> */
> static void relstack (lua_State *L) {
>   CallInfo *ci;
>   UpVal *up;
>   L->top.offset = savestack(L, L->top.p);
>   L->tbclist.offset = savestack(L, L->tbclist.p);
>   for (up = L->openupval; up != NULL; up = up->u.open.next)
>     up->v.offset = savestack(L, uplevel(up));
>   for (ci = L->ci; ci != NULL; ci = ci->previous) {
>     ci->top.offset = savestack(L, ci->top.p);
>     ci->func.offset = savestack(L, ci->func.p);
>   }
> }
> 
> 
> /*
> ** Change back all offsets into pointers.
> */
> static void correctstack (lua_State *L) {

163,164c185,186
<   L->top = (L->top - oldstack) + newstack;
<   L->tbclist = (L->tbclist - oldstack) + newstack;
>   L->top.p = restorestack(L, L->top.offset);
>   L->tbclist.p = restorestack(L, L->tbclist.offset);

166c188
<     up->v = s2v((uplevel(up) - oldstack) + newstack);
>     up->v.p = s2v(restorestack(L, up->v.offset));

168,169c190,191
<     ci->top = (ci->top - oldstack) + newstack;
<     ci->func = (ci->func - oldstack) + newstack;
>     ci->top.p = restorestack(L, ci->top.offset);
>     ci->func.p = restorestack(L, ci->func.offset);

179d200
< 

181,187c202,208
< ** Reallocate the stack to a new size, correcting all pointers into
< ** it. (There are pointers to a stack from its upvalues, from its list
< ** of call infos, plus a few individual pointers.) The reallocation is
< ** done in two steps (allocation + free) because the correction must be
< ** done while both addresses (the old stack and the new one) are valid.
< ** (In ISO C, any pointer use after the pointer has been deallocated is
< ** undefined behavior.)
> ** Reallocate the stack to a new size, correcting all pointers into it.
> ** In ISO C, any pointer use after the pointer has been deallocated is
> ** undefined behavior. So, before the reallocation, all pointers are
> ** changed to offsets, and after the reallocation they are changed back
> ** to pointers. As during the reallocation the pointers are invalid, the
> ** reallocation cannot run emergency collections.
> **

194,195c215,216
<   StkId newstack = luaM_reallocvector(L, NULL, 0,
<                                       newsize + EXTRA_STACK, StackValue);
>   StkId newstack;
>   int oldgcstop = G(L)->gcstopem;

196a218,222
>   relstack(L);  /* change pointers to offsets */
>   G(L)->gcstopem = 1;  /* stop emergency collection */
>   newstack = luaM_reallocvector(L, L->stack.p, oldsize + EXTRA_STACK,
>                                    newsize + EXTRA_STACK, StackValue);
>   G(L)->gcstopem = oldgcstop;  /* restore emergency collection */

197a224
>     correctstack(L);  /* change offsets back to pointers */

202,205c229,232
<   /* number of elements to be copied to the new stack */
<   i = ((oldsize <= newsize) ? oldsize : newsize) + EXTRA_STACK;
<   memcpy(newstack, L->stack, i * sizeof(StackValue));
<   for (; i < newsize + EXTRA_STACK; i++)
>   L->stack.p = newstack;
>   correctstack(L);  /* change offsets back to pointers */
>   L->stack_last.p = L->stack.p + newsize;
>   for (i = oldsize + EXTRA_STACK; i < newsize + EXTRA_STACK; i++)

207,210d233
<   correctstack(L, L->stack, newstack);
<   luaM_freearray(L, L->stack, oldsize + EXTRA_STACK);
<   L->stack = newstack;
<   L->stack_last = L->stack + newsize;

216c239
< ** Try to grow the stack by at least 'n' elements. when 'raiseerror'
> ** Try to grow the stack by at least 'n' elements. When 'raiseerror'

230c253
<   else {
>   else if (n < LUAI_MAXSTACK) {  /* avoids arithmetic overflows */

232c255
<     int needed = cast_int(L->top - L->stack) + n;
>     int needed = cast_int(L->top.p - L->stack.p) + n;

239,245d261
<     else {  /* stack overflow */
<       /* add extra size to be able to handle the error message */
<       luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);
<       if (raiseerror)
<         luaG_runerror(L, "stack overflow");
<       return 0;
<     }

246a263,268
>   /* else stack overflow */
>   /* add extra size to be able to handle the error message */
>   luaD_reallocstack(L, ERRORSTACKSIZE, raiseerror);
>   if (raiseerror)
>     luaG_runerror(L, "stack overflow");
>   return 0;

249a272,275
> /*
> ** Compute how much of the stack is being used, by computing the
> ** maximum top of all call frames in the stack and the current top.
> */

253c279
<   StkId lim = L->top;
>   StkId lim = L->top.p;

255c281
<     if (lim < ci->top) lim = ci->top;
>     if (lim < ci->top.p) lim = ci->top.p;

257,258c283,284
<   lua_assert(lim <= L->stack_last);
<   res = cast_int(lim - L->stack) + 1;  /* part of stack in use */
>   lua_assert(lim <= L->stack_last.p + EXTRA_STACK);
>   res = cast_int(lim - L->stack.p) + 1;  /* part of stack in use */

276,282c302
<   int nsize = inuse * 2;  /* proposed new size */
<   int max = inuse * 3;  /* maximum "reasonable" size */
<   if (max > LUAI_MAXSTACK) {
<     max = LUAI_MAXSTACK;  /* respect stack limit */
<     if (nsize > LUAI_MAXSTACK)
<       nsize = LUAI_MAXSTACK;
<   }
>   int max = (inuse > LUAI_MAXSTACK / 3) ? LUAI_MAXSTACK : inuse * 3;

285c305,306
<   if (inuse <= LUAI_MAXSTACK && stacksize(L) > max)
>   if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) {
>     int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2;

286a308
>   }

295c317
<   L->top++;
>   L->top.p++;

312,313c334,335
<     ptrdiff_t top = savestack(L, L->top);  /* preserve original 'top' */
<     ptrdiff_t ci_top = savestack(L, ci->top);  /* idem for 'ci->top' */
>     ptrdiff_t top = savestack(L, L->top.p);  /* preserve original 'top' */
>     ptrdiff_t ci_top = savestack(L, ci->top.p);  /* idem for 'ci->top' */

323,324c345,346
<     if (isLua(ci) && L->top < ci->top)
<       L->top = ci->top;  /* protect entire activation register */
>     if (isLua(ci) && L->top.p < ci->top.p)
>       L->top.p = ci->top.p;  /* protect entire activation register */

326,327c348,349
<     if (ci->top < L->top + LUA_MINSTACK)
<       ci->top = L->top + LUA_MINSTACK;
>     if (ci->top.p < L->top.p + LUA_MINSTACK)
>       ci->top.p = L->top.p + LUA_MINSTACK;

335,336c357,358
<     ci->top = restorestack(L, ci_top);
<     L->top = restorestack(L, top);
>     ci->top.p = restorestack(L, ci_top);
>     L->top.p = restorestack(L, top);

367c389
<     StkId firstres = L->top - nres;  /* index of first result */
>     StkId firstres = L->top.p - nres;  /* index of first result */

375,376c397,398
<     ci->func += delta;  /* if vararg, back to virtual 'func' */
<     ftransfer = cast(unsigned short, firstres - ci->func);
>     ci->func.p += delta;  /* if vararg, back to virtual 'func' */
>     ftransfer = cast(unsigned short, firstres - ci->func.p);

378c400
<     ci->func -= delta;
>     ci->func.p -= delta;

397c419
<   for (p = L->top; p > func; p--)  /* open space for metamethod */
>   for (p = L->top.p; p > func; p--)  /* open space for metamethod */

399c421
<   L->top++;  /* stack space pre-allocated by the caller */
>   L->top.p++;  /* stack space pre-allocated by the caller */

416c438
<       L->top = res;
>       L->top.p = res;

422,423c444,445
<         setobjs2s(L, res, L->top - nres);  /* move it to proper place */
<       L->top = res + 1;
>         setobjs2s(L, res, L->top.p - nres);  /* move it to proper place */
>       L->top.p = res + 1;

430d451
<         ptrdiff_t savedres = savestack(L, res);

433c454
<         luaF_close(L, res, CLOSEKTOP, 1);
>         res = luaF_close(L, res, CLOSEKTOP, 1);

435c456,457
<         if (L->hookmask)  /* if needed, call hook after '__close's */
>         if (L->hookmask) {  /* if needed, call hook after '__close's */
>           ptrdiff_t savedres = savestack(L, res);

437c459,460
<         res = restorestack(L, savedres);  /* close and hook can move stack */
>           res = restorestack(L, savedres);  /* hook can move stack */
>         }

445c468
<   firstresult = L->top - nres;  /* index of first result */
>   firstresult = L->top.p - nres;  /* index of first result */

452c475
<   L->top = res + wanted;  /* top points after the last result */
>   L->top.p = res + wanted;  /* top points after the last result */

467c490
<   moveresults(L, ci->func, nres, wanted);
>   moveresults(L, ci->func.p, nres, wanted);

482c505
<   ci->func = func;
>   ci->func.p = func;

485c508
<   ci->top = top;
>   ci->top.p = top;

499,500c522,523
<                                L->top + LUA_MINSTACK);
<   lua_assert(ci->top <= L->stack_last);
>                                L->top.p + LUA_MINSTACK);
>   lua_assert(ci->top.p <= L->stack_last.p);

502c525
<     int narg = cast_int(L->top - func) - 1;
>     int narg = cast_int(L->top.p - func) - 1;

534c557
<       ci->func -= delta;  /* restore 'func' (if vararg) */
>       ci->func.p -= delta;  /* restore 'func' (if vararg) */

536,537c559,560
<         setobjs2s(L, ci->func + i, func + i);
<       func = ci->func;  /* moved-down function */
>         setobjs2s(L, ci->func.p + i, func + i);
>       func = ci->func.p;  /* moved-down function */

540,541c563,564
<       ci->top = func + 1 + fsize;  /* top for new function */
<       lua_assert(ci->top <= L->stack_last);
>       ci->top.p = func + 1 + fsize;  /* top for new function */
>       lua_assert(ci->top.p <= L->stack_last.p);

544c567
<       L->top = func + narg1;  /* set top */
>       L->top.p = func + narg1;  /* set top */

577c600
<       int narg = cast_int(L->top - func) - 1;  /* number of real arguments */
>       int narg = cast_int(L->top.p - func) - 1;  /* number of real arguments */

584,585c607,608
<         setnilvalue(s2v(L->top++));  /* complete missing arguments */
<       lua_assert(ci->top <= L->stack_last);
>         setnilvalue(s2v(L->top.p++));  /* complete missing arguments */
>       lua_assert(ci->top.p <= L->stack_last.p);

600a624,626
> ** This function can be called with some use of EXTRA_STACK, so it should
> ** check the stack before doing anything else. 'luaD_precall' already
> ** does that.

602c628
< l_sinline void ccall (lua_State *L, StkId func, int nResults, int inc) {
> l_sinline void ccall (lua_State *L, StkId func, int nResults, l_uint32 inc) {

605c631,632
<   if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
>   if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) {
>     checkstackp(L, 0, func);  /* free any use of EXTRA_STACK */

606a634
>   }

654,655c682
<     luaF_close(L, func, status, 1);  /* can yield or raise an error */
<     func = restorestack(L, ci->u2.funcidx);  /* stack may be moved */
>     func = luaF_close(L, func, status, 1);  /* can yield or raise an error */

743,744c770,771
<   L->top -= narg;  /* remove args from the stack */
<   setsvalue2s(L, L->top, luaS_new(L, msg));  /* push error message */
>   L->top.p -= narg;  /* remove args from the stack */
>   setsvalue2s(L, L->top.p, luaS_new(L, msg));  /* push error message */

760c787
<   StkId firstArg = L->top - n;  /* first argument */
>   StkId firstArg = L->top.p - n;  /* first argument */

768c795
<       L->top = firstArg;  /* discard arguments */
>       L->top.p = firstArg;  /* discard arguments */

811c838
<     else if (L->top - (L->ci->func + 1) == nargs)  /* no function? */
>     else if (L->top.p - (L->ci->func.p + 1) == nargs)  /* no function? */

829,830c856,857
<     luaD_seterrorobj(L, status, L->top);  /* push error message */
<     L->ci->top = L->top;
>     luaD_seterrorobj(L, status, L->top.p);  /* push error message */
>     L->ci->top.p = L->top.p;

833c860
<                                     : cast_int(L->top - (L->ci->func + 1));
>                                     : cast_int(L->top.p - (L->ci->func.p + 1));

988c1015
<   status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
>   status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc);

src/ldo.h

10a11
> #include "llimits.h"

26c27
< 	if (l_unlikely(L->stack_last - L->top <= (n))) \
> 	if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \

35,36c36,37
< #define savestack(L,p)		((char *)(p) - (char *)L->stack)
< #define restorestack(L,n)	((StkId)((char *)L->stack + (n)))
> #define savestack(L,pt)		(cast_charp(pt) - cast_charp(L->stack.p))
> #define restorestack(L,n)	cast(StkId, cast_charp(L->stack.p) + (n))

39a41,47
> #define checkstackp(L,n,p)  \
>   luaD_checkstackaux(L, n, \
>     ptrdiff_t t__ = savestack(L, p),  /* save 'p' */ \
>     p = restorestack(L, t__))  /* 'pos' part: restore 'p' */
> 
> 
> /* macro to check stack size and GC, preserving 'p' */

61c69,70
< LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,                                                    int narg1, int delta);
> LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
>                                               int narg1, int delta);

src/ldump.c

12a13
> #include <limits.h>

58,59c59,63
< /* dumpInt Buff Size */
< #define DIBS    ((sizeof(size_t) * 8 / 7) + 1)
> /*
> ** 'dumpSize' buffer size: each byte can store up to 7 bits. (The "+6"
> ** rounds up the division.)
> */
> #define DIBS    ((sizeof(size_t) * CHAR_BIT + 6) / 7)

src/lfunc.c

53,54c53,54
<     uv->v = &uv->u.value;  /* make it closed */
<     setnilvalue(uv->v);
>     uv->v.p = &uv->u.value;  /* make it closed */
>     setnilvalue(uv->v.p);

65c65
< static UpVal *newupval (lua_State *L, int tbc, StkId level, UpVal **prev) {
> static UpVal *newupval (lua_State *L, StkId level, UpVal **prev) {

69,70c69
<   uv->v = s2v(level);  /* current value lives in the stack */
<   uv->tbc = tbc;
>   uv->v.p = s2v(level);  /* current value lives in the stack */

99c98
<   return newupval(L, 0, level, pp);
>   return newupval(L, level, pp);

109c108
<   StkId top = L->top;
>   StkId top = L->top.p;

114c113
<   L->top = top + 3;  /* add function and arguments */
>   L->top.p = top + 3;  /* add function and arguments */

129c128
<     int idx = cast_int(level - L->ci->func);  /* variable index */
>     int idx = cast_int(level - L->ci->func.p);  /* variable index */

163c162
< 	((256ul << ((sizeof(L->stack->tbclist.delta) - 1) * 8)) - 1)
> 	((256ul << ((sizeof(L->stack.p->tbclist.delta) - 1) * 8)) - 1)

170c169
<   lua_assert(level > L->tbclist);
>   lua_assert(level > L->tbclist.p);

174,176c173,175
<   while (cast_uint(level - L->tbclist) > MAXDELTA) {
<     L->tbclist += MAXDELTA;  /* create a dummy node at maximum delta */
<     L->tbclist->tbclist.delta = 0;
>   while (cast_uint(level - L->tbclist.p) > MAXDELTA) {
>     L->tbclist.p += MAXDELTA;  /* create a dummy node at maximum delta */
>     L->tbclist.p->tbclist.delta = 0;

178,179c177,178
<   level->tbclist.delta = cast(unsigned short, level - L->tbclist);
<   L->tbclist = level;
>   level->tbclist.delta = cast(unsigned short, level - L->tbclist.p);
>   L->tbclist.p = level;

199c198
<     lua_assert(uplevel(uv) < L->top);
>     lua_assert(uplevel(uv) < L->top.p);

201,202c200,201
<     setobj(L, slot, uv->v);  /* move value to upvalue slot */
<     uv->v = slot;  /* now current value lives here */
>     setobj(L, slot, uv->v.p);  /* move value to upvalue slot */
>     uv->v.p = slot;  /* now current value lives here */

212c211
< ** Remove firt element from the tbclist plus its dummy nodes.
> ** Remove first element from the tbclist plus its dummy nodes.

215c214
<   StkId tbc = L->tbclist;
>   StkId tbc = L->tbclist.p;

218c217
<   while (tbc > L->stack && tbc->tbclist.delta == 0)
>   while (tbc > L->stack.p && tbc->tbclist.delta == 0)

220c219
<   L->tbclist = tbc;
>   L->tbclist.p = tbc;

226c225
< ** level.
> ** level. Return restored 'level'.

228c227
< void luaF_close (lua_State *L, StkId level, int status, int yy) {
> StkId luaF_close (lua_State *L, StkId level, int status, int yy) {

231,232c230,231
<   while (L->tbclist >= level) {  /* traverse tbc's down to that level */
<     StkId tbc = L->tbclist;  /* get variable index */
>   while (L->tbclist.p >= level) {  /* traverse tbc's down to that level */
>     StkId tbc = L->tbclist.p;  /* get variable index */

236a236
>   return level;

src/lfunc.h

32c32
< #define upisopen(up)	((up)->v != &(up)->u.value)
> #define upisopen(up)	((up)->v.p != &(up)->u.value)

35c35
< #define uplevel(up)	check_exp(upisopen(up), cast(StkId, (up)->v))
> #define uplevel(up)	check_exp(upisopen(up), cast(StkId, (up)->v.p))

57c57
< LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy);
> LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);

src/lgc.c

255,256c255,256
< ** create a new collectable object (with given type and size) and link
< ** it to 'allgc' list.
> ** create a new collectable object (with given type, size, and offset)
> ** and link it to 'allgc' list.

258c258
< GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {
> GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz, size_t offset) {

260c260,261
<   GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));
>   char *p = cast_charp(luaM_newobject(L, novariant(tt), sz));
>   GCObject *o = cast(GCObject *, p + offset);

267a269,273
> 
> GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {
>   return luaC_newobjdt(L, tt, sz, 0);
> }
> 

304c310
<       markvalue(g, uv->v);  /* mark its content */
>       markvalue(g, uv->v.p);  /* mark its content */

379c385
<           markvalue(g, uv->v);  /* mark its value */
>           markvalue(g, uv->v.p);  /* mark its value */

623c629
<   StkId o = th->stack;
>   StkId o = th->stack.p;

630c636
<   for (; o < th->top; o++)  /* mark live elements in the stack */
>   for (; o < th->top.p; o++)  /* mark live elements in the stack */

635c641
<     for (; o < th->stack_last + EXTRA_STACK; o++)
>     for (; o < th->stack_last.p + EXTRA_STACK; o++)

895c901
<   luaD_callnoyield(L, L->top - 2, 0);
>   luaD_callnoyield(L, L->top.p - 2, 0);

912,913c918,919
<     setobj2s(L, L->top++, tm);  /* push finalizer... */
<     setobj2s(L, L->top++, &v);  /* ... and its argument */
>     setobj2s(L, L->top.p++, tm);  /* push finalizer... */
>     setobj2s(L, L->top.p++, &v);  /* ... and its argument */

915c921
<     status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
>     status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top.p - 2), 0);

921c927
<       L->top--;  /* pops error object */
>       L->top.p--;  /* pops error object */

1044c1050,1068
< static void setpause (global_State *g);
> 
> /*
> ** Set the "time" to wait before starting a new GC cycle; cycle will
> ** start when memory use hits the threshold of ('estimate' * pause /
> ** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
> ** because Lua cannot even start with less than PAUSEADJ bytes).
> */
> static void setpause (global_State *g) {
>   l_mem threshold, debt;
>   int pause = getgcparam(g->gcpause);
>   l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */
>   lua_assert(estimate > 0);
>   threshold = (pause < MAX_LMEM / estimate)  /* overflow? */
>             ? estimate * pause  /* no overflow */
>             : MAX_LMEM;  /* overflow; truncate to maximum */
>   debt = gettotalbytes(g) - threshold;
>   if (debt > 0) debt = 0;
>   luaE_setdebt(g, debt);
> }

1288a1313,1321
> ** 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));
> }
> 
> 
> /*

1299a1333
>   setminordebt(g);  /* set debt assuming next cycle will be minor */

1346,1354d1379
< ** 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));
< }
< 
< 
< /*

1425,1426c1450,1451
<            collection; keep doing minor collections */
<         setminordebt(g);
>            collection; keep doing minor collections. */
>         lua_assert(g->lastatomic == 0);

1453,1472d1477
< ** Set the "time" to wait before starting a new GC cycle; cycle will
< ** start when memory use hits the threshold of ('estimate' * pause /
< ** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
< ** because Lua cannot even start with less than PAUSEADJ bytes).
< */
< static void setpause (global_State *g) {
<   l_mem threshold, debt;
<   int pause = getgcparam(g->gcpause);
<   l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */
<   lua_assert(estimate > 0);
<   threshold = (pause < MAX_LMEM / estimate)  /* overflow? */
<             ? estimate * pause  /* no overflow */
<             : MAX_LMEM;  /* overflow; truncate to maximum */
<   debt = gettotalbytes(g) - threshold;
<   if (debt > 0) debt = 0;
<   luaE_setdebt(g, debt);
< }
< 
< 
< /*

1679c1684,1686
< ** performs a basic GC step if collector is running
> ** Performs a basic GC step if collector is running. (If collector is
> ** not running, set a reasonable debt to avoid it being called at
> ** every single check.)

1683,1684c1690,1692
<   lua_assert(!g->gcemergency);
<   if (gcrunning(g)) {  /* running? */
>   if (!gcrunning(g))  /* not running? */
>     luaE_setdebt(g, -2000);
>   else {

src/lgc.h

175,182d174
< #define luaC_barrier(L,p,v) (  \
< 	(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ?  \
< 	luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))
< 
< #define luaC_barrierback(L,p,v) (  \
< 	(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
< 	luaC_barrierback_(L,p) : cast_void(0))
< 

186a179,187
> #define luaC_barrier(L,p,v) (  \
> 	iscollectable(v) ? luaC_objbarrier(L,p,gcvalue(v)) : cast_void(0))
> 
> #define luaC_objbarrierback(L,p,o) (  \
> 	(isblack(p) && iswhite(o)) ? luaC_barrierback_(L,p) : cast_void(0))
> 
> #define luaC_barrierback(L,p,v) (  \
> 	iscollectable(v) ? luaC_objbarrierback(L, p, gcvalue(v)) : cast_void(0))
> 

192a194,195
> LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz,
>                                                  size_t offset);

src/llex.c

131c131
< ** is a TValue readly available. Later, the code generation can change
> ** is a TValue readily available. Later, the code generation can change

141c141
<     TValue *stv = s2v(L->top++);  /* reserve stack space for string */
>     TValue *stv = s2v(L->top.p++);  /* reserve stack space for string */

146c146
<     L->top--;  /* remove string from stack */
>     L->top.p--;  /* remove string from stack */

src/llimits.h

74,76c74,77
< ** conversion of pointer to unsigned integer:
< ** this is for hashing only; there is no problem if the integer
< ** cannot hold the whole pointer value
> ** conversion of pointer to unsigned integer: this is for hashing only;
> ** there is no problem if the integer cannot hold the whole pointer
> ** value. (In strict ISO C this may cause undefined behavior, but no
> ** actual machine seems to bother.)

78c79,91
< #define point2uint(p)	((unsigned int)((size_t)(p) & UINT_MAX))
> #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
>     __STDC_VERSION__ >= 199901L
> #include <stdint.h>
> #if defined(UINTPTR_MAX)  /* even in C99 this type is optional */
> #define L_P2I	uintptr_t
> #else  /* no 'intptr'? */
> #define L_P2I	uintmax_t  /* use the largest available integer */
> #endif
> #else  /* C89 option */
> #define L_P2I	size_t
> #endif
> 
> #define point2uint(p)	((unsigned int)((L_P2I)(p) & UINT_MAX))

src/lmathlib.c

270c270
< #if (ULONG_MAX >> 31 >> 31) >= 3
> #if ((ULONG_MAX >> 31) >> 31) >= 3

280c280
< #elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3
> #elif ((LUA_MAXUNSIGNED >> 31) >> 31) >= 3

282c282
< /* 'lua_Integer' has at least 64 bits */
> /* 'lua_Unsigned' has at least 64 bits */

503c503
<   return ((lua_Unsigned)trim32(x.h) << 31 << 1) | (lua_Unsigned)trim32(x.l);
>   return (((lua_Unsigned)trim32(x.h) << 31) << 1) | (lua_Unsigned)trim32(x.l);

508c508
<   return packI((lu_int32)(n >> 31 >> 1), (lu_int32)n);
>   return packI((lu_int32)((n >> 31) >> 1), (lu_int32)n);

src/lmem.c

25,43d24
< #if defined(EMERGENCYGCTESTS)
< /*
< ** First allocation will fail whenever not building initial state.
< ** (This fail will trigger 'tryagain' and a full GC cycle at every
< ** allocation.)
< */
< static void *firsttry (global_State *g, void *block, size_t os, size_t ns) {
<   if (completestate(g) && ns > 0)  /* frees never fail */
<     return NULL;  /* fail */
<   else  /* normal allocation */
<     return (*g->frealloc)(g->ud, block, os, ns);
< }
< #else
< #define firsttry(g,block,os,ns)    ((*g->frealloc)(g->ud, block, os, ns))
< #endif
< 
< 
< 
< 

62a44,80
> /*
> ** Macro to call the allocation function.
> */
> #define callfrealloc(g,block,os,ns)    ((*g->frealloc)(g->ud, block, os, ns))
> 
> 
> /*
> ** When an allocation fails, it will try again after an emergency
> ** collection, except when it cannot run a collection.  The GC should
> ** not be called while the state is not fully built, as the collector
> ** is not yet fully initialized. Also, it should not be called when
> ** 'gcstopem' is true, because then the interpreter is in the middle of
> ** a collection step.
> */
> #define cantryagain(g)	(completestate(g) && !g->gcstopem)
> 
> 
> 
> 
> #if defined(EMERGENCYGCTESTS)
> /*
> ** First allocation will fail except when freeing a block (frees never
> ** fail) and when it cannot try again; this fail will trigger 'tryagain'
> ** and a full GC cycle at every allocation.
> */
> static void *firsttry (global_State *g, void *block, size_t os, size_t ns) {
>   if (ns > 0 && cantryagain(g))
>     return NULL;  /* fail */
>   else  /* normal allocation */
>     return callfrealloc(g, block, os, ns);
> }
> #else
> #define firsttry(g,block,os,ns)    callfrealloc(g, block, os, ns)
> #endif
> 
> 
> 

135c153
<   (*g->frealloc)(g->ud, block, osize, 0);
>   callfrealloc(g, block, osize, 0);

143,146d160
< ** The GC should not be called while state is not fully built, as the
< ** collector is not yet fully initialized. Also, it should not be called
< ** when 'gcstopem' is true, because then the interpreter is in the
< ** middle of a collection step.

151c165
<   if (completestate(g) && !g->gcstopem) {
>   if (cantryagain(g)) {

153c167
<     return (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */
>     return callfrealloc(g, block, osize, nsize);  /* try again */

155c169
<   else return NULL;  /* cannot free any memory without a full state */
>   else return NULL;  /* cannot run an emergency collection */

src/loadlib.c

711,712c711,717
<   static const lua_CFunction searchers[] =
<     {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL};
>   static const lua_CFunction searchers[] = {
>     searcher_preload,
>     searcher_Lua,
>     searcher_C,
>     searcher_Croot,
>     NULL
>   };

src/lobject.c

65c65
<     case LUA_OPSHR: return luaV_shiftl(v1, -v2);
>     case LUA_OPSHR: return luaV_shiftr(v1, v2);

389,390c389,394
< /* size for buffer space used by 'luaO_pushvfstring' */
< #define BUFVFS		200
> /*
> ** Size for buffer space used by 'luaO_pushvfstring'. It should be
> ** (LUA_IDSIZE + MAXNUMBER2STR) + a minimal space for basic messages,
> ** so that 'luaG_addinfo' can work directly on the buffer.
> */
> #define BUFVFS		(LUA_IDSIZE + MAXNUMBER2STR + 95)

395c399
<   int pushed;  /* number of string pieces already on the stack */
>   int pushed;  /* true if there is a part of the result on the stack */

402,403c406,412
< ** Push given string to the stack, as part of the buffer, and
< ** join the partial strings in the stack into one.
> ** Push given string to the stack, as part of the result, and
> ** join it to previous partial result if there is one.
> ** It may call 'luaV_concat' while using one slot from EXTRA_STACK.
> ** This call cannot invoke metamethods, as both operands must be
> ** strings. It can, however, raise an error if the result is too
> ** long. In that case, 'luaV_concat' frees the extra slot before
> ** raising the error.

405c414
< static void pushstr (BuffFS *buff, const char *str, size_t l) {
> static void pushstr (BuffFS *buff, const char *str, size_t lstr) {

407,411c416,421
<   setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
<   L->top++;  /* may use one extra slot */
<   buff->pushed++;
<   luaV_concat(L, buff->pushed);  /* join partial results into one */
<   buff->pushed = 1;
>   setsvalue2s(L, L->top.p, luaS_newlstr(L, str, lstr));
>   L->top.p++;  /* may use one slot from EXTRA_STACK */
>   if (!buff->pushed)  /* no previous string on the stack? */
>     buff->pushed = 1;  /* now there is one */
>   else  /* join previous string with new one */
>     luaV_concat(L, 2);

457c467
< ** Add a number to the buffer.
> ** Add a numeral to the buffer.

535c545
<   return svalue(s2v(L->top - 1));
>   return svalue(s2v(L->top.p - 1));

src/lobject.h

54a55,56
>   /* not used, but may avoid warnings for uninitialized value */
>   lu_byte ub;

157a160,170
> 
> /*
> ** When reallocating the stack, change all pointers to the stack into
> ** proper offsets.
> */
> typedef union {
>   StkId p;  /* actual pointer */
>   ptrdiff_t offset;  /* used while the stack is being reallocated */
> } StkIdRel;
> 
> 

618,619c631,634
<   lu_byte tbc;  /* true if it represents a to-be-closed variable */
<   TValue *v;  /* points to stack or to its own value */
>   union {
>     TValue *p;  /* points to stack or to its own value */
>     ptrdiff_t offset;  /* used while the stack is being reallocated */
>   } v;

src/lopcodes.h

24c24
< isJ                           sJ(25)                     |   Op(7)     |
> isJ                           sJ (signed)(25)            |   Op(7)     |

src/loslib.c

33,43d32
< /* options for ANSI C 89 (only 1-char options) */
< #define L_STRFTIMEC89		"aAbBcdHIjmMpSUwWxXyYZ%"
< 
< /* options for ISO C 99 and POSIX */
< #define L_STRFTIMEC99 "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \
<     "||" "EcECExEXEyEY" "OdOeOHOIOmOMOSOuOUOVOwOWOy"  /* two-char options */
< 
< /* options for Windows */
< #define L_STRFTIMEWIN "aAbBcdHIjmMpSUwWxXyYzZ%" \
<     "||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y"  /* two-char options */
< 

45,47c34,37
< #define LUA_STRFTIMEOPTIONS	L_STRFTIMEWIN
< #elif defined(LUA_USE_C89)
< #define LUA_STRFTIMEOPTIONS	L_STRFTIMEC89
> #define LUA_STRFTIMEOPTIONS  "aAbBcdHIjmMpSUwWxXyYzZ%" \
>     "||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y"  /* two-char options */
> #elif defined(LUA_USE_C89)  /* ANSI C 89 (only 1-char options) */
> #define LUA_STRFTIMEOPTIONS  "aAbBcdHIjmMpSUwWxXyYZ%"

49c39,40
< #define LUA_STRFTIMEOPTIONS	L_STRFTIMEC99
> #define LUA_STRFTIMEOPTIONS  "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \
>     "||" "EcECExEXEyEY" "OdOeOHOIOmOMOSOuOUOVOwOWOy"  /* two-char options */

140a132,140
> #if !defined(l_system)
> #if defined(LUA_USE_IOS)
> /* Despite claiming to be ISO C, iOS does not implement 'system'. */
> #define l_system(cmd) ((cmd) == NULL ? 0 : -1)
> #else
> #define l_system(cmd)	system(cmd)  /* default definition */
> #endif
> #endif
> 

146c146
<   stat = system(cmd);
>   stat = l_system(cmd);

263,265c263
<     /* unsigned avoids overflow when lua_Integer has 32 bits */
<     if (!(res >= 0 ? (lua_Unsigned)res <= (lua_Unsigned)INT_MAX + delta
<                    : (lua_Integer)INT_MIN + delta <= res))
>     if (!(res >= 0 ? res - delta <= INT_MAX : INT_MIN + delta <= res))

src/lparser.c

470a471
>     luaK_exp2anyregup(fs, var);  /* but could be a constant */

523c524
< ** from the list of pending goto's.
> ** from the list of pending gotos.

528c529
<   Labellist *gl = &ls->dyd->gt;  /* list of goto's */
>   Labellist *gl = &ls->dyd->gt;  /* list of gotos */

582c583
< ** if any of the goto's need to close upvalues.
> ** if any of the gotos need to close upvalues.

603c604
< ** block. Solves all pending goto's to this new label and adds
> ** block. Solves all pending gotos to this new label and adds

676c677,679
<   if (bl->isloop)  /* fix pending breaks? */
>   removevars(fs, bl->nactvar);  /* remove block locals */
>   lua_assert(bl->nactvar == fs->nactvar);  /* back to level on entry */
>   if (bl->isloop)  /* has to fix pending breaks? */

678c681
<   if (!hasclose && bl->previous && bl->upval)
>   if (!hasclose && bl->previous && bl->upval)  /* still need a 'close'? */

680,682d682
<   fs->bl = bl->previous;
<   removevars(fs, bl->nactvar);
<   lua_assert(bl->nactvar == fs->nactvar);

685,686c685,687
<   if (bl->previous)  /* inner block? */
<     movegotosout(fs, bl);  /* update pending gotos to outer block */
>   fs->bl = bl->previous;  /* current block now is previous one */
>   if (bl->previous)  /* was it a nested block? */
>     movegotosout(fs, bl);  /* update pending gotos to enclosing block */

688c689
<     if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */
>     if (bl->firstgoto < ls->dyd->gt.n)  /* still pending gotos? */

1946c1947
<   setclLvalue2s(L, L->top, cl);  /* anchor it (to avoid being collected) */
>   setclLvalue2s(L, L->top.p, cl);  /* anchor it (to avoid being collected) */

1949c1950
<   sethvalue2s(L, L->top, lexstate.h);  /* anchor it */
>   sethvalue2s(L, L->top.p, lexstate.h);  /* anchor it */

1963c1964
<   L->top--;  /* remove scanner's table */
>   L->top.p--;  /* remove scanner's table */

src/lstate.c

183,184c183,184
<   L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
<   L1->tbclist = L1->stack;
>   L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
>   L1->tbclist.p = L1->stack.p;

186,188c186,188
<     setnilvalue(s2v(L1->stack + i));  /* erase new stack */
<   L1->top = L1->stack;
<   L1->stack_last = L1->stack + BASIC_STACK_SIZE;
>     setnilvalue(s2v(L1->stack.p + i));  /* erase new stack */
>   L1->top.p = L1->stack.p;
>   L1->stack_last.p = L1->stack.p + BASIC_STACK_SIZE;

193c193
<   ci->func = L1->top;
>   ci->func.p = L1->top.p;

196,198c196,198
<   setnilvalue(s2v(L1->top));  /* 'function' entry for this 'ci' */
<   L1->top++;
<   ci->top = L1->top + LUA_MINSTACK;
>   setnilvalue(s2v(L1->top.p));  /* 'function' entry for this 'ci' */
>   L1->top.p++;
>   ci->top.p = L1->top.p + LUA_MINSTACK;

204c204
<   if (L->stack == NULL)
>   if (L->stack.p == NULL)

209c209
<   luaM_freearray(L, L->stack, stacksize(L) + EXTRA_STACK);  /* free stack */
>   luaM_freearray(L, L->stack.p, stacksize(L) + EXTRA_STACK);  /* free stack */

251c251
<   L->stack = NULL;
>   L->stack.p = NULL;

287c287,288
<   global_State *g;
>   global_State *g = G(L);
>   GCObject *o;

290d290
<   g = G(L);

293,298c293,294
<   L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;
<   L1->marked = luaC_white(g);
<   L1->tt = LUA_VTHREAD;
<   /* link it on list 'allgc' */
<   L1->next = g->allgc;
<   g->allgc = obj2gco(L1);
>   o = luaC_newobjdt(L, LUA_TTHREAD, sizeof(LX), offsetof(LX, l));
>   L1 = gco2th(o);

300c296
<   setthvalue2s(L, L->top, L1);
>   setthvalue2s(L, L->top.p, L1);

319c315
<   luaF_closeupval(L1, L1->stack);  /* close all upvalues */
>   luaF_closeupval(L1, L1->stack.p);  /* close all upvalues */

329,330c325,326
<   setnilvalue(s2v(L->stack));  /* 'function' entry for basic 'ci' */
<   ci->func = L->stack;
>   setnilvalue(s2v(L->stack.p));  /* 'function' entry for basic 'ci' */
>   ci->func.p = L->stack.p;

337c333
<     luaD_seterrorobj(L, status, L->stack + 1);
>     luaD_seterrorobj(L, status, L->stack.p + 1);

339,341c335,337
<     L->top = L->stack + 1;
<   ci->top = L->top + LUA_MINSTACK;
<   luaD_reallocstack(L, cast_int(ci->top - L->stack), 0);
>     L->top.p = L->stack.p + 1;
>   ci->top.p = L->top.p + LUA_MINSTACK;
>   luaD_reallocstack(L, cast_int(ci->top.p - L->stack.p), 0);

346c342
< LUA_API int lua_resetthread (lua_State *L) {
> LUA_API int lua_resetthread (lua_State *L, lua_State *from) {

348a345
>   L->nCcalls = (from) ? getCcalls(from) : 0;

429c426
<   TValue *errobj = s2v(L->top - 1);  /* error object */
>   TValue *errobj = s2v(L->top.p - 1);  /* error object */

src/lstate.h

11a12,16
> 
> /* Some header files included here need this definition */
> typedef struct CallInfo CallInfo;
> 
> 

142c147
< #define stacksize(th)	cast_int((th)->stack_last - (th)->stack)
> #define stacksize(th)	cast_int((th)->stack_last.p - (th)->stack.p)

172,174c177,179
< typedef struct CallInfo {
<   StkId func;  /* function index in the stack */
<   StkId	top;  /* top for this function */
> struct CallInfo {
>   StkIdRel func;  /* function index in the stack */
>   StkIdRel	top;  /* top for this function */

199c204
< } CallInfo;
> };

294c299
<   struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */
>   struct Table *mt[LUA_NUMTYPES];  /* metatables for basic types */

309c314
<   StkId top;  /* first free slot in the stack */
>   StkIdRel top;  /* first free slot in the stack */

312,313c317,318
<   StkId stack_last;  /* end of stack (last element + 1) */
<   StkId stack;  /* stack base */
>   StkIdRel stack_last;  /* end of stack (last element + 1) */
>   StkIdRel stack;  /* stack base */

315c320
<   StkId tbclist;  /* list of to-be-closed variables */
>   StkIdRel tbclist;  /* list of to-be-closed variables */

src/lstrlib.c

573c573
<   init: /* using goto's to optimize tail recursion */
>   init: /* using goto to optimize tail recursion */

src/ltable.c

110c110
<   if (ui <= (unsigned int)INT_MAX)
>   if (ui <= cast_uint(INT_MAX))

259a260
> #if (UINT_MAX >> 14) > 3  /* unsigned int has more than 16 bits */

263a265
> #endif

491c493
<     for (i = 0; i < (int)size; i++) {
>     for (i = 0; i < cast_int(size); i++) {

977,978d978
< 
< int luaH_isdummy (const Table *t) { return isdummy(t); }

src/ltable.h

62d61
< LUAI_FUNC int luaH_isdummy (const Table *t);

src/ltablib.c

96c96
<     luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 1,
>     luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 2,

src/ltm.c

105c105
<   StkId func = L->top;
>   StkId func = L->top.p;

110c110
<   L->top = func + 4;
>   L->top.p = func + 4;

122c122
<   StkId func = L->top;
>   StkId func = L->top.p;

126c126
<   L->top += 3;
>   L->top.p += 3;

133c133
<   setobjs2s(L, res, --L->top);  /* move result to its place */
>   setobjs2s(L, res, --L->top.p);  /* move result to its place */

168c168
<   StkId top = L->top;
>   StkId top = L->top.p;

203,204c203,204
<   if (callbinTM(L, p1, p2, L->top, event))  /* try original event */
<     return !l_isfalse(s2v(L->top));
>   if (callbinTM(L, p1, p2, L->top.p, event))  /* try original event */
>     return !l_isfalse(s2v(L->top.p));

209c209
<       if (callbinTM(L, p2, p1, L->top, TM_LT)) {
>       if (callbinTM(L, p2, p1, L->top.p, TM_LT)) {

211c211
<         return l_isfalse(s2v(L->top));
>         return l_isfalse(s2v(L->top.p));

241c241
<   int actual = cast_int(L->top - ci->func) - 1;  /* number of arguments */
>   int actual = cast_int(L->top.p - ci->func.p) - 1;  /* number of arguments */

246c246
<   setobjs2s(L, L->top++, ci->func);
>   setobjs2s(L, L->top.p++, ci->func.p);

249,250c249,250
<     setobjs2s(L, L->top++, ci->func + i);
<     setnilvalue(s2v(ci->func + i));  /* erase original parameter (for GC) */
>     setobjs2s(L, L->top.p++, ci->func.p + i);
>     setnilvalue(s2v(ci->func.p + i));  /* erase original parameter (for GC) */

252,254c252,254
<   ci->func += actual + 1;
<   ci->top += actual + 1;
<   lua_assert(L->top <= ci->top && ci->top <= L->stack_last);
>   ci->func.p += actual + 1;
>   ci->top.p += actual + 1;
>   lua_assert(L->top.p <= ci->top.p && ci->top.p <= L->stack_last.p);

264c264
<     L->top = where + nextra;  /* next instruction will need top */
>     L->top.p = where + nextra;  /* next instruction will need top */

267c267
<     setobjs2s(L, where + i, ci->func - nextra + i);
>     setobjs2s(L, where + i, ci->func.p - nextra + i);

src/ltm.h

11a12
> #include "lstate.h"

98,99c99,100
<                                    struct CallInfo *ci, const Proto *p);
< LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci,
>                                    CallInfo *ci, const Proto *p);
> LUAI_FUNC void luaT_getvarargs (lua_State *L, CallInfo *ci,

src/lua.c

179a180,181
> ** (If there is no interpreter's name either, 'script' is -1, so
> ** table sizes are zero.)

183d184
<   if (script == argc) script = 0;  /* no script name? */

271,273c272,275
< ** needed before running any Lua code (or an error code if it finds
< ** any invalid argument). 'first' returns the first not-handled argument
< ** (either the script name or a bad argument in case of error).
> ** needed before running any Lua code or an error code if it finds any
> ** invalid argument. In case of error, 'first' is the index of the bad
> ** argument.  Otherwise, 'first' is -1 if there is no program name,
> ** 0 if there is no script name, or the index of the script name.

278c280,288
<   for (i = 1; argv[i] != NULL; i++) {
>   if (argv[0] != NULL) {  /* is there a program name? */
>     if (argv[0][0])  /* not empty? */
>       progname = argv[0];  /* save it */
>   }
>   else {  /* no program name */
>     *first = -1;
>     return 0;
>   }
>   for (i = 1; argv[i] != NULL; i++) {  /* handle arguments */

319c329
<   *first = i;  /* no script name */
>   *first = 0;  /* no script name */

611a622
>   int optlim = (script > 0) ? script : argc; /* first argv not an option */

613d623
<   if (argv[0] && argv[0][0]) progname = argv[0];

626c636,637
<   lua_gc(L, LUA_GCGEN, 0, 0);  /* GC in generational mode */
>   lua_gc(L, LUA_GCRESTART);  /* start GC... */
>   lua_gc(L, LUA_GCGEN, 0, 0);  /* ...in generational mode */

631c642
<   if (!runargs(L, argv, script))  /* execute arguments -e and -l */
>   if (!runargs(L, argv, optlim))  /* execute arguments -e and -l */

633,635c644,647
<   if (script < argc &&  /* execute main script (if there is one) */
<       handle_script(L, argv + script) != LUA_OK)
<     return 0;
>   if (script > 0) {  /* execute main script (if there is one) */
>     if (handle_script(L, argv + script) != LUA_OK)
>       return 0;  /* interrupt in case of error */
>   }

638c650
<   else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */
>   else if (script < 1 && !(args & (has_e | has_v))) { /* no active option? */

656a669
>   lua_gc(L, LUA_GCSTOP);  /* stop GC while building state */

src/lua.h

21c21
< #define LUA_VERSION_RELEASE	"4"
> #define LUA_VERSION_RELEASE	"5"

24c24
< #define LUA_VERSION_RELEASE_NUM		(LUA_VERSION_NUM * 100 + 4)
> #define LUA_VERSION_RELEASE_NUM		(LUA_VERSION_NUM * 100 + 5)

28c28
< #define LUA_COPYRIGHT	LUA_RELEASE "  Copyright (C) 1994-2022 Lua.org, PUC-Rio"
> #define LUA_COPYRIGHT	LUA_RELEASE "  Copyright (C) 1994-2023 Lua.org, PUC-Rio"

133a134,143
> /*
> ** Type used by the debug API to collect debug information
> */
> typedef struct lua_Debug lua_Debug;
> 
> 
> /*
> ** Functions to be called by the debugger in specific events
> */
> typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);

156c166
< LUA_API int        (lua_resetthread) (lua_State *L);
> LUA_API int        (lua_resetthread) (lua_State *L, lua_State *from);

445,450d454
< typedef struct lua_Debug lua_Debug;  /* activation record */
< 
< 
< /* Functions to be called by the debugger in specific events */
< typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
< 

495c499
< * Copyright (C) 1994-2022 Lua.org, PUC-Rio.
> * Copyright (C) 1994-2023 Lua.org, PUC-Rio.

src/luac.c

124c124
< #define FUNCTION "(function()end)();"
> #define FUNCTION "(function()end)();\n"

141c141
< #define toproto(L,i) getproto(s2v(L->top+(i)))
> #define toproto(L,i) getproto(s2v(L->top.p+(i)))

158,159d157
<   luaM_freearray(L,f->lineinfo,f->sizelineinfo);
<   f->sizelineinfo=0;

src/luaconf.h

72a73,78
> #if defined(LUA_USE_IOS)
> #define LUA_USE_POSIX
> #define LUA_USE_DLOPEN
> #endif
> 
> 

731c737
< ** (It must fit into max(size_t)/32.)
> ** (It must fit into max(size_t)/32 and max(int)/2.)

750c756
< @@ of a function in debug information.
> ** of a function in debug information.

757c763,764
< @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
> @@ LUAL_BUFFERSIZE is the initial buffer size used by the lauxlib
> ** buffer system.

src/lundump.c

123c123
<     setsvalue2s(L, L->top, ts);  /* anchor it ('loadVector' can GC) */
>     setsvalue2s(L, L->top.p, ts);  /* anchor it ('loadVector' can GC) */

126c126
<     L->top--;  /* pop string */
>     L->top.p--;  /* pop string */

250a251,252
>   if (n != 0)  /* does it have debug information? */
>     n = f->sizeupvalues;  /* must be this many */

324c326
<   setclLvalue2s(L, L->top, cl);
>   setclLvalue2s(L, L->top.p, cl);

src/lutf8lib.c

27a28,30
> 
> #define MSGInvalid	"invalid UTF-8 code"
> 

38c41,42
< #define iscont(p)	((*(p) & 0xC0) == 0x80)
> #define iscont(c)	(((c) & 0xC0) == 0x80)
> #define iscontp(p)	iscont(*(p))

68c72
<       if ((cc & 0xC0) != 0x80)  /* not a continuation byte? */
>       if (!iscont(cc))  /* not a continuation byte? */

143c147
<       return luaL_error(L, "invalid UTF-8 code");
>       return luaL_error(L, MSGInvalid);

193c197
<     while (posi > 0 && iscont(s + posi)) posi--;
>     while (posi > 0 && iscontp(s + posi)) posi--;

196c200
<     if (iscont(s + posi))
>     if (iscontp(s + posi))

202c206
<          } while (posi > 0 && iscont(s + posi));
>          } while (posi > 0 && iscontp(s + posi));

211c215
<          } while (iscont(s + posi));  /* (cannot pass final '\0') */
>          } while (iscontp(s + posi));  /* (cannot pass final '\0') */

229c233
<     while (iscont(s + n)) n++;  /* skip continuation bytes */
>     while (iscontp(s + n)) n++;  /* go to next character */

236,237c240,241
<     if (next == NULL)
<       return luaL_error(L, "invalid UTF-8 code");
>     if (next == NULL || iscontp(next))
>       return luaL_error(L, MSGInvalid);

256c260,261
<   luaL_checkstring(L, 1);
>   const char *s = luaL_checkstring(L, 1);
>   luaL_argcheck(L, !iscontp(s), 1, MSGInvalid);

src/lvm.c

611,612c611,612
<     luaT_callTMres(L, tm, t1, t2, L->top);  /* call TM */
<     return !l_isfalse(s2v(L->top));
>     luaT_callTMres(L, tm, t1, t2, L->top.p);  /* call TM */
>     return !l_isfalse(s2v(L->top.p));

636c636
< ** from 'L->top - total' up to 'L->top - 1'.
> ** from 'L->top.p - total' up to 'L->top.p - 1'.

642c642
<     StkId top = L->top;
>     StkId top = L->top.p;

646c646
<       luaT_tryconcatTM(L);
>       luaT_tryconcatTM(L);  /* may invalidate 'top' */

659c659,660
<         if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl))
>         if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) {
>           L->top.p = top - total;  /* pop strings to avoid wasting stack */

660a662
>         }

674,675c676,677
<     total -= n-1;  /* got 'n' strings to create 1 new */
<     L->top -= n-1;  /* popped 'n' strings and pushed one */
>     total -= n - 1;  /* got 'n' strings to create one new */
>     L->top.p -= n - 1;  /* popped 'n' strings and pushed one */

765a768
> 

769,771d771
< #define luaV_shiftr(x,y)	luaV_shiftl(x,intop(-, 0, y))
< 
< 

811c811
<   StkId base = ci->func + 1;
>   StkId base = ci->func.p + 1;

816c816
<       setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top);
>       setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top.p);

822c822
<       setobjs2s(L, base + GETARG_A(inst), --L->top);
>       setobjs2s(L, base + GETARG_A(inst), --L->top.p);

829,830c829,830
<       int res = !l_isfalse(s2v(L->top - 1));
<       L->top--;
>       int res = !l_isfalse(s2v(L->top.p - 1));
>       L->top.p--;

843c843
<       StkId top = L->top - 1;  /* top when 'luaT_tryconcatTM' was called */
>       StkId top = L->top.p - 1;  /* top when 'luaT_tryconcatTM' was called */

847c847
<       L->top = top - 1;  /* top is one after last element (at top-2) */
>       L->top.p = top - 1;  /* top is one after last element (at top-2) */

859c859
<       L->top = ra + ci->u2.nres;
>       L->top.p = ra + ci->u2.nres;

900a901
>   StkId ra = RA(i); \

928a930
>   StkId ra = RA(i); \

937a940
>   StkId ra = RA(i); \

946a950
>   StkId ra = RA(i); \

975a980
>   StkId ra = RA(i); \

988a994
>   StkId ra = RA(i); \

1003,1014c1009,1021
<         int cond;  \
<         TValue *rb = vRB(i);  \
<         if (ttisinteger(s2v(ra)) && ttisinteger(rb)) {  \
<           lua_Integer ia = ivalue(s2v(ra));  \
<           lua_Integer ib = ivalue(rb);  \
<           cond = opi(ia, ib);  \
<         }  \
<         else if (ttisnumber(s2v(ra)) && ttisnumber(rb))  \
<           cond = opn(s2v(ra), rb);  \
<         else  \
<           Protect(cond = other(L, s2v(ra), rb));  \
<         docondjump(); }
>   StkId ra = RA(i); \
>   int cond;  \
>   TValue *rb = vRB(i);  \
>   if (ttisinteger(s2v(ra)) && ttisinteger(rb)) {  \
>     lua_Integer ia = ivalue(s2v(ra));  \
>     lua_Integer ib = ivalue(rb);  \
>     cond = opi(ia, ib);  \
>   }  \
>   else if (ttisnumber(s2v(ra)) && ttisnumber(rb))  \
>     cond = opn(s2v(ra), rb);  \
>   else  \
>     Protect(cond = other(L, s2v(ra), rb));  \
>   docondjump(); }

1022,1035c1029,1043
<         int cond;  \
<         int im = GETARG_sB(i);  \
<         if (ttisinteger(s2v(ra)))  \
<           cond = opi(ivalue(s2v(ra)), im);  \
<         else if (ttisfloat(s2v(ra))) {  \
<           lua_Number fa = fltvalue(s2v(ra));  \
<           lua_Number fim = cast_num(im);  \
<           cond = opf(fa, fim);  \
<         }  \
<         else {  \
<           int isf = GETARG_C(i);  \
<           Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm));  \
<         }  \
<         docondjump(); }
>   StkId ra = RA(i); \
>   int cond;  \
>   int im = GETARG_sB(i);  \
>   if (ttisinteger(s2v(ra)))  \
>     cond = opi(ivalue(s2v(ra)), im);  \
>   else if (ttisfloat(s2v(ra))) {  \
>     lua_Number fa = fltvalue(s2v(ra));  \
>     lua_Number fim = cast_num(im);  \
>     cond = opf(fa, fim);  \
>   }  \
>   else {  \
>     int isf = GETARG_C(i);  \
>     Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm));  \
>   }  \
>   docondjump(); }

1064c1072
< #define updatebase(ci)	(base = ci->func + 1)
> #define updatebase(ci)	(base = ci->func.p + 1)

1099c1107
< #define savestate(L,ci)		(savepc(L), L->top = ci->top)
> #define savestate(L,ci)		(savepc(L), L->top.p = ci->top.p)

1119c1127
< 	{ luaC_condGC(L, (savepc(L), L->top = (c)), \
> 	{ luaC_condGC(L, (savepc(L), L->top.p = (c)), \

1131d1138
<   ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \

1151c1158
<   cl = clLvalue(s2v(ci->func));
>   cl = clLvalue(s2v(ci->func.p));

1163c1170
<   base = ci->func + 1;
>   base = ci->func.p + 1;

1167d1173
<     StkId ra;  /* instruction's A register */

1173,1174c1179,1180
<     lua_assert(base == ci->func + 1);
<     lua_assert(base <= L->top && L->top < L->stack_last);
>     lua_assert(base == ci->func.p + 1);
>     lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p);

1176c1182
<     lua_assert(isIT(i) || (cast_void(L->top = base), 1));
>     lua_assert(isIT(i) || (cast_void(L->top.p = base), 1));

1178a1185
>         StkId ra = RA(i);

1182a1190
>         StkId ra = RA(i);

1187a1196
>         StkId ra = RA(i);

1192a1202
>         StkId ra = RA(i);

1197a1208
>         StkId ra = RA(i);

1203a1215
>         StkId ra = RA(i);

1207a1220
>         StkId ra = RA(i);

1212a1226
>         StkId ra = RA(i);

1216a1231
>         StkId ra = RA(i);

1223a1239
>         StkId ra = RA(i);

1225c1241
<         setobj2s(L, ra, cl->upvals[b]->v);
>         setobj2s(L, ra, cl->upvals[b]->v.p);

1228a1245
>         StkId ra = RA(i);

1230c1247
<         setobj(L, uv->v, s2v(ra));
>         setobj(L, uv->v.p, s2v(ra));

1234a1252
>         StkId ra = RA(i);

1236c1254
<         TValue *upval = cl->upvals[GETARG_B(i)]->v;
>         TValue *upval = cl->upvals[GETARG_B(i)]->v.p;

1246a1265
>         StkId ra = RA(i);

1260a1280
>         StkId ra = RA(i);

1274a1295
>         StkId ra = RA(i);

1288c1309
<         TValue *upval = cl->upvals[GETARG_A(i)]->v;
>         TValue *upval = cl->upvals[GETARG_A(i)]->v.p;

1299a1321
>         StkId ra = RA(i);

1313a1336
>         StkId ra = RA(i);

1327a1351
>         StkId ra = RA(i);

1339a1364
>         StkId ra = RA(i);

1349c1374
<         L->top = ra + 1;  /* correct top in case of emergency GC */
>         L->top.p = ra + 1;  /* correct top in case of emergency GC */

1357a1383
>         StkId ra = RA(i);

1386a1413
>         savestate(L, ci);  /* in case of division by 0 */

1398a1426
>         savestate(L, ci);  /* in case of division by 0 */

1414a1443
>         StkId ra = RA(i);

1423a1453
>         StkId ra = RA(i);

1444a1475
>         savestate(L, ci);  /* in case of division by 0 */

1456a1488
>         savestate(L, ci);  /* in case of division by 0 */

1480a1513
>         StkId ra = RA(i);

1489a1523
>         StkId ra = RA(i);

1498a1533
>         StkId ra = RA(i);

1507a1543
>         StkId ra = RA(i);

1521a1558
>         StkId ra = RA(i);

1531a1569
>         StkId ra = RA(i);

1539a1578
>         StkId ra = RA(i);

1543a1583
>         StkId ra = RA(i);

1545c1585
<         L->top = ra + n;  /* mark the end of concat operands */
>         L->top.p = ra + n;  /* mark the end of concat operands */

1547c1587
<         checkGC(L, L->top); /* 'luaV_concat' ensures correct top */
>         checkGC(L, L->top.p); /* 'luaV_concat' ensures correct top */

1550a1591
>         StkId ra = RA(i);

1554a1596
>         StkId ra = RA(i);

1563a1606
>         StkId ra = RA(i);

1578a1622
>         StkId ra = RA(i);

1585a1630
>         StkId ra = RA(i);

1613a1659
>         StkId ra = RA(i);

1618a1665
>         StkId ra = RA(i);

1628a1676
>         StkId ra = RA(i);

1633c1681
<           L->top = ra + b;  /* top signals number of arguments */
>           L->top.p = ra + b;  /* top signals number of arguments */

1644a1693
>         StkId ra = RA(i);

1651c1700
<           L->top = ra + b;
>           L->top.p = ra + b;

1653c1702
<           b = cast_int(L->top - ra);
>           b = cast_int(L->top.p - ra);

1657,1658c1706,1707
<           lua_assert(L->tbclist < base);  /* no pending tbc variables */
<           lua_assert(base == ci->func + 1);
>           lua_assert(L->tbclist.p < base);  /* no pending tbc variables */
>           lua_assert(base == ci->func.p + 1);

1663c1712
<           ci->func -= delta;  /* restore 'func' (if vararg) */
>           ci->func.p -= delta;  /* restore 'func' (if vararg) */

1669a1719
>         StkId ra = RA(i);

1673c1723
<           n = cast_int(L->top - ra);  /* get what is available */
>           n = cast_int(L->top.p - ra);  /* get what is available */

1677,1678c1727,1728
<           if (L->top < ci->top)
<             L->top = ci->top;
>           if (L->top.p < ci->top.p)
>             L->top.p = ci->top.p;

1684,1685c1734,1735
<           ci->func -= ci->u.l.nextraargs + nparams1;
<         L->top = ra + n;  /* set call for 'luaD_poscall' */
>           ci->func.p -= ci->u.l.nextraargs + nparams1;
>         L->top.p = ra + n;  /* set call for 'luaD_poscall' */

1692c1742,1743
<           L->top = ra;
>           StkId ra = RA(i);
>           L->top.p = ra;

1700c1751
<           L->top = base - 1;
>           L->top.p = base - 1;

1702c1753
<             setnilvalue(s2v(L->top++));  /* all results are nil */
>             setnilvalue(s2v(L->top.p++));  /* all results are nil */

1708c1759,1760
<           L->top = ra + 1;
>           StkId ra = RA(i);
>           L->top.p = ra + 1;

1717c1769
<             L->top = base - 1;  /* asked for no results */
>             L->top.p = base - 1;  /* asked for no results */

1718a1771
>             StkId ra = RA(i);

1720c1773
<             L->top = base;
>             L->top.p = base;

1722c1775
<               setnilvalue(s2v(L->top++));  /* complete missing results */
>               setnilvalue(s2v(L->top.p++));  /* complete missing results */

1733a1787
>         StkId ra = RA(i);

1751a1806
>         StkId ra = RA(i);

1757a1813
>        StkId ra = RA(i);

1766c1822,1823
<        l_tforcall:
>        l_tforcall: {
>         StkId ra = RA(i);

1774c1831
<         L->top = ra + 4 + 3;
>         L->top.p = ra + 4 + 3;

1780c1837
<       }
>       }}

1782c1839,1840
<         l_tforloop:
>        l_tforloop: {
>         StkId ra = RA(i);

1788c1846
<       }
>       }}

1789a1848
>         StkId ra = RA(i);

1794c1853
<           n = cast_int(L->top - ra) - 1;  /* get up to the top */
>           n = cast_int(L->top.p - ra) - 1;  /* get up to the top */

1796c1855
<           L->top = ci->top;  /* correct top in case of emergency GC */
>           L->top.p = ci->top.p;  /* correct top in case of emergency GC */

1812a1872
>         StkId ra = RA(i);

1818a1879
>         StkId ra = RA(i);

src/lvm.h

112a113,117
> /*
> ** Shift right is the same as shift left with a negative 'y'
> */
> #define luaV_shiftr(x,y)	luaV_shiftl(x,intop(-, 0, y))
>