Lines Matching full:code

67 The Lua distribution includes a host program called <code>lua</code>,
80 (Frequently, this host is the stand-alone <code>lua</code> program.)
81 The host program can invoke functions to execute a piece of Lua code,
83 and can register C&nbsp;functions to be called by Lua code.
94 at Lua's official web site, <code>www.lua.org</code>.
163 (See macro <code>LUA_32BITS</code> in file <code>luaconf.h</code>.)
190 including embedded zeros ('<code>\0</code>').
236 undefined numerical results, such as <code>0/0</code>.)
250 providing <code>a.name</code> as syntactic sugar for <code>a["name"]</code>.
267 The expressions <code>a[i]</code> and <code>a[j]</code>
269 if and only if <code>i</code> and <code>j</code> are raw equal
273 (e.g., <code>1.0 == 1</code>).
277 For instance, if you write <code>a[2.0] = true</code>,
278 the actual key inserted into the table will be the integer <code>2</code>.
291 The library function <a href="#pdf-type"><code>type</code></a> returns a string describing the type
292 of a given value (see <a href="#pdf-type"><code>type</code></a>).
303 (that is, a name not bound to any declaration) <code>var</code>
304 is syntactically translated to <code>_ENV.var</code>.
306 an external local variable named <code>_ENV</code> (see <a href="#3.3.2">&sect;3.3.2</a>),
307 so <code>_ENV</code> itself is never a free name in a chunk.
311 Despite the existence of this external <code>_ENV</code> variable and
313 <code>_ENV</code> is a completely regular name.
316 Each reference to a free name uses the <code>_ENV</code> that is
322 Any table used as the value of <code>_ENV</code> is called an <em>environment</em>.
328 In Lua, the global variable <a href="#pdf-_G"><code>_G</code></a> is initialized with this same val…
329 (<a href="#pdf-_G"><code>_G</code></a> is never used internally,
330 so changing its value will affect only your own code.)
335 the default value for its <code>_ENV</code> variable
336 is the global environment (see <a href="#pdf-load"><code>load</code></a>).
338 free names in Lua code refer to entries in the global environment
342 You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>loadfile</c…
345 of its first upvalue; see <a href="#lua_setupvalue"><code>lua_setupvalue</code></a>.)
360 Lua code can explicitly raise an error by calling the
361 <a href="#pdf-error"><code>error</code></a> function.
368 using <a href="#pdf-pcall"><code>pcall</code></a> (or <a href="#pdf-xpcall"><code>xpcall</code></a>…
369 The function <a href="#pdf-pcall"><code>pcall</code></a> calls a given function in <em>protected mo…
371 and control returns immediately to <code>pcall</code>,
372 which returns a status code.
377 Lua code starts running by a call
378 from C&nbsp;code in the host program.
380 the <code>lua</code> application is the host program.)
403 When you use <a href="#pdf-xpcall"><code>xpcall</code></a> (or <a href="#lua_pcall"><code>lua_pcall…
422 Lua also offers a system of <em>warnings</em> (see <a href="#pdf-warn"><code>warn</code></a>).
426 although this behavior can be adapted from C (see <a href="#lua_setwarnf"><code>lua_setwarnf</code>…
442 Lua checks for a function in the field <code>__add</code> of the value's metatable.
453 In the previous example, the key is the string "<code>__add</code>"
457 which is either a function or a value with a <code>__call</code> metamethod.
462 using the <a href="#pdf-getmetatable"><code>getmetatable</code></a> function.
463 …s metamethods in metatables using a raw access (see <a href="#pdf-rawget"><code>rawget</code></a>).
468 using the <a href="#pdf-setmetatable"><code>setmetatable</code></a> function.
469 You cannot change the metatable of other types from Lua code,
493 <li><b><code>__add</code>: </b>
494 the addition (<code>+</code>) operation.
498 if that operand does not define a metamethod for <code>__add</code>,
509 <li><b><code>__sub</code>: </b>
510 the subtraction (<code>-</code>) operation.
514 <li><b><code>__mul</code>: </b>
515 the multiplication (<code>*</code>) operation.
519 <li><b><code>__div</code>: </b>
520 the division (<code>/</code>) operation.
524 <li><b><code>__mod</code>: </b>
525 the modulo (<code>%</code>) operation.
529 <li><b><code>__pow</code>: </b>
530 the exponentiation (<code>^</code>) operation.
534 <li><b><code>__unm</code>: </b>
535 the negation (unary <code>-</code>) operation.
539 <li><b><code>__idiv</code>: </b>
540 the floor division (<code>//</code>) operation.
544 <li><b><code>__band</code>: </b>
545 the bitwise AND (<code>&amp;</code>) operation.
552 <li><b><code>__bor</code>: </b>
553 the bitwise OR (<code>|</code>) operation.
557 <li><b><code>__bxor</code>: </b>
558 the bitwise exclusive OR (binary <code>~</code>) operation.
562 <li><b><code>__bnot</code>: </b>
563 the bitwise NOT (unary <code>~</code>) operation.
567 <li><b><code>__shl</code>: </b>
568 the bitwise left shift (<code>&lt;&lt;</code>) operation.
572 <li><b><code>__shr</code>: </b>
573 the bitwise right shift (<code>&gt;&gt;</code>) operation.
577 <li><b><code>__concat</code>: </b>
578 the concatenation (<code>..</code>) operation.
585 <li><b><code>__len</code>: </b>
586 the length (<code>#</code>) operation.
599 <li><b><code>__eq</code>: </b>
600 the equal (<code>==</code>) operation.
608 <li><b><code>__lt</code>: </b>
609 the less than (<code>&lt;</code>) operation.
616 <li><b><code>__le</code>: </b>
617 the less equal (<code>&lt;=</code>) operation.
621 <li><b><code>__index</code>: </b>
622 The indexing access operation <code>table[key]</code>.
623 This event happens when <code>table</code> is not a table or
624 when <code>key</code> is not present in <code>table</code>.
625 The metavalue is looked up in the metatable of <code>table</code>.
630 or any value with an <code>__index</code> metavalue.
632 it is called with <code>table</code> and <code>key</code> as arguments,
637 the final result is the result of indexing this metavalue with <code>key</code>.
639 and therefore can trigger another <code>__index</code> metavalue.
642 <li><b><code>__newindex</code>: </b>
643 The indexing assignment <code>table[key] = value</code>.
645 this event happens when <code>table</code> is not a table or
646 when <code>key</code> is not present in <code>table</code>.
647 The metavalue is looked up in the metatable of <code>table</code>.
653 or any value with an <code>__newindex</code> metavalue.
655 it is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments.
660 and therefore can trigger another <code>__newindex</code> metavalue.
664 Whenever a <code>__newindex</code> metavalue is invoked,
667 the metamethod itself can call <a href="#pdf-rawset"><code>rawset</code></a>
671 <li><b><code>__call</code>: </b>
672 The call operation <code>func(args)</code>.
674 (that is, <code>func</code> is not a function).
675 The metamethod is looked up in <code>func</code>.
677 the metamethod is called with <code>func</code> as its first argument,
678 followed by the arguments of the original call (<code>args</code>).
689 <code>__gc</code> (see <a href="#2.5.3">&sect;2.5.3</a>),
690 <code>__close</code> (see <a href="#3.3.8">&sect;3.3.8</a>),
691 <code>__mode</code> (see <a href="#2.5.4">&sect;2.5.4</a>),
692 and <code>__name</code>.
693 (The entry <code>__name</code>,
695 may be used by <a href="#pdf-tostring"><code>tostring</code></a> and in error messages.)
713 (e.g., <a href="#pdf-tostring"><code>tostring</code></a>)
720 In particular, the <code>__gc</code> metamethod works only when this order
760 Because Lua has no knowledge about C&nbsp;code,
782 <a href="#lua_gc"><code>lua_gc</code></a> in&nbsp;C
783 or <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> in Lua.
909 and the metatable has a <code>__gc</code> metamethod.
910 Note that if you set a metatable without a <code>__gc</code> field
922 it checks the object's <code>__gc</code> metamethod:
935 the execution of the regular code.
956 When you close a state (see <a href="#lua_close"><code>lua_close</code></a>),
999 <code>__mode</code> field of its metatable.
1001 "<code>k</code>", for a table with weak keys;
1002 "<code>v</code>", for a table with weak values;
1003 or "<code>kv</code>", for a table with both weak keys and values.
1072 You create a coroutine by calling <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>.
1075 The <code>create</code> function only creates a new coroutine and
1081 You execute a coroutine by calling <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a…
1082 When you first call <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
1084 a thread returned by <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
1087 Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are pas…
1099 <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>true</b>,
1101 In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>fal…
1109 A coroutine yields by calling <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
1111 the corresponding <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns immedia…
1115 In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also retu…
1116 plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
1119 with the call to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a> returning any extra
1120 arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
1124 Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
1125 the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine,
1129 go as extra arguments to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
1130 …utine.wrap"><code>coroutine.wrap</code></a> returns all the values returned by <a href="#pdf-corou…
1131 except the first one (the boolean error code).
1132 Unlike <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
1133 the function created by <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a>
1136 …on also closes the coroutine (see <a href="#pdf-coroutine.close"><code>coroutine.close</code></a>).
1141 consider the following code:
1178 …ee functions <a href="#lua_newthread"><code>lua_newthread</code></a>, <a href="#lua_resume"><code>…
1179 and <a href="#lua_yield"><code>lua_yield</code></a>.
1219 In source code,
1249 <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>
1254 one or more uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>).
1272 '<code>\a</code>' (bell),
1273 '<code>\b</code>' (backspace),
1274 '<code>\f</code>' (form feed),
1275 '<code>\n</code>' (newline),
1276 '<code>\r</code>' (carriage return),
1277 '<code>\t</code>' (horizontal tab),
1278 '<code>\v</code>' (vertical tab),
1279 '<code>\\</code>' (backslash),
1280 '<code>\"</code>' (quotation mark [double quote]),
1281 and '<code>\'</code>' (apostrophe [single quote]).
1284 The escape sequence '<code>\z</code>' skips the following span
1299 with the escape sequence <code>\x<em>XX</em></code>,
1301 or with the escape sequence <code>\<em>ddd</em></code>,
1310 the escape sequence <code>\u{<em>XXX</em>}</code>
1313 representing the character code point.
1314 This code point can be any value less than <em>2<sup>31</sup></em>.
1316 which is not restricted to valid Unicode code points.)
1325 So, an opening long bracket of level&nbsp;0 is written as <code>[[</code>,
1326 an opening long bracket of level&nbsp;1 is written as <code>[=[</code>,
1330 a closing long bracket of level&nbsp;4 is written as <code>]====]</code>.
1347 (in which '<code>a</code>' is coded as&nbsp;97,
1348 newline is coded as&nbsp;10, and '<code>1</code>' is coded as&nbsp;49),
1377 marked by a letter '<code>e</code>' or '<code>E</code>'.
1379 which start with <code>0x</code> or <code>0X</code>.
1382 marked by a letter '<code>p</code>' or '<code>P</code>' and written in decimal.
1383 (For instance, <code>0x1.fp10</code> denotes 1984,
1415 A <em>comment</em> starts with a double hyphen (<code>--</code>)
1417 If the text immediately after <code>--</code> is not an opening long bracket,
1469 The syntax <code>var.Name</code> is just syntactic sugar for
1470 <code>var["Name"]</code>:
1477 An access to a global variable <code>x</code>
1478 is equivalent to <code>_ENV.x</code>.
1480 the variable <code>_ENV</code> itself is never global (see <a href="#2.2">&sect;2.2</a>).
1582 scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">&sect;2.2</a>).
1583 The resulting function always has <code>_ENV</code> as its only external variable,
1591 precompiling the chunk's code into instructions for a virtual machine,
1592 and then Lua executes the compiled code
1598 see the program <code>luac</code> and the function <a href="#pdf-string.dump"><code>string.dump</co…
1600 …tically detects the file type and acts accordingly (see <a href="#pdf-load"><code>load</code></a>).
1634 Thus the code
1640 sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>
1641 because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)
1648 exchanges the values of <code>x</code> and <code>y</code>,
1654 cyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.
1666 An assignment to a global name <code>x = val</code>
1668 <code>_ENV.x = val</code> (see <a href="#2.2">&sect;2.2</a>).
1764 as in the idiom <code>do return end</code>,
1783 The numerical <b>for</b> loop repeats a block of code while a
1941 <code>const</code>, which declares a constant variable,
1944 and <code>close</code>, which declares a to-be-closed variable (see <a href="#3.3.8">&sect;3.3.8</a…
1972 to call its <code>__close</code> metamethod.
1982 must have a <code>__close</code> metamethod
1994 that error is handled like an error in the regular code
2011 or call <a href="#pdf-coroutine.close"><code>coroutine.close</code></a> to close the variables.
2013 through <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a>,
2050 denoted by three dots ('<code>...</code>'), can only be used when
2073 <li><b><code>+</code>: </b>addition</li>
2074 <li><b><code>-</code>: </b>subtraction</li>
2075 <li><b><code>*</code>: </b>multiplication</li>
2076 <li><b><code>/</code>: </b>float division</li>
2077 <li><b><code>//</code>: </b>floor division</li>
2078 <li><b><code>%</code>: </b>modulo</li>
2079 <li><b><code>^</code>: </b>exponentiation</li>
2080 <li><b><code>-</code>: </b>unary minus</li>
2099 Exponentiation and float division (<code>/</code>)
2102 Exponentiation uses the ISO&nbsp;C function <code>pow</code>,
2107 Floor division (<code>//</code>) is a division
2127 <li><b><code>&amp;</code>: </b>bitwise AND</li>
2128 <li><b><code>&#124;</code>: </b>bitwise OR</li>
2129 <li><b><code>~</code>: </b>bitwise exclusive OR</li>
2130 <li><b><code>&gt;&gt;</code>: </b>right shift</li>
2131 <li><b><code>&lt;&lt;</code>: </b>left shift</li>
2132 <li><b><code>~</code>: </b>unary bitwise NOT</li>
2201 in particular, <code>"1"==1</code> is false and <code>"1"&lt;1</code> raises an error
2226 use the function <a href="#pdf-string.format"><code>string.format</code></a>.
2236 <li><b><code>==</code>: </b>equality</li>
2237 <li><b><code>~=</code>: </b>inequality</li>
2238 <li><b><code>&lt;</code>: </b>less than</li>
2239 <li><b><code>&gt;</code>: </b>greater than</li>
2240 <li><b><code>&lt;=</code>: </b>less or equal</li>
2241 <li><b><code>&gt;=</code>: </b>greater or equal</li>
2247 Equality (<code>==</code>) first compares the type of its operands.
2271 by using the <code>__eq</code> metamethod (see <a href="#2.4">&sect;2.4</a>).
2277 Thus, <code>"0"==0</code> evaluates to <b>false</b>,
2278 and <code>t[0]</code> and <code>t["0"]</code> denote different
2283 The operator <code>~=</code> is exactly the negation of equality (<code>==</code>).
2293 Otherwise, Lua tries to call the <code>__lt</code> or the <code>__le</code>
2295 A comparison <code>a &gt; b</code> is translated to <code>b &lt; a</code>
2296 and <code>a &gt;= b</code> is translated to <code>b &lt;= a</code>.
2345 denoted by two dots ('<code>..</code>').
2349 Otherwise, the <code>__concat</code> metamethod is called (see <a href="#2.4">&sect;2.4</a>).
2358 The length operator is denoted by the unary prefix operator <code>#</code>.
2370 A <em>border</em> in a table <code>t</code> is any non-negative integer
2389 For instance, the table <code>{10, 20, 30, 40, 50}</code> is a sequence,
2391 The table <code>{10, 20, 30, nil, 50}</code> has two borders (3 and 5),
2394 The table <code>{nil, 20, 30, nil, nil, 60, nil}</code>
2397 The table <code>{}</code> is a sequence with border 0.
2401 When <code>t</code> is a sequence,
2402 <code>#t</code> returns its only border,
2404 When <code>t</code> is not a sequence,
2405 <code>#t</code> can return any of its borders.
2420 any value but strings through the <code>__len</code> metamethod (see <a href="#2.4">&sect;2.4</a>).
2446 The concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')
2469 Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry
2470 with key <code>exp1</code> and value <code>exp2</code>.
2471 A field of the form <code>name = exp</code> is equivalent to
2472 <code>["name"] = exp</code>.
2473 Fields of the form <code>exp</code> are equivalent to
2474 <code>[i] = exp</code>, where <code>i</code> are consecutive integers
2504 If the last field in the list has the form <code>exp</code>
2512 as a convenience for machine-generated code.
2530 the prefixexp <code>__call</code> metamethod is called:
2543 A call <code>v:name(<em>args</em>)</code>
2544 is syntactic sugar for <code>v.name(v,<em>args</em>)</code>,
2545 except that <code>v</code> is evaluated only once.
2557 A call of the form <code>f{<em>fields</em>}</code> is
2558 syntactic sugar for <code>f({<em>fields</em>})</code>;
2560 A call of the form <code>f'<em>string</em>'</code>
2561 (or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>)
2562 is syntactic sugar for <code>f('<em>string</em>')</code>;
2567 A call of the form <code>return <em>functioncall</em></code> not in the
2650 contains references to <code>f</code>.)
2676 which is indicated by three dots ('<code>...</code>')
2729 adding an implicit extra parameter <code>self</code> to the function.
2768 for instance <code>return e1, e2, e3</code> (see <a href="#3.3.4">&sect;3.3.4</a>).</li>
2771 for instance <code>{e1, e2, e3}</code> (see <a href="#3.4.9">&sect;3.4.9</a>).</li>
2774 for instance <code>foo(e1, e2, e3)</code> (see <a href="#3.4.10">&sect;3.4.10</a>).</li>
2777 for instance <code>a , b, c = e1, e2, e3</code> (see <a href="#3.3.3">&sect;3.3.3</a>).</li>
2780 for instance <code>local a , b, c = e1, e2, e3</code> (see <a href="#3.3.7">&sect;3.3.7</a>).</li>
2783 for instance <code>for k in e1, e2, e3 do ... end</code> (see <a href="#3.3.5">&sect;3.3.5</a>).</l…
2889 Notice that, in a declaration like <code>local x = x</code>,
2890 the new <code>x</code> being declared is not in scope yet,
2891 and so the second <code>x</code> refers to the outside variable.
2918 Each of these closures uses a different <code>y</code> variable,
2919 while all of them share the same <code>x</code>.
2935 are declared in the header file <a name="pdf-lua.h"><code>lua.h</code></a>.
2952 with the macro <a name="pdf-LUA_USE_APICHECK"><code>LUA_USE_APICHECK</code></a> defined.
2965 The type <a href="#lua_State"><code>lua_State</code></a> (despite its name) refers to a thread.
2972 every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,
2999 to be returned to the caller (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
3037 without a fixed number of results (see <a href="#lua_call"><code>lua_call</code></a>),
3041 you should use <a href="#lua_checkstack"><code>lua_checkstack</code></a>.
3047 at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> extra elements;
3048 that is, you can safely push up to <code>LUA_MINSTACK</code> values into it.
3049 <code>LUA_MINSTACK</code> is defined as 20,
3051 unless your code has loops pushing elements onto the stack.
3053 you can use the function <a href="#lua_checkstack"><code>lua_checkstack</code></a>
3071 (<code>1 &le; abs(index) &le; top</code>)
3074 which represent some positions that are accessible to C&nbsp;code
3106 contains a value of a virtual type <a name="pdf-LUA_TNONE"><code>LUA_TNONE</code></a>,
3116 Several functions in the API return pointers (<code>const char*</code>)
3118 (See <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>, <a href="#lua_pushlstring"><code>…
3119 <a href="#lua_pushstring"><code>lua_pushstring</code></a>, and <a href="#lua_tolstring"><code>lua_t…
3120 … <a href="#luaL_checklstring"><code>luaL_checklstring</code></a>, <a href="#luaL_checkstring"><cod…
3121 and <a href="#luaL_tolstring"><code>luaL_tolstring</code></a> in the auxiliary library.)
3140 namely <a href="#lua_getlocal"><code>lua_getlocal</code></a>, <a href="#lua_getupvalue"><code>lua_g…
3141 <a href="#lua_setlocal"><code>lua_setlocal</code></a>, and <a href="#lua_setupvalue"><code>lua_setu…
3164 (see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>);
3173 <a href="#lua_upvalueindex"><code>lua_upvalueindex</code></a>.
3175 <code>lua_upvalueindex(1)</code>, and so on.
3176 Any access to <code>lua_upvalueindex(<em>n</em>)</code>,
3196 a predefined table that can be used by any C&nbsp;code to
3199 <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>.
3205 or a light userdata with the address of a C&nbsp;object in your code,
3206 or any Lua object created by your code.
3214 by the reference mechanism (see <a href="#luaL_ref"><code>luaL_ref</code></a>)
3224 defined as constants in <code>lua.h</code>.
3228 <li><b><a name="pdf-LUA_RIDX_MAINTHREAD"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index t…
3233 <li><b><a name="pdf-LUA_RIDX_GLOBALS"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the reg…
3246 Internally, Lua uses the C <code>longjmp</code> facility to handle errors.
3248 search for <code>LUAI_THROW</code> in the source code for details.)
3253 A <em>protected environment</em> uses <code>setjmp</code>
3260 by calling <a href="#lua_error"><code>lua_error</code></a>.
3272 Lua calls a <em>panic function</em> (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>)
3273 and then calls <code>abort</code>,
3290 when C code operates on other Lua states
3293 the result of <a href="#lua_newthread"><code>lua_newthread</code></a>),
3316 <li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> no errors.</li>
3318 <li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>: </b> a runtime error.</li>
3320 <li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b>
3325 <li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>: </b> error while running the message h…
3327 <li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b> syntax error during precomp…
3329 <li><b><a name="pdf-LUA_YIELD"><code>LUA_YIELD</code></a>: </b> the thread (coroutine) yields.</li>
3331 <li><b><a name="pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a>: </b> a file-related error;
3335 These constants are defined in the header file <code>lua.h</code>.
3346 Internally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.
3347 Therefore, if a C&nbsp;function <code>foo</code> calls an API function
3350 Lua cannot return to <code>foo</code> any more,
3351 because the <code>longjmp</code> removes its frame from the C&nbsp;stack.
3358 …#lua_yieldk"><code>lua_yieldk</code></a>, <a href="#lua_callk"><code>lua_callk</code></a>, and <a …
3360 (as a parameter named <code>k</code>) to continue execution after a yield.
3370 This can happen when the callee function is <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
3371 …unction is either <a href="#lua_callk"><code>lua_callk</code></a> or <a href="#lua_pcallk"><code>l…
3394 ... /* code 1 */
3396 ... /* code 2 */
3400 the Lua code being run by <a href="#lua_pcall"><code>lua_pcall</code></a> to yield.
3405 ... /* code 2 */
3409 ... /* code 1 */
3413 In the above code,
3414 the new function <code>k</code> is a
3415 <em>continuation function</em> (with type <a href="#lua_KFunction"><code>lua_KFunction</code></a>),
3417 was doing after calling <a href="#lua_pcall"><code>lua_pcall</code></a>.
3418 Now, we must inform Lua that it must call <code>k</code> if the Lua code
3419 being executed by <a href="#lua_pcall"><code>lua_pcall</code></a> gets interrupted in some way
3421 so we rewrite the code as here,
3422 replacing <a href="#lua_pcall"><code>lua_pcall</code></a> by <a href="#lua_pcallk"><code>lua_pcallk…
3426 ... /* code 1 */
3434 <a href="#lua_pcallk"><code>lua_pcallk</code></a> (and <a href="#lua_callk"><code>lua_callk</code><…
3442 the final status of the call and the context value (<code>ctx</code>) that
3443 was passed originally to <a href="#lua_pcallk"><code>lua_pcallk</code></a>.
3447 For <a href="#lua_pcallk"><code>lua_pcallk</code></a>,
3448 the status is the same value that would be returned by <a href="#lua_pcallk"><code>lua_pcallk</code
3449 except that it is <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> when being executed after a y…
3450 (instead of <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>).
3451 For <a href="#lua_yieldk"><code>lua_yieldk</code></a> and <a href="#lua_callk"><code>lua_callk</cod…
3452 the status is always <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> when Lua calls the continu…
3456 Similarly, when using <a href="#lua_callk"><code>lua_callk</code></a>,
3458 with <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> as the status.
3459 (For <a href="#lua_yieldk"><code>lua_yieldk</code></a>, there is not much point in calling
3461 because <a href="#lua_yieldk"><code>lua_yieldk</code></a> usually does not return.)
3470 after a <a href="#lua_callk"><code>lua_callk</code></a> the function and its arguments are
3490 The first field, <code>o</code>,
3492 The second field, <code>p</code>,
3495 A field in the form <code>x|y</code> means the function can push (or pop)
3496 <code>x</code> or <code>y</code> elements,
3498 an interrogation mark '<code>?</code>' means that
3502 The third field, <code>x</code>,
3504 '<code>-</code>' means the function never raises any error;
3505 '<code>m</code>' means the function may raise only out-of-memory errors;
3506 '<code>v</code>' means the function may raise the errors explained in the text;
3507 '<code>e</code>' means the function can run arbitrary Lua code,
3513 <hr><h3><a name="lua_absindex"><code>lua_absindex</code></a></h3><p>
3518 Converts the acceptable index <code>idx</code>
3526 <hr><h3><a name="lua_Alloc"><code>lua_Alloc</code></a></h3>
3535 functionality similar to <code>realloc</code>,
3538 <code>ud</code>, an opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>;
3539 <code>ptr</code>, a pointer to the block being allocated/reallocated/freed;
3540 <code>osize</code>, the original size of the block or some code about what
3542 and <code>nsize</code>, the new size of the block.
3546 When <code>ptr</code> is not <code>NULL</code>,
3547 <code>osize</code> is the size of the block pointed by <code>ptr</code>,
3552 When <code>ptr</code> is <code>NULL</code>,
3553 <code>osize</code> encodes the kind of object that Lua is allocating.
3554 <code>osize</code> is any of
3555 …RING"><code>LUA_TSTRING</code></a>, <a href="#pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>, <a href…
3556 <a href="#pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>, or <a href="#pdf-LUA_TTHREAD"><code>LU…
3558 When <code>osize</code> is some other value,
3567 When <code>nsize</code> is zero,
3568 the allocator must behave like <code>free</code>
3569 and then return <code>NULL</code>.
3573 When <code>nsize</code> is not zero,
3574 the allocator must behave like <code>realloc</code>.
3575 In particular, the allocator returns <code>NULL</code>
3581 It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>.
3596 that <code>free(NULL)</code> has no effect and that
3597 <code>realloc(NULL,size)</code> is equivalent to <code>malloc(size)</code>.
3603 <hr><h3><a name="lua_arith"><code>lua_arith</code></a></h3><p>
3618 The value of <code>op</code> must be one of the following constants:
3622 <li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)<…
3623 <li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code
3624 <li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</c…
3625 <li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>: </b> performs float division (<code>/</c…
3626 <li><b><a name="pdf-LUA_OPIDIV"><code>LUA_OPIDIV</code></a>: </b> performs floor division (<code>//…
3627 <li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</l…
3628 <li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</c…
3629 <li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (una…
3630 <li><b><a name="pdf-LUA_OPBNOT"><code>LUA_OPBNOT</code></a>: </b> performs bitwise NOT (<code>~</co…
3631 <li><b><a name="pdf-LUA_OPBAND"><code>LUA_OPBAND</code></a>: </b> performs bitwise AND (<code>&amp;…
3632 <li><b><a name="pdf-LUA_OPBOR"><code>LUA_OPBOR</code></a>: </b> performs bitwise OR (<code>|</code>…
3633 <li><b><a name="pdf-LUA_OPBXOR"><code>LUA_OPBXOR</code></a>: </b> performs bitwise exclusive OR (<c…
3634 <li><b><a name="pdf-LUA_OPSHL"><code>LUA_OPSHL</code></a>: </b> performs left shift (<code>&lt;&lt;…
3635 <li><b><a name="pdf-LUA_OPSHR"><code>LUA_OPSHR</code></a>: </b> performs right shift (<code>&gt;&gt…
3642 <hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3><p>
3653 <hr><h3><a name="lua_call"><code>lua_call</code></a></h3><p>
3660 <code>lua_call</code> respects the <code>__call</code> metamethod.
3671 Finally you call <a href="#lua_call"><code>lua_call</code></a>;
3672 <code>nargs</code> is the number of arguments that you pushed onto the stack.
3676 The number of results is adjusted to <code>nresults</code>,
3677 unless <code>nresults</code> is <a name="pdf-LUA_MULTRET"><code>LUA_MULTRET</code></a>.
3688 (with a <code>longjmp</code>).
3693 equivalent to this Lua code:
3710 Note that the code above is <em>balanced</em>:
3718 <hr><h3><a name="lua_callk"><code>lua_callk</code></a></h3><p>
3727 This function behaves exactly like <a href="#lua_call"><code>lua_call</code></a>,
3734 <hr><h3><a name="lua_CFunction"><code>lua_CFunction</code></a></h3>
3748 <code>lua_gettop(L)</code> returns the number of arguments received by the function.
3750 and its last argument is at index <code>lua_gettop(L)</code>.
3785 <hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3><p>
3790 Ensures that the stack has space for at least <code>n</code> extra elements,
3791 that is, that you can safely push up to <code>n</code> values into it.
3805 <hr><h3><a name="lua_close"><code>lua_close</code></a></h3><p>
3827 <hr><h3><a name="lua_closeslot"><code>lua_closeslot</code></a></h3><p>
3834 (see <a href="#lua_toclose"><code>lua_toclose</code></a>) that is still active (that is, not closed…
3838 A <code>__close</code> metamethod cannot yield
3849 <hr><h3><a name="lua_closethread"><code>lua_closethread</code></a></h3><p>
3856 Returns a status code:
3857 <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> for no errors in the thread
3866 The parameter <code>from</code> represents the coroutine that is resetting <code>L</code>.
3868 this parameter can be <code>NULL</code>.
3878 <hr><h3><a name="lua_compare"><code>lua_compare</code></a></h3><p>
3884 Returns 1 if the value at index <code>index1</code> satisfies <code>op</code>
3885 when compared with the value at index <code>index2</code>,
3893 The value of <code>op</code> must be one of the following constants:
3897 <li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code
3898 <li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>: </b> compares for less than (<code>&lt;</c…
3899 <li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code>&lt…
3906 <hr><h3><a name="lua_concat"><code>lua_concat</code></a></h3><p>
3911 Concatenates the <code>n</code> values at the top of the stack,
3913 If <code>n</code>&nbsp;is&nbsp;1, the result is the single value on the stack
3915 if <code>n</code> is 0, the result is the empty string.
3923 <hr><h3><a name="lua_copy"><code>lua_copy</code></a></h3><p>
3928 Copies the element at index <code>fromidx</code>
3929 into the valid index <code>toidx</code>,
3937 <hr><h3><a name="lua_createtable"><code>lua_createtable</code></a></h3><p>
3943 Parameter <code>narr</code> is a hint for how many elements the table
3945 parameter <code>nrec</code> is a hint for how many other elements
3950 Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.
3956 <hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p>
3970 <a href="#lua_dump"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href="#lua…
3971 with the given <code>data</code>
3976 If <code>strip</code> is true,
3983 The value returned is the error code returned by the last
3995 <hr><h3><a name="lua_error"><code>lua_error</code></a></h3><p>
4004 (see <a href="#luaL_error"><code>luaL_error</code></a>).
4010 <hr><h3><a name="lua_gc"><code>lua_gc</code></a></h3><p>
4020 according to the value of the parameter <code>what</code>.
4026 <li><b><code>LUA_GCCOLLECT</code>: </b>
4030 <li><b><code>LUA_GCSTOP</code>: </b>
4034 <li><b><code>LUA_GCRESTART</code>: </b>
4038 <li><b><code>LUA_GCCOUNT</code>: </b>
4042 <li><b><code>LUA_GCCOUNTB</code>: </b>
4047 <li><b><code>LUA_GCSTEP</code> <code>(int stepsize)</code>: </b>
4049 corresponding to the allocation of <code>stepsize</code> Kbytes.
4052 <li><b><code>LUA_GCISRUNNING</code>: </b>
4057 <li><b><code>LUA_GCINC</code> (int pause, int stepmul, stepsize): </b>
4060 Returns the previous mode (<code>LUA_GCGEN</code> or <code>LUA_GCINC</code>).
4063 <li><b><code>LUA_GCGEN</code> (int minormul, int majormul): </b>
4066 Returns the previous mode (<code>LUA_GCGEN</code> or <code>LUA_GCINC</code>).
4071 see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>.
4081 <hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3><p>
4087 If <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the
4094 <hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3><p>
4099 Pushes onto the stack the value <code>t[k]</code>,
4100 where <code>t</code> is the value at the given index.
4112 <hr><h3><a name="lua_getextraspace"><code>lua_getextraspace</code></a></h3><p>
4131 (See <code>LUA_EXTRASPACE</code> in <code>luaconf.h</code>.)
4137 <hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3><p>
4142 Pushes onto the stack the value of the global <code>name</code>.
4149 <hr><h3><a name="lua_geti"><code>lua_geti</code></a></h3><p>
4154 Pushes onto the stack the value <code>t[i]</code>,
4155 where <code>t</code> is the value at the given index.
4167 <hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3><p>
4181 <hr><h3><a name="lua_gettable"><code>lua_gettable</code></a></h3><p>
4186 Pushes onto the stack the value <code>t[k]</code>,
4187 where <code>t</code> is the value at the given index
4188 and <code>k</code> is the value on the top of the stack.
4205 <hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3><p>
4219 <hr><h3><a name="lua_getiuservalue"><code>lua_getiuservalue</code></a></h3><p>
4224 Pushes onto the stack the <code>n</code>-th user value associated with the
4231 pushes <b>nil</b> and returns <a href="#pdf-LUA_TNONE"><code>LUA_TNONE</code></a>.
4237 <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p>
4251 <hr><h3><a name="lua_Integer"><code>lua_Integer</code></a></h3>
4259 By default this type is <code>long long</code>,
4261 but that can be changed to <code>long</code> or <code>int</code>
4263 (See <code>LUA_INT_TYPE</code> in <code>luaconf.h</code>.)
4268 <a name="pdf-LUA_MININTEGER"><code>LUA_MININTEGER</code></a> and <a name="pdf-LUA_MAXINTEGER"><code
4275 <hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3><p>
4287 <hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3><p>
4299 <hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3><p>
4311 <hr><h3><a name="lua_isinteger"><code>lua_isinteger</code></a></h3><p>
4324 <hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3><p>
4336 <hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3><p>
4348 <hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3><p>
4360 <hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3><p>
4373 <hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3><p>
4386 <hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3><p>
4399 <hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3><p>
4411 <hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3><p>
4423 <hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3><p>
4435 <hr><h3><a name="lua_isyieldable"><code>lua_isyieldable</code></a></h3><p>
4447 <hr><h3><a name="lua_KContext"><code>lua_KContext</code></a></h3>
4453 This type is defined as <code>intptr_t</code>
4454 when <code>intptr_t</code> is available,
4456 Otherwise, it is defined as <code>ptrdiff_t</code>.
4462 <hr><h3><a name="lua_KFunction"><code>lua_KFunction</code></a></h3>
4472 <hr><h3><a name="lua_len"><code>lua_len</code></a></h3><p>
4478 It is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.7">&sect;3.4.7</a>) and
4486 <hr><h3><a name="lua_load"><code>lua_load</code></a></h3><p>
4497 <code>lua_load</code> pushes the compiled chunk as a Lua
4503 The <code>lua_load</code> function uses a user-supplied <code>reader</code> function
4504 to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>).
4505 The <code>data</code> argument is an opaque value passed to the reader function.
4509 The <code>chunkname</code> argument gives a name to the chunk,
4514 <code>lua_load</code> automatically detects whether the chunk is text or binary
4515 and loads it accordingly (see program <code>luac</code>).
4516 The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>,
4518 a <code>NULL</code> value is equivalent to the string "<code>bt</code>".
4522 <code>lua_load</code> uses the stack internally,
4528 <code>lua_load</code> can return
4529 …UA_OK"><code>LUA_OK</code></a>, <a href="#pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>, or <a…
4537 stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.3">&sect;4.3</a>).
4539 this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).
4546 <hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3><p>
4552 Returns <code>NULL</code> if it cannot create the state
4554 The argument <code>f</code> is the allocator function;
4556 through this function (see <a href="#lua_Alloc"><code>lua_Alloc</code></a>).
4557 The second argument, <code>ud</code>, is an opaque pointer that Lua
4564 <hr><h3><a name="lua_newtable"><code>lua_newtable</code></a></h3><p>
4570 It is equivalent to <code>lua_createtable(L, 0, 0)</code>.
4576 <hr><h3><a name="lua_newthread"><code>lua_newthread</code></a></h3><p>
4582 and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new…
4596 <hr><h3><a name="lua_newuserdatauv"><code>lua_newuserdatauv</code></a></h3><p>
4602 with <code>nuvalue</code> associated Lua values, called <code>user values</code>,
4603 plus an associated block of raw memory with <code>size</code> bytes.
4605 … href="#lua_setiuservalue"><code>lua_setiuservalue</code></a> and <a href="#lua_getiuservalue"><co…
4619 <hr><h3><a name="lua_next"><code>lua_next</code></a></h3><p>
4628 then <a href="#lua_next"><code>lua_next</code></a> returns&nbsp;0 and pushes nothing.
4649 avoid calling <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,
4651 Recall that <a href="#lua_tolstring"><code>lua_tolstring</code></a> may change
4653 this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.
4659 See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
4666 <hr><h3><a name="lua_Number"><code>lua_Number</code></a></h3>
4676 (See <code>LUA_FLOAT_TYPE</code> in <code>luaconf.h</code>.)
4682 <hr><h3><a name="lua_numbertointeger"><code>lua_numbertointeger</code></a></h3>
4687 the float <code>n</code> must have an integral value.
4689 it is converted to an integer and assigned to <code>*p</code>.
4703 <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3><p>
4712 Both <code>nargs</code> and <code>nresults</code> have the same meaning as
4713 in <a href="#lua_call"><code>lua_call</code></a>.
4715 <a href="#lua_pcall"><code>lua_pcall</code></a> behaves exactly like <a href="#lua_call"><code>lua_…
4717 <a href="#lua_pcall"><code>lua_pcall</code></a> catches it,
4719 and returns an error code.
4720 Like <a href="#lua_call"><code>lua_call</code></a>,
4721 <a href="#lua_pcall"><code>lua_pcall</code></a> always removes the function
4726 If <code>msgh</code> is 0,
4729 Otherwise, <code>msgh</code> is the stack index of a
4735 returned on the stack by <a href="#lua_pcall"><code>lua_pcall</code></a>.
4741 Such information cannot be gathered after the return of <a href="#lua_pcall"><code>lua_pcall</code>…
4746 The <a href="#lua_pcall"><code>lua_pcall</code></a> function returns one of the following status co…
4747code>LUA_OK</code></a>, <a href="#pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>, <a href="#pdf-LUA_E…
4753 <hr><h3><a name="lua_pcallk"><code>lua_pcallk</code></a></h3><p>
4763 This function behaves exactly like <a href="#lua_pcall"><code>lua_pcall</code></a>,
4770 <hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3><p>
4775 Pops <code>n</code> elements from the stack.
4776 It is implemented as a macro over <a href="#lua_settop"><code>lua_settop</code></a>.
4782 <hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3><p>
4787 Pushes a boolean value with value <code>b</code> onto the stack.
4793 <hr><h3><a name="lua_pushcclosure"><code>lua_pushcclosure</code></a></h3><p>
4800 and pushes onto the stack a Lua value of type <code>function</code> that,
4802 The parameter <code>n</code> tells how many upvalues this function will have
4809 and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
4821 Then <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>
4823 with the argument <code>n</code> telling how many values will be
4825 <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.
4829 The maximum value for <code>n</code> is 255.
4833 When <code>n</code> is zero,
4842 <hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3><p>
4848 This function is equivalent to <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> with n…
4854 <hr><h3><a name="lua_pushfstring"><code>lua_pushfstring</code></a></h3><p>
4861 It is similar to the ISO&nbsp;C function <code>sprintf</code>,
4871 '<code>%%</code>' (inserts the character '<code>%</code>'),
4872 '<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),
4873 '<code>%f</code>' (inserts a <a href="#lua_Number"><code>lua_Number</code></a>),
4874 '<code>%I</code>' (inserts a <a href="#lua_Integer"><code>lua_Integer</code></a>),
4875 '<code>%p</code>' (inserts a pointer),
4876 '<code>%d</code>' (inserts an <code>int</code>),
4877 '<code>%c</code>' (inserts an <code>int</code> as a one-byte character), and
4878 '<code>%U</code>' (inserts a <code>long int</code> as a UTF-8 byte sequence).
4889 <hr><h3><a name="lua_pushglobaltable"><code>lua_pushglobaltable</code></a></h3><p>
4900 <hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3><p>
4905 Pushes an integer with value <code>n</code> onto the stack.
4911 <hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3><p>
4921 A <em>light userdata</em> represents a pointer, a <code>void*</code>.
4932 <hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p>
4937 This macro is equivalent to <a href="#lua_pushstring"><code>lua_pushstring</code></a>,
4938 but should be used only when <code>s</code> is a literal string.
4945 <hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3><p>
4950 Pushes the string pointed to by <code>s</code> with size <code>len</code>
4953 so the memory at <code>s</code> can be freed or reused immediately after
4966 <hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3><p>
4977 <hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3><p>
4982 Pushes a float with value <code>n</code> onto the stack.
4988 <hr><h3><a name="lua_pushstring"><code>lua_pushstring</code></a></h3><p>
4993 Pushes the zero-terminated string pointed to by <code>s</code>
4996 so the memory at <code>s</code> can be freed or reused immediately after
5005 If <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>.
5011 <hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3><p>
5016 Pushes the thread represented by <code>L</code> onto the stack.
5023 <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p>
5035 <hr><h3><a name="lua_pushvfstring"><code>lua_pushvfstring</code></a></h3><p>
5042 …alent to <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>, except that it receives a <c…
5049 <hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3><p>
5054 Returns 1 if the two values in indices <code>index1</code> and
5055 <code>index2</code> are primitively equal
5056 (that is, equal without calling the <code>__eq</code> metamethod).
5064 <hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3><p>
5069 Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw access
5071 The value at <code>index</code> must be a table.
5077 <hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3><p>
5082 Pushes onto the stack the value <code>t[n]</code>,
5083 where <code>t</code> is the table at the given index.
5085 that is, it does not use the <code>__index</code> metavalue.
5095 <hr><h3><a name="lua_rawgetp"><code>lua_rawgetp</code></a></h3><p>
5100 Pushes onto the stack the value <code>t[k]</code>,
5101 where <code>t</code> is the table at the given index and
5102 <code>k</code> is the pointer <code>p</code> represented as a light userdata.
5104 that is, it does not use the <code>__index</code> metavalue.
5114 <hr><h3><a name="lua_rawlen"><code>lua_rawlen</code></a></h3><p>
5121 for tables, this is the result of the length operator ('<code>#</code>')
5131 <hr><h3><a name="lua_rawset"><code>lua_rawset</code></a></h3><p>
5136 Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw assignment
5138 The value at <code>index</code> must be a table.
5144 <hr><h3><a name="lua_rawseti"><code>lua_rawseti</code></a></h3><p>
5149 Does the equivalent of <code>t[i] = v</code>,
5150 where <code>t</code> is the table at the given index
5151 and <code>v</code> is the value on the top of the stack.
5157 that is, it does not use the <code>__newindex</code> metavalue.
5163 <hr><h3><a name="lua_rawsetp"><code>lua_rawsetp</code></a></h3><p>
5168 Does the equivalent of <code>t[p] = v</code>,
5169 where <code>t</code> is the table at the given index,
5170 <code>p</code> is encoded as a light userdata,
5171 and <code>v</code> is the value on the top of the stack.
5177 that is, it does not use the <code>__newindex</code> metavalue.
5183 <hr><h3><a name="lua_Reader"><code>lua_Reader</code></a></h3>
5189 The reader function used by <a href="#lua_load"><code>lua_load</code></a>.
5190 Every time <a href="#lua_load"><code>lua_load</code></a> needs another piece of the chunk,
5192 passing along its <code>data</code> parameter.
5195 and set <code>size</code> to the block size.
5198 the reader must return <code>NULL</code> or set <code>size</code> to zero.
5205 <hr><h3><a name="lua_register"><code>lua_register</code></a></h3><p>
5210 Sets the C&nbsp;function <code>f</code> as the new value of global <code>name</code>.
5221 <hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3><p>
5235 <hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3><p>
5249 <hr><h3><a name="lua_resetthread"><code>lua_resetthread</code></a></h3><p>
5255 it is equivalent to <a href="#lua_closethread"><code>lua_closethread</code></a> with
5256 <code>from</code> being <code>NULL</code>.
5262 <hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3><p>
5268 Starts and resumes a coroutine in the given thread <code>L</code>.
5275 then you call <a href="#lua_resume"><code>lua_resume</code></a>,
5276 with <code>nargs</code> being the number of arguments.
5279 <code>*nresults</code> is updated and
5281 the <code>*nresults</code> values passed to <a href="#lua_yield"><code>lua_yield</code></a>
5283 <a href="#lua_resume"><code>lua_resume</code></a> returns
5284 <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the coroutine yields,
5285 <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if the coroutine finishes its execution
5287 or an error code in case of errors (see <a href="#4.4.1">&sect;4.4.1</a>).
5294 you remove the <code>*nresults</code> yielded values from its stack,
5295 push the values to be passed as results from <code>yield</code>,
5296 and then call <a href="#lua_resume"><code>lua_resume</code></a>.
5300 The parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.
5302 this parameter can be <code>NULL</code>.
5308 <hr><h3><a name="lua_rotate"><code>lua_rotate</code></a></h3><p>
5313 Rotates the stack elements between the valid index <code>idx</code>
5315 The elements are rotated <code>n</code> positions in the direction of the top,
5316 for a positive <code>n</code>,
5317 or <code>-n</code> positions in the direction of the bottom,
5318 for a negative <code>n</code>.
5319 The absolute value of <code>n</code> must not be greater than the size
5328 <hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3><p>
5333 Changes the allocator function of a given state to <code>f</code>
5334 with user data <code>ud</code>.
5340 <hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3><p>
5345 Does the equivalent to <code>t[k] = v</code>,
5346 where <code>t</code> is the value at the given index
5347 and <code>v</code> is the value on the top of the stack.
5359 <hr><h3><a name="lua_setglobal"><code>lua_setglobal</code></a></h3><p>
5365 sets it as the new value of global <code>name</code>.
5371 <hr><h3><a name="lua_seti"><code>lua_seti</code></a></h3><p>
5376 Does the equivalent to <code>t[n] = v</code>,
5377 where <code>t</code> is the value at the given index
5378 and <code>v</code> is the value on the top of the stack.
5390 <hr><h3><a name="lua_setiuservalue"><code>lua_setiuservalue</code></a></h3><p>
5396 the new <code>n</code>-th user value associated to the
5404 <hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3><p>
5415 (For historical reasons, this function returns an <code>int</code>,
5422 <hr><h3><a name="lua_settable"><code>lua_settable</code></a></h3><p>
5427 Does the equivalent to <code>t[k] = v</code>,
5428 where <code>t</code> is the value at the given index,
5429 <code>v</code> is the value on the top of the stack,
5430 and <code>k</code> is the value just below the top.
5442 <hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3><p>
5451 If <code>index</code> is&nbsp;0, then all stack elements are removed.
5455 This function can run arbitrary code when removing an index
5462 <hr><h3><a name="lua_setwarnf"><code>lua_setwarnf</code></a></h3><p>
5468 (see <a href="#lua_WarnFunction"><code>lua_WarnFunction</code></a>).
5469 The <code>ud</code> parameter sets the value <code>ud</code> passed to
5476 <hr><h3><a name="lua_State"><code>lua_State</code></a></h3>
5489 every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,
5496 <hr><h3><a name="lua_status"><code>lua_status</code></a></h3><p>
5501 Returns the status of the thread <code>L</code>.
5505 The status can be <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> for a normal thread,
5506 an error code if the thread finished the execution
5507 of a <a href="#lua_resume"><code>lua_resume</code></a> with an error,
5508 or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the thread is suspended.
5512 You can call functions only in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.
5513 You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>
5514 (to start a new coroutine) or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a>
5521 <hr><h3><a name="lua_stringtonumber"><code>lua_stringtonumber</code></a></h3><p>
5526 Converts the zero-terminated string <code>s</code> to a number,
5542 <hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3><p>
5550 <a href="#lua_toboolean"><code>lua_toboolean</code></a> returns true for any Lua value
5554 use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)
5560 <hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3><p>
5567 otherwise, returns <code>NULL</code>.
5573 <hr><h3><a name="lua_toclose"><code>lua_toclose</code></a></h3><p>
5587 <a href="#lua_settop"><code>lua_settop</code></a> or <a href="#lua_pop"><code>lua_pop</code></a>,
5588 or there is a call to <a href="#lua_closeslot"><code>lua_closeslot</code></a>.
5590 … in the API except <a href="#lua_settop"><code>lua_settop</code></a> or <a href="#lua_pop"><code>l…
5591 unless previously deactivated by <a href="#lua_closeslot"><code>lua_closeslot</code></a>.
5601 by the time the <code>__close</code> metamethod runs,
5610 <hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p>
5615 …alent to <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> with <code>isnum</code> equal t…
5621 <hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p>
5627 to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>.
5630 otherwise, <code>lua_tointegerx</code> returns&nbsp;0.
5634 If <code>isnum</code> is not <code>NULL</code>,
5642 <hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3><p>
5648 If <code>len</code> is not <code>NULL</code>,
5649 it sets <code>*len</code> with the string length.
5651 otherwise, the function returns <code>NULL</code>.
5653 then <code>lua_tolstring</code> also
5655 (This change confuses <a href="#lua_next"><code>lua_next</code></a>
5656 when <code>lua_tolstring</code> is applied to keys during a table traversal.)
5660 <code>lua_tolstring</code> returns a pointer
5662 This string always has a zero ('<code>\0</code>')
5670 <hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p>
5675 …ivalent to <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> with <code>isnum</code> equal t…
5681 <hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p>
5687 …he C&nbsp;type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>…
5690 otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns&nbsp;0.
5694 If <code>isnum</code> is not <code>NULL</code>,
5702 <hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p>
5708 C&nbsp;pointer (<code>void*</code>).
5710 otherwise, <code>lua_topointer</code> returns <code>NULL</code>.
5722 <hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3><p>
5727 …uivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to…
5733 <hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p>
5739 (represented as <code>lua_State*</code>).
5741 otherwise, the function returns <code>NULL</code>.
5747 <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>
5756 Otherwise, returns <code>NULL</code>.
5762 <hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p>
5768 or <code>LUA_TNONE</code> for a non-valid but acceptable index.
5769 The types returned by <a href="#lua_type"><code>lua_type</code></a> are coded by the following cons…
5770 defined in <code>lua.h</code>:
5771 <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>,
5772 <a name="pdf-LUA_TNUMBER"><code>LUA_TNUMBER</code></a>,
5773 <a name="pdf-LUA_TBOOLEAN"><code>LUA_TBOOLEAN</code></a>,
5774 <a name="pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>,
5775 <a name="pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>,
5776 <a name="pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>,
5777 <a name="pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>,
5778 <a name="pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a>,
5780 <a name="pdf-LUA_TLIGHTUSERDATA"><code>LUA_TLIGHTUSERDATA</code></a>.
5786 <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p>
5791 Returns the name of the type encoded by the value <code>tp</code>,
5792 which must be one the values returned by <a href="#lua_type"><code>lua_type</code></a>.
5798 <hr><h3><a name="lua_Unsigned"><code>lua_Unsigned</code></a></h3>
5802 The unsigned version of <a href="#lua_Integer"><code>lua_Integer</code></a>.
5808 <hr><h3><a name="lua_upvalueindex"><code>lua_upvalueindex</code></a></h3><p>
5813 Returns the pseudo-index that represents the <code>i</code>-th upvalue of
5815 <code>i</code> must be in the range <em>[1,256]</em>.
5821 <hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p>
5832 <hr><h3><a name="lua_WarnFunction"><code>lua_WarnFunction</code></a></h3>
5838 set by <a href="#lua_setwarnf"><code>lua_setwarnf</code></a>.
5846 See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
5852 <hr><h3><a name="lua_warning"><code>lua_warning</code></a></h3><p>
5858 A message in a call with <code>tocont</code> true should be
5863 See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
5869 <hr><h3><a name="lua_Writer"><code>lua_Writer</code></a></h3>
5876 The type of the writer function used by <a href="#lua_dump"><code>lua_dump</code></a>.
5877 Every time <a href="#lua_dump"><code>lua_dump</code></a> produces another piece of chunk,
5879 passing along the buffer to be written (<code>p</code>),
5880 its size (<code>sz</code>),
5881 and the <code>ud</code> parameter supplied to <a href="#lua_dump"><code>lua_dump</code></a>.
5885 The writer returns an error code:
5887 any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from
5894 <hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p>
5903 This function pops <code>n</code> values from the stack <code>from</code>,
5904 and pushes them onto the stack <code>to</code>.
5910 <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p>
5915 This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
5919 the function calling <code>lua_yield</code>.
5927 <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p>
5939 When a C&nbsp;function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
5941 and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine retur…
5942 The parameter <code>nresults</code> is the number of values from the stack
5943 that will be passed as results to <a href="#lua_resume"><code>lua_resume</code></a>.
5948 Lua calls the given continuation function <code>k</code> to continue
5952 with the <code>n</code> results removed and
5953 replaced by the arguments passed to <a href="#lua_resume"><code>lua_resume</code></a>.
5955 the continuation function receives the value <code>ctx</code>
5956 that was passed to <a href="#lua_yieldk"><code>lua_yieldk</code></a>.
5966 In that case, <code>lua_yieldk</code> should be called with no continuation
5967 (probably in the form of <a href="#lua_yield"><code>lua_yield</code></a>) and no results,
6000 <hr><h3><a name="lua_Debug"><code>lua_Debug</code></a></h3>
6025 <a href="#lua_getstack"><code>lua_getstack</code></a> fills only the private part
6027 To fill the other fields of <a href="#lua_Debug"><code>lua_Debug</code></a> with useful information,
6028 you must call <a href="#lua_getinfo"><code>lua_getinfo</code></a> with an appropriate parameter.
6031 to the parameter <code>what</code> of <a href="#lua_getinfo"><code>lua_getinfo</code></a>.)
6035 The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning:
6039 <li><b><code>source</code>: </b>
6041 If <code>source</code> starts with a '<code>@</code>',
6043 the file name follows the '<code>@</code>'.
6044 If <code>source</code> starts with a '<code>=</code>',
6048 <code>source</code> is that string.
6051 <li><b><code>srclen</code>: </b>
6052 The length of the string <code>source</code>.
6055 <li><b><code>short_src</code>: </b>
6056 a "printable" version of <code>source</code>, to be used in error messages.
6059 <li><b><code>linedefined</code>: </b>
6063 <li><b><code>lastlinedefined</code>: </b>
6067 <li><b><code>what</code>: </b>
6068 the string <code>"Lua"</code> if the function is a Lua function,
6069 <code>"C"</code> if it is a C&nbsp;function,
6070 <code>"main"</code> if it is the main part of a chunk.
6073 <li><b><code>currentline</code>: </b>
6076 <code>currentline</code> is set to -1.
6079 <li><b><code>name</code>: </b>
6085 The <code>lua_getinfo</code> function checks how the function was
6088 then <code>name</code> is set to <code>NULL</code>.
6091 <li><b><code>namewhat</code>: </b>
6092 explains the <code>name</code> field.
6093 The value of <code>namewhat</code> can be
6094 <code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
6095 <code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),
6100 <li><b><code>istailcall</code>: </b>
6105 <li><b><code>nups</code>: </b>
6109 <li><b><code>nparams</code>: </b>
6114 <li><b><code>isvararg</code>: </b>
6119 <li><b><code>ftransfer</code>: </b>
6124 through <a href="#lua_getlocal"><code>lua_getlocal</code></a> and <a href="#lua_setlocal"><code>lua…
6131 <li><b><code>ntransfer</code>: </b>
6134 this value is always equal to <code>nparams</code>.)
6142 <hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p>
6153 <hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p>
6164 <hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p>
6175 <hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3><p>
6185 the parameter <code>ar</code> must be a valid activation record that was
6186 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
6187 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
6192 and start the <code>what</code> string with the character '<code>&gt;</code>'.
6194 <code>lua_getinfo</code> pops the function from the top of the stack.)
6195 For instance, to know in which line a function <code>f</code> was defined,
6196 you can write the following code:
6206 Each character in the string <code>what</code>
6207 selects some fields of the structure <code>ar</code> to be filled or
6210 the structure <a href="#lua_Debug"><code>lua_Debug</code></a>,
6215 <li><b>'<code>f</code>': </b>
6220 <li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;
6223 <li><b>'<code>n</code>': </b> fills in the fields <code>name</code> and <code>namewhat</code>;
6226 <li><b>'<code>r</code>': </b> fills in the fields <code>ftransfer</code> and <code>ntransfer</code>;
6229 <li><b>'<code>S</code>': </b>
6230 fills in the fields <code>source</code>, <code>short_src</code>,
6231 <code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
6234 <li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;
6237 <li><b>'<code>u</code>': </b> fills in the fields
6238 <code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;
6241 <li><b>'<code>L</code>': </b>
6243 the lines on the function with some associated code,
6245 (Lines with no code include empty lines and comments.)
6246 If this option is given together with option '<code>f</code>',
6254 This function returns 0 to signal an invalid option in <code>what</code>;
6261 <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p>
6272 the parameter <code>ar</code> must be a valid activation record that was
6273 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
6274 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
6275 The index <code>n</code> selects which local variable to inspect;
6276 see <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for details about variable indices
6281 <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack
6286 In the second case, <code>ar</code> must be <code>NULL</code> and the function
6294 Returns <code>NULL</code> (and pushes nothing)
6302 <hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p>
6311 This function fills parts of a <a href="#lua_Debug"><code>lua_Debug</code></a> structure with
6318 <a href="#lua_getstack"><code>lua_getstack</code></a> returns 0;
6325 <hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p>
6330 Gets information about the <code>n</code>-th upvalue
6331 of the closure at index <code>funcindex</code>.
6334 Returns <code>NULL</code> (and pushes nothing)
6335 when the index <code>n</code> is greater than the number of upvalues.
6339 See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about up…
6345 <hr><h3><a name="lua_Hook"><code>lua_Hook</code></a></h3>
6353 Whenever a hook is called, its <code>ar</code> argument has its field
6354 <code>event</code> set to the specific event that triggered the hook.
6356 <a name="pdf-LUA_HOOKCALL"><code>LUA_HOOKCALL</code></a>, <a name="pdf-LUA_HOOKRET"><code>LUA_HOOKR…
6357 <a name="pdf-LUA_HOOKTAILCALL"><code>LUA_HOOKTAILCALL</code></a>, <a name="pdf-LUA_HOOKLINE"><code>…
6358 and <a name="pdf-LUA_HOOKCOUNT"><code>LUA_HOOKCOUNT</code></a>.
6359 Moreover, for line events, the field <code>currentline</code> is also set.
6360 To get the value of any other field in <code>ar</code>,
6361 the hook must call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.
6365 For call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,
6366 the normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;
6378 that is, they cannot call <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
6379 …a href="#lua_pcallk"><code>lua_pcallk</code></a>, or <a href="#lua_callk"><code>lua_callk</code></…
6386 calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero
6393 <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p>
6402 Argument <code>f</code> is the hook function.
6403 <code>mask</code> specifies on which events the hook will be called:
6405 <a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>,
6406 <a name="pdf-LUA_MASKRET"><code>LUA_MASKRET</code></a>,
6407 <a name="pdf-LUA_MASKLINE"><code>LUA_MASKLINE</code></a>,
6408 and <a name="pdf-LUA_MASKCOUNT"><code>LUA_MASKCOUNT</code></a>.
6409 The <code>count</code> argument is only meaningful when the mask
6410 includes <code>LUA_MASKCOUNT</code>.
6424 start the execution of a new line of code,
6425 or when it jumps back in the code (even to the same line).
6430 <code>count</code> instructions.
6437 Hooks are disabled by setting <code>mask</code> to zero.
6443 <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p>
6455 Returns <code>NULL</code> (and pops nothing)
6461 Parameters <code>ar</code> and <code>n</code> are as in the function <a href="#lua_getlocal"><code>…
6467 <hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p>
6479 Returns <code>NULL</code> (and pops nothing)
6480 when the index <code>n</code> is greater than the number of upvalues.
6484 Parameters <code>funcindex</code> and <code>n</code> are as in
6485 the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>.
6491 <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p>
6496 Returns a unique identifier for the upvalue numbered <code>n</code>
6497 from the closure at index <code>funcindex</code>.
6509 Parameters <code>funcindex</code> and <code>n</code> are as in
6510 the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>,
6511 but <code>n</code> cannot be greater than the number of upvalues.
6517 <hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3><p>
6523 Make the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>
6524 refer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.
6548 are defined in header file <code>lauxlib.h</code> and
6549 have a prefix <code>luaL_</code>.
6557 more consistency to your code.
6572 (e.g., "<code>bad argument #1</code>"),
6577 Functions called <code>luaL_check*</code>
6592 <hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3><p>
6597 Adds the byte <code>c</code> to the buffer <code>B</code>
6598 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6604 <hr><h3><a name="luaL_addgsub"><code>luaL_addgsub</code></a></h3><p>
6610 Adds a copy of the string <code>s</code> to the buffer <code>B</code> (see <a href="#luaL_Buffer"><
6611 replacing any occurrence of the string <code>p</code>
6612 with the string <code>r</code>.
6618 <hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3><p>
6623 Adds the string pointed to by <code>s</code> with length <code>l</code> to
6624 the buffer <code>B</code>
6625 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6632 <hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3><p>
6637 Adds to the buffer <code>B</code>
6638 a string of length <code>n</code> previously copied to the
6639 buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>).
6645 <hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3><p>
6650 Adds the zero-terminated string pointed to by <code>s</code>
6651 to the buffer <code>B</code>
6652 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6658 <hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3><p>
6664 to the buffer <code>B</code>
6665 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6678 <hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3><p>
6686 Checks whether <code>cond</code> is true.
6687 …ses an error with a standard message (see <a href="#luaL_argerror"><code>luaL_argerror</code></a>).
6693 <hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3><p>
6698 Raises an error reporting a problem with argument <code>arg</code>
6701 that includes <code>extramsg</code> as a comment:
6712 <hr><h3><a name="luaL_argexpected"><code>luaL_argexpected</code></a></h3><p>
6720 Checks whether <code>cond</code> is true.
6721 If it is not, raises an error about the type of the argument <code>arg</code>
6722 with a standard message (see <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>).
6728 <hr><h3><a name="luaL_Buffer"><code>luaL_Buffer</code></a></h3>
6736 A string buffer allows C&nbsp;code to build Lua strings piecemeal.
6741 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code>…
6743 <li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>
6747 the <code>luaL_add*</code> functions.
6751 Finish by calling <code>luaL_pushresult(&amp;b)</code>.
6763 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code>…
6766 size <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>
6771 Finish by calling <code>luaL_pushresultsize(&amp;b, sz)</code>,
6772 where <code>sz</code> is the total size of the resulting string
6790 (The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.)
6791 After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a>,
6799 <hr><h3><a name="luaL_buffaddr"><code>luaL_buffaddr</code></a></h3><p>
6804 Returns the address of the current content of buffer <code>B</code>
6805 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6812 <hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p>
6817 Initializes a buffer <code>B</code>
6818 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6826 <hr><h3><a name="luaL_bufflen"><code>luaL_bufflen</code></a></h3><p>
6831 Returns the length of the current content of buffer <code>B</code>
6832 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6838 <hr><h3><a name="luaL_buffinitsize"><code>luaL_buffinitsize</code></a></h3><p>
6844 <a href="#luaL_buffinit"><code>luaL_buffinit</code></a>, <a href="#luaL_prepbuffsize"><code>luaL_pr…
6850 <hr><h3><a name="luaL_buffsub"><code>luaL_buffsub</code></a></h3><p>
6855 Removes <code>n</code> bytes from the buffer <code>B</code>
6856 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6863 <hr><h3><a name="luaL_callmeta"><code>luaL_callmeta</code></a></h3><p>
6872 If the object at index <code>obj</code> has a metatable and this
6873 metatable has a field <code>e</code>,
6884 <hr><h3><a name="luaL_checkany"><code>luaL_checkany</code></a></h3><p>
6890 of any type (including <b>nil</b>) at position <code>arg</code>.
6896 <hr><h3><a name="luaL_checkinteger"><code>luaL_checkinteger</code></a></h3><p>
6901 Checks whether the function argument <code>arg</code> is an integer
6909 <hr><h3><a name="luaL_checklstring"><code>luaL_checklstring</code></a></h3><p>
6914 Checks whether the function argument <code>arg</code> is a string
6916 if <code>l</code> is not <code>NULL</code> fills its referent
6921 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
6928 <hr><h3><a name="luaL_checknumber"><code>luaL_checknumber</code></a></h3><p>
6933 Checks whether the function argument <code>arg</code> is a number
6934 and returns this number converted to a <code>lua_Number</code>.
6940 <hr><h3><a name="luaL_checkoption"><code>luaL_checkoption</code></a></h3><p>
6948 Checks whether the function argument <code>arg</code> is a string and
6949 searches for this string in the array <code>lst</code>
6957 If <code>def</code> is not <code>NULL</code>,
6958 the function uses <code>def</code> as a default value when
6959 there is no argument <code>arg</code> or when this argument is <b>nil</b>.
6971 <hr><h3><a name="luaL_checkstack"><code>luaL_checkstack</code></a></h3><p>
6976 Grows the stack size to <code>top + sz</code> elements,
6978 <code>msg</code> is an additional text to go into the error message
6979 (or <code>NULL</code> for no additional text).
6985 <hr><h3><a name="luaL_checkstring"><code>luaL_checkstring</code></a></h3><p>
6990 Checks whether the function argument <code>arg</code> is a string
6995 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
7002 <hr><h3><a name="luaL_checktype"><code>luaL_checktype</code></a></h3><p>
7007 Checks whether the function argument <code>arg</code> has type <code>t</code>.
7008 See <a href="#lua_type"><code>lua_type</code></a> for the encoding of types for <code>t</code>.
7014 <hr><h3><a name="luaL_checkudata"><code>luaL_checkudata</code></a></h3><p>
7019 Checks whether the function argument <code>arg</code> is a userdata
7020 of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>…
7021 …he userdata's memory-block address (see <a href="#lua_touserdata"><code>lua_touserdata</code></a>).
7027 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
7032 Checks whether the code making the call and the Lua library being called
7039 <hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3><p>
7050 It returns&nbsp;0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) if there are no errors,
7057 <hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p>
7068 It returns&nbsp;0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) if there are no errors,
7075 <hr><h3><a name="luaL_error"><code>luaL_error</code></a></h3><p>
7081 The error message format is given by <code>fmt</code>
7083 following the same rules of <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>.
7092 as <code>return luaL_error(<em>args</em>)</code>.
7098 <hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p>
7105 (<a href="#pdf-os.execute"><code>os.execute</code></a> and <a href="#pdf-io.close"><code>io.close</
7111 <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p>
7118 …pdf-io.open"><code>io.open</code></a>, <a href="#pdf-os.rename"><code>os.rename</code></a>, <a hre…
7124 <hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3><p>
7129 Pushes onto the stack the field <code>e</code> from the metatable
7130 of the object at index <code>obj</code> and returns the type of the pushed value.
7133 pushes nothing and returns <code>LUA_TNIL</code>.
7139 <hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p>
7144 Pushes onto the stack the metatable associated with the name <code>tname</code>
7145 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>),
7153 <hr><h3><a name="luaL_getsubtable"><code>luaL_getsubtable</code></a></h3><p>
7158 Ensures that the value <code>t[fname]</code>,
7159 where <code>t</code> is the value at index <code>idx</code>,
7169 <hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3><p>
7177 Creates a copy of string <code>s</code>,
7178 replacing any occurrence of the string <code>p</code>
7179 with the string <code>r</code>.
7186 <hr><h3><a name="luaL_len"><code>luaL_len</code></a></h3><p>
7193 it is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.7">&sect;3.4.7</a>).
7201 <hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p>
7209 …ent to <a href="#luaL_loadbufferx"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal …
7215 <hr><h3><a name="luaL_loadbufferx"><code>luaL_loadbufferx</code></a></h3><p>
7225 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the
7226 buffer pointed to by <code>buff</code> with size <code>sz</code>.
7230 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
7231 <code>name</code> is the chunk name,
7233 The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.
7239 <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p>
7244 …valent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal t…
7250 <hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p>
7257 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file
7258 named <code>filename</code>.
7259 If <code>filename</code> is <code>NULL</code>,
7261 The first line in the file is ignored if it starts with a <code>#</code>.
7265 The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.
7269 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>
7270 or <a href="#pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a> for file-related errors.
7274 As <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
7281 <hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p>
7287 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in
7288 the zero-terminated string <code>s</code>.
7292 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
7296 Also as <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
7303 <hr><h3><a name="luaL_newlib"><code>luaL_newlib</code></a></h3><p>
7309 the functions in the list <code>l</code>.
7318 The array <code>l</code> must be the actual array,
7325 <hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p>
7331 to store all entries in the array <code>l</code>
7333 It is intended to be used in conjunction with <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></…
7334 (see <a href="#luaL_newlib"><code>luaL_newlib</code></a>).
7339 The array <code>l</code> must be the actual array,
7346 <hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3><p>
7351 If the registry already has the key <code>tname</code>,
7355 adds to this new table the pair <code>__name = tname</code>,
7356 adds to the registry the pair <code>[tname] = new table</code>,
7363 with <code>tname</code> in the registry.
7369 <hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p>
7375 It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
7383 or <code>NULL</code> if there is a memory allocation error.
7389 <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p>
7400 <hr><h3><a name="luaL_opt"><code>luaL_opt</code></a></h3><p>
7410 In words, if the argument <code>arg</code> is nil or absent,
7411 the macro results in the default <code>dflt</code>.
7412 Otherwise, it results in the result of calling <code>func</code>
7413 with the state <code>L</code> and the argument index <code>arg</code> as
7415 Note that it evaluates the expression <code>dflt</code> only if needed.
7421 <hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3><p>
7428 If the function argument <code>arg</code> is an integer
7432 returns <code>d</code>.
7439 <hr><h3><a name="luaL_optlstring"><code>luaL_optlstring</code></a></h3><p>
7447 If the function argument <code>arg</code> is a string,
7450 returns <code>d</code>.
7455 If <code>l</code> is not <code>NULL</code>,
7457 If the result is <code>NULL</code>
7458 (only possible when returning <code>d</code> and <code>d == NULL</code>),
7463 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
7470 <hr><h3><a name="luaL_optnumber"><code>luaL_optnumber</code></a></h3><p>
7475 If the function argument <code>arg</code> is a number,
7476 returns this number as a <code>lua_Number</code>.
7478 returns <code>d</code>.
7485 <hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3><p>
7492 If the function argument <code>arg</code> is a string,
7495 returns <code>d</code>.
7502 <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p>
7507 Equivalent to <a href="#luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a>
7508 with the predefined size <a name="pdf-LUAL_BUFFERSIZE"><code>LUAL_BUFFERSIZE</code></a>.
7514 <hr><h3><a name="luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a></h3><p>
7519 Returns an address to a space of size <code>sz</code>
7520 where you can copy a string to be added to buffer <code>B</code>
7521 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
7523 <a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add
7530 <hr><h3><a name="luaL_pushfail"><code>luaL_pushfail</code></a></h3><p>
7541 <hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3><p>
7546 Finishes the use of buffer <code>B</code> leaving the final string on
7553 <hr><h3><a name="luaL_pushresultsize"><code>luaL_pushresultsize</code></a></h3><p>
7558 …sequence <a href="#luaL_addsize"><code>luaL_addsize</code></a>, <a href="#luaL_pushresult"><code>l…
7564 <hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3><p>
7570 in the table at index <code>t</code>,
7576 As long as you do not manually add integer keys into the table <code>t</code>,
7577 <a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.
7578 You can retrieve an object referred by the reference <code>r</code>
7579 by calling <code>lua_rawgeti(L, t, r)</code>.
7580 The function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference.
7585 <a href="#luaL_ref"><code>luaL_ref</code></a> returns the constant <a name="pdf-LUA_REFNIL"><code>L…
7586 The constant <a name="pdf-LUA_NOREF"><code>LUA_NOREF</code></a> is guaranteed to be different
7587 from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
7593 <hr><h3><a name="luaL_Reg"><code>luaL_Reg</code></a></h3>
7601 <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a>.
7602 <code>name</code> is the function name and <code>func</code> is a pointer to
7604 Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with a sentinel entry
7605 in which both <code>name</code> and <code>func</code> are <code>NULL</code>.
7611 <hr><h3><a name="luaL_requiref"><code>luaL_requiref</code></a></h3><p>
7617 If <code>package.loaded[modname]</code> is not true,
7618 calls the function <code>openf</code> with the string <code>modname</code> as an argument
7619 and sets the call result to <code>package.loaded[modname]</code>,
7620 as if that function has been called through <a href="#pdf-require"><code>require</code></a>.
7624 If <code>glb</code> is true,
7625 also stores the module into the global <code>modname</code>.
7635 <hr><h3><a name="luaL_setfuncs"><code>luaL_setfuncs</code></a></h3><p>
7640 Registers all functions in the array <code>l</code>
7641 (see <a href="#luaL_Reg"><code>luaL_Reg</code></a>) into the table on the top of the stack
7646 When <code>nup</code> is not zero,
7647 all functions are created with <code>nup</code> upvalues,
7648 initialized with copies of the <code>nup</code> values
7655 A function with a <code>NULL</code> value represents a placeholder,
7662 <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p>
7668 as the metatable associated with name <code>tname</code>
7669 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
7675 <hr><h3><a name="luaL_Stream"><code>luaL_Stream</code></a></h3>
7688 with a metatable called <code>LUA_FILEHANDLE</code>
7689 (where <code>LUA_FILEHANDLE</code> is a macro with the actual metatable's name).
7691 (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
7695 This userdata must start with the structure <code>luaL_Stream</code>;
7697 The field <code>f</code> points to the corresponding C stream
7698 (or it can be <code>NULL</code> to indicate an incompletely created handle).
7699 The field <code>closef</code> points to a Lua function
7706 it changes the field value to <code>NULL</code>
7713 <hr><h3><a name="luaL_testudata"><code>luaL_testudata</code></a></h3><p>
7718 This function works like <a href="#luaL_checkudata"><code>luaL_checkudata</code></a>,
7720 it returns <code>NULL</code> instead of raising an error.
7726 <hr><h3><a name="luaL_tolstring"><code>luaL_tolstring</code></a></h3><p>
7735 If <code>len</code> is not <code>NULL</code>,
7736 the function also sets <code>*len</code> with the string length.
7740 If the value has a metatable with a <code>__tostring</code> field,
7741 then <code>luaL_tolstring</code> calls the corresponding metamethod
7749 <hr><h3><a name="luaL_traceback"><code>luaL_traceback</code></a></h3><p>
7755 Creates and pushes a traceback of the stack <code>L1</code>.
7756 If <code>msg</code> is not <code>NULL</code>, it is appended
7758 The <code>level</code> parameter tells at which level
7765 <hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p>
7770 Raises a type error for the argument <code>arg</code>
7773 <code>tname</code> is a "name" for the expected type.
7780 <hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p>
7791 <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p>
7796 Releases the reference <code>ref</code> from the table at index <code>t</code>
7797 (see <a href="#luaL_ref"><code>luaL_ref</code></a>).
7800 The reference <code>ref</code> is also freed to be used again.
7804 If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a href="#pdf-LUA_REF…
7805 <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
7811 <hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3><p>
7817 of the control at level <code>lvl</code> in the call stack.
7845 (e.g., <a href="#pdf-type"><code>type</code></a> and <a href="#pdf-getmetatable"><code>getmetatable…
7849 deserve an implementation in C (e.g., <a href="#pdf-table.sort"><code>table.sort</code></a>).
7858 For instance, a function documented as <code>foo(arg)</code>
7868 with <code>(not status)</code>, instead of <code>(status == nil)</code>.)
7904 the C&nbsp;host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> fun…
7908 <a href="#luaL_requiref"><code>luaL_requiref</code></a> to call
7909 <a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),
7910 <a name="pdf-luaopen_package"><code>luaopen_package</code></a> (for the package library),
7911 <a name="pdf-luaopen_coroutine"><code>luaopen_coroutine</code></a> (for the coroutine library),
7912 <a name="pdf-luaopen_string"><code>luaopen_string</code></a> (for the string library),
7913 <a name="pdf-luaopen_utf8"><code>luaopen_utf8</code></a> (for the UTF-8 library),
7914 <a name="pdf-luaopen_table"><code>luaopen_table</code></a> (for the table library),
7915 <a name="pdf-luaopen_math"><code>luaopen_math</code></a> (for the mathematical library),
7916 <a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O library),
7917 <a name="pdf-luaopen_os"><code>luaopen_os</code></a> (for the operating system library),
7918 and <a name="pdf-luaopen_debug"><code>luaopen_debug</code></a> (for the debug library).
7919 These functions are declared in <a name="pdf-lualib.h"><code>lualib.h</code></a>.
7935 <hr><h3><a name="pdf-assert"><code>assert (v [, message])</code></a></h3>
7940 the value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);
7943 <code>message</code> is the error object;
7944 when absent, it defaults to "<code>assertion failed!</code>"
7950 <hr><h3><a name="pdf-collectgarbage"><code>collectgarbage ([opt [, arg]])</code></a></h3>
7955 It performs different functions according to its first argument, <code>opt</code>:
7959 <li><b>"<code>collect</code>": </b>
7964 <li><b>"<code>stop</code>": </b>
7970 <li><b>"<code>restart</code>": </b>
7974 <li><b>"<code>count</code>": </b>
7981 <li><b>"<code>step</code>": </b>
7983 The step "size" is controlled by <code>arg</code>.
7992 <li><b>"<code>isrunning</code>": </b>
7997 <li><b>"<code>incremental</code>": </b>
8006 <li><b>"<code>generational</code>": </b>
8026 <hr><h3><a name="pdf-dofile"><code>dofile ([filename])</code></a></h3>
8029 <code>dofile</code> executes the content of the standard input (<code>stdin</code>).
8031 In case of errors, <code>dofile</code> propagates the error
8033 (That is, <code>dofile</code> does not run in protected mode.)
8039 <hr><h3><a name="pdf-error"><code>error (message [, level])</code></a></h3>
8040 Raises an error (see <a href="#2.3">&sect;2.3</a>) with <code>message</code> as the error object.
8045 Usually, <code>error</code> adds some information about the error position
8047 The <code>level</code> argument specifies how to get the error position.
8049 <code>error</code> function was called.
8051 that called <code>error</code> was called; and so on.
8059 <hr><h3><a name="pdf-_G"><code>_G</code></a></h3>
8070 <hr><h3><a name="pdf-getmetatable"><code>getmetatable (object)</code></a></h3>
8074 If <code>object</code> does not have a metatable, returns <b>nil</b>.
8076 if the object's metatable has a <code>__metatable</code> field,
8084 <hr><h3><a name="pdf-ipairs"><code>ipairs (t)</code></a></h3>
8088 Returns three values (an iterator function, the table <code>t</code>, and 0)
8095 (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
8102 <hr><h3><a name="pdf-load"><code>load (chunk [, chunkname [, mode [, env]]])</code></a></h3>
8110 If <code>chunk</code> is a string, the chunk is this string.
8111 If <code>chunk</code> is a function,
8112 <code>load</code> calls it repeatedly to get the chunk pieces.
8113 Each call to <code>chunk</code> must return a string that concatenates
8120 <code>load</code> returns the compiled chunk as a function;
8127 the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).
8129 …binary chunk created from a function (see <a href="#pdf-string.dump"><code>string.dump</code></a>),
8132 the <code>_ENV</code> variable.
8133 (A non-main function may not even have an <code>_ENV</code> upvalue.)
8138 its first upvalue is set to the value of <code>env</code>,
8147 <code>chunkname</code> is used as the name of the chunk for error messages
8150 it defaults to <code>chunk</code>, if <code>chunk</code> is a string,
8151 or to "<code>=(load)</code>" otherwise.
8155 The string <code>mode</code> controls whether the chunk can be text or binary
8157 It may be the string "<code>b</code>" (only binary chunks),
8158 "<code>t</code>" (only text chunks),
8159 or "<code>bt</code>" (both binary and text).
8160 The default is "<code>bt</code>".
8165 <code>load</code> signals an appropriate error.
8167 Lua does not check the consistency of the code inside binary chunks;
8174 <hr><h3><a name="pdf-loadfile"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>
8178 Similar to <a href="#pdf-load"><code>load</code></a>,
8179 but gets the chunk from file <code>filename</code>
8187 <hr><h3><a name="pdf-next"><code>next (table [, index])</code></a></h3>
8194 A call to <code>next</code> returns the next index of the table
8197 <code>next</code> returns an initial index
8201 <code>next</code> returns <b>nil</b>.
8204 you can use <code>next(t)</code> to check whether a table is empty.
8224 <hr><h3><a name="pdf-pairs"><code>pairs (t)</code></a></h3>
8228 If <code>t</code> has a metamethod <code>__pairs</code>,
8229 calls it with <code>t</code> as argument and returns the first three
8235 returns three values: the <a href="#pdf-next"><code>next</code></a> function, the table <code>t</co…
8241 will iterate over all key&ndash;value pairs of table <code>t</code>.
8245 See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
8252 <hr><h3><a name="pdf-pcall"><code>pcall (f [, arg1, &middot;&middot;&middot;])</code></a></h3>
8256 Calls the function <code>f</code> with
8258 This means that any error inside&nbsp;<code>f</code> is not propagated;
8259 instead, <code>pcall</code> catches the error
8260 and returns a status code.
8261 Its first result is the status code (a boolean),
8263 In such case, <code>pcall</code> also returns all results from the call,
8265 In case of any error, <code>pcall</code> returns <b>false</b> plus the error object.
8266 Note that errors caught by <code>pcall</code> do not call a message handler.
8272 <hr><h3><a name="pdf-print"><code>print (&middot;&middot;&middot;)</code></a></h3>
8274 and prints their values to <code>stdout</code>,
8276 following the same rules of <a href="#pdf-tostring"><code>tostring</code></a>.
8280 The function <code>print</code> is not intended for formatted output,
8284 use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>i…
8290 <hr><h3><a name="pdf-rawequal"><code>rawequal (v1, v2)</code></a></h3>
8291 Checks whether <code>v1</code> is equal to <code>v2</code>,
8292 without invoking the <code>__eq</code> metamethod.
8299 <hr><h3><a name="pdf-rawget"><code>rawget (table, index)</code></a></h3>
8300 Gets the real value of <code>table[index]</code>,
8301 without using the <code>__index</code> metavalue.
8302 <code>table</code> must be a table;
8303 <code>index</code> may be any value.
8309 <hr><h3><a name="pdf-rawlen"><code>rawlen (v)</code></a></h3>
8310 Returns the length of the object <code>v</code>,
8312 without invoking the <code>__len</code> metamethod.
8319 <hr><h3><a name="pdf-rawset"><code>rawset (table, index, value)</code></a></h3>
8320 Sets the real value of <code>table[index]</code> to <code>value</code>,
8321 without using the <code>__newindex</code> metavalue.
8322 <code>table</code> must be a table,
8323 <code>index</code> any value different from <b>nil</b> and NaN,
8324 and <code>value</code> any Lua value.
8328 This function returns <code>table</code>.
8334 <hr><h3><a name="pdf-select"><code>select (index, &middot;&middot;&middot;)</code></a></h3>
8338 If <code>index</code> is a number,
8339 returns all arguments after argument number <code>index</code>;
8341 Otherwise, <code>index</code> must be the string <code>"#"</code>,
8342 and <code>select</code> returns the total number of extra arguments it received.
8348 <hr><h3><a name="pdf-setmetatable"><code>setmetatable (table, metatable)</code></a></h3>
8353 If <code>metatable</code> is <b>nil</b>,
8355 If the original metatable has a <code>__metatable</code> field,
8360 This function returns <code>table</code>.
8364 To change the metatable of other types from Lua code,
8371 <hr><h3><a name="pdf-tonumber"><code>tonumber (e [, base])</code></a></h3>
8375 When called with no <code>base</code>,
8376 <code>tonumber</code> tries to convert its argument to a number.
8379 then <code>tonumber</code> returns this number;
8390 When called with <code>base</code>,
8391 then <code>e</code> must be a string to be interpreted as
8394 In bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)
8395 represents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,
8396 with '<code>Z</code>' representing 35.
8397 If the string <code>e</code> is not a valid numeral in the given base,
8404 <hr><h3><a name="pdf-tostring"><code>tostring (v)</code></a></h3>
8413 If the metatable of <code>v</code> has a <code>__tostring</code> field,
8414 then <code>tostring</code> calls the corresponding value
8415 with <code>v</code> as argument,
8417 Otherwise, if the metatable of <code>v</code> has a <code>__name</code> field
8419 <code>tostring</code> may use that string in its final result.
8424 use <a href="#pdf-string.format"><code>string.format</code></a>.
8430 <hr><h3><a name="pdf-type"><code>type (v)</code></a></h3>
8436 "<code>nil</code>" (a string, not the value <b>nil</b>),
8437 "<code>number</code>",
8438 "<code>string</code>",
8439 "<code>boolean</code>",
8440 "<code>table</code>",
8441 "<code>function</code>",
8442 "<code>thread</code>",
8443 and "<code>userdata</code>".
8449 <hr><h3><a name="pdf-_VERSION"><code>_VERSION</code></a></h3>
8455 The current value of this variable is "<code>Lua 5.4</code>".
8461 <hr><h3><a name="pdf-warn"><code>warn (msg1, &middot;&middot;&middot;)</code></a></h3>
8471 a one-piece message starting with '<code>@</code>'
8475 recognizes the control messages "<code>@off</code>",
8477 and "<code>@on</code>", to (re)start the emission;
8484 <hr><h3><a name="pdf-xpcall"><code>xpcall (f, msgh [, arg1, &middot;&middot;&middot;])</code></a></…
8488 This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
8489 except that it sets a new message handler <code>msgh</code>.
8501 which come inside the table <a name="pdf-coroutine"><code>coroutine</code></a>.
8506 <hr><h3><a name="pdf-coroutine.close"><code>coroutine.close (co)</code></a></h3>
8510 Closes coroutine <code>co</code>,
8525 <hr><h3><a name="pdf-coroutine.create"><code>coroutine.create (f)</code></a></h3>
8529 Creates a new coroutine, with body <code>f</code>.
8530 <code>f</code> must be a function.
8532 an object with type <code>"thread"</code>.
8538 <hr><h3><a name="pdf-coroutine.isyieldable"><code>coroutine.isyieldable ([co])</code></a></h3>
8542 Returns <b>true</b> when the coroutine <code>co</code> can yield.
8543 The default for <code>co</code> is the running coroutine.
8554 <hr><h3><a name="pdf-coroutine.resume"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;…
8558 Starts or continues the execution of coroutine <code>co</code>.
8561 The values <code>val1</code>, ... are passed
8564 <code>resume</code> restarts it;
8565 the values <code>val1</code>, ... are passed
8571 <code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>
8575 <code>resume</code> returns <b>false</b> plus the error message.
8581 <hr><h3><a name="pdf-coroutine.running"><code>coroutine.running ()</code></a></h3>
8592 <hr><h3><a name="pdf-coroutine.status"><code>coroutine.status (co)</code></a></h3>
8596 Returns the status of the coroutine <code>co</code>, as a string:
8597 <code>"running"</code>,
8599 (that is, it is the one that called <code>status</code>);
8600 <code>"suspended"</code>, if the coroutine is suspended in a call to <code>yield</code>,
8602 <code>"normal"</code> if the coroutine is active but not running
8604 and <code>"dead"</code> if the coroutine has finished its body function,
8611 <hr><h3><a name="pdf-coroutine.wrap"><code>coroutine.wrap (f)</code></a></h3>
8615 Creates a new coroutine, with body <code>f</code>;
8616 <code>f</code> must be a function.
8619 extra arguments to <code>resume</code>.
8620 The function returns the same values returned by <code>resume</code>,
8629 <hr><h3><a name="pdf-coroutine.yield"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></…
8634 Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>.
8648 <a href="#pdf-require"><code>require</code></a>.
8649 Everything else is exported in the table <a name="pdf-package"><code>package</code></a>.
8653 <hr><h3><a name="pdf-require"><code>require (modname)</code></a></h3>
8658 The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></…
8659 to determine whether <code>modname</code> is already loaded.
8660 If it is, then <code>require</code> returns the value stored
8661 at <code>package.loaded[modname]</code>.
8669 <code>require</code> is guided by the table <a href="#pdf-package.searchers"><code>package.searcher…
8673 we can change how <code>require</code> looks for a module.
8675 for <a href="#pdf-package.searchers"><code>package.searchers</code></a>.
8679 First <code>require</code> queries <code>package.preload[modname]</code>.
8682 Otherwise <code>require</code> searches for a Lua loader using the
8683 path stored in <a href="#pdf-package.path"><code>package.path</code></a>.
8685 path stored in <a href="#pdf-package.cpath"><code>package.cpath</code></a>.
8687 …m>all-in-one</em> loader (see <a href="#pdf-package.searchers"><code>package.searchers</code></a>).
8692 <code>require</code> calls the loader with two arguments:
8693 <code>modname</code> and an extra value,
8702 <code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.
8704 has not assigned any value to <code>package.loaded[modname]</code>,
8705 then <code>require</code> assigns <b>true</b> to this entry.
8706 In any case, <code>require</code> returns the
8707 final value of <code>package.loaded[modname]</code>.
8708 Besides that value, <code>require</code> also returns as a second result
8710 which indicates how <code>require</code> found the module.
8716 then <code>require</code> raises an error.
8722 <hr><h3><a name="pdf-package.config"><code>package.config</code></a></h3>
8732 Default is '<code>\</code>' for Windows and '<code>/</code>' for all other systems.</li>
8735 Default is '<code>;</code>'.</li>
8739 Default is '<code>?</code>'.</li>
8743 Default is '<code>!</code>'.</li>
8746 when building the <code>luaopen_</code> function name.
8747 Default is '<code>-</code>'.</li>
8754 <hr><h3><a name="pdf-package.cpath"><code>package.cpath</code></a></h3>
8758 A string with the path used by <a href="#pdf-require"><code>require</code></a>
8763 Lua initializes the C&nbsp;path <a href="#pdf-package.cpath"><code>package.cpath</code></a> in the …
8764 it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>,
8765 using the environment variable <a name="pdf-LUA_CPATH_5_4"><code>LUA_CPATH_5_4</code></a>,
8766 or the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a>,
8767 or a default path defined in <code>luaconf.h</code>.
8773 <hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3>
8777 A table used by <a href="#pdf-require"><code>require</code></a> to control which
8779 When you require a module <code>modname</code> and
8780 <code>package.loaded[modname]</code> is not false,
8781 <a href="#pdf-require"><code>require</code></a> simply returns the value stored there.
8787 table used by <a href="#pdf-require"><code>require</code></a>.
8789 indexed by the key <a name="pdf-LUA_LOADED_TABLE"><code>LUA_LOADED_TABLE</code></a>, a string.
8795 <hr><h3><a name="pdf-package.loadlib"><code>package.loadlib (libname, funcname)</code></a></h3>
8799 Dynamically links the host program with the C&nbsp;library <code>libname</code>.
8803 If <code>funcname</code> is "<code>*</code>",
8808 it looks for a function <code>funcname</code> inside the library
8810 So, <code>funcname</code> must follow the <a href="#lua_CFunction"><code>lua_CFunction</code></a> p…
8811 (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
8817 Unlike <a href="#pdf-require"><code>require</code></a>,
8820 <code>libname</code> must be the complete file name of the C&nbsp;library,
8822 <code>funcname</code> must be the exact name exported by the C&nbsp;library
8830 plus other Unix systems that support the <code>dlfcn</code> standard).
8839 (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
8848 <hr><h3><a name="pdf-package.path"><code>package.path</code></a></h3>
8852 A string with the path used by <a href="#pdf-require"><code>require</code></a>
8858 the value of the environment variable <a name="pdf-LUA_PATH_5_4"><code>LUA_PATH_5_4</code></a> or
8859 the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or
8860 with a default path defined in <code>luaconf.h</code>,
8862 A "<code>;;</code>" in the value of the environment variable
8869 <hr><h3><a name="pdf-package.preload"><code>package.preload</code></a></h3>
8874 (see <a href="#pdf-require"><code>require</code></a>).
8880 table used by <a href="#pdf-require"><code>require</code></a>.
8882 indexed by the key <a name="pdf-LUA_PRELOAD_TABLE"><code>LUA_PRELOAD_TABLE</code></a>, a string.
8888 <hr><h3><a name="pdf-package.searchers"><code>package.searchers</code></a></h3>
8892 A table used by <a href="#pdf-require"><code>require</code></a> to control how to find modules.
8898 <a href="#pdf-require"><code>require</code></a> calls each of these searchers in ascending order,
8899 with the module name (the argument given to <a href="#pdf-require"><code>require</code></a>) as its
8905 returned as a second result by <a href="#pdf-require"><code>require</code></a>.
8917 <a href="#pdf-package.preload"><code>package.preload</code></a> table.
8922 using the path stored at <a href="#pdf-package.path"><code>package.path</code></a>.
8923 …one as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8928 using the path given by the variable <a href="#pdf-package.cpath"><code>package.cpath</code></a>.
8930 …one as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8937 the searcher for module <code>foo</code>
8938 will try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,
8939 and <code>/usr/local/foo/init.so</code>, in that order.
8945 The name of this C&nbsp;function is the string "<code>luaopen_</code>"
8950 For instance, if the module name is <code>a.b.c-v2.1</code>,
8951 the function name will be <code>luaopen_a_b_c</code>.
8958 For instance, when requiring <code>a.b.c</code>,
8959 it will search for a C&nbsp;library for <code>a</code>.
8962 in our example, that would be <code>luaopen_a_b_c</code>.
8971 as returned by <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8972 The first searcher always returns the string "<code>:preload:</code>".
8984 <hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep [, rep]])</cod…
8988 Searches for the given <code>name</code> in the given <code>path</code>.
8996 in the template with a copy of <code>name</code>
8997 wherein all occurrences of <code>sep</code>
8999 were replaced by <code>rep</code>
9010 the search for the name <code>foo.a</code>
9012 <code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and
9013 <code>/usr/local/foo/a/init.lua</code>, in that order.
9044 <a name="pdf-string"><code>string</code></a>.
9046 where the <code>__index</code> field points to the <code>string</code> table.
9048 For instance, <code>string.byte(s,i)</code>
9049 can be written as <code>s:byte(i)</code>.
9057 <hr><h3><a name="pdf-string.byte"><code>string.byte (s [, i [, j]])</code></a></h3>
9058 Returns the internal numeric codes of the characters <code>s[i]</code>,
9059 <code>s[i+1]</code>, ..., <code>s[j]</code>.
9060 The default value for <code>i</code> is&nbsp;1;
9061 the default value for <code>j</code> is&nbsp;<code>i</code>.
9063 following the same rules of function <a href="#pdf-string.sub"><code>string.sub</code></a>.
9073 <hr><h3><a name="pdf-string.char"><code>string.char (&middot;&middot;&middot;)</code></a></h3>
9076 in which each character has the internal numeric code equal
9087 <hr><h3><a name="pdf-string.dump"><code>string.dump (function [, strip])</code></a></h3>
9094 so that a later <a href="#pdf-load"><code>load</code></a> on this string returns
9096 If <code>strip</code> is a true value,
9106 (See the <a href="#pdf-load"><code>load</code></a> function for details about
9116 <hr><h3><a name="pdf-string.find"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>
9121 <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) in the string <code>s</code>.
9122 If it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>
9125 A third, optional numeric argument <code>init</code> specifies
9128 A <b>true</b> as a fourth, optional argument <code>plain</code>
9131 with no characters in <code>pattern</code> being considered magic.
9144 <hr><h3><a name="pdf-string.format"><code>string.format (formatstring, &middot;&middot;&middot;)</c…
9151 The format string follows the same rules as the ISO&nbsp;C function <code>sprintf</code>.
9153 <code>F</code>, <code>n</code>, <code>*</code>, <code>h</code>, <code>L</code>, and <code>l</code> …
9154 and that there is an extra specifier, <code>q</code>.
9160 The specifier <code>q</code> formats booleans, nil, numbers, and strings
9161 in a way that the result is a valid constant in Lua source code.
9163 (<code>true</code>, <code>false</code>, <code>nil</code>).
9185 <code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,
9186 <code>G</code>, and <code>g</code> all expect a number as argument.
9187 The specifiers <code>c</code>, <code>d</code>,
9188 <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>
9191 the specifiers <code>A</code> and <code>a</code> (hexadecimal floats)
9196 The specifier <code>s</code> expects a string;
9198 it is converted to one following the same rules of <a href="#pdf-tostring"><code>tostring</code></a…
9204 The specifier <code>p</code> formats the pointer
9205 returned by <a href="#lua_topointer"><code>lua_topointer</code></a>.
9210 the pointer <code>NULL</code>.
9216 <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern [, init])</code></a></h3>
9219 returns the next captures from <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>)
9220 over the string <code>s</code>.
9221 If <code>pattern</code> specifies no captures,
9223 A third, optional numeric argument <code>init</code> specifies
9230 will iterate over all the words from string <code>s</code>,
9239 The next example collects all pairs <code>key=value</code> from the
9251 For this function, a caret '<code>^</code>' at the start of a pattern does not
9258 <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>
9259 Returns a copy of <code>s</code>
9260 in which all (or the first <code>n</code>, if given)
9261 occurrences of the <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) have been
9262 replaced by a replacement string specified by <code>repl</code>,
9264 <code>gsub</code> also returns, as its second value,
9266 The name <code>gsub</code> comes from <em>Global SUBstitution</em>.
9270 If <code>repl</code> is a string, then its value is used for replacement.
9271 The character&nbsp;<code>%</code> works as an escape character:
9272 any sequence in <code>repl</code> of the form <code>%<em>d</em></code>,
9275 the sequence <code>%0</code> stands for the whole match;
9276 the sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.
9280 If <code>repl</code> is a table, then the table is queried for every match,
9285 If <code>repl</code> is a function, then this function is called every time a
9334 <hr><h3><a name="pdf-string.len"><code>string.len (s)</code></a></h3>
9339 The empty string <code>""</code> has length 0.
9341 so <code>"a\000bc\000"</code> has length 5.
9347 <hr><h3><a name="pdf-string.lower"><code>string.lower (s)</code></a></h3>
9360 <hr><h3><a name="pdf-string.match"><code>string.match (s, pattern [, init])</code></a></h3>
9365 the <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) in the string <code>s</code>.
9366 If it finds one, then <code>match</code> returns
9369 If <code>pattern</code> specifies no captures,
9371 A third, optional numeric argument <code>init</code> specifies
9379 <hr><h3><a name="pdf-string.pack"><code>string.pack (fmt, v1, v2, &middot;&middot;&middot;)</code><…
9383 Returns a binary string containing the values <code>v1</code>, <code>v2</code>, etc.
9385 according to the format string <code>fmt</code> (see <a href="#6.4.2">&sect;6.4.2</a>).
9391 <hr><h3><a name="pdf-string.packsize"><code>string.packsize (fmt)</code></a></h3>
9395 Returns the length of a string resulting from <a href="#pdf-string.pack"><code>string.pack</code></…
9398 '<code>s</code>' or '<code>z</code>' (see <a href="#6.4.2">&sect;6.4.2</a>).
9404 <hr><h3><a name="pdf-string.rep"><code>string.rep (s, n [, sep])</code></a></h3>
9408 Returns a string that is the concatenation of <code>n</code> copies of
9409 the string <code>s</code> separated by the string <code>sep</code>.
9410 The default value for <code>sep</code> is the empty string
9412 Returns the empty string if <code>n</code> is not positive.
9423 <hr><h3><a name="pdf-string.reverse"><code>string.reverse (s)</code></a></h3>
9427 Returns a string that is the string <code>s</code> reversed.
9433 <hr><h3><a name="pdf-string.sub"><code>string.sub (s, i [, j])</code></a></h3>
9437 Returns the substring of <code>s</code> that
9438 starts at <code>i</code> and continues until <code>j</code>;
9439 <code>i</code> and <code>j</code> can be negative.
9440 If <code>j</code> is absent, then it is assumed to be equal to -1
9443 the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>
9444 with length <code>j</code>,
9445 and <code>string.sub(s, -i)</code> (for a positive <code>i</code>)
9446 returns a suffix of <code>s</code>
9447 with length <code>i</code>.
9452 <code>i</code> is less than 1,
9454 If <code>j</code> is greater than the string length,
9457 <code>i</code> is greater than <code>j</code>,
9464 <hr><h3><a name="pdf-string.unpack"><code>string.unpack (fmt, s [, pos])</code></a></h3>
9468 Returns the values packed in string <code>s</code> (see <a href="#pdf-string.pack"><code>string.pac…
9469 according to the format string <code>fmt</code> (see <a href="#6.4.2">&sect;6.4.2</a>).
9470 An optional <code>pos</code> marks where
9471 to start reading in <code>s</code> (default is 1).
9473 this function also returns the index of the first unread byte in <code>s</code>.
9479 <hr><h3><a name="pdf-string.upper"><code>string.upper (s)</code></a></h3>
9501 <a href="#pdf-string.find"><code>string.find</code></a>,
9502 <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>,
9503 <a href="#pdf-string.gsub"><code>string.gsub</code></a>,
9504 and <a href="#pdf-string.match"><code>string.match</code></a>.
9520 <code>^$()%.[]*+-?</code>)
9524 <li><b><code>.</code>: </b> (a dot) represents all characters.</li>
9526 <li><b><code>%a</code>: </b> represents all letters.</li>
9528 <li><b><code>%c</code>: </b> represents all control characters.</li>
9530 <li><b><code>%d</code>: </b> represents all digits.</li>
9532 <li><b><code>%g</code>: </b> represents all printable characters except space.</li>
9534 <li><b><code>%l</code>: </b> represents all lowercase letters.</li>
9536 <li><b><code>%p</code>: </b> represents all punctuation characters.</li>
9538 <li><b><code>%s</code>: </b> represents all space characters.</li>
9540 <li><b><code>%u</code>: </b> represents all uppercase letters.</li>
9542 <li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>
9544 <li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>
9546 <li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)
9551 can be preceded by a '<code>%</code>' to represent itself in a pattern.
9554 <li><b><code>[<em>set</em>]</code>: </b>
9559 in ascending order, with a '<code>-</code>'.
9560 All classes <code>%</code><em>x</em> described above can also be used as
9563 For example, <code>[%w_]</code> (or <code>[_%w]</code>)
9565 <code>[0-7]</code> represents the octal digits,
9566 and <code>[0-7%l%-]</code> represents the octal digits plus
9567 the lowercase letters plus the '<code>-</code>' character.
9580 Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>
9584 <li><b><code>[^<em>set</em>]</code>: </b>
9590 For all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),
9592 For instance, <code>%S</code> represents all non-space characters.
9598 In particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.
9615 a single character class followed by '<code>*</code>',
9621 a single character class followed by '<code>+</code>',
9627 a single character class followed by '<code>-</code>',
9629 Unlike '<code>*</code>',
9634 a single character class followed by '<code>?</code>',
9640 <code>%<em>n</em></code>, for <em>n</em> between 1 and 9;
9646 <code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;
9652 For instance, the item <code>%b()</code> matches expressions with
9657 <code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>;
9663 they were the character '<code>\0</code>'.
9673 A caret '<code>^</code>' at the beginning of a pattern anchors the match at the
9675 A '<code>$</code>' at the end of a pattern anchors the match at the
9678 '<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.
9690 For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>,
9691 the part of the string matching <code>"a*(.)%w(%s*)"</code> is
9693 the character matching "<code>.</code>" is captured with number&nbsp;2,
9694 and the part matching "<code>%s*</code>" has number&nbsp;3.
9698 As a special case, the capture <code>()</code> captures
9700 For instance, if we apply the pattern <code>"()aa()"</code> on the
9701 string <code>"flaaap"</code>, there will be two captures: 3&nbsp;and&nbsp;5.
9708 …a href="#pdf-string.gsub"><code>string.gsub</code></a> and the iterator <a href="#pdf-string.gmatc…
9716 consider the results of the following code:
9725 string after '<code>b</code>' and another one after '<code>c</code>'.
9726 Lua does not match an empty string after '<code>a</code>',
9738 The first argument to <a href="#pdf-string.pack"><code>string.pack</code></a>,
9739 …a href="#pdf-string.packsize"><code>string.packsize</code></a>, and <a href="#pdf-string.unpack"><
9749 <li><b><code>&lt;</code>: </b>sets little endian</li>
9750 <li><b><code>&gt;</code>: </b>sets big endian</li>
9751 <li><b><code>=</code>: </b>sets native endian</li>
9752 <li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code>
9754 <li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li>
9755 <li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li>
9756 <li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li>
9757 <li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li>
9758 <li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li>
9759 <li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li>
9760 <li><b><code>j</code>: </b>a <code>lua_Integer</code></li>
9761 <li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li>
9762 <li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li>
9763 <li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes
9765 <li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes
9767 <li><b><code>f</code>: </b>a <code>float</code> (native size)</li>
9768 <li><b><code>d</code>: </b>a <code>double</code> (native size)</li>
9769 <li><b><code>n</code>: </b>a <code>lua_Number</code></li>
9770 <li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li>
9771 <li><b><code>z</code>: </b>a zero-terminated string</li>
9772 <li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length
9773 coded as an unsigned integer with <code>n</code> bytes
9774 (default is a <code>size_t</code>)</li>
9775 <li><b><code>x</code>: </b>one byte of padding</li>
9776 <li><b><code>X<em>op</em></code>: </b>an empty item that aligns
9777 according to option <code>op</code>
9779 <li><b>'<code> </code>': </b>(space) ignored</li>
9781 (A "<code>[<em>n</em>]</code>" means an optional integral numeral.)
9783 (options "<code>xX &lt;=&gt;!</code>"),
9784 each option corresponds to an argument in <a href="#pdf-string.pack"><code>string.pack</code></a>
9785 or a result in <a href="#pdf-string.unpack"><code>string.unpack</code></a>.
9789 For options "<code>!<em>n</em></code>", "<code>s<em>n</em></code>", "<code>i<em>n</em></code>", and…
9790 <code>n</code> can be any integer between 1 and 16.
9792 <a href="#pdf-string.pack"><code>string.pack</code></a> checks whether the given value fits in the …
9793 <a href="#pdf-string.unpack"><code>string.unpack</code></a> checks whether the read value fits in a…
9799 Any format string starts as if prefixed by "<code>!1=</code>",
9819 Options "<code>c</code>" and "<code>z</code>" are not aligned;
9820 option "<code>s</code>" follows the alignment of its starting integer.
9824 All padding is filled with zeros by <a href="#pdf-string.pack"><code>string.pack</code></a>
9825 and ignored by <a href="#pdf-string.unpack"><code>string.unpack</code></a>.
9837 It provides all its functions inside the table <a name="pdf-utf8"><code>utf8</code></a>.
9855 accept all values up to <code>0x7FFFFFFF</code>,
9864 that result in valid Unicode code points,
9865 rejecting values greater than <code>10FFFF</code> and surrogates.
9866 A boolean argument <code>lax</code>, when available,
9868 so that all values up to <code>0x7FFFFFFF</code> are accepted.
9873 <hr><h3><a name="pdf-utf8.char"><code>utf8.char (&middot;&middot;&middot;)</code></a></h3>
9885 <hr><h3><a name="pdf-utf8.charpattern"><code>utf8.charpattern</code></a></h3>
9889 The pattern (a string, not a function) "<code>[\0-\x7F\xC2-\xFD][\x80-\xBF]*</code>"
9898 <hr><h3><a name="pdf-utf8.codes"><code>utf8.codes (s [, lax])</code></a></h3>
9907 will iterate over all UTF-8 characters in string <code>s</code>,
9908 with <code>p</code> being the position (in bytes) and <code>c</code> the code point
9916 <hr><h3><a name="pdf-utf8.codepoint"><code>utf8.codepoint (s [, i [, j [, lax]]])</code></a></h3>
9920 Returns the code points (as integers) from all characters in <code>s</code>
9921 that start between byte position <code>i</code> and <code>j</code> (both included).
9922 The default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>.
9929 <hr><h3><a name="pdf-utf8.len"><code>utf8.len (s [, i [, j [, lax]]])</code></a></h3>
9933 Returns the number of UTF-8 characters in string <code>s</code>
9934 that start between positions <code>i</code> and <code>j</code> (both inclusive).
9935 The default for <code>i</code> is 1 and for <code>j</code> is -1.
9943 <hr><h3><a name="pdf-utf8.offset"><code>utf8.offset (s, n [, i])</code></a></h3>
9948 <code>n</code>-th character of <code>s</code>
9949 (counting from position <code>i</code>) starts.
9950 A negative <code>n</code> gets characters before position <code>i</code>.
9951 The default for <code>i</code> is 1 when <code>n</code> is non-negative
9952 and <code>#s + 1</code> otherwise,
9953 so that <code>utf8.offset(s, -n)</code> gets the offset of the
9954 <code>n</code>-th character from the end of the string.
9962 when <code>n</code> is 0 the function returns the start of the encoding
9963 of the character that contains the <code>i</code>-th byte of <code>s</code>.
9967 This function assumes that <code>s</code> is a valid UTF-8 string.
9979 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>.
9990 <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>
9995 returns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.
9996 The default value for <code>sep</code> is the empty string,
9997 the default for <code>i</code> is 1,
9998 and the default for <code>j</code> is <code>#list</code>.
9999 If <code>i</code> is greater than <code>j</code>, returns the empty string.
10005 <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3>
10009 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>,
10011 <code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.
10012 The default value for <code>pos</code> is <code>#list+1</code>,
10013 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
10014 of the list <code>t</code>.
10020 <hr><h3><a name="pdf-table.move"><code>table.move (a1, f, e, t [,a2])</code></a></h3>
10024 Moves elements from the table <code>a1</code> to the table <code>a2</code>,
10027 <code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.
10028 The default for <code>a2</code> is <code>a1</code>.
10034 Returns the destination table <code>a2</code>.
10040 <hr><h3><a name="pdf-table.pack"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>
10045 and with a field "<code>n</code>" with the total number of arguments.
10053 <hr><h3><a name="pdf-table.remove"><code>table.remove (list [, pos])</code></a></h3>
10057 Removes from <code>list</code> the element at position <code>pos</code>,
10059 When <code>pos</code> is an integer between 1 and <code>#list</code>,
10061 <code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>
10062 and erases element <code>list[#list]</code>;
10063 The index <code>pos</code> can also be 0 when <code>#list</code> is 0,
10064 or <code>#list + 1</code>.
10068 The default value for <code>pos</code> is <code>#list</code>,
10069 so that a call <code>table.remove(l)</code> removes the last element
10070 of the list <code>l</code>.
10076 <hr><h3><a name="pdf-table.sort"><code>table.sort (list [, comp])</code></a></h3>
10081 from <code>list[1]</code> to <code>list[#list]</code>.
10082 If <code>comp</code> is given,
10087 <code>i &lt;= j</code> implies <code>not comp(list[j],list[i])</code>.
10088 If <code>comp</code> is not given,
10089 then the standard Lua operator <code>&lt;</code> is used instead.
10093 The <code>comp</code> function must define a consistent order;
10108 <hr><h3><a name="pdf-table.unpack"><code>table.unpack (list [, i [, j]])</code></a></h3>
10118 By default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.
10130 It provides all its functions and constants inside the table <a name="pdf-math"><code>math</code></…
10131 Functions with the annotation "<code>integer/float</code>" give
10135 …th.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a…
10141 <hr><h3><a name="pdf-math.abs"><code>math.abs (x)</code></a></h3>
10145 Returns the maximum value between <code>x</code> and <code>-x</code>. (integer/float)
10151 <hr><h3><a name="pdf-math.acos"><code>math.acos (x)</code></a></h3>
10155 Returns the arc cosine of <code>x</code> (in radians).
10161 <hr><h3><a name="pdf-math.asin"><code>math.asin (x)</code></a></h3>
10165 Returns the arc sine of <code>x</code> (in radians).
10171 <hr><h3><a name="pdf-math.atan"><code>math.atan (y [, x])</code></a></h3>
10176 Returns the arc tangent of <code>y/x</code> (in radians),
10179 It also handles correctly the case of <code>x</code> being zero.
10183 The default value for <code>x</code> is 1,
10184 so that the call <code>math.atan(y)</code>
10185 returns the arc tangent of <code>y</code>.
10191 <hr><h3><a name="pdf-math.ceil"><code>math.ceil (x)</code></a></h3>
10195 Returns the smallest integral value greater than or equal to <code>x</code>.
10201 <hr><h3><a name="pdf-math.cos"><code>math.cos (x)</code></a></h3>
10205 Returns the cosine of <code>x</code> (assumed to be in radians).
10211 <hr><h3><a name="pdf-math.deg"><code>math.deg (x)</code></a></h3>
10215 Converts the angle <code>x</code> from radians to degrees.
10221 <hr><h3><a name="pdf-math.exp"><code>math.exp (x)</code></a></h3>
10226 (where <code>e</code> is the base of natural logarithms).
10232 <hr><h3><a name="pdf-math.floor"><code>math.floor (x)</code></a></h3>
10236 Returns the largest integral value less than or equal to <code>x</code>.
10242 <hr><h3><a name="pdf-math.fmod"><code>math.fmod (x, y)</code></a></h3>
10246 Returns the remainder of the division of <code>x</code> by <code>y</code>
10253 <hr><h3><a name="pdf-math.huge"><code>math.huge</code></a></h3>
10257 The float value <code>HUGE_VAL</code>,
10264 <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3>
10268 Returns the logarithm of <code>x</code> in the given base.
10269 The default for <code>base</code> is <em>e</em>
10270 (so that the function returns the natural logarithm of <code>x</code>).
10276 <hr><h3><a name="pdf-math.max"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>
10281 according to the Lua operator <code>&lt;</code>.
10287 <hr><h3><a name="pdf-math.maxinteger"><code>math.maxinteger</code></a></h3>
10294 <hr><h3><a name="pdf-math.min"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>
10299 according to the Lua operator <code>&lt;</code>.
10305 <hr><h3><a name="pdf-math.mininteger"><code>math.mininteger</code></a></h3>
10312 <hr><h3><a name="pdf-math.modf"><code>math.modf (x)</code></a></h3>
10316 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>.
10323 <hr><h3><a name="pdf-math.pi"><code>math.pi</code></a></h3>
10333 <hr><h3><a name="pdf-math.rad"><code>math.rad (x)</code></a></h3>
10337 Converts the angle <code>x</code> from degrees to radians.
10343 <hr><h3><a name="pdf-math.random"><code>math.random ([m [, n]])</code></a></h3>
10350 When called with two integers <code>m</code> and <code>n</code>,
10351 <code>math.random</code> returns a pseudo-random integer
10353 The call <code>math.random(n)</code>, for a positive <code>n</code>,
10354 is equivalent to <code>math.random(1,n)</code>.
10355 The call <code>math.random(0)</code> produces an integer with
10360 This function uses the <code>xoshiro256**</code> algorithm to produce
10369 a call to <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with no arguments,
10370 so that <code>math.random</code> should generate
10377 <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed ([x [, y]])</code></a></h3>
10382 the integer parameters <code>x</code> and <code>y</code> are
10386 The default for <code>y</code> is zero.
10405 you should call <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with explicit argum…
10411 <hr><h3><a name="pdf-math.sin"><code>math.sin (x)</code></a></h3>
10415 Returns the sine of <code>x</code> (assumed to be in radians).
10421 <hr><h3><a name="pdf-math.sqrt"><code>math.sqrt (x)</code></a></h3>
10425 Returns the square root of <code>x</code>.
10426 (You can also use the expression <code>x^0.5</code> to compute this value.)
10432 <hr><h3><a name="pdf-math.tan"><code>math.tan (x)</code></a></h3>
10436 Returns the tangent of <code>x</code> (assumed to be in radians).
10442 <hr><h3><a name="pdf-math.tointeger"><code>math.tointeger (x)</code></a></h3>
10446 If the value <code>x</code> is convertible to an integer,
10454 <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3>
10458 Returns "<code>integer</code>" if <code>x</code> is an integer,
10459 "<code>float</code>" if it is a float,
10460 or <b>fail</b> if <code>x</code> is not a number.
10466 <hr><h3><a name="pdf-math.ult"><code>math.ult (m, n)</code></a></h3>
10471 <b>true</b> if and only if integer <code>m</code> is below integer <code>n</code> when
10493 all operations are supplied by table <a name="pdf-io"><code>io</code></a>.
10495 the operation <a href="#pdf-io.open"><code>io.open</code></a> returns a file handle
10501 for <code>__gc</code> and <code>__close</code> that try
10506 The table <code>io</code> also provides
10508 …f-io.stdin"><code>io.stdin</code></a>, <a name="pdf-io.stdout"><code>io.stdout</code></a>, and <a …
10516 a system-dependent error code as a third result,
10519 the computation of the error message and error code
10522 because they rely on the global C variable <code>errno</code>.
10526 <hr><h3><a name="pdf-io.close"><code>io.close ([file])</code></a></h3>
10530 Equivalent to <code>file:close()</code>.
10531 Without a <code>file</code>, closes the default output file.
10537 <hr><h3><a name="pdf-io.flush"><code>io.flush ()</code></a></h3>
10541 Equivalent to <code>io.output():flush()</code>.
10547 <hr><h3><a name="pdf-io.input"><code>io.input ([file])</code></a></h3>
10561 instead of returning an error code.
10567 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename, &middot;&middot;&middot;])</code></a></h3>
10573 works like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.
10577 <code>io.lines</code> returns three other values:
10586 The call <code>io.lines()</code> (with no file name) is equivalent
10587 to <code>io.input():lines("l")</code>;
10595 instead of returning an error code.
10601 <hr><h3><a name="pdf-io.open"><code>io.open (filename [, mode])</code></a></h3>
10606 in the mode specified in the string <code>mode</code>.
10612 The <code>mode</code> string can be any of the following:
10615 <li><b>"<code>r</code>": </b> read mode (the default);</li>
10616 <li><b>"<code>w</code>": </b> write mode;</li>
10617 <li><b>"<code>a</code>": </b> append mode;</li>
10618 <li><b>"<code>r+</code>": </b> update mode, all previous data is preserved;</li>
10619 <li><b>"<code>w+</code>": </b> update mode, all previous data is erased;</li>
10620 <li><b>"<code>a+</code>": </b> append update mode, previous data is preserved,
10623 The <code>mode</code> string can also have a '<code>b</code>' at the end,
10630 <hr><h3><a name="pdf-io.output"><code>io.output ([file])</code></a></h3>
10634 Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output …
10640 <hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3>
10649 Starts the program <code>prog</code> in a separated process and returns
10651 (if <code>mode</code> is <code>"r"</code>, the default)
10653 (if <code>mode</code> is <code>"w"</code>).
10659 <hr><h3><a name="pdf-io.read"><code>io.read (&middot;&middot;&middot;)</code></a></h3>
10663 Equivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.
10669 <hr><h3><a name="pdf-io.tmpfile"><code>io.tmpfile ()</code></a></h3>
10682 <hr><h3><a name="pdf-io.type"><code>io.type (obj)</code></a></h3>
10686 Checks whether <code>obj</code> is a valid file handle.
10687 Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,
10688 <code>"closed file"</code> if <code>obj</code> is a closed file handle,
10689 or <b>fail</b> if <code>obj</code> is not a file handle.
10695 <hr><h3><a name="pdf-io.write"><code>io.write (&middot;&middot;&middot;)</code></a></h3>
10699 Equivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.
10705 <hr><h3><a name="pdf-file:close"><code>file:close ()</code></a></h3>
10709 Closes <code>file</code>.
10716 When closing a file handle created with <a href="#pdf-io.popen"><code>io.popen</code></a>,
10717 <a href="#pdf-file:close"><code>file:close</code></a> returns the same values
10718 returned by <a href="#pdf-os.execute"><code>os.execute</code></a>.
10724 <hr><h3><a name="pdf-file:flush"><code>file:flush ()</code></a></h3>
10728 Saves any written data to <code>file</code>.
10734 <hr><h3><a name="pdf-file:lines"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>
10742 uses "<code>l</code>" as a default.
10750 Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
10757 <hr><h3><a name="pdf-file:read"><code>file:read (&middot;&middot;&middot;)</code></a></h3>
10761 Reads the file <code>file</code>,
10778 <li><b>"<code>n</code>": </b>
10785 (e.g., an empty string, "<code>0x</code>", or "<code>3.4e-</code>")
10790 <li><b>"<code>a</code>": </b>
10796 <li><b>"<code>l</code>": </b>
10802 <li><b>"<code>L</code>": </b>
10810 If <code>number</code> is zero,
10816 The formats "<code>l</code>" and "<code>L</code>" should be used only for text files.
10822 <hr><h3><a name="pdf-file:seek"><code>file:seek ([whence [, offset]])</code></a></h3>
10828 to the position given by <code>offset</code> plus a base
10829 specified by the string <code>whence</code>, as follows:
10832 <li><b>"<code>set</code>": </b> base is position 0 (beginning of the file);</li>
10833 <li><b>"<code>cur</code>": </b> base is current position;</li>
10834 <li><b>"<code>end</code>": </b> base is end of file;</li>
10836 In case of success, <code>seek</code> returns the final file position,
10838 If <code>seek</code> fails, it returns <b>fail</b>,
10843 The default value for <code>whence</code> is <code>"cur"</code>,
10844 and for <code>offset</code> is 0.
10845 Therefore, the call <code>file:seek()</code> returns the current
10847 the call <code>file:seek("set")</code> sets the position to the
10849 and the call <code>file:seek("end")</code> sets the position to the
10856 <hr><h3><a name="pdf-file:setvbuf"><code>file:setvbuf (mode [, size])</code></a></h3>
10864 <li><b>"<code>no</code>": </b> no buffering.</li>
10865 <li><b>"<code>full</code>": </b> full buffering.</li>
10866 <li><b>"<code>line</code>": </b> line buffering.</li>
10871 <code>size</code> is a hint for the size of the buffer, in bytes.
10877 check the underlying ISO&nbsp;C function <code>setvbuf</code> in your platform for
10884 <hr><h3><a name="pdf-file:write"><code>file:write (&middot;&middot;&middot;)</code></a></h3>
10888 Writes the value of each of its arguments to <code>file</code>.
10893 In case of success, this function returns <code>file</code>.
10904 This library is implemented through table <a name="pdf-os"><code>os</code></a>.
10908 <hr><h3><a name="pdf-os.clock"><code>os.clock ()</code></a></h3>
10914 as returned by the underlying ISO&nbsp;C function <code>clock</code>.
10920 <hr><h3><a name="pdf-os.date"><code>os.date ([format [, time]])</code></a></h3>
10925 formatted according to the given string <code>format</code>.
10929 If the <code>time</code> argument is present,
10931 (see the <a href="#pdf-os.time"><code>os.time</code></a> function for a description of this value).
10932 Otherwise, <code>date</code> formats the current time.
10936 If <code>format</code> starts with '<code>!</code>',
10939 if <code>format</code> is the string "<code>*t</code>",
10940 then <code>date</code> returns a table with the following fields:
10941 <code>year</code>, <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),
10942 <code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59),
10943 <code>sec</code> (0&ndash;61, due to leap seconds),
10944 <code>wday</code> (weekday, 1&ndash;7, Sunday is&nbsp;1),
10945 <code>yday</code> (day of the year, 1&ndash;366),
10946 and <code>isdst</code> (daylight saving flag, a boolean).
10952 If <code>format</code> is not "<code>*t</code>",
10953 then <code>date</code> returns the date as a string,
10954 formatted according to the same rules as the ISO&nbsp;C function <code>strftime</code>.
10958 If <code>format</code> is absent, it defaults to "<code>%c</code>",
10966 because of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime<…
10972 <hr><h3><a name="pdf-os.difftime"><code>os.difftime (t2, t1)</code></a></h3>
10977 from time <code>t1</code> to time <code>t2</code>
10978 (where the times are values returned by <a href="#pdf-os.time"><code>os.time</code></a>).
10980 this value is exactly <code>t2</code><em>-</em><code>t1</code>.
10986 <hr><h3><a name="pdf-os.execute"><code>os.execute ([command])</code></a></h3>
10990 This function is equivalent to the ISO&nbsp;C function <code>system</code>.
10991 It passes <code>command</code> to be executed by an operating system shell.
11001 <li><b>"<code>exit</code>": </b>
11006 <li><b>"<code>signal</code>": </b>
11014 When called without a <code>command</code>,
11015 <code>os.execute</code> returns a boolean that is true if a shell is available.
11021 <hr><h3><a name="pdf-os.exit"><code>os.exit ([code [, close]])</code></a></h3>
11025 Calls the ISO&nbsp;C function <code>exit</code> to terminate the host program.
11026 If <code>code</code> is <b>true</b>,
11027 the returned status is <code>EXIT_SUCCESS</code>;
11028 if <code>code</code> is <b>false</b>,
11029 the returned status is <code>EXIT_FAILURE</code>;
11030 if <code>code</code> is a number,
11032 The default value for <code>code</code> is <b>true</b>.
11036 If the optional second argument <code>close</code> is true,
11037 the function closes the Lua state before exiting (see <a href="#lua_close"><code>lua_close</code></…
11043 <hr><h3><a name="pdf-os.getenv"><code>os.getenv (varname)</code></a></h3>
11047 Returns the value of the process environment variable <code>varname</code>
11054 <hr><h3><a name="pdf-os.remove"><code>os.remove (filename)</code></a></h3>
11061 plus a string describing the error and the error code.
11068 <hr><h3><a name="pdf-os.rename"><code>os.rename (oldname, newname)</code></a></h3>
11072 Renames the file or directory named <code>oldname</code> to <code>newname</code>.
11074 plus a string describing the error and the error code.
11081 <hr><h3><a name="pdf-os.setlocale"><code>os.setlocale (locale [, category])</code></a></h3>
11086 <code>locale</code> is a system-dependent string specifying a locale;
11087 <code>category</code> is an optional string describing which category to change:
11088 <code>"all"</code>, <code>"collate"</code>, <code>"ctype"</code>,
11089 <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>;
11090 the default category is <code>"all"</code>.
11096 If <code>locale</code> is the empty string,
11098 If <code>locale</code> is the string "<code>C</code>",
11110 because of its reliance on C&nbsp;function <code>setlocale</code>.
11116 <hr><h3><a name="pdf-os.time"><code>os.time ([table])</code></a></h3>
11122 This table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,
11124 <code>hour</code> (default is 12),
11125 <code>min</code> (default is 0),
11126 <code>sec</code> (default is 0),
11127 and <code>isdst</code> (default is <b>nil</b>).
11129 For a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function.
11135 For instance, if <code>sec</code> is -10,
11137 if <code>hour</code> is 1000,
11147 and the number returned by <code>time</code> can be used only as an argument to
11148 <a href="#pdf-os.date"><code>os.date</code></a> and <a href="#pdf-os.difftime"><code>os.difftime</c…
11153 <code>os.time</code> also normalizes all the fields
11154 documented in the <a href="#pdf-os.date"><code>os.date</code></a> function,
11162 <hr><h3><a name="pdf-os.tmpname"><code>os.tmpname ()</code></a></h3>
11184 you may prefer to use <a href="#pdf-io.tmpfile"><code>io.tmpfile</code></a>,
11200 violate basic assumptions about Lua code
11203 that userdata metatables cannot be changed by Lua code;
11205 and therefore can compromise otherwise secure code.
11211 inside the <a name="pdf-debug"><code>debug</code></a> table.
11219 <hr><h3><a name="pdf-debug.debug"><code>debug.debug ()</code></a></h3>
11228 A line containing only the word <code>cont</code> finishes this function,
11233 Note that commands for <code>debug.debug</code> are not lexically nested
11240 <hr><h3><a name="pdf-debug.gethook"><code>debug.gethook ([thread])</code></a></h3>
11247 as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function.
11257 <hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>
11263 or you can give a number as the value of <code>f</code>,
11264 which means the function running at level <code>f</code> of the call stack
11266 level&nbsp;0 is the current function (<code>getinfo</code> itself);
11267 level&nbsp;1 is the function that called <code>getinfo</code>
11270 If <code>f</code> is a number greater than the number of active functions,
11271 then <code>getinfo</code> returns <b>fail</b>.
11275 …d table can contain all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>,
11276 with the string <code>what</code> describing which fields to fill in.
11277 The default for <code>what</code> is to get all information available,
11280 the option '<code>f</code>'
11281 adds a field named <code>func</code> with the function itself.
11283 the option '<code>L</code>'
11284 adds a field named <code>activelines</code> with the table of
11289 For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
11292 and the expression <code>debug.getinfo(print)</code>
11294 about the <a href="#pdf-print"><code>print</code></a> function.
11300 <hr><h3><a name="pdf-debug.getlocal"><code>debug.getlocal ([thread,] f, local)</code></a></h3>
11305 with index <code>local</code> of the function at level <code>f</code> of the stack.
11312 following the order that they are declared in the code,
11322 (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the leve…
11326 Variable names starting with '<code>(</code>' (open parenthesis)
11333 The parameter <code>f</code> may also be a function.
11334 In that case, <code>getlocal</code> returns only the name of function parameters.
11340 <hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (value)</code></a></h3>
11344 Returns the metatable of the given <code>value</code>
11351 <hr><h3><a name="pdf-debug.getregistry"><code>debug.getregistry ()</code></a></h3>
11361 <hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (f, up)</code></a></h3>
11366 with index <code>up</code> of the function <code>f</code>.
11378 For C&nbsp;functions, this function uses the empty string <code>""</code>
11383 Variable name '<code>?</code>' (interrogation mark)
11391 <hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u, n)</code></a></h3>
11395 Returns the <code>n</code>-th user value associated
11396 to the userdata <code>u</code> plus a boolean,
11403 <hr><h3><a name="pdf-debug.sethook"><code>debug.sethook ([thread,] hook, mask [, count])</code></a>…
11408 The string <code>mask</code> and the number <code>count</code> describe
11414 <li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li>
11415 <li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>
11416 <li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>
11419 with a <code>count</code> different from zero,
11420 the hook is called also after every <code>count</code> instructions.
11425 <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> turns off the hook.
11431 <code>"call"</code>, <code>"tail call"</code>, <code>"return"</code>,
11432 <code>"line"</code>, and <code>"count"</code>.
11436 you can call <code>getinfo</code> with level&nbsp;2 to get more information about
11438 (Level&nbsp;0 is the <code>getinfo</code> function,
11445 <hr><h3><a name="pdf-debug.setlocal"><code>debug.setlocal ([thread,] level, local, value)</code></a…
11449 This function assigns the value <code>value</code> to the local variable
11450 with index <code>local</code> of the function at level <code>level</code> of the stack.
11453 and raises an error when called with a <code>level</code> out of range.
11454 (You can call <code>getinfo</code> to check whether the level is valid.)
11459 See <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for more information about
11466 <hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (value, table)</code></a></h3>
11470 Sets the metatable for the given <code>value</code> to the given <code>table</code>
11472 Returns <code>value</code>.
11478 <hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (f, up, value)</code></a></h3>
11482 This function assigns the value <code>value</code> to the upvalue
11483 with index <code>up</code> of the function <code>f</code>.
11490 See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about up…
11496 <hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value, n)</code></a></h3>
11500 Sets the given <code>value</code> as
11501 the <code>n</code>-th user value associated to the given <code>udata</code>.
11502 <code>udata</code> must be a full userdata.
11506 Returns <code>udata</code>,
11513 <hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message [, level]])</code><…
11517 If <code>message</code> is present but is neither a string nor <b>nil</b>,
11518 this function returns <code>message</code> without further processing.
11521 The optional <code>message</code> string is appended
11523 An optional <code>level</code> number tells at which level
11525 (default is 1, the function calling <code>traceback</code>).
11531 <hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (f, n)</code></a></h3>
11536 for the upvalue numbered <code>n</code>
11551 <hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>
11555 Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>
11556 refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.
11571 called simply <code>lua</code>,
11583 <li><b><code>-e <em>stat</em></code>: </b> execute string <em>stat</em>;</li>
11584 <li><b><code>-i</code>: </b> enter interactive mode after running <em>script</em>;</li>
11585 <li><b><code>-l <em>mod</em></code>: </b> "require" <em>mod</em> and assign the
11587 <li><b><code>-l <em>g=mod</em></code>: </b> "require" <em>mod</em> and assign the
11589 <li><b><code>-v</code>: </b> print version information;</li>
11590 <li><b><code>-E</code>: </b> ignore environment variables;</li>
11591 <li><b><code>-W</code>: </b> turn warnings on;</li>
11592 <li><b><code>--</code>: </b> stop handling options;</li>
11593 <li><b><code>-</code>: </b> execute <code>stdin</code> as a file and stop handling options.</li>
11595 (The form <code>-l <em>g=mod</em></code> was introduced in release&nbsp;5.4.4.)
11599 After handling its options, <code>lua</code> runs the given <em>script</em>.
11601 <code>lua</code> behaves as <code>lua -v -i</code>
11602 when the standard input (<code>stdin</code>) is a terminal,
11603 and as <code>lua -</code> otherwise.
11607 When called without the option <code>-E</code>,
11608 …rpreter checks for an environment variable <a name="pdf-LUA_INIT_5_4"><code>LUA_INIT_5_4</code></a>
11609 (or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if the versioned name is not defined)
11611 If the variable content has the format <code>@<em>filename</em></code>,
11612 then <code>lua</code> executes the file.
11613 Otherwise, <code>lua</code> executes the string itself.
11617 When called with the option <code>-E</code>,
11620 … of <a href="#pdf-package.path"><code>package.path</code></a> and <a href="#pdf-package.cpath"><co…
11621 are set with the default paths defined in <code>luaconf.h</code>.
11625 The options <code>-e</code>, <code>-l</code>, and <code>-W</code> are handled in
11632 will first set <code>a</code> to 1, then require the library <code>lib1</code>,
11633 and finally run the file <code>script.lua</code> with no arguments.
11634 (Here <code>$</code> is the shell prompt. Your prompt may be different.)
11638 Before running any code,
11639 <code>lua</code> collects all command-line arguments
11640 in a global table called <code>arg</code>.
11667 will print "<code>-e</code>".
11670 <code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.
11688 If the global variable <a name="pdf-_PROMPT"><code>_PROMPT</code></a> contains a string,
11690 Similarly, if the global variable <a name="pdf-_PROMPT2"><code>_PROMPT2</code></a> contains a strin…
11699 has a metamethod <code>__tostring</code>,
11710 (see <a href="#lua_close"><code>lua_close</code></a>).
11712 calling <a href="#pdf-os.exit"><code>os.exit</code></a> to terminate.
11718 Lua skips the first line of a file chunk if it starts with <code>#</code>.
11720 by using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,
11728 If <code>lua</code> is in your <code>PATH</code>,
11749 appropriate options (see file <code>luaconf.h</code>).
11756 you should try to test your code with a version of Lua compiled
11763 do not imply source-code changes in a program,
11800 For instance, the result of <code>"1" + "2"</code> now is an integer,
11813 The use of the <code>__lt</code> metamethod to emulate <code>__le</code>
11832 Lua does not ignore <code>__gc</code> metamethods that are not functions.
11847 The function <a href="#pdf-print"><code>print</code></a> does not call <a href="#pdf-tostring"><cod…
11850 You should use <code>__tostring</code> to modify how values are printed.
11854 …andom number generator used by the function <a href="#pdf-math.random"><code>math.random</code></a>
11860 By default, the decoding functions in the <a href="#pdf-utf8"><code>utf8</code></a> library
11861 do not accept surrogates as valid code points.
11866 The options "<code>setpause</code>" and "<code>setstepmul</code>"
11867 of the function <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> are deprecated.
11868 You should use the new option "<code>incremental</code>" to set them.
11872 The function <a href="#pdf-io.lines"><code>io.lines</code></a> now returns four values,
11876 such as in <code>load(io.lines(filename, "L"))</code>.
11894 Therefore, the functions <code>lua_newuserdata</code>,
11895 <code>lua_setuservalue</code>, and <code>lua_getuservalue</code> were
11896 replaced by <a href="#lua_newuserdatauv"><code>lua_newuserdatauv</code></a>,
11897 … href="#lua_setiuservalue"><code>lua_setiuservalue</code></a>, and <a href="#lua_getiuservalue"><c…
11909 The function <a href="#lua_resume"><code>lua_resume</code></a> has an extra parameter.
11917 The function <a href="#lua_version"><code>lua_version</code></a> returns the version number,
11926 The constant <code>LUA_ERRGCMM</code> was removed.
11932 The options <code>LUA_GCSETPAUSE</code> and <code>LUA_GCSETSTEPMUL</code>
11933 of the function <a href="#lua_gc"><code>lua_gc</code></a> are deprecated.
11934 You should use the new option <code>LUA_GCINC</code> to set them.