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>.
5596 neither has a <code>__close</code> metamethod nor is a false value.
5606 by the time the <code>__close</code> metamethod runs,
5615 <hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p>
5620 …alent to <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> with <code>isnum</code> equal t…
5626 <hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p>
5632 to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>.
5635 otherwise, <code>lua_tointegerx</code> returns&nbsp;0.
5639 If <code>isnum</code> is not <code>NULL</code>,
5647 <hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3><p>
5653 If <code>len</code> is not <code>NULL</code>,
5654 it sets <code>*len</code> with the string length.
5656 otherwise, the function returns <code>NULL</code>.
5658 then <code>lua_tolstring</code> also
5660 (This change confuses <a href="#lua_next"><code>lua_next</code></a>
5661 when <code>lua_tolstring</code> is applied to keys during a table traversal.)
5665 <code>lua_tolstring</code> returns a pointer
5667 This string always has a zero ('<code>\0</code>')
5681 <hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p>
5686 …ivalent to <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> with <code>isnum</code> equal t…
5692 <hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p>
5698 …he C&nbsp;type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>…
5701 otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns&nbsp;0.
5705 If <code>isnum</code> is not <code>NULL</code>,
5713 <hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p>
5719 C&nbsp;pointer (<code>void*</code>).
5721 otherwise, <code>lua_topointer</code> returns <code>NULL</code>.
5733 <hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3><p>
5738 …uivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to…
5744 <hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p>
5750 (represented as <code>lua_State*</code>).
5752 otherwise, the function returns <code>NULL</code>.
5758 <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>
5767 Otherwise, returns <code>NULL</code>.
5773 <hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p>
5779 or <code>LUA_TNONE</code> for a non-valid but acceptable index.
5780 The types returned by <a href="#lua_type"><code>lua_type</code></a> are coded by the following cons…
5781 defined in <code>lua.h</code>:
5782 <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>,
5783 <a name="pdf-LUA_TNUMBER"><code>LUA_TNUMBER</code></a>,
5784 <a name="pdf-LUA_TBOOLEAN"><code>LUA_TBOOLEAN</code></a>,
5785 <a name="pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>,
5786 <a name="pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>,
5787 <a name="pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>,
5788 <a name="pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>,
5789 <a name="pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a>,
5791 <a name="pdf-LUA_TLIGHTUSERDATA"><code>LUA_TLIGHTUSERDATA</code></a>.
5797 <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p>
5802 Returns the name of the type encoded by the value <code>tp</code>,
5803 which must be one the values returned by <a href="#lua_type"><code>lua_type</code></a>.
5809 <hr><h3><a name="lua_Unsigned"><code>lua_Unsigned</code></a></h3>
5813 The unsigned version of <a href="#lua_Integer"><code>lua_Integer</code></a>.
5819 <hr><h3><a name="lua_upvalueindex"><code>lua_upvalueindex</code></a></h3><p>
5824 Returns the pseudo-index that represents the <code>i</code>-th upvalue of
5826 <code>i</code> must be in the range <em>[1,256]</em>.
5832 <hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p>
5843 <hr><h3><a name="lua_WarnFunction"><code>lua_WarnFunction</code></a></h3>
5849 set by <a href="#lua_setwarnf"><code>lua_setwarnf</code></a>.
5857 See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
5863 <hr><h3><a name="lua_warning"><code>lua_warning</code></a></h3><p>
5869 A message in a call with <code>tocont</code> true should be
5874 See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
5880 <hr><h3><a name="lua_Writer"><code>lua_Writer</code></a></h3>
5887 The type of the writer function used by <a href="#lua_dump"><code>lua_dump</code></a>.
5888 Every time <a href="#lua_dump"><code>lua_dump</code></a> produces another piece of chunk,
5890 passing along the buffer to be written (<code>p</code>),
5891 its size (<code>sz</code>),
5892 and the <code>ud</code> parameter supplied to <a href="#lua_dump"><code>lua_dump</code></a>.
5896 The writer returns an error code:
5898 any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from
5905 <hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p>
5914 This function pops <code>n</code> values from the stack <code>from</code>,
5915 and pushes them onto the stack <code>to</code>.
5921 <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p>
5926 This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
5930 the function calling <code>lua_yield</code>.
5938 <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p>
5950 When a C&nbsp;function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
5952 and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine retur…
5953 The parameter <code>nresults</code> is the number of values from the stack
5954 that will be passed as results to <a href="#lua_resume"><code>lua_resume</code></a>.
5959 Lua calls the given continuation function <code>k</code> to continue
5963 with the <code>n</code> results removed and
5964 replaced by the arguments passed to <a href="#lua_resume"><code>lua_resume</code></a>.
5966 the continuation function receives the value <code>ctx</code>
5967 that was passed to <a href="#lua_yieldk"><code>lua_yieldk</code></a>.
5977 In that case, <code>lua_yieldk</code> should be called with no continuation
5978 (probably in the form of <a href="#lua_yield"><code>lua_yield</code></a>) and no results,
6011 <hr><h3><a name="lua_Debug"><code>lua_Debug</code></a></h3>
6036 <a href="#lua_getstack"><code>lua_getstack</code></a> fills only the private part
6038 To fill the other fields of <a href="#lua_Debug"><code>lua_Debug</code></a> with useful information,
6039 you must call <a href="#lua_getinfo"><code>lua_getinfo</code></a> with an appropriate parameter.
6042 to the parameter <code>what</code> of <a href="#lua_getinfo"><code>lua_getinfo</code></a>.)
6046 The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning:
6050 <li><b><code>source</code>: </b>
6052 If <code>source</code> starts with a '<code>@</code>',
6054 the file name follows the '<code>@</code>'.
6055 If <code>source</code> starts with a '<code>=</code>',
6059 <code>source</code> is that string.
6062 <li><b><code>srclen</code>: </b>
6063 The length of the string <code>source</code>.
6066 <li><b><code>short_src</code>: </b>
6067 a "printable" version of <code>source</code>, to be used in error messages.
6070 <li><b><code>linedefined</code>: </b>
6074 <li><b><code>lastlinedefined</code>: </b>
6078 <li><b><code>what</code>: </b>
6079 the string <code>"Lua"</code> if the function is a Lua function,
6080 <code>"C"</code> if it is a C&nbsp;function,
6081 <code>"main"</code> if it is the main part of a chunk.
6084 <li><b><code>currentline</code>: </b>
6087 <code>currentline</code> is set to -1.
6090 <li><b><code>name</code>: </b>
6096 The <code>lua_getinfo</code> function checks how the function was
6099 then <code>name</code> is set to <code>NULL</code>.
6102 <li><b><code>namewhat</code>: </b>
6103 explains the <code>name</code> field.
6104 The value of <code>namewhat</code> can be
6105 <code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
6106 <code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),
6111 <li><b><code>istailcall</code>: </b>
6116 <li><b><code>nups</code>: </b>
6120 <li><b><code>nparams</code>: </b>
6125 <li><b><code>isvararg</code>: </b>
6130 <li><b><code>ftransfer</code>: </b>
6135 through <a href="#lua_getlocal"><code>lua_getlocal</code></a> and <a href="#lua_setlocal"><code>lua…
6142 <li><b><code>ntransfer</code>: </b>
6145 this value is always equal to <code>nparams</code>.)
6153 <hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p>
6164 <hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p>
6175 <hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p>
6186 <hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3><p>
6196 the parameter <code>ar</code> must be a valid activation record that was
6197 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
6198 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
6203 and start the <code>what</code> string with the character '<code>&gt;</code>'.
6205 <code>lua_getinfo</code> pops the function from the top of the stack.)
6206 For instance, to know in which line a function <code>f</code> was defined,
6207 you can write the following code:
6217 Each character in the string <code>what</code>
6218 selects some fields of the structure <code>ar</code> to be filled or
6221 the structure <a href="#lua_Debug"><code>lua_Debug</code></a>,
6226 <li><b>'<code>f</code>': </b>
6231 <li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;
6234 <li><b>'<code>n</code>': </b> fills in the fields <code>name</code> and <code>namewhat</code>;
6237 <li><b>'<code>r</code>': </b> fills in the fields <code>ftransfer</code> and <code>ntransfer</code>;
6240 <li><b>'<code>S</code>': </b>
6241 fills in the fields <code>source</code>, <code>short_src</code>,
6242 <code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
6245 <li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;
6248 <li><b>'<code>u</code>': </b> fills in the fields
6249 <code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;
6252 <li><b>'<code>L</code>': </b>
6254 the lines on the function with some associated code,
6256 (Lines with no code include empty lines and comments.)
6257 If this option is given together with option '<code>f</code>',
6265 This function returns 0 to signal an invalid option in <code>what</code>;
6272 <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p>
6283 the parameter <code>ar</code> must be a valid activation record that was
6284 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
6285 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
6286 The index <code>n</code> selects which local variable to inspect;
6287 see <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for details about variable indices
6292 <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack
6297 In the second case, <code>ar</code> must be <code>NULL</code> and the function
6305 Returns <code>NULL</code> (and pushes nothing)
6313 <hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p>
6322 This function fills parts of a <a href="#lua_Debug"><code>lua_Debug</code></a> structure with
6329 <a href="#lua_getstack"><code>lua_getstack</code></a> returns 0;
6336 <hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p>
6341 Gets information about the <code>n</code>-th upvalue
6342 of the closure at index <code>funcindex</code>.
6345 Returns <code>NULL</code> (and pushes nothing)
6346 when the index <code>n</code> is greater than the number of upvalues.
6350 See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about up…
6356 <hr><h3><a name="lua_Hook"><code>lua_Hook</code></a></h3>
6364 Whenever a hook is called, its <code>ar</code> argument has its field
6365 <code>event</code> set to the specific event that triggered the hook.
6367 <a name="pdf-LUA_HOOKCALL"><code>LUA_HOOKCALL</code></a>, <a name="pdf-LUA_HOOKRET"><code>LUA_HOOKR…
6368 <a name="pdf-LUA_HOOKTAILCALL"><code>LUA_HOOKTAILCALL</code></a>, <a name="pdf-LUA_HOOKLINE"><code>…
6369 and <a name="pdf-LUA_HOOKCOUNT"><code>LUA_HOOKCOUNT</code></a>.
6370 Moreover, for line events, the field <code>currentline</code> is also set.
6371 To get the value of any other field in <code>ar</code>,
6372 the hook must call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.
6376 For call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,
6377 the normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;
6389 that is, they cannot call <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
6390 …a href="#lua_pcallk"><code>lua_pcallk</code></a>, or <a href="#lua_callk"><code>lua_callk</code></…
6397 calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero
6404 <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p>
6413 Argument <code>f</code> is the hook function.
6414 <code>mask</code> specifies on which events the hook will be called:
6416 <a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>,
6417 <a name="pdf-LUA_MASKRET"><code>LUA_MASKRET</code></a>,
6418 <a name="pdf-LUA_MASKLINE"><code>LUA_MASKLINE</code></a>,
6419 and <a name="pdf-LUA_MASKCOUNT"><code>LUA_MASKCOUNT</code></a>.
6420 The <code>count</code> argument is only meaningful when the mask
6421 includes <code>LUA_MASKCOUNT</code>.
6435 start the execution of a new line of code,
6436 or when it jumps back in the code (even to the same line).
6441 <code>count</code> instructions.
6448 Hooks are disabled by setting <code>mask</code> to zero.
6454 <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p>
6466 Returns <code>NULL</code> (and pops nothing)
6472 Parameters <code>ar</code> and <code>n</code> are as in the function <a href="#lua_getlocal"><code>…
6478 <hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p>
6490 Returns <code>NULL</code> (and pops nothing)
6491 when the index <code>n</code> is greater than the number of upvalues.
6495 Parameters <code>funcindex</code> and <code>n</code> are as in
6496 the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>.
6502 <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p>
6507 Returns a unique identifier for the upvalue numbered <code>n</code>
6508 from the closure at index <code>funcindex</code>.
6520 Parameters <code>funcindex</code> and <code>n</code> are as in
6521 the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>,
6522 but <code>n</code> cannot be greater than the number of upvalues.
6528 <hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3><p>
6534 Make the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>
6535 refer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.
6559 are defined in header file <code>lauxlib.h</code> and
6560 have a prefix <code>luaL_</code>.
6568 more consistency to your code.
6583 (e.g., "<code>bad argument #1</code>"),
6588 Functions called <code>luaL_check*</code>
6603 <hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3><p>
6608 Adds the byte <code>c</code> to the buffer <code>B</code>
6609 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6615 <hr><h3><a name="luaL_addgsub"><code>luaL_addgsub</code></a></h3><p>
6621 Adds a copy of the string <code>s</code> to the buffer <code>B</code> (see <a href="#luaL_Buffer"><
6622 replacing any occurrence of the string <code>p</code>
6623 with the string <code>r</code>.
6629 <hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3><p>
6634 Adds the string pointed to by <code>s</code> with length <code>l</code> to
6635 the buffer <code>B</code>
6636 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6643 <hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3><p>
6648 Adds to the buffer <code>B</code>
6649 a string of length <code>n</code> previously copied to the
6650 buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>).
6656 <hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3><p>
6661 Adds the zero-terminated string pointed to by <code>s</code>
6662 to the buffer <code>B</code>
6663 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6669 <hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3><p>
6675 to the buffer <code>B</code>
6676 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6689 <hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3><p>
6697 Checks whether <code>cond</code> is true.
6698 …ses an error with a standard message (see <a href="#luaL_argerror"><code>luaL_argerror</code></a>).
6704 <hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3><p>
6709 Raises an error reporting a problem with argument <code>arg</code>
6712 that includes <code>extramsg</code> as a comment:
6723 <hr><h3><a name="luaL_argexpected"><code>luaL_argexpected</code></a></h3><p>
6731 Checks whether <code>cond</code> is true.
6732 If it is not, raises an error about the type of the argument <code>arg</code>
6733 with a standard message (see <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>).
6739 <hr><h3><a name="luaL_Buffer"><code>luaL_Buffer</code></a></h3>
6747 A string buffer allows C&nbsp;code to build Lua strings piecemeal.
6752 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code>…
6754 <li>Then initialize it with a call <code>luaL_buffinit(L, &amp;b)</code>.</li>
6758 the <code>luaL_add*</code> functions.
6762 Finish by calling <code>luaL_pushresult(&amp;b)</code>.
6774 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code>…
6777 size <code>sz</code> with a call <code>luaL_buffinitsize(L, &amp;b, sz)</code>.</li>
6782 Finish by calling <code>luaL_pushresultsize(&amp;b, sz)</code>,
6783 where <code>sz</code> is the total size of the resulting string
6801 (The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.)
6802 After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a>,
6810 <hr><h3><a name="luaL_buffaddr"><code>luaL_buffaddr</code></a></h3><p>
6815 Returns the address of the current content of buffer <code>B</code>
6816 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6823 <hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p>
6828 Initializes a buffer <code>B</code>
6829 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6837 <hr><h3><a name="luaL_bufflen"><code>luaL_bufflen</code></a></h3><p>
6842 Returns the length of the current content of buffer <code>B</code>
6843 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6849 <hr><h3><a name="luaL_buffinitsize"><code>luaL_buffinitsize</code></a></h3><p>
6855 <a href="#luaL_buffinit"><code>luaL_buffinit</code></a>, <a href="#luaL_prepbuffsize"><code>luaL_pr…
6861 <hr><h3><a name="luaL_buffsub"><code>luaL_buffsub</code></a></h3><p>
6866 Removes <code>n</code> bytes from the buffer <code>B</code>
6867 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6874 <hr><h3><a name="luaL_callmeta"><code>luaL_callmeta</code></a></h3><p>
6883 If the object at index <code>obj</code> has a metatable and this
6884 metatable has a field <code>e</code>,
6895 <hr><h3><a name="luaL_checkany"><code>luaL_checkany</code></a></h3><p>
6901 of any type (including <b>nil</b>) at position <code>arg</code>.
6907 <hr><h3><a name="luaL_checkinteger"><code>luaL_checkinteger</code></a></h3><p>
6912 Checks whether the function argument <code>arg</code> is an integer
6920 <hr><h3><a name="luaL_checklstring"><code>luaL_checklstring</code></a></h3><p>
6925 Checks whether the function argument <code>arg</code> is a string
6927 if <code>l</code> is not <code>NULL</code> fills its referent
6932 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
6939 <hr><h3><a name="luaL_checknumber"><code>luaL_checknumber</code></a></h3><p>
6944 Checks whether the function argument <code>arg</code> is a number
6945 and returns this number converted to a <code>lua_Number</code>.
6951 <hr><h3><a name="luaL_checkoption"><code>luaL_checkoption</code></a></h3><p>
6959 Checks whether the function argument <code>arg</code> is a string and
6960 searches for this string in the array <code>lst</code>
6968 If <code>def</code> is not <code>NULL</code>,
6969 the function uses <code>def</code> as a default value when
6970 there is no argument <code>arg</code> or when this argument is <b>nil</b>.
6982 <hr><h3><a name="luaL_checkstack"><code>luaL_checkstack</code></a></h3><p>
6987 Grows the stack size to <code>top + sz</code> elements,
6989 <code>msg</code> is an additional text to go into the error message
6990 (or <code>NULL</code> for no additional text).
6996 <hr><h3><a name="luaL_checkstring"><code>luaL_checkstring</code></a></h3><p>
7001 Checks whether the function argument <code>arg</code> is a string
7006 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
7013 <hr><h3><a name="luaL_checktype"><code>luaL_checktype</code></a></h3><p>
7018 Checks whether the function argument <code>arg</code> has type <code>t</code>.
7019 See <a href="#lua_type"><code>lua_type</code></a> for the encoding of types for <code>t</code>.
7025 <hr><h3><a name="luaL_checkudata"><code>luaL_checkudata</code></a></h3><p>
7030 Checks whether the function argument <code>arg</code> is a userdata
7031 of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>…
7032 …he userdata's memory-block address (see <a href="#lua_touserdata"><code>lua_touserdata</code></a>).
7038 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
7043 Checks whether the code making the call and the Lua library being called
7050 <hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3><p>
7061 It returns&nbsp;0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) if there are no errors,
7068 <hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p>
7079 It returns&nbsp;0 (<a href="#pdf-LUA_OK"><code>LUA_OK</code></a>) if there are no errors,
7086 <hr><h3><a name="luaL_error"><code>luaL_error</code></a></h3><p>
7092 The error message format is given by <code>fmt</code>
7094 following the same rules of <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>.
7103 as <code>return luaL_error(<em>args</em>)</code>.
7109 <hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p>
7116 (<a href="#pdf-os.execute"><code>os.execute</code></a> and <a href="#pdf-io.close"><code>io.close</
7122 <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p>
7129 …pdf-io.open"><code>io.open</code></a>, <a href="#pdf-os.rename"><code>os.rename</code></a>, <a hre…
7135 <hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3><p>
7140 Pushes onto the stack the field <code>e</code> from the metatable
7141 of the object at index <code>obj</code> and returns the type of the pushed value.
7144 pushes nothing and returns <code>LUA_TNIL</code>.
7150 <hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p>
7155 Pushes onto the stack the metatable associated with the name <code>tname</code>
7156 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>),
7164 <hr><h3><a name="luaL_getsubtable"><code>luaL_getsubtable</code></a></h3><p>
7169 Ensures that the value <code>t[fname]</code>,
7170 where <code>t</code> is the value at index <code>idx</code>,
7180 <hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3><p>
7188 Creates a copy of string <code>s</code>,
7189 replacing any occurrence of the string <code>p</code>
7190 with the string <code>r</code>.
7197 <hr><h3><a name="luaL_len"><code>luaL_len</code></a></h3><p>
7204 it is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.7">&sect;3.4.7</a>).
7212 <hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p>
7220 …ent to <a href="#luaL_loadbufferx"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal …
7226 <hr><h3><a name="luaL_loadbufferx"><code>luaL_loadbufferx</code></a></h3><p>
7236 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the
7237 buffer pointed to by <code>buff</code> with size <code>sz</code>.
7241 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
7242 <code>name</code> is the chunk name,
7244 The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.
7250 <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p>
7255 …valent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal t…
7261 <hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p>
7268 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file
7269 named <code>filename</code>.
7270 If <code>filename</code> is <code>NULL</code>,
7272 The first line in the file is ignored if it starts with a <code>#</code>.
7276 The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.
7280 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>
7281 or <a href="#pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a> for file-related errors.
7285 As <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
7292 <hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p>
7298 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in
7299 the zero-terminated string <code>s</code>.
7303 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
7307 Also as <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
7314 <hr><h3><a name="luaL_newlib"><code>luaL_newlib</code></a></h3><p>
7320 the functions in the list <code>l</code>.
7329 The array <code>l</code> must be the actual array,
7336 <hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p>
7342 to store all entries in the array <code>l</code>
7344 It is intended to be used in conjunction with <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></…
7345 (see <a href="#luaL_newlib"><code>luaL_newlib</code></a>).
7350 The array <code>l</code> must be the actual array,
7357 <hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3><p>
7362 If the registry already has the key <code>tname</code>,
7366 adds to this new table the pair <code>__name = tname</code>,
7367 adds to the registry the pair <code>[tname] = new table</code>,
7374 with <code>tname</code> in the registry.
7380 <hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p>
7386 It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
7394 or <code>NULL</code> if there is a memory allocation error.
7400 <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p>
7411 <hr><h3><a name="luaL_opt"><code>luaL_opt</code></a></h3><p>
7421 In words, if the argument <code>arg</code> is nil or absent,
7422 the macro results in the default <code>dflt</code>.
7423 Otherwise, it results in the result of calling <code>func</code>
7424 with the state <code>L</code> and the argument index <code>arg</code> as
7426 Note that it evaluates the expression <code>dflt</code> only if needed.
7432 <hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3><p>
7439 If the function argument <code>arg</code> is an integer
7443 returns <code>d</code>.
7450 <hr><h3><a name="luaL_optlstring"><code>luaL_optlstring</code></a></h3><p>
7458 If the function argument <code>arg</code> is a string,
7461 returns <code>d</code>.
7466 If <code>l</code> is not <code>NULL</code>,
7468 If the result is <code>NULL</code>
7469 (only possible when returning <code>d</code> and <code>d == NULL</code>),
7474 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
7481 <hr><h3><a name="luaL_optnumber"><code>luaL_optnumber</code></a></h3><p>
7486 If the function argument <code>arg</code> is a number,
7487 returns this number as a <code>lua_Number</code>.
7489 returns <code>d</code>.
7496 <hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3><p>
7503 If the function argument <code>arg</code> is a string,
7506 returns <code>d</code>.
7513 <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p>
7518 Equivalent to <a href="#luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a>
7519 with the predefined size <a name="pdf-LUAL_BUFFERSIZE"><code>LUAL_BUFFERSIZE</code></a>.
7525 <hr><h3><a name="luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a></h3><p>
7530 Returns an address to a space of size <code>sz</code>
7531 where you can copy a string to be added to buffer <code>B</code>
7532 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
7534 <a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add
7541 <hr><h3><a name="luaL_pushfail"><code>luaL_pushfail</code></a></h3><p>
7552 <hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3><p>
7557 Finishes the use of buffer <code>B</code> leaving the final string on
7564 <hr><h3><a name="luaL_pushresultsize"><code>luaL_pushresultsize</code></a></h3><p>
7569 …sequence <a href="#luaL_addsize"><code>luaL_addsize</code></a>, <a href="#luaL_pushresult"><code>l…
7575 <hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3><p>
7581 in the table at index <code>t</code>,
7587 As long as you do not manually add integer keys into the table <code>t</code>,
7588 <a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.
7589 You can retrieve an object referred by the reference <code>r</code>
7590 by calling <code>lua_rawgeti(L, t, r)</code>.
7591 The function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference.
7596 <a href="#luaL_ref"><code>luaL_ref</code></a> returns the constant <a name="pdf-LUA_REFNIL"><code>L…
7597 The constant <a name="pdf-LUA_NOREF"><code>LUA_NOREF</code></a> is guaranteed to be different
7598 from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
7604 <hr><h3><a name="luaL_Reg"><code>luaL_Reg</code></a></h3>
7612 <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a>.
7613 <code>name</code> is the function name and <code>func</code> is a pointer to
7615 Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with a sentinel entry
7616 in which both <code>name</code> and <code>func</code> are <code>NULL</code>.
7622 <hr><h3><a name="luaL_requiref"><code>luaL_requiref</code></a></h3><p>
7628 If <code>package.loaded[modname]</code> is not true,
7629 calls the function <code>openf</code> with the string <code>modname</code> as an argument
7630 and sets the call result to <code>package.loaded[modname]</code>,
7631 as if that function has been called through <a href="#pdf-require"><code>require</code></a>.
7635 If <code>glb</code> is true,
7636 also stores the module into the global <code>modname</code>.
7646 <hr><h3><a name="luaL_setfuncs"><code>luaL_setfuncs</code></a></h3><p>
7651 Registers all functions in the array <code>l</code>
7652 (see <a href="#luaL_Reg"><code>luaL_Reg</code></a>) into the table on the top of the stack
7657 When <code>nup</code> is not zero,
7658 all functions are created with <code>nup</code> upvalues,
7659 initialized with copies of the <code>nup</code> values
7666 A function with a <code>NULL</code> value represents a placeholder,
7673 <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p>
7679 as the metatable associated with name <code>tname</code>
7680 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
7686 <hr><h3><a name="luaL_Stream"><code>luaL_Stream</code></a></h3>
7699 with a metatable called <code>LUA_FILEHANDLE</code>
7700 (where <code>LUA_FILEHANDLE</code> is a macro with the actual metatable's name).
7702 (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
7706 This userdata must start with the structure <code>luaL_Stream</code>;
7708 The field <code>f</code> points to the corresponding C stream
7709 (or it can be <code>NULL</code> to indicate an incompletely created handle).
7710 The field <code>closef</code> points to a Lua function
7717 it changes the field value to <code>NULL</code>
7724 <hr><h3><a name="luaL_testudata"><code>luaL_testudata</code></a></h3><p>
7729 This function works like <a href="#luaL_checkudata"><code>luaL_checkudata</code></a>,
7731 it returns <code>NULL</code> instead of raising an error.
7737 <hr><h3><a name="luaL_tolstring"><code>luaL_tolstring</code></a></h3><p>
7746 If <code>len</code> is not <code>NULL</code>,
7747 the function also sets <code>*len</code> with the string length.
7751 If the value has a metatable with a <code>__tostring</code> field,
7752 then <code>luaL_tolstring</code> calls the corresponding metamethod
7760 <hr><h3><a name="luaL_traceback"><code>luaL_traceback</code></a></h3><p>
7766 Creates and pushes a traceback of the stack <code>L1</code>.
7767 If <code>msg</code> is not <code>NULL</code>, it is appended
7769 The <code>level</code> parameter tells at which level
7776 <hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p>
7781 Raises a type error for the argument <code>arg</code>
7784 <code>tname</code> is a "name" for the expected type.
7791 <hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p>
7802 <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p>
7807 Releases the reference <code>ref</code> from the table at index <code>t</code>
7808 (see <a href="#luaL_ref"><code>luaL_ref</code></a>).
7811 The reference <code>ref</code> is also freed to be used again.
7815 If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a href="#pdf-LUA_REF…
7816 <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
7822 <hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3><p>
7828 of the control at level <code>lvl</code> in the call stack.
7856 (e.g., <a href="#pdf-type"><code>type</code></a> and <a href="#pdf-getmetatable"><code>getmetatable…
7860 deserve an implementation in C (e.g., <a href="#pdf-table.sort"><code>table.sort</code></a>).
7869 For instance, a function documented as <code>foo(arg)</code>
7879 with <code>(not status)</code>, instead of <code>(status == nil)</code>.)
7915 the C&nbsp;host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> fun…
7919 <a href="#luaL_requiref"><code>luaL_requiref</code></a> to call
7920 <a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),
7921 <a name="pdf-luaopen_package"><code>luaopen_package</code></a> (for the package library),
7922 <a name="pdf-luaopen_coroutine"><code>luaopen_coroutine</code></a> (for the coroutine library),
7923 <a name="pdf-luaopen_string"><code>luaopen_string</code></a> (for the string library),
7924 <a name="pdf-luaopen_utf8"><code>luaopen_utf8</code></a> (for the UTF-8 library),
7925 <a name="pdf-luaopen_table"><code>luaopen_table</code></a> (for the table library),
7926 <a name="pdf-luaopen_math"><code>luaopen_math</code></a> (for the mathematical library),
7927 <a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O library),
7928 <a name="pdf-luaopen_os"><code>luaopen_os</code></a> (for the operating system library),
7929 and <a name="pdf-luaopen_debug"><code>luaopen_debug</code></a> (for the debug library).
7930 These functions are declared in <a name="pdf-lualib.h"><code>lualib.h</code></a>.
7946 <hr><h3><a name="pdf-assert"><code>assert (v [, message])</code></a></h3>
7951 the value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);
7954 <code>message</code> is the error object;
7955 when absent, it defaults to "<code>assertion failed!</code>"
7961 <hr><h3><a name="pdf-collectgarbage"><code>collectgarbage ([opt [, arg]])</code></a></h3>
7966 It performs different functions according to its first argument, <code>opt</code>:
7970 <li><b>"<code>collect</code>": </b>
7975 <li><b>"<code>stop</code>": </b>
7981 <li><b>"<code>restart</code>": </b>
7985 <li><b>"<code>count</code>": </b>
7992 <li><b>"<code>step</code>": </b>
7994 The step "size" is controlled by <code>arg</code>.
8003 <li><b>"<code>isrunning</code>": </b>
8008 <li><b>"<code>incremental</code>": </b>
8017 <li><b>"<code>generational</code>": </b>
8037 <hr><h3><a name="pdf-dofile"><code>dofile ([filename])</code></a></h3>
8040 <code>dofile</code> executes the content of the standard input (<code>stdin</code>).
8042 In case of errors, <code>dofile</code> propagates the error
8044 (That is, <code>dofile</code> does not run in protected mode.)
8050 <hr><h3><a name="pdf-error"><code>error (message [, level])</code></a></h3>
8051 Raises an error (see <a href="#2.3">&sect;2.3</a>) with <code>message</code> as the error object.
8056 Usually, <code>error</code> adds some information about the error position
8058 The <code>level</code> argument specifies how to get the error position.
8060 <code>error</code> function was called.
8062 that called <code>error</code> was called; and so on.
8070 <hr><h3><a name="pdf-_G"><code>_G</code></a></h3>
8081 <hr><h3><a name="pdf-getmetatable"><code>getmetatable (object)</code></a></h3>
8085 If <code>object</code> does not have a metatable, returns <b>nil</b>.
8087 if the object's metatable has a <code>__metatable</code> field,
8095 <hr><h3><a name="pdf-ipairs"><code>ipairs (t)</code></a></h3>
8099 Returns three values (an iterator function, the table <code>t</code>, and 0)
8106 (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
8113 <hr><h3><a name="pdf-load"><code>load (chunk [, chunkname [, mode [, env]]])</code></a></h3>
8121 If <code>chunk</code> is a string, the chunk is this string.
8122 If <code>chunk</code> is a function,
8123 <code>load</code> calls it repeatedly to get the chunk pieces.
8124 Each call to <code>chunk</code> must return a string that concatenates
8131 <code>load</code> returns the compiled chunk as a function;
8138 the <code>_ENV</code> variable (see <a href="#2.2">&sect;2.2</a>).
8140 …binary chunk created from a function (see <a href="#pdf-string.dump"><code>string.dump</code></a>),
8143 the <code>_ENV</code> variable.
8144 (A non-main function may not even have an <code>_ENV</code> upvalue.)
8149 its first upvalue is set to the value of <code>env</code>,
8158 <code>chunkname</code> is used as the name of the chunk for error messages
8161 it defaults to <code>chunk</code>, if <code>chunk</code> is a string,
8162 or to "<code>=(load)</code>" otherwise.
8166 The string <code>mode</code> controls whether the chunk can be text or binary
8168 It may be the string "<code>b</code>" (only binary chunks),
8169 "<code>t</code>" (only text chunks),
8170 or "<code>bt</code>" (both binary and text).
8171 The default is "<code>bt</code>".
8176 <code>load</code> signals an appropriate error.
8178 Lua does not check the consistency of the code inside binary chunks;
8185 <hr><h3><a name="pdf-loadfile"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>
8189 Similar to <a href="#pdf-load"><code>load</code></a>,
8190 but gets the chunk from file <code>filename</code>
8198 <hr><h3><a name="pdf-next"><code>next (table [, index])</code></a></h3>
8205 A call to <code>next</code> returns the next index of the table
8208 <code>next</code> returns an initial index
8212 <code>next</code> returns <b>nil</b>.
8215 you can use <code>next(t)</code> to check whether a table is empty.
8235 <hr><h3><a name="pdf-pairs"><code>pairs (t)</code></a></h3>
8239 If <code>t</code> has a metamethod <code>__pairs</code>,
8240 calls it with <code>t</code> as argument and returns the first three
8246 returns three values: the <a href="#pdf-next"><code>next</code></a> function, the table <code>t</co…
8252 will iterate over all key&ndash;value pairs of table <code>t</code>.
8256 See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
8263 <hr><h3><a name="pdf-pcall"><code>pcall (f [, arg1, &middot;&middot;&middot;])</code></a></h3>
8267 Calls the function <code>f</code> with
8269 This means that any error inside&nbsp;<code>f</code> is not propagated;
8270 instead, <code>pcall</code> catches the error
8271 and returns a status code.
8272 Its first result is the status code (a boolean),
8274 In such case, <code>pcall</code> also returns all results from the call,
8276 In case of any error, <code>pcall</code> returns <b>false</b> plus the error object.
8277 Note that errors caught by <code>pcall</code> do not call a message handler.
8283 <hr><h3><a name="pdf-print"><code>print (&middot;&middot;&middot;)</code></a></h3>
8285 and prints their values to <code>stdout</code>,
8287 following the same rules of <a href="#pdf-tostring"><code>tostring</code></a>.
8291 The function <code>print</code> is not intended for formatted output,
8295 use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>i…
8301 <hr><h3><a name="pdf-rawequal"><code>rawequal (v1, v2)</code></a></h3>
8302 Checks whether <code>v1</code> is equal to <code>v2</code>,
8303 without invoking the <code>__eq</code> metamethod.
8310 <hr><h3><a name="pdf-rawget"><code>rawget (table, index)</code></a></h3>
8311 Gets the real value of <code>table[index]</code>,
8312 without using the <code>__index</code> metavalue.
8313 <code>table</code> must be a table;
8314 <code>index</code> may be any value.
8320 <hr><h3><a name="pdf-rawlen"><code>rawlen (v)</code></a></h3>
8321 Returns the length of the object <code>v</code>,
8323 without invoking the <code>__len</code> metamethod.
8330 <hr><h3><a name="pdf-rawset"><code>rawset (table, index, value)</code></a></h3>
8331 Sets the real value of <code>table[index]</code> to <code>value</code>,
8332 without using the <code>__newindex</code> metavalue.
8333 <code>table</code> must be a table,
8334 <code>index</code> any value different from <b>nil</b> and NaN,
8335 and <code>value</code> any Lua value.
8339 This function returns <code>table</code>.
8345 <hr><h3><a name="pdf-select"><code>select (index, &middot;&middot;&middot;)</code></a></h3>
8349 If <code>index</code> is a number,
8350 returns all arguments after argument number <code>index</code>;
8352 Otherwise, <code>index</code> must be the string <code>"#"</code>,
8353 and <code>select</code> returns the total number of extra arguments it received.
8359 <hr><h3><a name="pdf-setmetatable"><code>setmetatable (table, metatable)</code></a></h3>
8364 If <code>metatable</code> is <b>nil</b>,
8366 If the original metatable has a <code>__metatable</code> field,
8371 This function returns <code>table</code>.
8375 To change the metatable of other types from Lua code,
8382 <hr><h3><a name="pdf-tonumber"><code>tonumber (e [, base])</code></a></h3>
8386 When called with no <code>base</code>,
8387 <code>tonumber</code> tries to convert its argument to a number.
8390 then <code>tonumber</code> returns this number;
8401 When called with <code>base</code>,
8402 then <code>e</code> must be a string to be interpreted as
8405 In bases above&nbsp;10, the letter '<code>A</code>' (in either upper or lower case)
8406 represents&nbsp;10, '<code>B</code>' represents&nbsp;11, and so forth,
8407 with '<code>Z</code>' representing 35.
8408 If the string <code>e</code> is not a valid numeral in the given base,
8415 <hr><h3><a name="pdf-tostring"><code>tostring (v)</code></a></h3>
8424 If the metatable of <code>v</code> has a <code>__tostring</code> field,
8425 then <code>tostring</code> calls the corresponding value
8426 with <code>v</code> as argument,
8428 Otherwise, if the metatable of <code>v</code> has a <code>__name</code> field
8430 <code>tostring</code> may use that string in its final result.
8435 use <a href="#pdf-string.format"><code>string.format</code></a>.
8441 <hr><h3><a name="pdf-type"><code>type (v)</code></a></h3>
8447 "<code>nil</code>" (a string, not the value <b>nil</b>),
8448 "<code>number</code>",
8449 "<code>string</code>",
8450 "<code>boolean</code>",
8451 "<code>table</code>",
8452 "<code>function</code>",
8453 "<code>thread</code>",
8454 and "<code>userdata</code>".
8460 <hr><h3><a name="pdf-_VERSION"><code>_VERSION</code></a></h3>
8466 The current value of this variable is "<code>Lua 5.4</code>".
8472 <hr><h3><a name="pdf-warn"><code>warn (msg1, &middot;&middot;&middot;)</code></a></h3>
8482 a one-piece message starting with '<code>@</code>'
8486 recognizes the control messages "<code>@off</code>",
8488 and "<code>@on</code>", to (re)start the emission;
8495 <hr><h3><a name="pdf-xpcall"><code>xpcall (f, msgh [, arg1, &middot;&middot;&middot;])</code></a></…
8499 This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
8500 except that it sets a new message handler <code>msgh</code>.
8512 which come inside the table <a name="pdf-coroutine"><code>coroutine</code></a>.
8517 <hr><h3><a name="pdf-coroutine.close"><code>coroutine.close (co)</code></a></h3>
8521 Closes coroutine <code>co</code>,
8536 <hr><h3><a name="pdf-coroutine.create"><code>coroutine.create (f)</code></a></h3>
8540 Creates a new coroutine, with body <code>f</code>.
8541 <code>f</code> must be a function.
8543 an object with type <code>"thread"</code>.
8549 <hr><h3><a name="pdf-coroutine.isyieldable"><code>coroutine.isyieldable ([co])</code></a></h3>
8553 Returns <b>true</b> when the coroutine <code>co</code> can yield.
8554 The default for <code>co</code> is the running coroutine.
8565 <hr><h3><a name="pdf-coroutine.resume"><code>coroutine.resume (co [, val1, &middot;&middot;&middot;…
8569 Starts or continues the execution of coroutine <code>co</code>.
8572 The values <code>val1</code>, ... are passed
8575 <code>resume</code> restarts it;
8576 the values <code>val1</code>, ... are passed
8582 <code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>
8586 <code>resume</code> returns <b>false</b> plus the error message.
8592 <hr><h3><a name="pdf-coroutine.running"><code>coroutine.running ()</code></a></h3>
8603 <hr><h3><a name="pdf-coroutine.status"><code>coroutine.status (co)</code></a></h3>
8607 Returns the status of the coroutine <code>co</code>, as a string:
8608 <code>"running"</code>,
8610 (that is, it is the one that called <code>status</code>);
8611 <code>"suspended"</code>, if the coroutine is suspended in a call to <code>yield</code>,
8613 <code>"normal"</code> if the coroutine is active but not running
8615 and <code>"dead"</code> if the coroutine has finished its body function,
8622 <hr><h3><a name="pdf-coroutine.wrap"><code>coroutine.wrap (f)</code></a></h3>
8626 Creates a new coroutine, with body <code>f</code>;
8627 <code>f</code> must be a function.
8630 extra arguments to <code>resume</code>.
8631 The function returns the same values returned by <code>resume</code>,
8640 <hr><h3><a name="pdf-coroutine.yield"><code>coroutine.yield (&middot;&middot;&middot;)</code></a></…
8645 Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>.
8659 <a href="#pdf-require"><code>require</code></a>.
8660 Everything else is exported in the table <a name="pdf-package"><code>package</code></a>.
8664 <hr><h3><a name="pdf-require"><code>require (modname)</code></a></h3>
8669 The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></…
8670 to determine whether <code>modname</code> is already loaded.
8671 If it is, then <code>require</code> returns the value stored
8672 at <code>package.loaded[modname]</code>.
8680 <code>require</code> is guided by the table <a href="#pdf-package.searchers"><code>package.searcher…
8684 we can change how <code>require</code> looks for a module.
8686 for <a href="#pdf-package.searchers"><code>package.searchers</code></a>.
8690 First <code>require</code> queries <code>package.preload[modname]</code>.
8693 Otherwise <code>require</code> searches for a Lua loader using the
8694 path stored in <a href="#pdf-package.path"><code>package.path</code></a>.
8696 path stored in <a href="#pdf-package.cpath"><code>package.cpath</code></a>.
8698 …m>all-in-one</em> loader (see <a href="#pdf-package.searchers"><code>package.searchers</code></a>).
8703 <code>require</code> calls the loader with two arguments:
8704 <code>modname</code> and an extra value,
8713 <code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.
8715 has not assigned any value to <code>package.loaded[modname]</code>,
8716 then <code>require</code> assigns <b>true</b> to this entry.
8717 In any case, <code>require</code> returns the
8718 final value of <code>package.loaded[modname]</code>.
8719 Besides that value, <code>require</code> also returns as a second result
8721 which indicates how <code>require</code> found the module.
8727 then <code>require</code> raises an error.
8733 <hr><h3><a name="pdf-package.config"><code>package.config</code></a></h3>
8743 Default is '<code>\</code>' for Windows and '<code>/</code>' for all other systems.</li>
8746 Default is '<code>;</code>'.</li>
8750 Default is '<code>?</code>'.</li>
8754 Default is '<code>!</code>'.</li>
8757 when building the <code>luaopen_</code> function name.
8758 Default is '<code>-</code>'.</li>
8765 <hr><h3><a name="pdf-package.cpath"><code>package.cpath</code></a></h3>
8769 A string with the path used by <a href="#pdf-require"><code>require</code></a>
8774 Lua initializes the C&nbsp;path <a href="#pdf-package.cpath"><code>package.cpath</code></a> in the …
8775 it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>,
8776 using the environment variable <a name="pdf-LUA_CPATH_5_4"><code>LUA_CPATH_5_4</code></a>,
8777 or the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a>,
8778 or a default path defined in <code>luaconf.h</code>.
8784 <hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3>
8788 A table used by <a href="#pdf-require"><code>require</code></a> to control which
8790 When you require a module <code>modname</code> and
8791 <code>package.loaded[modname]</code> is not false,
8792 <a href="#pdf-require"><code>require</code></a> simply returns the value stored there.
8798 table used by <a href="#pdf-require"><code>require</code></a>.
8800 indexed by the key <a name="pdf-LUA_LOADED_TABLE"><code>LUA_LOADED_TABLE</code></a>, a string.
8806 <hr><h3><a name="pdf-package.loadlib"><code>package.loadlib (libname, funcname)</code></a></h3>
8810 Dynamically links the host program with the C&nbsp;library <code>libname</code>.
8814 If <code>funcname</code> is "<code>*</code>",
8819 it looks for a function <code>funcname</code> inside the library
8821 So, <code>funcname</code> must follow the <a href="#lua_CFunction"><code>lua_CFunction</code></a> p…
8822 (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
8828 Unlike <a href="#pdf-require"><code>require</code></a>,
8831 <code>libname</code> must be the complete file name of the C&nbsp;library,
8833 <code>funcname</code> must be the exact name exported by the C&nbsp;library
8841 plus other Unix systems that support the <code>dlfcn</code> standard).
8850 (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
8859 <hr><h3><a name="pdf-package.path"><code>package.path</code></a></h3>
8863 A string with the path used by <a href="#pdf-require"><code>require</code></a>
8869 the value of the environment variable <a name="pdf-LUA_PATH_5_4"><code>LUA_PATH_5_4</code></a> or
8870 the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or
8871 with a default path defined in <code>luaconf.h</code>,
8873 A "<code>;;</code>" in the value of the environment variable
8880 <hr><h3><a name="pdf-package.preload"><code>package.preload</code></a></h3>
8885 (see <a href="#pdf-require"><code>require</code></a>).
8891 table used by <a href="#pdf-require"><code>require</code></a>.
8893 indexed by the key <a name="pdf-LUA_PRELOAD_TABLE"><code>LUA_PRELOAD_TABLE</code></a>, a string.
8899 <hr><h3><a name="pdf-package.searchers"><code>package.searchers</code></a></h3>
8903 A table used by <a href="#pdf-require"><code>require</code></a> to control how to find modules.
8909 <a href="#pdf-require"><code>require</code></a> calls each of these searchers in ascending order,
8910 with the module name (the argument given to <a href="#pdf-require"><code>require</code></a>) as its
8916 returned as a second result by <a href="#pdf-require"><code>require</code></a>.
8928 <a href="#pdf-package.preload"><code>package.preload</code></a> table.
8933 using the path stored at <a href="#pdf-package.path"><code>package.path</code></a>.
8934 …one as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8939 using the path given by the variable <a href="#pdf-package.cpath"><code>package.cpath</code></a>.
8941 …one as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8948 the searcher for module <code>foo</code>
8949 will try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,
8950 and <code>/usr/local/foo/init.so</code>, in that order.
8956 The name of this C&nbsp;function is the string "<code>luaopen_</code>"
8961 For instance, if the module name is <code>a.b.c-v2.1</code>,
8962 the function name will be <code>luaopen_a_b_c</code>.
8969 For instance, when requiring <code>a.b.c</code>,
8970 it will search for a C&nbsp;library for <code>a</code>.
8973 in our example, that would be <code>luaopen_a_b_c</code>.
8982 as returned by <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8983 The first searcher always returns the string "<code>:preload:</code>".
8995 <hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep [, rep]])</cod…
8999 Searches for the given <code>name</code> in the given <code>path</code>.
9007 in the template with a copy of <code>name</code>
9008 wherein all occurrences of <code>sep</code>
9010 were replaced by <code>rep</code>
9021 the search for the name <code>foo.a</code>
9023 <code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and
9024 <code>/usr/local/foo/a/init.lua</code>, in that order.
9055 <a name="pdf-string"><code>string</code></a>.
9057 where the <code>__index</code> field points to the <code>string</code> table.
9059 For instance, <code>string.byte(s,i)</code>
9060 can be written as <code>s:byte(i)</code>.
9068 <hr><h3><a name="pdf-string.byte"><code>string.byte (s [, i [, j]])</code></a></h3>
9069 Returns the internal numeric codes of the characters <code>s[i]</code>,
9070 <code>s[i+1]</code>, ..., <code>s[j]</code>.
9071 The default value for <code>i</code> is&nbsp;1;
9072 the default value for <code>j</code> is&nbsp;<code>i</code>.
9074 following the same rules of function <a href="#pdf-string.sub"><code>string.sub</code></a>.
9084 <hr><h3><a name="pdf-string.char"><code>string.char (&middot;&middot;&middot;)</code></a></h3>
9087 in which each character has the internal numeric code equal
9098 <hr><h3><a name="pdf-string.dump"><code>string.dump (function [, strip])</code></a></h3>
9105 so that a later <a href="#pdf-load"><code>load</code></a> on this string returns
9107 If <code>strip</code> is a true value,
9117 (See the <a href="#pdf-load"><code>load</code></a> function for details about
9127 <hr><h3><a name="pdf-string.find"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>
9132 <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) in the string <code>s</code>.
9133 If it finds a match, then <code>find</code> returns the indices of&nbsp;<code>s</code>
9136 A third, optional numeric argument <code>init</code> specifies
9139 A <b>true</b> as a fourth, optional argument <code>plain</code>
9142 with no characters in <code>pattern</code> being considered magic.
9155 <hr><h3><a name="pdf-string.format"><code>string.format (formatstring, &middot;&middot;&middot;)</c…
9162 The format string follows the same rules as the ISO&nbsp;C function <code>sprintf</code>.
9164 <code>F</code>, <code>n</code>, <code>*</code>, <code>h</code>, <code>L</code>, and <code>l</code> …
9165 and that there is an extra specifier, <code>q</code>.
9171 The specifier <code>q</code> formats booleans, nil, numbers, and strings
9172 in a way that the result is a valid constant in Lua source code.
9174 (<code>true</code>, <code>false</code>, <code>nil</code>).
9196 <code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,
9197 <code>G</code>, and <code>g</code> all expect a number as argument.
9198 The specifiers <code>c</code>, <code>d</code>,
9199 <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>
9202 the specifiers <code>A</code> and <code>a</code> (hexadecimal floats)
9207 The specifier <code>s</code> expects a string;
9209 it is converted to one following the same rules of <a href="#pdf-tostring"><code>tostring</code></a…
9215 The specifier <code>p</code> formats the pointer
9216 returned by <a href="#lua_topointer"><code>lua_topointer</code></a>.
9221 the pointer <code>NULL</code>.
9227 <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern [, init])</code></a></h3>
9230 returns the next captures from <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>)
9231 over the string <code>s</code>.
9232 If <code>pattern</code> specifies no captures,
9234 A third, optional numeric argument <code>init</code> specifies
9241 will iterate over all the words from string <code>s</code>,
9250 The next example collects all pairs <code>key=value</code> from the
9262 For this function, a caret '<code>^</code>' at the start of a pattern does not
9269 <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>
9270 Returns a copy of <code>s</code>
9271 in which all (or the first <code>n</code>, if given)
9272 occurrences of the <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) have been
9273 replaced by a replacement string specified by <code>repl</code>,
9275 <code>gsub</code> also returns, as its second value,
9277 The name <code>gsub</code> comes from <em>Global SUBstitution</em>.
9281 If <code>repl</code> is a string, then its value is used for replacement.
9282 The character&nbsp;<code>%</code> works as an escape character:
9283 any sequence in <code>repl</code> of the form <code>%<em>d</em></code>,
9286 the sequence <code>%0</code> stands for the whole match;
9287 the sequence <code>%%</code> stands for a single&nbsp;<code>%</code>.
9291 If <code>repl</code> is a table, then the table is queried for every match,
9296 If <code>repl</code> is a function, then this function is called every time a
9345 <hr><h3><a name="pdf-string.len"><code>string.len (s)</code></a></h3>
9350 The empty string <code>""</code> has length 0.
9352 so <code>"a\000bc\000"</code> has length 5.
9358 <hr><h3><a name="pdf-string.lower"><code>string.lower (s)</code></a></h3>
9371 <hr><h3><a name="pdf-string.match"><code>string.match (s, pattern [, init])</code></a></h3>
9376 the <code>pattern</code> (see <a href="#6.4.1">&sect;6.4.1</a>) in the string <code>s</code>.
9377 If it finds one, then <code>match</code> returns
9380 If <code>pattern</code> specifies no captures,
9382 A third, optional numeric argument <code>init</code> specifies
9390 <hr><h3><a name="pdf-string.pack"><code>string.pack (fmt, v1, v2, &middot;&middot;&middot;)</code><…
9394 Returns a binary string containing the values <code>v1</code>, <code>v2</code>, etc.
9396 according to the format string <code>fmt</code> (see <a href="#6.4.2">&sect;6.4.2</a>).
9402 <hr><h3><a name="pdf-string.packsize"><code>string.packsize (fmt)</code></a></h3>
9406 Returns the length of a string resulting from <a href="#pdf-string.pack"><code>string.pack</code></…
9409 '<code>s</code>' or '<code>z</code>' (see <a href="#6.4.2">&sect;6.4.2</a>).
9415 <hr><h3><a name="pdf-string.rep"><code>string.rep (s, n [, sep])</code></a></h3>
9419 Returns a string that is the concatenation of <code>n</code> copies of
9420 the string <code>s</code> separated by the string <code>sep</code>.
9421 The default value for <code>sep</code> is the empty string
9423 Returns the empty string if <code>n</code> is not positive.
9434 <hr><h3><a name="pdf-string.reverse"><code>string.reverse (s)</code></a></h3>
9438 Returns a string that is the string <code>s</code> reversed.
9444 <hr><h3><a name="pdf-string.sub"><code>string.sub (s, i [, j])</code></a></h3>
9448 Returns the substring of <code>s</code> that
9449 starts at <code>i</code> and continues until <code>j</code>;
9450 <code>i</code> and <code>j</code> can be negative.
9451 If <code>j</code> is absent, then it is assumed to be equal to -1
9454 the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>
9455 with length <code>j</code>,
9456 and <code>string.sub(s, -i)</code> (for a positive <code>i</code>)
9457 returns a suffix of <code>s</code>
9458 with length <code>i</code>.
9463 <code>i</code> is less than 1,
9465 If <code>j</code> is greater than the string length,
9468 <code>i</code> is greater than <code>j</code>,
9475 <hr><h3><a name="pdf-string.unpack"><code>string.unpack (fmt, s [, pos])</code></a></h3>
9479 Returns the values packed in string <code>s</code> (see <a href="#pdf-string.pack"><code>string.pac…
9480 according to the format string <code>fmt</code> (see <a href="#6.4.2">&sect;6.4.2</a>).
9481 An optional <code>pos</code> marks where
9482 to start reading in <code>s</code> (default is 1).
9484 this function also returns the index of the first unread byte in <code>s</code>.
9490 <hr><h3><a name="pdf-string.upper"><code>string.upper (s)</code></a></h3>
9512 <a href="#pdf-string.find"><code>string.find</code></a>,
9513 <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>,
9514 <a href="#pdf-string.gsub"><code>string.gsub</code></a>,
9515 and <a href="#pdf-string.match"><code>string.match</code></a>.
9531 <code>^$()%.[]*+-?</code>)
9535 <li><b><code>.</code>: </b> (a dot) represents all characters.</li>
9537 <li><b><code>%a</code>: </b> represents all letters.</li>
9539 <li><b><code>%c</code>: </b> represents all control characters.</li>
9541 <li><b><code>%d</code>: </b> represents all digits.</li>
9543 <li><b><code>%g</code>: </b> represents all printable characters except space.</li>
9545 <li><b><code>%l</code>: </b> represents all lowercase letters.</li>
9547 <li><b><code>%p</code>: </b> represents all punctuation characters.</li>
9549 <li><b><code>%s</code>: </b> represents all space characters.</li>
9551 <li><b><code>%u</code>: </b> represents all uppercase letters.</li>
9553 <li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>
9555 <li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>
9557 <li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)
9562 can be preceded by a '<code>%</code>' to represent itself in a pattern.
9565 <li><b><code>[<em>set</em>]</code>: </b>
9570 in ascending order, with a '<code>-</code>'.
9571 All classes <code>%</code><em>x</em> described above can also be used as
9574 For example, <code>[%w_]</code> (or <code>[_%w]</code>)
9576 <code>[0-7]</code> represents the octal digits,
9577 and <code>[0-7%l%-]</code> represents the octal digits plus
9578 the lowercase letters plus the '<code>-</code>' character.
9591 Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>
9595 <li><b><code>[^<em>set</em>]</code>: </b>
9601 For all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),
9603 For instance, <code>%S</code> represents all non-space characters.
9609 In particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.
9626 a single character class followed by '<code>*</code>',
9632 a single character class followed by '<code>+</code>',
9638 a single character class followed by '<code>-</code>',
9640 Unlike '<code>*</code>',
9645 a single character class followed by '<code>?</code>',
9651 <code>%<em>n</em></code>, for <em>n</em> between 1 and 9;
9657 <code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;
9663 For instance, the item <code>%b()</code> matches expressions with
9668 <code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>;
9674 they were the character '<code>\0</code>'.
9684 A caret '<code>^</code>' at the beginning of a pattern anchors the match at the
9686 A '<code>$</code>' at the end of a pattern anchors the match at the
9689 '<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.
9701 For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>,
9702 the part of the string matching <code>"a*(.)%w(%s*)"</code> is
9704 the character matching "<code>.</code>" is captured with number&nbsp;2,
9705 and the part matching "<code>%s*</code>" has number&nbsp;3.
9709 As a special case, the capture <code>()</code> captures
9711 For instance, if we apply the pattern <code>"()aa()"</code> on the
9712 string <code>"flaaap"</code>, there will be two captures: 3&nbsp;and&nbsp;5.
9719 …a href="#pdf-string.gsub"><code>string.gsub</code></a> and the iterator <a href="#pdf-string.gmatc…
9727 consider the results of the following code:
9736 string after '<code>b</code>' and another one after '<code>c</code>'.
9737 Lua does not match an empty string after '<code>a</code>',
9749 The first argument to <a href="#pdf-string.pack"><code>string.pack</code></a>,
9750 …a href="#pdf-string.packsize"><code>string.packsize</code></a>, and <a href="#pdf-string.unpack"><
9760 <li><b><code>&lt;</code>: </b>sets little endian</li>
9761 <li><b><code>&gt;</code>: </b>sets big endian</li>
9762 <li><b><code>=</code>: </b>sets native endian</li>
9763 <li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code>
9765 <li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li>
9766 <li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li>
9767 <li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li>
9768 <li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li>
9769 <li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li>
9770 <li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li>
9771 <li><b><code>j</code>: </b>a <code>lua_Integer</code></li>
9772 <li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li>
9773 <li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li>
9774 <li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes
9776 <li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes
9778 <li><b><code>f</code>: </b>a <code>float</code> (native size)</li>
9779 <li><b><code>d</code>: </b>a <code>double</code> (native size)</li>
9780 <li><b><code>n</code>: </b>a <code>lua_Number</code></li>
9781 <li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li>
9782 <li><b><code>z</code>: </b>a zero-terminated string</li>
9783 <li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length
9784 coded as an unsigned integer with <code>n</code> bytes
9785 (default is a <code>size_t</code>)</li>
9786 <li><b><code>x</code>: </b>one byte of padding</li>
9787 <li><b><code>X<em>op</em></code>: </b>an empty item that aligns
9788 according to option <code>op</code>
9790 <li><b>'<code> </code>': </b>(space) ignored</li>
9792 (A "<code>[<em>n</em>]</code>" means an optional integral numeral.)
9794 (options "<code>xX &lt;=&gt;!</code>"),
9795 each option corresponds to an argument in <a href="#pdf-string.pack"><code>string.pack</code></a>
9796 or a result in <a href="#pdf-string.unpack"><code>string.unpack</code></a>.
9800 For options "<code>!<em>n</em></code>", "<code>s<em>n</em></code>", "<code>i<em>n</em></code>", and…
9801 <code>n</code> can be any integer between 1 and 16.
9803 <a href="#pdf-string.pack"><code>string.pack</code></a> checks whether the given value fits in the …
9804 <a href="#pdf-string.unpack"><code>string.unpack</code></a> checks whether the read value fits in a…
9810 Any format string starts as if prefixed by "<code>!1=</code>",
9830 Options "<code>c</code>" and "<code>z</code>" are not aligned;
9831 option "<code>s</code>" follows the alignment of its starting integer.
9835 All padding is filled with zeros by <a href="#pdf-string.pack"><code>string.pack</code></a>
9836 and ignored by <a href="#pdf-string.unpack"><code>string.unpack</code></a>.
9848 It provides all its functions inside the table <a name="pdf-utf8"><code>utf8</code></a>.
9866 accept all values up to <code>0x7FFFFFFF</code>,
9875 that result in valid Unicode code points,
9876 rejecting values greater than <code>10FFFF</code> and surrogates.
9877 A boolean argument <code>lax</code>, when available,
9879 so that all values up to <code>0x7FFFFFFF</code> are accepted.
9884 <hr><h3><a name="pdf-utf8.char"><code>utf8.char (&middot;&middot;&middot;)</code></a></h3>
9896 <hr><h3><a name="pdf-utf8.charpattern"><code>utf8.charpattern</code></a></h3>
9900 The pattern (a string, not a function) "<code>[\0-\x7F\xC2-\xFD][\x80-\xBF]*</code>"
9909 <hr><h3><a name="pdf-utf8.codes"><code>utf8.codes (s [, lax])</code></a></h3>
9918 will iterate over all UTF-8 characters in string <code>s</code>,
9919 with <code>p</code> being the position (in bytes) and <code>c</code> the code point
9927 <hr><h3><a name="pdf-utf8.codepoint"><code>utf8.codepoint (s [, i [, j [, lax]]])</code></a></h3>
9931 Returns the code points (as integers) from all characters in <code>s</code>
9932 that start between byte position <code>i</code> and <code>j</code> (both included).
9933 The default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>.
9940 <hr><h3><a name="pdf-utf8.len"><code>utf8.len (s [, i [, j [, lax]]])</code></a></h3>
9944 Returns the number of UTF-8 characters in string <code>s</code>
9945 that start between positions <code>i</code> and <code>j</code> (both inclusive).
9946 The default for <code>i</code> is 1 and for <code>j</code> is -1.
9954 <hr><h3><a name="pdf-utf8.offset"><code>utf8.offset (s, n [, i])</code></a></h3>
9959 <code>n</code>-th character of <code>s</code>
9960 (counting from position <code>i</code>) starts.
9961 A negative <code>n</code> gets characters before position <code>i</code>.
9962 The default for <code>i</code> is 1 when <code>n</code> is non-negative
9963 and <code>#s + 1</code> otherwise,
9964 so that <code>utf8.offset(s, -n)</code> gets the offset of the
9965 <code>n</code>-th character from the end of the string.
9973 when <code>n</code> is 0 the function returns the start of the encoding
9974 of the character that contains the <code>i</code>-th byte of <code>s</code>.
9978 This function assumes that <code>s</code> is a valid UTF-8 string.
9990 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>.
10001 <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>
10006 returns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.
10007 The default value for <code>sep</code> is the empty string,
10008 the default for <code>i</code> is 1,
10009 and the default for <code>j</code> is <code>#list</code>.
10010 If <code>i</code> is greater than <code>j</code>, returns the empty string.
10016 <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3>
10020 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>,
10022 <code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.
10023 The default value for <code>pos</code> is <code>#list+1</code>,
10024 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
10025 of the list <code>t</code>.
10031 <hr><h3><a name="pdf-table.move"><code>table.move (a1, f, e, t [,a2])</code></a></h3>
10035 Moves elements from the table <code>a1</code> to the table <code>a2</code>,
10038 <code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.
10039 The default for <code>a2</code> is <code>a1</code>.
10045 Returns the destination table <code>a2</code>.
10051 <hr><h3><a name="pdf-table.pack"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>
10056 and with a field "<code>n</code>" with the total number of arguments.
10064 <hr><h3><a name="pdf-table.remove"><code>table.remove (list [, pos])</code></a></h3>
10068 Removes from <code>list</code> the element at position <code>pos</code>,
10070 When <code>pos</code> is an integer between 1 and <code>#list</code>,
10072 <code>list[pos+1], list[pos+2], &middot;&middot;&middot;, list[#list]</code>
10073 and erases element <code>list[#list]</code>;
10074 The index <code>pos</code> can also be 0 when <code>#list</code> is 0,
10075 or <code>#list + 1</code>.
10079 The default value for <code>pos</code> is <code>#list</code>,
10080 so that a call <code>table.remove(l)</code> removes the last element
10081 of the list <code>l</code>.
10087 <hr><h3><a name="pdf-table.sort"><code>table.sort (list [, comp])</code></a></h3>
10092 from <code>list[1]</code> to <code>list[#list]</code>.
10093 If <code>comp</code> is given,
10098 <code>i &lt;= j</code> implies <code>not comp(list[j],list[i])</code>.
10099 If <code>comp</code> is not given,
10100 then the standard Lua operator <code>&lt;</code> is used instead.
10104 The <code>comp</code> function must define a consistent order;
10119 <hr><h3><a name="pdf-table.unpack"><code>table.unpack (list [, i [, j]])</code></a></h3>
10129 By default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.
10141 It provides all its functions and constants inside the table <a name="pdf-math"><code>math</code></…
10142 Functions with the annotation "<code>integer/float</code>" give
10146 …th.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a…
10152 <hr><h3><a name="pdf-math.abs"><code>math.abs (x)</code></a></h3>
10156 Returns the maximum value between <code>x</code> and <code>-x</code>. (integer/float)
10162 <hr><h3><a name="pdf-math.acos"><code>math.acos (x)</code></a></h3>
10166 Returns the arc cosine of <code>x</code> (in radians).
10172 <hr><h3><a name="pdf-math.asin"><code>math.asin (x)</code></a></h3>
10176 Returns the arc sine of <code>x</code> (in radians).
10182 <hr><h3><a name="pdf-math.atan"><code>math.atan (y [, x])</code></a></h3>
10187 Returns the arc tangent of <code>y/x</code> (in radians),
10190 It also handles correctly the case of <code>x</code> being zero.
10194 The default value for <code>x</code> is 1,
10195 so that the call <code>math.atan(y)</code>
10196 returns the arc tangent of <code>y</code>.
10202 <hr><h3><a name="pdf-math.ceil"><code>math.ceil (x)</code></a></h3>
10206 Returns the smallest integral value greater than or equal to <code>x</code>.
10212 <hr><h3><a name="pdf-math.cos"><code>math.cos (x)</code></a></h3>
10216 Returns the cosine of <code>x</code> (assumed to be in radians).
10222 <hr><h3><a name="pdf-math.deg"><code>math.deg (x)</code></a></h3>
10226 Converts the angle <code>x</code> from radians to degrees.
10232 <hr><h3><a name="pdf-math.exp"><code>math.exp (x)</code></a></h3>
10237 (where <code>e</code> is the base of natural logarithms).
10243 <hr><h3><a name="pdf-math.floor"><code>math.floor (x)</code></a></h3>
10247 Returns the largest integral value less than or equal to <code>x</code>.
10253 <hr><h3><a name="pdf-math.fmod"><code>math.fmod (x, y)</code></a></h3>
10257 Returns the remainder of the division of <code>x</code> by <code>y</code>
10264 <hr><h3><a name="pdf-math.huge"><code>math.huge</code></a></h3>
10268 The float value <code>HUGE_VAL</code>,
10275 <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3>
10279 Returns the logarithm of <code>x</code> in the given base.
10280 The default for <code>base</code> is <em>e</em>
10281 (so that the function returns the natural logarithm of <code>x</code>).
10287 <hr><h3><a name="pdf-math.max"><code>math.max (x, &middot;&middot;&middot;)</code></a></h3>
10292 according to the Lua operator <code>&lt;</code>.
10298 <hr><h3><a name="pdf-math.maxinteger"><code>math.maxinteger</code></a></h3>
10305 <hr><h3><a name="pdf-math.min"><code>math.min (x, &middot;&middot;&middot;)</code></a></h3>
10310 according to the Lua operator <code>&lt;</code>.
10316 <hr><h3><a name="pdf-math.mininteger"><code>math.mininteger</code></a></h3>
10323 <hr><h3><a name="pdf-math.modf"><code>math.modf (x)</code></a></h3>
10327 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>.
10334 <hr><h3><a name="pdf-math.pi"><code>math.pi</code></a></h3>
10344 <hr><h3><a name="pdf-math.rad"><code>math.rad (x)</code></a></h3>
10348 Converts the angle <code>x</code> from degrees to radians.
10354 <hr><h3><a name="pdf-math.random"><code>math.random ([m [, n]])</code></a></h3>
10361 When called with two integers <code>m</code> and <code>n</code>,
10362 <code>math.random</code> returns a pseudo-random integer
10364 The call <code>math.random(n)</code>, for a positive <code>n</code>,
10365 is equivalent to <code>math.random(1,n)</code>.
10366 The call <code>math.random(0)</code> produces an integer with
10371 This function uses the <code>xoshiro256**</code> algorithm to produce
10380 a call to <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with no arguments,
10381 so that <code>math.random</code> should generate
10388 <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed ([x [, y]])</code></a></h3>
10393 the integer parameters <code>x</code> and <code>y</code> are
10397 The default for <code>y</code> is zero.
10416 you should call <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with explicit argum…
10422 <hr><h3><a name="pdf-math.sin"><code>math.sin (x)</code></a></h3>
10426 Returns the sine of <code>x</code> (assumed to be in radians).
10432 <hr><h3><a name="pdf-math.sqrt"><code>math.sqrt (x)</code></a></h3>
10436 Returns the square root of <code>x</code>.
10437 (You can also use the expression <code>x^0.5</code> to compute this value.)
10443 <hr><h3><a name="pdf-math.tan"><code>math.tan (x)</code></a></h3>
10447 Returns the tangent of <code>x</code> (assumed to be in radians).
10453 <hr><h3><a name="pdf-math.tointeger"><code>math.tointeger (x)</code></a></h3>
10457 If the value <code>x</code> is convertible to an integer,
10465 <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3>
10469 Returns "<code>integer</code>" if <code>x</code> is an integer,
10470 "<code>float</code>" if it is a float,
10471 or <b>fail</b> if <code>x</code> is not a number.
10477 <hr><h3><a name="pdf-math.ult"><code>math.ult (m, n)</code></a></h3>
10482 <b>true</b> if and only if integer <code>m</code> is below integer <code>n</code> when
10504 all operations are supplied by table <a name="pdf-io"><code>io</code></a>.
10506 the operation <a href="#pdf-io.open"><code>io.open</code></a> returns a file handle
10512 for <code>__gc</code> and <code>__close</code> that try
10517 The table <code>io</code> also provides
10519 …f-io.stdin"><code>io.stdin</code></a>, <a name="pdf-io.stdout"><code>io.stdout</code></a>, and <a …
10527 a system-dependent error code as a third result,
10530 the computation of the error message and error code
10533 because they rely on the global C variable <code>errno</code>.
10537 <hr><h3><a name="pdf-io.close"><code>io.close ([file])</code></a></h3>
10541 Equivalent to <code>file:close()</code>.
10542 Without a <code>file</code>, closes the default output file.
10548 <hr><h3><a name="pdf-io.flush"><code>io.flush ()</code></a></h3>
10552 Equivalent to <code>io.output():flush()</code>.
10558 <hr><h3><a name="pdf-io.input"><code>io.input ([file])</code></a></h3>
10572 instead of returning an error code.
10578 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename, &middot;&middot;&middot;])</code></a></h3>
10584 works like <code>file:lines(&middot;&middot;&middot;)</code> over the opened file.
10588 <code>io.lines</code> returns three other values:
10597 The call <code>io.lines()</code> (with no file name) is equivalent
10598 to <code>io.input():lines("l")</code>;
10606 instead of returning an error code.
10612 <hr><h3><a name="pdf-io.open"><code>io.open (filename [, mode])</code></a></h3>
10617 in the mode specified in the string <code>mode</code>.
10623 The <code>mode</code> string can be any of the following:
10626 <li><b>"<code>r</code>": </b> read mode (the default);</li>
10627 <li><b>"<code>w</code>": </b> write mode;</li>
10628 <li><b>"<code>a</code>": </b> append mode;</li>
10629 <li><b>"<code>r+</code>": </b> update mode, all previous data is preserved;</li>
10630 <li><b>"<code>w+</code>": </b> update mode, all previous data is erased;</li>
10631 <li><b>"<code>a+</code>": </b> append update mode, previous data is preserved,
10634 The <code>mode</code> string can also have a '<code>b</code>' at the end,
10641 <hr><h3><a name="pdf-io.output"><code>io.output ([file])</code></a></h3>
10645 Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output …
10651 <hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3>
10660 Starts the program <code>prog</code> in a separated process and returns
10662 (if <code>mode</code> is <code>"r"</code>, the default)
10664 (if <code>mode</code> is <code>"w"</code>).
10670 <hr><h3><a name="pdf-io.read"><code>io.read (&middot;&middot;&middot;)</code></a></h3>
10674 Equivalent to <code>io.input():read(&middot;&middot;&middot;)</code>.
10680 <hr><h3><a name="pdf-io.tmpfile"><code>io.tmpfile ()</code></a></h3>
10693 <hr><h3><a name="pdf-io.type"><code>io.type (obj)</code></a></h3>
10697 Checks whether <code>obj</code> is a valid file handle.
10698 Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,
10699 <code>"closed file"</code> if <code>obj</code> is a closed file handle,
10700 or <b>fail</b> if <code>obj</code> is not a file handle.
10706 <hr><h3><a name="pdf-io.write"><code>io.write (&middot;&middot;&middot;)</code></a></h3>
10710 Equivalent to <code>io.output():write(&middot;&middot;&middot;)</code>.
10716 <hr><h3><a name="pdf-file:close"><code>file:close ()</code></a></h3>
10720 Closes <code>file</code>.
10727 When closing a file handle created with <a href="#pdf-io.popen"><code>io.popen</code></a>,
10728 <a href="#pdf-file:close"><code>file:close</code></a> returns the same values
10729 returned by <a href="#pdf-os.execute"><code>os.execute</code></a>.
10735 <hr><h3><a name="pdf-file:flush"><code>file:flush ()</code></a></h3>
10739 Saves any written data to <code>file</code>.
10745 <hr><h3><a name="pdf-file:lines"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>
10753 uses "<code>l</code>" as a default.
10761 Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
10768 <hr><h3><a name="pdf-file:read"><code>file:read (&middot;&middot;&middot;)</code></a></h3>
10772 Reads the file <code>file</code>,
10789 <li><b>"<code>n</code>": </b>
10796 (e.g., an empty string, "<code>0x</code>", or "<code>3.4e-</code>")
10801 <li><b>"<code>a</code>": </b>
10807 <li><b>"<code>l</code>": </b>
10813 <li><b>"<code>L</code>": </b>
10821 If <code>number</code> is zero,
10827 The formats "<code>l</code>" and "<code>L</code>" should be used only for text files.
10833 <hr><h3><a name="pdf-file:seek"><code>file:seek ([whence [, offset]])</code></a></h3>
10839 to the position given by <code>offset</code> plus a base
10840 specified by the string <code>whence</code>, as follows:
10843 <li><b>"<code>set</code>": </b> base is position 0 (beginning of the file);</li>
10844 <li><b>"<code>cur</code>": </b> base is current position;</li>
10845 <li><b>"<code>end</code>": </b> base is end of file;</li>
10847 In case of success, <code>seek</code> returns the final file position,
10849 If <code>seek</code> fails, it returns <b>fail</b>,
10854 The default value for <code>whence</code> is <code>"cur"</code>,
10855 and for <code>offset</code> is 0.
10856 Therefore, the call <code>file:seek()</code> returns the current
10858 the call <code>file:seek("set")</code> sets the position to the
10860 and the call <code>file:seek("end")</code> sets the position to the
10867 <hr><h3><a name="pdf-file:setvbuf"><code>file:setvbuf (mode [, size])</code></a></h3>
10875 <li><b>"<code>no</code>": </b> no buffering.</li>
10876 <li><b>"<code>full</code>": </b> full buffering.</li>
10877 <li><b>"<code>line</code>": </b> line buffering.</li>
10882 <code>size</code> is a hint for the size of the buffer, in bytes.
10888 check the underlying ISO&nbsp;C function <code>setvbuf</code> in your platform for
10895 <hr><h3><a name="pdf-file:write"><code>file:write (&middot;&middot;&middot;)</code></a></h3>
10899 Writes the value of each of its arguments to <code>file</code>.
10904 In case of success, this function returns <code>file</code>.
10915 This library is implemented through table <a name="pdf-os"><code>os</code></a>.
10919 <hr><h3><a name="pdf-os.clock"><code>os.clock ()</code></a></h3>
10925 as returned by the underlying ISO&nbsp;C function <code>clock</code>.
10931 <hr><h3><a name="pdf-os.date"><code>os.date ([format [, time]])</code></a></h3>
10936 formatted according to the given string <code>format</code>.
10940 If the <code>time</code> argument is present,
10942 (see the <a href="#pdf-os.time"><code>os.time</code></a> function for a description of this value).
10943 Otherwise, <code>date</code> formats the current time.
10947 If <code>format</code> starts with '<code>!</code>',
10950 if <code>format</code> is the string "<code>*t</code>",
10951 then <code>date</code> returns a table with the following fields:
10952 <code>year</code>, <code>month</code> (1&ndash;12), <code>day</code> (1&ndash;31),
10953 <code>hour</code> (0&ndash;23), <code>min</code> (0&ndash;59),
10954 <code>sec</code> (0&ndash;61, due to leap seconds),
10955 <code>wday</code> (weekday, 1&ndash;7, Sunday is&nbsp;1),
10956 <code>yday</code> (day of the year, 1&ndash;366),
10957 and <code>isdst</code> (daylight saving flag, a boolean).
10963 If <code>format</code> is not "<code>*t</code>",
10964 then <code>date</code> returns the date as a string,
10965 formatted according to the same rules as the ISO&nbsp;C function <code>strftime</code>.
10969 If <code>format</code> is absent, it defaults to "<code>%c</code>",
10977 because of its reliance on C&nbsp;function <code>gmtime</code> and C&nbsp;function <code>localtime<…
10983 <hr><h3><a name="pdf-os.difftime"><code>os.difftime (t2, t1)</code></a></h3>
10988 from time <code>t1</code> to time <code>t2</code>
10989 (where the times are values returned by <a href="#pdf-os.time"><code>os.time</code></a>).
10991 this value is exactly <code>t2</code><em>-</em><code>t1</code>.
10997 <hr><h3><a name="pdf-os.execute"><code>os.execute ([command])</code></a></h3>
11001 This function is equivalent to the ISO&nbsp;C function <code>system</code>.
11002 It passes <code>command</code> to be executed by an operating system shell.
11012 <li><b>"<code>exit</code>": </b>
11017 <li><b>"<code>signal</code>": </b>
11025 When called without a <code>command</code>,
11026 <code>os.execute</code> returns a boolean that is true if a shell is available.
11032 <hr><h3><a name="pdf-os.exit"><code>os.exit ([code [, close]])</code></a></h3>
11036 Calls the ISO&nbsp;C function <code>exit</code> to terminate the host program.
11037 If <code>code</code> is <b>true</b>,
11038 the returned status is <code>EXIT_SUCCESS</code>;
11039 if <code>code</code> is <b>false</b>,
11040 the returned status is <code>EXIT_FAILURE</code>;
11041 if <code>code</code> is a number,
11043 The default value for <code>code</code> is <b>true</b>.
11047 If the optional second argument <code>close</code> is true,
11048 the function closes the Lua state before exiting (see <a href="#lua_close"><code>lua_close</code></…
11054 <hr><h3><a name="pdf-os.getenv"><code>os.getenv (varname)</code></a></h3>
11058 Returns the value of the process environment variable <code>varname</code>
11065 <hr><h3><a name="pdf-os.remove"><code>os.remove (filename)</code></a></h3>
11072 plus a string describing the error and the error code.
11079 <hr><h3><a name="pdf-os.rename"><code>os.rename (oldname, newname)</code></a></h3>
11083 Renames the file or directory named <code>oldname</code> to <code>newname</code>.
11085 plus a string describing the error and the error code.
11092 <hr><h3><a name="pdf-os.setlocale"><code>os.setlocale (locale [, category])</code></a></h3>
11097 <code>locale</code> is a system-dependent string specifying a locale;
11098 <code>category</code> is an optional string describing which category to change:
11099 <code>"all"</code>, <code>"collate"</code>, <code>"ctype"</code>,
11100 <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>;
11101 the default category is <code>"all"</code>.
11107 If <code>locale</code> is the empty string,
11109 If <code>locale</code> is the string "<code>C</code>",
11121 because of its reliance on C&nbsp;function <code>setlocale</code>.
11127 <hr><h3><a name="pdf-os.time"><code>os.time ([table])</code></a></h3>
11133 This table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,
11135 <code>hour</code> (default is 12),
11136 <code>min</code> (default is 0),
11137 <code>sec</code> (default is 0),
11138 and <code>isdst</code> (default is <b>nil</b>).
11140 For a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function.
11146 For instance, if <code>sec</code> is -10,
11148 if <code>hour</code> is 1000,
11158 and the number returned by <code>time</code> can be used only as an argument to
11159 <a href="#pdf-os.date"><code>os.date</code></a> and <a href="#pdf-os.difftime"><code>os.difftime</c…
11164 <code>os.time</code> also normalizes all the fields
11165 documented in the <a href="#pdf-os.date"><code>os.date</code></a> function,
11173 <hr><h3><a name="pdf-os.tmpname"><code>os.tmpname ()</code></a></h3>
11195 you may prefer to use <a href="#pdf-io.tmpfile"><code>io.tmpfile</code></a>,
11211 violate basic assumptions about Lua code
11214 that userdata metatables cannot be changed by Lua code;
11216 and therefore can compromise otherwise secure code.
11222 inside the <a name="pdf-debug"><code>debug</code></a> table.
11230 <hr><h3><a name="pdf-debug.debug"><code>debug.debug ()</code></a></h3>
11239 A line containing only the word <code>cont</code> finishes this function,
11244 Note that commands for <code>debug.debug</code> are not lexically nested
11251 <hr><h3><a name="pdf-debug.gethook"><code>debug.gethook ([thread])</code></a></h3>
11258 as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function.
11268 <hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>
11274 or you can give a number as the value of <code>f</code>,
11275 which means the function running at level <code>f</code> of the call stack
11277 level&nbsp;0 is the current function (<code>getinfo</code> itself);
11278 level&nbsp;1 is the function that called <code>getinfo</code>
11281 If <code>f</code> is a number greater than the number of active functions,
11282 then <code>getinfo</code> returns <b>fail</b>.
11286 …d table can contain all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>,
11287 with the string <code>what</code> describing which fields to fill in.
11288 The default for <code>what</code> is to get all information available,
11290 The option '<code>f</code>'
11291 adds a field named <code>func</code> with the function itself.
11292 The option '<code>L</code>' adds a field named <code>activelines</code>
11300 For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
11303 and the expression <code>debug.getinfo(print)</code>
11305 about the <a href="#pdf-print"><code>print</code></a> function.
11311 <hr><h3><a name="pdf-debug.getlocal"><code>debug.getlocal ([thread,] f, local)</code></a></h3>
11316 with index <code>local</code> of the function at level <code>f</code> of the stack.
11323 following the order that they are declared in the code,
11333 (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the leve…
11337 Variable names starting with '<code>(</code>' (open parenthesis)
11344 The parameter <code>f</code> may also be a function.
11345 In that case, <code>getlocal</code> returns only the name of function parameters.
11351 <hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (value)</code></a></h3>
11355 Returns the metatable of the given <code>value</code>
11362 <hr><h3><a name="pdf-debug.getregistry"><code>debug.getregistry ()</code></a></h3>
11372 <hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (f, up)</code></a></h3>
11377 with index <code>up</code> of the function <code>f</code>.
11389 For C&nbsp;functions, this function uses the empty string <code>""</code>
11394 Variable name '<code>?</code>' (interrogation mark)
11402 <hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u, n)</code></a></h3>
11406 Returns the <code>n</code>-th user value associated
11407 to the userdata <code>u</code> plus a boolean,
11414 <hr><h3><a name="pdf-debug.sethook"><code>debug.sethook ([thread,] hook, mask [, count])</code></a>…
11419 The string <code>mask</code> and the number <code>count</code> describe
11425 <li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li>
11426 <li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>
11427 <li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>
11430 with a <code>count</code> different from zero,
11431 the hook is called also after every <code>count</code> instructions.
11436 <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> turns off the hook.
11442 <code>"call"</code>, <code>"tail call"</code>, <code>"return"</code>,
11443 <code>"line"</code>, and <code>"count"</code>.
11447 you can call <code>getinfo</code> with level&nbsp;2 to get more information about
11449 (Level&nbsp;0 is the <code>getinfo</code> function,
11456 <hr><h3><a name="pdf-debug.setlocal"><code>debug.setlocal ([thread,] level, local, value)</code></a…
11460 This function assigns the value <code>value</code> to the local variable
11461 with index <code>local</code> of the function at level <code>level</code> of the stack.
11464 and raises an error when called with a <code>level</code> out of range.
11465 (You can call <code>getinfo</code> to check whether the level is valid.)
11470 See <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for more information about
11477 <hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (value, table)</code></a></h3>
11481 Sets the metatable for the given <code>value</code> to the given <code>table</code>
11483 Returns <code>value</code>.
11489 <hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (f, up, value)</code></a></h3>
11493 This function assigns the value <code>value</code> to the upvalue
11494 with index <code>up</code> of the function <code>f</code>.
11501 See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about up…
11507 <hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value, n)</code></a></h3>
11511 Sets the given <code>value</code> as
11512 the <code>n</code>-th user value associated to the given <code>udata</code>.
11513 <code>udata</code> must be a full userdata.
11517 Returns <code>udata</code>,
11524 <hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message [, level]])</code><…
11528 If <code>message</code> is present but is neither a string nor <b>nil</b>,
11529 this function returns <code>message</code> without further processing.
11532 The optional <code>message</code> string is appended
11534 An optional <code>level</code> number tells at which level
11536 (default is 1, the function calling <code>traceback</code>).
11542 <hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (f, n)</code></a></h3>
11547 for the upvalue numbered <code>n</code>
11562 <hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>
11566 Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>
11567 refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.
11582 called simply <code>lua</code>,
11594 <li><b><code>-e <em>stat</em></code>: </b> execute string <em>stat</em>;</li>
11595 <li><b><code>-i</code>: </b> enter interactive mode after running <em>script</em>;</li>
11596 <li><b><code>-l <em>mod</em></code>: </b> "require" <em>mod</em> and assign the
11598 <li><b><code>-l <em>g=mod</em></code>: </b> "require" <em>mod</em> and assign the
11600 <li><b><code>-v</code>: </b> print version information;</li>
11601 <li><b><code>-E</code>: </b> ignore environment variables;</li>
11602 <li><b><code>-W</code>: </b> turn warnings on;</li>
11603 <li><b><code>--</code>: </b> stop handling options;</li>
11604 <li><b><code>-</code>: </b> execute <code>stdin</code> as a file and stop handling options.</li>
11606 (The form <code>-l <em>g=mod</em></code> was introduced in release&nbsp;5.4.4.)
11610 After handling its options, <code>lua</code> runs the given <em>script</em>.
11612 <code>lua</code> behaves as <code>lua -v -i</code>
11613 when the standard input (<code>stdin</code>) is a terminal,
11614 and as <code>lua -</code> otherwise.
11618 When called without the option <code>-E</code>,
11619 …rpreter checks for an environment variable <a name="pdf-LUA_INIT_5_4"><code>LUA_INIT_5_4</code></a>
11620 (or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if the versioned name is not defined)
11622 If the variable content has the format <code>@<em>filename</em></code>,
11623 then <code>lua</code> executes the file.
11624 Otherwise, <code>lua</code> executes the string itself.
11628 When called with the option <code>-E</code>,
11631 … of <a href="#pdf-package.path"><code>package.path</code></a> and <a href="#pdf-package.cpath"><co…
11632 are set with the default paths defined in <code>luaconf.h</code>.
11635 <code>"LUA_NOENV"</code> in the registry to a true value.
11640 The options <code>-e</code>, <code>-l</code>, and <code>-W</code> are handled in
11647 will first set <code>a</code> to 1, then require the library <code>lib1</code>,
11648 and finally run the file <code>script.lua</code> with no arguments.
11649 (Here <code>$</code> is the shell prompt. Your prompt may be different.)
11653 Before running any code,
11654 <code>lua</code> collects all command-line arguments
11655 in a global table called <code>arg</code>.
11682 will print "<code>-e</code>".
11685 <code>arg[1]</code>, &middot;&middot;&middot;, <code>arg[#arg]</code>.
11703 If the global variable <a name="pdf-_PROMPT"><code>_PROMPT</code></a> contains a string,
11705 Similarly, if the global variable <a name="pdf-_PROMPT2"><code>_PROMPT2</code></a> contains a strin…
11714 has a metamethod <code>__tostring</code>,
11725 (see <a href="#lua_close"><code>lua_close</code></a>).
11727 calling <a href="#pdf-os.exit"><code>os.exit</code></a> to terminate.
11733 Lua skips the first line of a file chunk if it starts with <code>#</code>.
11735 by using <code>chmod +x</code> and the&nbsp;<code>#!</code> form,
11743 If <code>lua</code> is in your <code>PATH</code>,
11764 appropriate options (see file <code>luaconf.h</code>).
11771 you should try to test your code with a version of Lua compiled
11778 do not imply source-code changes in a program,
11815 For instance, the result of <code>"1" + "2"</code> now is an integer,
11828 The use of the <code>__lt</code> metamethod to emulate <code>__le</code>
11847 Lua does not ignore <code>__gc</code> metamethods that are not functions.
11862 The function <a href="#pdf-print"><code>print</code></a> does not call <a href="#pdf-tostring"><cod…
11865 You should use <code>__tostring</code> to modify how values are printed.
11869 …andom number generator used by the function <a href="#pdf-math.random"><code>math.random</code></a>
11875 By default, the decoding functions in the <a href="#pdf-utf8"><code>utf8</code></a> library
11876 do not accept surrogates as valid code points.
11881 The options "<code>setpause</code>" and "<code>setstepmul</code>"
11882 of the function <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> are deprecated.
11883 You should use the new option "<code>incremental</code>" to set them.
11887 The function <a href="#pdf-io.lines"><code>io.lines</code></a> now returns four values,
11891 such as in <code>load(io.lines(filename, "L"))</code>.
11909 Therefore, the functions <code>lua_newuserdata</code>,
11910 <code>lua_setuservalue</code>, and <code>lua_getuservalue</code> were
11911 replaced by <a href="#lua_newuserdatauv"><code>lua_newuserdatauv</code></a>,
11912 … href="#lua_setiuservalue"><code>lua_setiuservalue</code></a>, and <a href="#lua_getiuservalue"><c…
11924 The function <a href="#lua_resume"><code>lua_resume</code></a> has an extra parameter.
11932 The function <a href="#lua_version"><code>lua_version</code></a> returns the version number,
11941 The constant <code>LUA_ERRGCMM</code> was removed.
11947 The options <code>LUA_GCSETPAUSE</code> and <code>LUA_GCSETSTEPMUL</code>
11948 of the function <a href="#lua_gc"><code>lua_gc</code></a> are deprecated.
11949 You should use the new option <code>LUA_GCINC</code> to set them.