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 functions to be called by Lua code.
94 at Lua's official web site, <code>www.lua.org</code>.
158 (See macro <code>LUA_32BITS</code> in file <code>luaconf.h</code>.)
185 including embedded zeros ('<code>\0</code>').
231 undefined numerical results, such as <code>0/0</code>.)
245 providing <code>a.name</code> as syntactic sugar for <code>a["name"]</code>.
262 The expressions <code>a[i]</code> and <code>a[j]</code>
264 if and only if <code>i</code> and <code>j</code> are raw equal
268 (e.g., <code>1.0 == 1</code>).
272 For instance, if you write <code>a[2.0] = true</code>,
273 the actual key inserted into the table will be the integer <code>2</code>.
286 The library function <a href="#pdf-type"><code>type</code></a> returns a string describing the type
287 of a given value (see <a href="#pdf-type"><code>type</code></a>).
298 (that is, a name not bound to any declaration) <code>var</code>
299 is syntactically translated to <code>_ENV.var</code>.
301 an external local variable named <code>_ENV</code> (see <a href="#3.3.2">§3.3.2</a>),
302 so <code>_ENV</code> itself is never a free name in a chunk.
306 Despite the existence of this external <code>_ENV</code> variable and
308 <code>_ENV</code> is a completely regular name.
311 Each reference to a free name uses the <code>_ENV</code> that is
317 Any table used as the value of <code>_ENV</code> is called an <em>environment</em>.
323 In Lua, the global variable <a href="#pdf-_G"><code>_G</code></a> is initialized with this same val…
324 (<a href="#pdf-_G"><code>_G</code></a> is never used internally,
325 so changing its value will affect only your own code.)
330 the default value for its <code>_ENV</code> variable
331 is the global environment (see <a href="#pdf-load"><code>load</code></a>).
333 free names in Lua code refer to entries in the global environment
337 You can use <a href="#pdf-load"><code>load</code></a> (or <a href="#pdf-loadfile"><code>loadfile</c…
340 of its first upvalue; see <a href="#lua_setupvalue"><code>lua_setupvalue</code></a>.)
355 Lua code can explicitly raise an error by calling the
356 <a href="#pdf-error"><code>error</code></a> function.
363 using <a href="#pdf-pcall"><code>pcall</code></a> (or <a href="#pdf-xpcall"><code>xpcall</code></a>…
364 The function <a href="#pdf-pcall"><code>pcall</code></a> calls a given function in <em>protected mo…
366 and control returns immediately to <code>pcall</code>,
367 which returns a status code.
372 Lua code starts running by a call
373 from C code in the host program.
375 the <code>lua</code> application is the host program.)
398 When you use <a href="#pdf-xpcall"><code>xpcall</code></a> (or <a href="#lua_pcall"><code>lua_pcall…
417 Lua also offers a system of <em>warnings</em> (see <a href="#pdf-warn"><code>warn</code></a>).
421 although this behavior can be adapted from C (see <a href="#lua_setwarnf"><code>lua_setwarnf</code>…
437 Lua checks for a function in the field "<code>__add</code>" of the value's metatable.
448 In the previous example, the key is the string "<code>__add</code>"
452 which is either a function or a value with a <code>__call</code> metamethod.
457 using the <a href="#pdf-getmetatable"><code>getmetatable</code></a> function.
458 …s metamethods in metatables using a raw access (see <a href="#pdf-rawget"><code>rawget</code></a>).
463 using the <a href="#pdf-setmetatable"><code>setmetatable</code></a> function.
464 You cannot change the metatable of other types from Lua code,
488 <li><b><code>__add</code>: </b>
489 the addition (<code>+</code>) operation.
493 if that operand does not define a metamethod for <code>__add</code>,
504 <li><b><code>__sub</code>: </b>
505 the subtraction (<code>-</code>) operation.
509 <li><b><code>__mul</code>: </b>
510 the multiplication (<code>*</code>) operation.
514 <li><b><code>__div</code>: </b>
515 the division (<code>/</code>) operation.
519 <li><b><code>__mod</code>: </b>
520 the modulo (<code>%</code>) operation.
524 <li><b><code>__pow</code>: </b>
525 the exponentiation (<code>^</code>) operation.
529 <li><b><code>__unm</code>: </b>
530 the negation (unary <code>-</code>) operation.
534 <li><b><code>__idiv</code>: </b>
535 the floor division (<code>//</code>) operation.
539 <li><b><code>__band</code>: </b>
540 the bitwise AND (<code>&</code>) operation.
547 <li><b><code>__bor</code>: </b>
548 the bitwise OR (<code>|</code>) operation.
552 <li><b><code>__bxor</code>: </b>
553 the bitwise exclusive OR (binary <code>~</code>) operation.
557 <li><b><code>__bnot</code>: </b>
558 the bitwise NOT (unary <code>~</code>) operation.
562 <li><b><code>__shl</code>: </b>
563 the bitwise left shift (<code><<</code>) operation.
567 <li><b><code>__shr</code>: </b>
568 the bitwise right shift (<code>>></code>) operation.
572 <li><b><code>__concat</code>: </b>
573 the concatenation (<code>..</code>) operation.
580 <li><b><code>__len</code>: </b>
581 the length (<code>#</code>) operation.
594 <li><b><code>__eq</code>: </b>
595 the equal (<code>==</code>) operation.
603 <li><b><code>__lt</code>: </b>
604 the less than (<code><</code>) operation.
611 <li><b><code>__le</code>: </b>
612 the less equal (<code><=</code>) operation.
616 <li><b><code>__index</code>: </b>
617 The indexing access operation <code>table[key]</code>.
618 This event happens when <code>table</code> is not a table or
619 when <code>key</code> is not present in <code>table</code>.
620 The metavalue is looked up in the metatable of <code>table</code>.
625 or any value with an <code>__index</code> metavalue.
627 it is called with <code>table</code> and <code>key</code> as arguments,
632 the final result is the result of indexing this metavalue with <code>key</code>.
634 and therefore can trigger another <code>__index</code> metavalue.
637 <li><b><code>__newindex</code>: </b>
638 The indexing assignment <code>table[key] = value</code>.
640 this event happens when <code>table</code> is not a table or
641 when <code>key</code> is not present in <code>table</code>.
642 The metavalue is looked up in the metatable of <code>table</code>.
648 or any value with an <code>__newindex</code> metavalue.
650 it is called with <code>table</code>, <code>key</code>, and <code>value</code> as arguments.
655 and therefore can trigger another <code>__newindex</code> metavalue.
659 Whenever a <code>__newindex</code> metavalue is invoked,
662 the metamethod itself can call <a href="#pdf-rawset"><code>rawset</code></a>
666 <li><b><code>__call</code>: </b>
667 The call operation <code>func(args)</code>.
669 (that is, <code>func</code> is not a function).
670 The metamethod is looked up in <code>func</code>.
672 the metamethod is called with <code>func</code> as its first argument,
673 followed by the arguments of the original call (<code>args</code>).
684 <code>__gc</code> (see <a href="#2.5.3">§2.5.3</a>),
685 <code>__close</code> (see <a href="#3.3.8">§3.3.8</a>),
686 <code>__mode</code> (see <a href="#2.5.4">§2.5.4</a>),
687 and <code>__name</code>.
688 (The entry <code>__name</code>,
690 may be used by <a href="#pdf-tostring"><code>tostring</code></a> and in error messages.)
708 (e.g., <a href="#pdf-tostring"><code>tostring</code></a>)
715 In particular, the <code>__gc</code> metamethod works only when this order
755 Because Lua has no knowledge about C code,
777 <a href="#lua_gc"><code>lua_gc</code></a> in C
778 or <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> in Lua.
904 and the metatable has a field indexed by the string "<code>__gc</code>".
905 Note that if you set a metatable without a <code>__gc</code> field
917 it checks the object's <code>__gc</code> metamethod:
930 the execution of the regular code.
951 When you close a state (see <a href="#lua_close"><code>lua_close</code></a>),
997 <code>__mode</code> field of its metatable.
999 "<code>k</code>", for a table with weak keys;
1000 "<code>v</code>", for a table with weak values;
1001 or "<code>kv</code>", for a table with both weak keys and values.
1070 You create a coroutine by calling <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>.
1073 The <code>create</code> function only creates a new coroutine and
1079 You execute a coroutine by calling <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a…
1080 When you first call <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
1082 a thread returned by <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
1085 Extra arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> are pas…
1097 <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>true</b>,
1099 In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>fal…
1107 A coroutine yields by calling <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
1109 the corresponding <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns immedia…
1113 In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also retu…
1114 plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>.
1117 with the call to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a> returning any extra
1118 arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
1122 Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>,
1123 the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine,
1127 go as extra arguments to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>.
1128 …utine.wrap"><code>coroutine.wrap</code></a> returns all the values returned by <a href="#pdf-corou…
1129 except the first one (the boolean error code).
1130 Unlike <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a>,
1131 the function created by <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a>
1134 …on also closes the coroutine (see <a href="#pdf-coroutine.close"><code>coroutine.close</code></a>).
1139 consider the following code:
1176 …ee functions <a href="#lua_newthread"><code>lua_newthread</code></a>, <a href="#lua_resume"><code>…
1177 and <a href="#lua_yield"><code>lua_yield</code></a>.
1217 In source code,
1247 <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code>
1252 one or more uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>).
1270 '<code>\a</code>' (bell),
1271 '<code>\b</code>' (backspace),
1272 '<code>\f</code>' (form feed),
1273 '<code>\n</code>' (newline),
1274 '<code>\r</code>' (carriage return),
1275 '<code>\t</code>' (horizontal tab),
1276 '<code>\v</code>' (vertical tab),
1277 '<code>\\</code>' (backslash),
1278 '<code>\"</code>' (quotation mark [double quote]),
1279 and '<code>\'</code>' (apostrophe [single quote]).
1282 The escape sequence '<code>\z</code>' skips the following span
1297 with the escape sequence <code>\x<em>XX</em></code>,
1299 or with the escape sequence <code>\<em>ddd</em></code>,
1308 the escape sequence <code>\u{<em>XXX</em>}</code>
1311 representing the character code point.
1312 This code point can be any value less than <em>2<sup>31</sup></em>.
1314 which is not restricted to valid Unicode code points.)
1323 So, an opening long bracket of level 0 is written as <code>[[</code>,
1324 an opening long bracket of level 1 is written as <code>[=[</code>,
1328 a closing long bracket of level 4 is written as <code>]====]</code>.
1345 (in which '<code>a</code>' is coded as 97,
1346 newline is coded as 10, and '<code>1</code>' is coded as 49),
1375 marked by a letter '<code>e</code>' or '<code>E</code>'.
1377 which start with <code>0x</code> or <code>0X</code>.
1380 marked by a letter '<code>p</code>' or '<code>P</code>'.
1411 A <em>comment</em> starts with a double hyphen (<code>--</code>)
1413 If the text immediately after <code>--</code> is not an opening long bracket,
1465 The syntax <code>var.Name</code> is just syntactic sugar for
1466 <code>var["Name"]</code>:
1473 An access to a global variable <code>x</code>
1474 is equivalent to <code>_ENV.x</code>.
1476 the variable <code>_ENV</code> itself is never global (see <a href="#2.2">§2.2</a>).
1578 scope of an external local variable called <code>_ENV</code> (see <a href="#2.2">§2.2</a>).
1579 The resulting function always has <code>_ENV</code> as its only external variable,
1587 precompiling the chunk's code into instructions for a virtual machine,
1588 and then Lua executes the compiled code
1594 see the program <code>luac</code> and the function <a href="#pdf-string.dump"><code>string.dump</co…
1596 …tically detects the file type and acts accordingly (see <a href="#pdf-load"><code>load</code></a>).
1636 Thus the code
1642 sets <code>a[3]</code> to 20, without affecting <code>a[4]</code>
1643 because the <code>i</code> in <code>a[i]</code> is evaluated (to 3)
1650 exchanges the values of <code>x</code> and <code>y</code>,
1656 cyclically permutes the values of <code>x</code>, <code>y</code>, and <code>z</code>.
1660 An assignment to a global name <code>x = val</code>
1662 <code>_ENV.x = val</code> (see <a href="#2.2">§2.2</a>).
1763 as in the idiom <code>do return end</code>,
1782 The numerical <b>for</b> loop repeats a block of code while a
1940 <code>const</code>, which declares a constant variable,
1943 and <code>close</code>, which declares a to-be-closed variable (see <a href="#3.3.8">§3.3.8</a…
1971 to call its <code>__close</code> metamethod.
1981 must have a <code>__close</code> metamethod
1993 that error is handled like an error in the regular code
2018 or call <a href="#pdf-coroutine.close"><code>coroutine.close</code></a> to close the variables.
2020 through <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a>,
2057 denoted by three dots ('<code>...</code>'), can only be used when
2113 <code>(f(x,y,z))</code> is always a single value,
2114 even if <code>f</code> returns several values.
2115 (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code>
2116 or <b>nil</b> if <code>f</code> does not return any values.)
2126 <li><b><code>+</code>: </b>addition</li>
2127 <li><b><code>-</code>: </b>subtraction</li>
2128 <li><b><code>*</code>: </b>multiplication</li>
2129 <li><b><code>/</code>: </b>float division</li>
2130 <li><b><code>//</code>: </b>floor division</li>
2131 <li><b><code>%</code>: </b>modulo</li>
2132 <li><b><code>^</code>: </b>exponentiation</li>
2133 <li><b><code>-</code>: </b>unary minus</li>
2152 Exponentiation and float division (<code>/</code>)
2155 Exponentiation uses the ISO C function <code>pow</code>,
2160 Floor division (<code>//</code>) is a division
2180 <li><b><code>&</code>: </b>bitwise AND</li>
2181 <li><b><code>|</code>: </b>bitwise OR</li>
2182 <li><b><code>~</code>: </b>bitwise exclusive OR</li>
2183 <li><b><code>>></code>: </b>right shift</li>
2184 <li><b><code><<</code>: </b>left shift</li>
2185 <li><b><code>~</code>: </b>unary bitwise NOT</li>
2253 in particular, <code>"1"==1</code> is false and <code>"1"<1</code> raises an error
2278 use the function <a href="#pdf-string.format"><code>string.format</code></a>.
2288 <li><b><code>==</code>: </b>equality</li>
2289 <li><b><code>~=</code>: </b>inequality</li>
2290 <li><b><code><</code>: </b>less than</li>
2291 <li><b><code>></code>: </b>greater than</li>
2292 <li><b><code><=</code>: </b>less or equal</li>
2293 <li><b><code>>=</code>: </b>greater or equal</li>
2299 Equality (<code>==</code>) first compares the type of its operands.
2323 by using the <code>__eq</code> metamethod (see <a href="#2.4">§2.4</a>).
2329 Thus, <code>"0"==0</code> evaluates to <b>false</b>,
2330 and <code>t[0]</code> and <code>t["0"]</code> denote different
2335 The operator <code>~=</code> is exactly the negation of equality (<code>==</code>).
2345 Otherwise, Lua tries to call the <code>__lt</code> or the <code>__le</code>
2347 A comparison <code>a > b</code> is translated to <code>b < a</code>
2348 and <code>a >= b</code> is translated to <code>b <= a</code>.
2397 denoted by two dots ('<code>..</code>').
2401 Otherwise, the <code>__concat</code> metamethod is called (see <a href="#2.4">§2.4</a>).
2410 The length operator is denoted by the unary prefix operator <code>#</code>.
2422 A <em>border</em> in a table <code>t</code> is any natural number
2436 For instance, the table <code>{10, 20, 30, 40, 50}</code> is a sequence,
2438 The table <code>{10, 20, 30, nil, 50}</code> has two borders (3 and 5),
2441 The table <code>{nil, 20, 30, nil, nil, 60, nil}</code>
2445 The table <code>{}</code> is a sequence with border 0.
2451 When <code>t</code> is a sequence,
2452 <code>#t</code> returns its only border,
2454 When <code>t</code> is not a sequence,
2455 <code>#t</code> can return any of its borders.
2470 any value but strings through the <code>__len</code> metamethod (see <a href="#2.4">§2.4</a>).
2496 The concatenation ('<code>..</code>') and exponentiation ('<code>^</code>')
2519 Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry
2520 with key <code>exp1</code> and value <code>exp2</code>.
2521 A field of the form <code>name = exp</code> is equivalent to
2522 <code>["name"] = exp</code>.
2523 Fields of the form <code>exp</code> are equivalent to
2524 <code>[i] = exp</code>, where <code>i</code> are consecutive integers
2554 If the last field in the list has the form <code>exp</code>
2562 as a convenience for machine-generated code.
2580 the prefixexp <code>__call</code> metamethod is called:
2593 A call <code>v:name(<em>args</em>)</code>
2594 is syntactic sugar for <code>v.name(v,<em>args</em>)</code>,
2595 except that <code>v</code> is evaluated only once.
2607 A call of the form <code>f{<em>fields</em>}</code> is
2608 syntactic sugar for <code>f({<em>fields</em>})</code>;
2610 A call of the form <code>f'<em>string</em>'</code>
2611 (or <code>f"<em>string</em>"</code> or <code>f[[<em>string</em>]]</code>)
2612 is syntactic sugar for <code>f('<em>string</em>')</code>;
2617 A call of the form <code>return <em>functioncall</em></code> not in the
2700 contains references to <code>f</code>.)
2726 which is indicated by three dots ('<code>...</code>')
2785 adding an implicit extra parameter <code>self</code> to the function.
2828 Notice that, in a declaration like <code>local x = x</code>,
2829 the new <code>x</code> being declared is not in scope yet,
2830 and so the second <code>x</code> refers to the outside variable.
2857 Each of these closures uses a different <code>y</code> variable,
2858 while all of them share the same <code>x</code>.
2874 are declared in the header file <a name="pdf-lua.h"><code>lua.h</code></a>.
2891 with the macro <a name="pdf-LUA_USE_APICHECK"><code>LUA_USE_APICHECK</code></a> defined.
2904 The type <a href="#lua_State"><code>lua_State</code></a> (despite its name) refers to a thread.
2911 every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,
2938 to be returned to the caller (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
2969 You can use the function <a href="#lua_checkstack"><code>lua_checkstack</code></a>
2976 at least <a name="pdf-LUA_MINSTACK"><code>LUA_MINSTACK</code></a> extra elements;
2977 that is, you can safely push up to <code>LUA_MINSTACK</code> values into it.
2978 <code>LUA_MINSTACK</code> is defined as 20,
2980 unless your code has loops pushing elements onto the stack.
2985 without a fixed number of results (see <a href="#lua_call"><code>lua_call</code></a>),
2989 you should use <a href="#lua_checkstack"><code>lua_checkstack</code></a>.
3006 (<code>1 ≤ abs(index) ≤ top</code>)
3009 which represent some positions that are accessible to C code
3041 contains a value of a virtual type <a name="pdf-LUA_TNONE"><code>LUA_TNONE</code></a>,
3051 Several functions in the API return pointers (<code>const char*</code>)
3053 (See <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>, <a href="#lua_pushlstring"><code>…
3054 <a href="#lua_pushstring"><code>lua_pushstring</code></a>, and <a href="#lua_tolstring"><code>lua_t…
3055 … <a href="#luaL_checklstring"><code>luaL_checklstring</code></a>, <a href="#luaL_checkstring"><cod…
3056 and <a href="#luaL_tolstring"><code>luaL_tolstring</code></a> in the auxiliary library.)
3074 namely <a href="#lua_getlocal"><code>lua_getlocal</code></a>, <a href="#lua_getupvalue"><code>lua_g…
3075 <a href="#lua_setlocal"><code>lua_setlocal</code></a>, and <a href="#lua_setupvalue"><code>lua_setu…
3098 (see <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>);
3107 <a href="#lua_upvalueindex"><code>lua_upvalueindex</code></a>.
3109 <code>lua_upvalueindex(1)</code>, and so on.
3110 Any access to <code>lua_upvalueindex(<em>n</em>)</code>,
3130 a predefined table that can be used by any C code to
3133 <a name="pdf-LUA_REGISTRYINDEX"><code>LUA_REGISTRYINDEX</code></a>.
3139 or a light userdata with the address of a C object in your code,
3140 or any Lua object created by your code.
3148 by the reference mechanism (see <a href="#luaL_ref"><code>luaL_ref</code></a>)
3158 defined as constants in <code>lua.h</code>.
3162 <li><b><a name="pdf-LUA_RIDX_MAINTHREAD"><code>LUA_RIDX_MAINTHREAD</code></a>: </b> At this index t…
3167 <li><b><a name="pdf-LUA_RIDX_GLOBALS"><code>LUA_RIDX_GLOBALS</code></a>: </b> At this index the reg…
3180 Internally, Lua uses the C <code>longjmp</code> facility to handle errors.
3182 search for <code>LUAI_THROW</code> in the source code for details.)
3187 A <em>protected environment</em> uses <code>setjmp</code>
3194 by calling <a href="#lua_error"><code>lua_error</code></a>.
3206 Lua calls a <em>panic function</em> (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>)
3207 and then calls <code>abort</code>,
3224 when C code operates on other Lua states
3227 the result of <a href="#lua_newthread"><code>lua_newthread</code></a>),
3250 <li><b><a name="pdf-LUA_OK"><code>LUA_OK</code></a> (0): </b> no errors.</li>
3252 <li><b><a name="pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>: </b> a runtime error.</li>
3254 <li><b><a name="pdf-LUA_ERRMEM"><code>LUA_ERRMEM</code></a>: </b>
3259 <li><b><a name="pdf-LUA_ERRERR"><code>LUA_ERRERR</code></a>: </b> error while running the message h…
3261 <li><b><a name="pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>: </b> syntax error during precomp…
3263 <li><b><a name="pdf-LUA_YIELD"><code>LUA_YIELD</code></a>: </b> the thread (coroutine) yields.</li>
3265 <li><b><a name="pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a>: </b> a file-related error;
3269 These constants are defined in the header file <code>lua.h</code>.
3280 Internally, Lua uses the C <code>longjmp</code> facility to yield a coroutine.
3281 Therefore, if a C function <code>foo</code> calls an API function
3284 Lua cannot return to <code>foo</code> any more,
3285 because the <code>longjmp</code> removes its frame from the C stack.
3292 …#lua_yieldk"><code>lua_yieldk</code></a>, <a href="#lua_callk"><code>lua_callk</code></a>, and <a …
3294 (as a parameter named <code>k</code>) to continue execution after a yield.
3304 This can happen when the callee function is <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
3305 …unction is either <a href="#lua_callk"><code>lua_callk</code></a> or <a href="#lua_pcallk"><code>l…
3328 ... /* code 1 */
3330 ... /* code 2 */
3334 the Lua code being run by <a href="#lua_pcall"><code>lua_pcall</code></a> to yield.
3339 ... /* code 2 */
3343 ... /* code 1 */
3347 In the above code,
3348 the new function <code>k</code> is a
3349 <em>continuation function</em> (with type <a href="#lua_KFunction"><code>lua_KFunction</code></a>),
3351 was doing after calling <a href="#lua_pcall"><code>lua_pcall</code></a>.
3352 Now, we must inform Lua that it must call <code>k</code> if the Lua code
3353 being executed by <a href="#lua_pcall"><code>lua_pcall</code></a> gets interrupted in some way
3355 so we rewrite the code as here,
3356 replacing <a href="#lua_pcall"><code>lua_pcall</code></a> by <a href="#lua_pcallk"><code>lua_pcallk…
3360 ... /* code 1 */
3368 <a href="#lua_pcallk"><code>lua_pcallk</code></a> (and <a href="#lua_callk"><code>lua_callk</code><…
3376 the final status of the call and the context value (<code>ctx</code>) that
3377 was passed originally to <a href="#lua_pcallk"><code>lua_pcallk</code></a>.
3381 For <a href="#lua_pcallk"><code>lua_pcallk</code></a>,
3382 the status is the same value that would be returned by <a href="#lua_pcallk"><code>lua_pcallk</code…
3383 except that it is <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> when being executed after a y…
3384 (instead of <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>).
3385 For <a href="#lua_yieldk"><code>lua_yieldk</code></a> and <a href="#lua_callk"><code>lua_callk</cod…
3386 the status is always <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> when Lua calls the continu…
3390 Similarly, when using <a href="#lua_callk"><code>lua_callk</code></a>,
3392 with <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> as the status.
3393 (For <a href="#lua_yieldk"><code>lua_yieldk</code></a>, there is not much point in calling
3395 because <a href="#lua_yieldk"><code>lua_yieldk</code></a> usually does not return.)
3404 after a <a href="#lua_callk"><code>lua_callk</code></a> the function and its arguments are
3424 The first field, <code>o</code>,
3426 The second field, <code>p</code>,
3429 A field in the form <code>x|y</code> means the function can push (or pop)
3430 <code>x</code> or <code>y</code> elements,
3432 an interrogation mark '<code>?</code>' means that
3436 The third field, <code>x</code>,
3438 '<code>-</code>' means the function never raises any error;
3439 '<code>m</code>' means the function may raise only out-of-memory errors;
3440 '<code>v</code>' means the function may raise the errors explained in the text;
3441 '<code>e</code>' means the function can run arbitrary Lua code,
3447 <hr><h3><a name="lua_absindex"><code>lua_absindex</code></a></h3><p>
3452 Converts the acceptable index <code>idx</code>
3460 <hr><h3><a name="lua_Alloc"><code>lua_Alloc</code></a></h3>
3469 functionality similar to <code>realloc</code>,
3472 <code>ud</code>, an opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>;
3473 <code>ptr</code>, a pointer to the block being allocated/reallocated/freed;
3474 <code>osize</code>, the original size of the block or some code about what
3476 and <code>nsize</code>, the new size of the block.
3480 When <code>ptr</code> is not <code>NULL</code>,
3481 <code>osize</code> is the size of the block pointed by <code>ptr</code>,
3486 When <code>ptr</code> is <code>NULL</code>,
3487 <code>osize</code> encodes the kind of object that Lua is allocating.
3488 <code>osize</code> is any of
3489 …RING"><code>LUA_TSTRING</code></a>, <a href="#pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>, <a href…
3490 <a href="#pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>, or <a href="#pdf-LUA_TTHREAD"><code>LU…
3492 When <code>osize</code> is some other value,
3501 When <code>nsize</code> is zero,
3502 the allocator must behave like <code>free</code>
3503 and then return <code>NULL</code>.
3507 When <code>nsize</code> is not zero,
3508 the allocator must behave like <code>realloc</code>.
3509 In particular, the allocator returns <code>NULL</code>
3515 It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>.
3530 that <code>free(NULL)</code> has no effect and that
3531 <code>realloc(NULL,size)</code> is equivalent to <code>malloc(size)</code>.
3537 <hr><h3><a name="lua_arith"><code>lua_arith</code></a></h3><p>
3552 The value of <code>op</code> must be one of the following constants:
3556 <li><b><a name="pdf-LUA_OPADD"><code>LUA_OPADD</code></a>: </b> performs addition (<code>+</code>)<…
3557 <li><b><a name="pdf-LUA_OPSUB"><code>LUA_OPSUB</code></a>: </b> performs subtraction (<code>-</code…
3558 <li><b><a name="pdf-LUA_OPMUL"><code>LUA_OPMUL</code></a>: </b> performs multiplication (<code>*</c…
3559 <li><b><a name="pdf-LUA_OPDIV"><code>LUA_OPDIV</code></a>: </b> performs float division (<code>/</c…
3560 <li><b><a name="pdf-LUA_OPIDIV"><code>LUA_OPIDIV</code></a>: </b> performs floor division (<code>//…
3561 <li><b><a name="pdf-LUA_OPMOD"><code>LUA_OPMOD</code></a>: </b> performs modulo (<code>%</code>)</l…
3562 <li><b><a name="pdf-LUA_OPPOW"><code>LUA_OPPOW</code></a>: </b> performs exponentiation (<code>^</c…
3563 <li><b><a name="pdf-LUA_OPUNM"><code>LUA_OPUNM</code></a>: </b> performs mathematical negation (una…
3564 <li><b><a name="pdf-LUA_OPBNOT"><code>LUA_OPBNOT</code></a>: </b> performs bitwise NOT (<code>~</co…
3565 <li><b><a name="pdf-LUA_OPBAND"><code>LUA_OPBAND</code></a>: </b> performs bitwise AND (<code>&…
3566 <li><b><a name="pdf-LUA_OPBOR"><code>LUA_OPBOR</code></a>: </b> performs bitwise OR (<code>|</code>…
3567 <li><b><a name="pdf-LUA_OPBXOR"><code>LUA_OPBXOR</code></a>: </b> performs bitwise exclusive OR (<c…
3568 <li><b><a name="pdf-LUA_OPSHL"><code>LUA_OPSHL</code></a>: </b> performs left shift (<code><<…
3569 <li><b><a name="pdf-LUA_OPSHR"><code>LUA_OPSHR</code></a>: </b> performs right shift (<code>>>…
3576 <hr><h3><a name="lua_atpanic"><code>lua_atpanic</code></a></h3><p>
3587 <hr><h3><a name="lua_call"><code>lua_call</code></a></h3><p>
3594 <code>lua_call</code> respects the <code>__call</code> metamethod.
3605 Finally you call <a href="#lua_call"><code>lua_call</code></a>;
3606 <code>nargs</code> is the number of arguments that you pushed onto the stack.
3610 The number of results is adjusted to <code>nresults</code>,
3611 unless <code>nresults</code> is <a name="pdf-LUA_MULTRET"><code>LUA_MULTRET</code></a>.
3622 (with a <code>longjmp</code>).
3627 equivalent to this Lua code:
3644 Note that the code above is <em>balanced</em>:
3652 <hr><h3><a name="lua_callk"><code>lua_callk</code></a></h3><p>
3661 This function behaves exactly like <a href="#lua_call"><code>lua_call</code></a>,
3668 <hr><h3><a name="lua_CFunction"><code>lua_CFunction</code></a></h3>
3682 <code>lua_gettop(L)</code> returns the number of arguments received by the function.
3684 and its last argument is at index <code>lua_gettop(L)</code>.
3719 <hr><h3><a name="lua_checkstack"><code>lua_checkstack</code></a></h3><p>
3724 Ensures that the stack has space for at least <code>n</code> extra elements,
3725 that is, that you can safely push up to <code>n</code> values into it.
3739 <hr><h3><a name="lua_close"><code>lua_close</code></a></h3><p>
3761 <hr><h3><a name="lua_compare"><code>lua_compare</code></a></h3><p>
3767 Returns 1 if the value at index <code>index1</code> satisfies <code>op</code>
3768 when compared with the value at index <code>index2</code>,
3776 The value of <code>op</code> must be one of the following constants:
3780 <li><b><a name="pdf-LUA_OPEQ"><code>LUA_OPEQ</code></a>: </b> compares for equality (<code>==</code…
3781 <li><b><a name="pdf-LUA_OPLT"><code>LUA_OPLT</code></a>: </b> compares for less than (<code><</c…
3782 <li><b><a name="pdf-LUA_OPLE"><code>LUA_OPLE</code></a>: </b> compares for less or equal (<code><…
3789 <hr><h3><a name="lua_concat"><code>lua_concat</code></a></h3><p>
3794 Concatenates the <code>n</code> values at the top of the stack,
3796 If <code>n</code> is 1, the result is the single value on the stack
3798 if <code>n</code> is 0, the result is the empty string.
3806 <hr><h3><a name="lua_copy"><code>lua_copy</code></a></h3><p>
3811 Copies the element at index <code>fromidx</code>
3812 into the valid index <code>toidx</code>,
3820 <hr><h3><a name="lua_createtable"><code>lua_createtable</code></a></h3><p>
3826 Parameter <code>narr</code> is a hint for how many elements the table
3828 parameter <code>nrec</code> is a hint for how many other elements
3833 Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>.
3839 <hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p>
3853 <a href="#lua_dump"><code>lua_dump</code></a> calls function <code>writer</code> (see <a href="#lua…
3854 with the given <code>data</code>
3859 If <code>strip</code> is true,
3866 The value returned is the error code returned by the last
3878 <hr><h3><a name="lua_error"><code>lua_error</code></a></h3><p>
3887 (see <a href="#luaL_error"><code>luaL_error</code></a>).
3893 <hr><h3><a name="lua_gc"><code>lua_gc</code></a></h3><p>
3903 according to the value of the parameter <code>what</code>.
3909 <li><b><code>LUA_GCCOLLECT</code>: </b>
3913 <li><b><code>LUA_GCSTOP</code>: </b>
3917 <li><b><code>LUA_GCRESTART</code>: </b>
3921 <li><b><code>LUA_GCCOUNT</code>: </b>
3925 <li><b><code>LUA_GCCOUNTB</code>: </b>
3930 <li><b><code>LUA_GCSTEP</code> <code>(int stepsize)</code>: </b>
3932 corresponding to the allocation of <code>stepsize</code> Kbytes.
3935 <li><b><code>LUA_GCISRUNNING</code>: </b>
3940 <li><b><code>LUA_GCINC</code> (int pause, int stepmul, stepsize): </b>
3943 Returns the previous mode (<code>LUA_GCGEN</code> or <code>LUA_GCINC</code>).
3946 <li><b><code>LUA_GCGEN</code> (int minormul, int majormul): </b>
3949 Returns the previous mode (<code>LUA_GCGEN</code> or <code>LUA_GCINC</code>).
3954 see <a href="#pdf-collectgarbage"><code>collectgarbage</code></a>.
3960 <hr><h3><a name="lua_getallocf"><code>lua_getallocf</code></a></h3><p>
3966 If <code>ud</code> is not <code>NULL</code>, Lua stores in <code>*ud</code> the
3973 <hr><h3><a name="lua_getfield"><code>lua_getfield</code></a></h3><p>
3978 Pushes onto the stack the value <code>t[k]</code>,
3979 where <code>t</code> is the value at the given index.
3991 <hr><h3><a name="lua_getextraspace"><code>lua_getextraspace</code></a></h3><p>
4010 (See <code>LUA_EXTRASPACE</code> in <code>luaconf.h</code>.)
4016 <hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3><p>
4021 Pushes onto the stack the value of the global <code>name</code>.
4028 <hr><h3><a name="lua_geti"><code>lua_geti</code></a></h3><p>
4033 Pushes onto the stack the value <code>t[i]</code>,
4034 where <code>t</code> is the value at the given index.
4046 <hr><h3><a name="lua_getmetatable"><code>lua_getmetatable</code></a></h3><p>
4060 <hr><h3><a name="lua_gettable"><code>lua_gettable</code></a></h3><p>
4065 Pushes onto the stack the value <code>t[k]</code>,
4066 where <code>t</code> is the value at the given index
4067 and <code>k</code> is the value on the top of the stack.
4084 <hr><h3><a name="lua_gettop"><code>lua_gettop</code></a></h3><p>
4098 <hr><h3><a name="lua_getiuservalue"><code>lua_getiuservalue</code></a></h3><p>
4103 Pushes onto the stack the <code>n</code>-th user value associated with the
4110 pushes <b>nil</b> and returns <a href="#pdf-LUA_TNONE"><code>LUA_TNONE</code></a>.
4116 <hr><h3><a name="lua_insert"><code>lua_insert</code></a></h3><p>
4130 <hr><h3><a name="lua_Integer"><code>lua_Integer</code></a></h3>
4138 By default this type is <code>long long</code>,
4140 but that can be changed to <code>long</code> or <code>int</code>
4142 (See <code>LUA_INT_TYPE</code> in <code>luaconf.h</code>.)
4147 <a name="pdf-LUA_MININTEGER"><code>LUA_MININTEGER</code></a> and <a name="pdf-LUA_MAXINTEGER"><code…
4154 <hr><h3><a name="lua_isboolean"><code>lua_isboolean</code></a></h3><p>
4166 <hr><h3><a name="lua_iscfunction"><code>lua_iscfunction</code></a></h3><p>
4178 <hr><h3><a name="lua_isfunction"><code>lua_isfunction</code></a></h3><p>
4190 <hr><h3><a name="lua_isinteger"><code>lua_isinteger</code></a></h3><p>
4203 <hr><h3><a name="lua_islightuserdata"><code>lua_islightuserdata</code></a></h3><p>
4215 <hr><h3><a name="lua_isnil"><code>lua_isnil</code></a></h3><p>
4227 <hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3><p>
4239 <hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3><p>
4252 <hr><h3><a name="lua_isnumber"><code>lua_isnumber</code></a></h3><p>
4265 <hr><h3><a name="lua_isstring"><code>lua_isstring</code></a></h3><p>
4278 <hr><h3><a name="lua_istable"><code>lua_istable</code></a></h3><p>
4290 <hr><h3><a name="lua_isthread"><code>lua_isthread</code></a></h3><p>
4302 <hr><h3><a name="lua_isuserdata"><code>lua_isuserdata</code></a></h3><p>
4314 <hr><h3><a name="lua_isyieldable"><code>lua_isyieldable</code></a></h3><p>
4326 <hr><h3><a name="lua_KContext"><code>lua_KContext</code></a></h3>
4332 This type is defined as <code>intptr_t</code>
4333 when <code>intptr_t</code> is available,
4335 Otherwise, it is defined as <code>ptrdiff_t</code>.
4341 <hr><h3><a name="lua_KFunction"><code>lua_KFunction</code></a></h3>
4351 <hr><h3><a name="lua_len"><code>lua_len</code></a></h3><p>
4357 It is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.7">§3.4.7</a>) and
4365 <hr><h3><a name="lua_load"><code>lua_load</code></a></h3><p>
4376 <code>lua_load</code> pushes the compiled chunk as a Lua
4382 The <code>lua_load</code> function uses a user-supplied <code>reader</code> function
4383 to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>).
4384 The <code>data</code> argument is an opaque value passed to the reader function.
4388 The <code>chunkname</code> argument gives a name to the chunk,
4393 <code>lua_load</code> automatically detects whether the chunk is text or binary
4394 and loads it accordingly (see program <code>luac</code>).
4395 The string <code>mode</code> works as in function <a href="#pdf-load"><code>load</code></a>,
4397 a <code>NULL</code> value is equivalent to the string "<code>bt</code>".
4401 <code>lua_load</code> uses the stack internally,
4407 <code>lua_load</code> can return
4408 …UA_OK"><code>LUA_OK</code></a>, <a href="#pdf-LUA_ERRSYNTAX"><code>LUA_ERRSYNTAX</code></a>, or <a…
4416 stored at index <code>LUA_RIDX_GLOBALS</code> in the registry (see <a href="#4.3">§4.3</a>).
4418 this upvalue will be the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>).
4425 <hr><h3><a name="lua_newstate"><code>lua_newstate</code></a></h3><p>
4431 Returns <code>NULL</code> if it cannot create the state
4433 The argument <code>f</code> is the allocator function;
4435 through this function (see <a href="#lua_Alloc"><code>lua_Alloc</code></a>).
4436 The second argument, <code>ud</code>, is an opaque pointer that Lua
4443 <hr><h3><a name="lua_newtable"><code>lua_newtable</code></a></h3><p>
4449 It is equivalent to <code>lua_createtable(L, 0, 0)</code>.
4455 <hr><h3><a name="lua_newthread"><code>lua_newthread</code></a></h3><p>
4461 and returns a pointer to a <a href="#lua_State"><code>lua_State</code></a> that represents this new…
4475 <hr><h3><a name="lua_newuserdatauv"><code>lua_newuserdatauv</code></a></h3><p>
4481 with <code>nuvalue</code> associated Lua values, called <code>user values</code>,
4482 plus an associated block of raw memory with <code>size</code> bytes.
4484 … href="#lua_setiuservalue"><code>lua_setiuservalue</code></a> and <a href="#lua_getiuservalue"><co…
4498 <hr><h3><a name="lua_next"><code>lua_next</code></a></h3><p>
4507 then <a href="#lua_next"><code>lua_next</code></a> returns 0 and pushes nothing.
4528 avoid calling <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key,
4530 Recall that <a href="#lua_tolstring"><code>lua_tolstring</code></a> may change
4532 this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>.
4538 See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
4545 <hr><h3><a name="lua_Number"><code>lua_Number</code></a></h3>
4555 (See <code>LUA_FLOAT_TYPE</code> in <code>luaconf.h</code>.)
4561 <hr><h3><a name="lua_numbertointeger"><code>lua_numbertointeger</code></a></h3>
4566 the float <code>n</code> must have an integral value.
4568 it is converted to an integer and assigned to <code>*p</code>.
4582 <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3><p>
4591 Both <code>nargs</code> and <code>nresults</code> have the same meaning as
4592 in <a href="#lua_call"><code>lua_call</code></a>.
4594 <a href="#lua_pcall"><code>lua_pcall</code></a> behaves exactly like <a href="#lua_call"><code>lua_…
4596 <a href="#lua_pcall"><code>lua_pcall</code></a> catches it,
4598 and returns an error code.
4599 Like <a href="#lua_call"><code>lua_call</code></a>,
4600 <a href="#lua_pcall"><code>lua_pcall</code></a> always removes the function
4605 If <code>msgh</code> is 0,
4608 Otherwise, <code>msgh</code> is the stack index of a
4614 returned on the stack by <a href="#lua_pcall"><code>lua_pcall</code></a>.
4620 Such information cannot be gathered after the return of <a href="#lua_pcall"><code>lua_pcall</code>…
4625 The <a href="#lua_pcall"><code>lua_pcall</code></a> function returns one of the following status co…
4626 …code>LUA_OK</code></a>, <a href="#pdf-LUA_ERRRUN"><code>LUA_ERRRUN</code></a>, <a href="#pdf-LUA_E…
4632 <hr><h3><a name="lua_pcallk"><code>lua_pcallk</code></a></h3><p>
4642 This function behaves exactly like <a href="#lua_pcall"><code>lua_pcall</code></a>,
4649 <hr><h3><a name="lua_pop"><code>lua_pop</code></a></h3><p>
4654 Pops <code>n</code> elements from the stack.
4660 <hr><h3><a name="lua_pushboolean"><code>lua_pushboolean</code></a></h3><p>
4665 Pushes a boolean value with value <code>b</code> onto the stack.
4671 <hr><h3><a name="lua_pushcclosure"><code>lua_pushcclosure</code></a></h3><p>
4678 and pushes onto the stack a Lua value of type <code>function</code> that,
4680 The parameter <code>n</code> tells how many upvalues this function will have
4687 and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
4699 Then <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a>
4701 with the argument <code>n</code> telling how many values will be
4703 <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack.
4707 The maximum value for <code>n</code> is 255.
4711 When <code>n</code> is zero,
4720 <hr><h3><a name="lua_pushcfunction"><code>lua_pushcfunction</code></a></h3><p>
4726 This function is equivalent to <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> with n…
4732 <hr><h3><a name="lua_pushfstring"><code>lua_pushfstring</code></a></h3><p>
4739 It is similar to the ISO C function <code>sprintf</code>,
4749 '<code>%%</code>' (inserts the character '<code>%</code>'),
4750 '<code>%s</code>' (inserts a zero-terminated string, with no size restrictions),
4751 '<code>%f</code>' (inserts a <a href="#lua_Number"><code>lua_Number</code></a>),
4752 '<code>%I</code>' (inserts a <a href="#lua_Integer"><code>lua_Integer</code></a>),
4753 '<code>%p</code>' (inserts a pointer),
4754 '<code>%d</code>' (inserts an <code>int</code>),
4755 '<code>%c</code>' (inserts an <code>int</code> as a one-byte character), and
4756 '<code>%U</code>' (inserts a <code>long int</code> as a UTF-8 byte sequence).
4767 <hr><h3><a name="lua_pushglobaltable"><code>lua_pushglobaltable</code></a></h3><p>
4778 <hr><h3><a name="lua_pushinteger"><code>lua_pushinteger</code></a></h3><p>
4783 Pushes an integer with value <code>n</code> onto the stack.
4789 <hr><h3><a name="lua_pushlightuserdata"><code>lua_pushlightuserdata</code></a></h3><p>
4799 A <em>light userdata</em> represents a pointer, a <code>void*</code>.
4810 <hr><h3><a name="lua_pushliteral"><code>lua_pushliteral</code></a></h3><p>
4815 This macro is equivalent to <a href="#lua_pushstring"><code>lua_pushstring</code></a>,
4816 but should be used only when <code>s</code> is a literal string.
4823 <hr><h3><a name="lua_pushlstring"><code>lua_pushlstring</code></a></h3><p>
4828 Pushes the string pointed to by <code>s</code> with size <code>len</code>
4831 so the memory at <code>s</code> can be freed or reused immediately after
4844 <hr><h3><a name="lua_pushnil"><code>lua_pushnil</code></a></h3><p>
4855 <hr><h3><a name="lua_pushnumber"><code>lua_pushnumber</code></a></h3><p>
4860 Pushes a float with value <code>n</code> onto the stack.
4866 <hr><h3><a name="lua_pushstring"><code>lua_pushstring</code></a></h3><p>
4871 Pushes the zero-terminated string pointed to by <code>s</code>
4874 so the memory at <code>s</code> can be freed or reused immediately after
4883 If <code>s</code> is <code>NULL</code>, pushes <b>nil</b> and returns <code>NULL</code>.
4889 <hr><h3><a name="lua_pushthread"><code>lua_pushthread</code></a></h3><p>
4894 Pushes the thread represented by <code>L</code> onto the stack.
4901 <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p>
4913 <hr><h3><a name="lua_pushvfstring"><code>lua_pushvfstring</code></a></h3><p>
4920 …alent to <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>, except that it receives a <c…
4927 <hr><h3><a name="lua_rawequal"><code>lua_rawequal</code></a></h3><p>
4932 Returns 1 if the two values in indices <code>index1</code> and
4933 <code>index2</code> are primitively equal
4934 (that is, equal without calling the <code>__eq</code> metamethod).
4942 <hr><h3><a name="lua_rawget"><code>lua_rawget</code></a></h3><p>
4947 Similar to <a href="#lua_gettable"><code>lua_gettable</code></a>, but does a raw access
4954 <hr><h3><a name="lua_rawgeti"><code>lua_rawgeti</code></a></h3><p>
4959 Pushes onto the stack the value <code>t[n]</code>,
4960 where <code>t</code> is the table at the given index.
4962 that is, it does not use the <code>__index</code> metavalue.
4972 <hr><h3><a name="lua_rawgetp"><code>lua_rawgetp</code></a></h3><p>
4977 Pushes onto the stack the value <code>t[k]</code>,
4978 where <code>t</code> is the table at the given index and
4979 <code>k</code> is the pointer <code>p</code> represented as a light userdata.
4981 that is, it does not use the <code>__index</code> metavalue.
4991 <hr><h3><a name="lua_rawlen"><code>lua_rawlen</code></a></h3><p>
4998 for tables, this is the result of the length operator ('<code>#</code>')
5008 <hr><h3><a name="lua_rawset"><code>lua_rawset</code></a></h3><p>
5013 Similar to <a href="#lua_settable"><code>lua_settable</code></a>, but does a raw assignment
5020 <hr><h3><a name="lua_rawseti"><code>lua_rawseti</code></a></h3><p>
5025 Does the equivalent of <code>t[i] = v</code>,
5026 where <code>t</code> is the table at the given index
5027 and <code>v</code> is the value on the top of the stack.
5033 that is, it does not use the <code>__newindex</code> metavalue.
5039 <hr><h3><a name="lua_rawsetp"><code>lua_rawsetp</code></a></h3><p>
5044 Does the equivalent of <code>t[p] = v</code>,
5045 where <code>t</code> is the table at the given index,
5046 <code>p</code> is encoded as a light userdata,
5047 and <code>v</code> is the value on the top of the stack.
5053 that is, it does not use the <code>__newindex</code> metavalue.
5059 <hr><h3><a name="lua_Reader"><code>lua_Reader</code></a></h3>
5065 The reader function used by <a href="#lua_load"><code>lua_load</code></a>.
5066 Every time <a href="#lua_load"><code>lua_load</code></a> needs another piece of the chunk,
5068 passing along its <code>data</code> parameter.
5071 and set <code>size</code> to the block size.
5074 the reader must return <code>NULL</code> or set <code>size</code> to zero.
5081 <hr><h3><a name="lua_register"><code>lua_register</code></a></h3><p>
5086 Sets the C function <code>f</code> as the new value of global <code>name</code>.
5097 <hr><h3><a name="lua_remove"><code>lua_remove</code></a></h3><p>
5111 <hr><h3><a name="lua_replace"><code>lua_replace</code></a></h3><p>
5125 <hr><h3><a name="lua_resetthread"><code>lua_resetthread</code></a></h3><p>
5132 Returns a status code:
5133 <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> for no errors in closing methods,
5142 <hr><h3><a name="lua_resume"><code>lua_resume</code></a></h3><p>
5148 Starts and resumes a coroutine in the given thread <code>L</code>.
5155 then you call <a href="#lua_resume"><code>lua_resume</code></a>,
5156 with <code>nargs</code> being the number of arguments.
5159 <code>*nresults</code> is updated and
5161 the <code>*nresults</code> values passed to <a href="#lua_yield"><code>lua_yield</code></a>
5163 <a href="#lua_resume"><code>lua_resume</code></a> returns
5164 <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the coroutine yields,
5165 <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if the coroutine finishes its execution
5167 or an error code in case of errors (see <a href="#4.4.1">§4.4.1</a>).
5174 you remove the <code>*nresults</code> yielded values from its stack,
5175 push the values to be passed as results from <code>yield</code>,
5176 and then call <a href="#lua_resume"><code>lua_resume</code></a>.
5180 The parameter <code>from</code> represents the coroutine that is resuming <code>L</code>.
5182 this parameter can be <code>NULL</code>.
5188 <hr><h3><a name="lua_rotate"><code>lua_rotate</code></a></h3><p>
5193 Rotates the stack elements between the valid index <code>idx</code>
5195 The elements are rotated <code>n</code> positions in the direction of the top,
5196 for a positive <code>n</code>,
5197 or <code>-n</code> positions in the direction of the bottom,
5198 for a negative <code>n</code>.
5199 The absolute value of <code>n</code> must not be greater than the size
5208 <hr><h3><a name="lua_setallocf"><code>lua_setallocf</code></a></h3><p>
5213 Changes the allocator function of a given state to <code>f</code>
5214 with user data <code>ud</code>.
5220 <hr><h3><a name="lua_setfield"><code>lua_setfield</code></a></h3><p>
5225 Does the equivalent to <code>t[k] = v</code>,
5226 where <code>t</code> is the value at the given index
5227 and <code>v</code> is the value on the top of the stack.
5239 <hr><h3><a name="lua_setglobal"><code>lua_setglobal</code></a></h3><p>
5245 sets it as the new value of global <code>name</code>.
5251 <hr><h3><a name="lua_seti"><code>lua_seti</code></a></h3><p>
5256 Does the equivalent to <code>t[n] = v</code>,
5257 where <code>t</code> is the value at the given index
5258 and <code>v</code> is the value on the top of the stack.
5270 <hr><h3><a name="lua_setiuservalue"><code>lua_setiuservalue</code></a></h3><p>
5276 the new <code>n</code>-th user value associated to the
5284 <hr><h3><a name="lua_setmetatable"><code>lua_setmetatable</code></a></h3><p>
5295 (For historical reasons, this function returns an <code>int</code>,
5302 <hr><h3><a name="lua_settable"><code>lua_settable</code></a></h3><p>
5307 Does the equivalent to <code>t[k] = v</code>,
5308 where <code>t</code> is the value at the given index,
5309 <code>v</code> is the value on the top of the stack,
5310 and <code>k</code> is the value just below the top.
5322 <hr><h3><a name="lua_settop"><code>lua_settop</code></a></h3><p>
5331 If <code>index</code> is 0, then all stack elements are removed.
5337 <hr><h3><a name="lua_setwarnf"><code>lua_setwarnf</code></a></h3><p>
5343 (see <a href="#lua_WarnFunction"><code>lua_WarnFunction</code></a>).
5344 The <code>ud</code> parameter sets the value <code>ud</code> passed to
5351 <hr><h3><a name="lua_State"><code>lua_State</code></a></h3>
5364 every function in the library, except to <a href="#lua_newstate"><code>lua_newstate</code></a>,
5371 <hr><h3><a name="lua_status"><code>lua_status</code></a></h3><p>
5376 Returns the status of the thread <code>L</code>.
5380 The status can be <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> for a normal thread,
5381 an error code if the thread finished the execution
5382 of a <a href="#lua_resume"><code>lua_resume</code></a> with an error,
5383 or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the thread is suspended.
5387 You can call functions only in threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>.
5388 You can resume threads with status <a href="#pdf-LUA_OK"><code>LUA_OK</code></a>
5389 (to start a new coroutine) or <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a>
5396 <hr><h3><a name="lua_stringtonumber"><code>lua_stringtonumber</code></a></h3><p>
5401 Converts the zero-terminated string <code>s</code> to a number,
5417 <hr><h3><a name="lua_toboolean"><code>lua_toboolean</code></a></h3><p>
5425 <a href="#lua_toboolean"><code>lua_toboolean</code></a> returns true for any Lua value
5429 use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.)
5435 <hr><h3><a name="lua_tocfunction"><code>lua_tocfunction</code></a></h3><p>
5442 otherwise, returns <code>NULL</code>.
5448 <hr><h3><a name="lua_toclose"><code>lua_toclose</code></a></h3><p>
5462 <a href="#lua_settop"><code>lua_settop</code></a> or <a href="#lua_pop"><code>lua_pop</code></a>.
5464 … in the API except <a href="#lua_settop"><code>lua_settop</code></a> or <a href="#lua_pop"><code>l…
5480 by the time the <code>__close</code> metamethod runs,
5489 <hr><h3><a name="lua_tointeger"><code>lua_tointeger</code></a></h3><p>
5494 …alent to <a href="#lua_tointegerx"><code>lua_tointegerx</code></a> with <code>isnum</code> equal t…
5500 <hr><h3><a name="lua_tointegerx"><code>lua_tointegerx</code></a></h3><p>
5506 to the signed integral type <a href="#lua_Integer"><code>lua_Integer</code></a>.
5509 otherwise, <code>lua_tointegerx</code> returns 0.
5513 If <code>isnum</code> is not <code>NULL</code>,
5521 <hr><h3><a name="lua_tolstring"><code>lua_tolstring</code></a></h3><p>
5527 If <code>len</code> is not <code>NULL</code>,
5528 it sets <code>*len</code> with the string length.
5530 otherwise, the function returns <code>NULL</code>.
5532 then <code>lua_tolstring</code> also
5534 (This change confuses <a href="#lua_next"><code>lua_next</code></a>
5535 when <code>lua_tolstring</code> is applied to keys during a table traversal.)
5539 <code>lua_tolstring</code> returns a pointer
5541 This string always has a zero ('<code>\0</code>')
5549 <hr><h3><a name="lua_tonumber"><code>lua_tonumber</code></a></h3><p>
5554 …ivalent to <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> with <code>isnum</code> equal t…
5560 <hr><h3><a name="lua_tonumberx"><code>lua_tonumberx</code></a></h3><p>
5566 …he C type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>…
5569 otherwise, <a href="#lua_tonumberx"><code>lua_tonumberx</code></a> returns 0.
5573 If <code>isnum</code> is not <code>NULL</code>,
5581 <hr><h3><a name="lua_topointer"><code>lua_topointer</code></a></h3><p>
5587 C pointer (<code>void*</code>).
5589 otherwise, <code>lua_topointer</code> returns <code>NULL</code>.
5601 <hr><h3><a name="lua_tostring"><code>lua_tostring</code></a></h3><p>
5606 …uivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to…
5612 <hr><h3><a name="lua_tothread"><code>lua_tothread</code></a></h3><p>
5618 (represented as <code>lua_State*</code>).
5620 otherwise, the function returns <code>NULL</code>.
5626 <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p>
5635 Otherwise, returns <code>NULL</code>.
5641 <hr><h3><a name="lua_type"><code>lua_type</code></a></h3><p>
5647 or <code>LUA_TNONE</code> for a non-valid but acceptable index.
5648 The types returned by <a href="#lua_type"><code>lua_type</code></a> are coded by the following cons…
5649 defined in <code>lua.h</code>:
5650 <a name="pdf-LUA_TNIL"><code>LUA_TNIL</code></a>,
5651 <a name="pdf-LUA_TNUMBER"><code>LUA_TNUMBER</code></a>,
5652 <a name="pdf-LUA_TBOOLEAN"><code>LUA_TBOOLEAN</code></a>,
5653 <a name="pdf-LUA_TSTRING"><code>LUA_TSTRING</code></a>,
5654 <a name="pdf-LUA_TTABLE"><code>LUA_TTABLE</code></a>,
5655 <a name="pdf-LUA_TFUNCTION"><code>LUA_TFUNCTION</code></a>,
5656 <a name="pdf-LUA_TUSERDATA"><code>LUA_TUSERDATA</code></a>,
5657 <a name="pdf-LUA_TTHREAD"><code>LUA_TTHREAD</code></a>,
5659 <a name="pdf-LUA_TLIGHTUSERDATA"><code>LUA_TLIGHTUSERDATA</code></a>.
5665 <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p>
5670 Returns the name of the type encoded by the value <code>tp</code>,
5671 which must be one the values returned by <a href="#lua_type"><code>lua_type</code></a>.
5677 <hr><h3><a name="lua_Unsigned"><code>lua_Unsigned</code></a></h3>
5681 The unsigned version of <a href="#lua_Integer"><code>lua_Integer</code></a>.
5687 <hr><h3><a name="lua_upvalueindex"><code>lua_upvalueindex</code></a></h3><p>
5692 Returns the pseudo-index that represents the <code>i</code>-th upvalue of
5694 <code>i</code> must be in the range <em>[1,256]</em>.
5700 <hr><h3><a name="lua_version"><code>lua_version</code></a></h3><p>
5711 <hr><h3><a name="lua_WarnFunction"><code>lua_WarnFunction</code></a></h3>
5717 set by <a href="#lua_setwarnf"><code>lua_setwarnf</code></a>.
5725 See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
5731 <hr><h3><a name="lua_warning"><code>lua_warning</code></a></h3><p>
5737 A message in a call with <code>tocont</code> true should be
5742 See <a href="#pdf-warn"><code>warn</code></a> for more details about warnings.
5748 <hr><h3><a name="lua_Writer"><code>lua_Writer</code></a></h3>
5755 The type of the writer function used by <a href="#lua_dump"><code>lua_dump</code></a>.
5756 Every time <a href="#lua_dump"><code>lua_dump</code></a> produces another piece of chunk,
5758 passing along the buffer to be written (<code>p</code>),
5759 its size (<code>sz</code>),
5760 and the <code>ud</code> parameter supplied to <a href="#lua_dump"><code>lua_dump</code></a>.
5764 The writer returns an error code:
5766 any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from
5773 <hr><h3><a name="lua_xmove"><code>lua_xmove</code></a></h3><p>
5782 This function pops <code>n</code> values from the stack <code>from</code>,
5783 and pushes them onto the stack <code>to</code>.
5789 <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p>
5794 This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
5798 the function calling <code>lua_yield</code>.
5806 <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p>
5818 When a C function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
5820 and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine retur…
5821 The parameter <code>nresults</code> is the number of values from the stack
5822 that will be passed as results to <a href="#lua_resume"><code>lua_resume</code></a>.
5827 Lua calls the given continuation function <code>k</code> to continue
5831 with the <code>n</code> results removed and
5832 replaced by the arguments passed to <a href="#lua_resume"><code>lua_resume</code></a>.
5834 the continuation function receives the value <code>ctx</code>
5835 that was passed to <a href="#lua_yieldk"><code>lua_yieldk</code></a>.
5845 In that case, <code>lua_yieldk</code> should be called with no continuation
5846 (probably in the form of <a href="#lua_yield"><code>lua_yield</code></a>) and no results,
5879 <hr><h3><a name="lua_Debug"><code>lua_Debug</code></a></h3>
5904 <a href="#lua_getstack"><code>lua_getstack</code></a> fills only the private part
5906 To fill the other fields of <a href="#lua_Debug"><code>lua_Debug</code></a> with useful information,
5907 you must call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.
5911 The fields of <a href="#lua_Debug"><code>lua_Debug</code></a> have the following meaning:
5915 <li><b><code>source</code>: </b>
5917 If <code>source</code> starts with a '<code>@</code>',
5919 the file name follows the '<code>@</code>'.
5920 If <code>source</code> starts with a '<code>=</code>',
5924 <code>source</code> is that string.
5927 <li><b><code>srclen</code>: </b>
5928 The length of the string <code>source</code>.
5931 <li><b><code>short_src</code>: </b>
5932 a "printable" version of <code>source</code>, to be used in error messages.
5935 <li><b><code>linedefined</code>: </b>
5939 <li><b><code>lastlinedefined</code>: </b>
5943 <li><b><code>what</code>: </b>
5944 the string <code>"Lua"</code> if the function is a Lua function,
5945 <code>"C"</code> if it is a C function,
5946 <code>"main"</code> if it is the main part of a chunk.
5949 <li><b><code>currentline</code>: </b>
5952 <code>currentline</code> is set to -1.
5955 <li><b><code>name</code>: </b>
5961 The <code>lua_getinfo</code> function checks how the function was
5964 then <code>name</code> is set to <code>NULL</code>.
5967 <li><b><code>namewhat</code>: </b>
5968 explains the <code>name</code> field.
5969 The value of <code>namewhat</code> can be
5970 <code>"global"</code>, <code>"local"</code>, <code>"method"</code>,
5971 <code>"field"</code>, <code>"upvalue"</code>, or <code>""</code> (the empty string),
5976 <li><b><code>istailcall</code>: </b>
5981 <li><b><code>nups</code>: </b>
5985 <li><b><code>nparams</code>: </b>
5990 <li><b><code>isvararg</code>: </b>
5995 <li><b><code>ftransfer</code>: </b>
6000 through <a href="#lua_getlocal"><code>lua_getlocal</code></a> and <a href="#lua_setlocal"><code>lua…
6007 <li><b><code>ntransfer</code>: </b>
6010 this value is always equal to <code>nparams</code>.)
6018 <hr><h3><a name="lua_gethook"><code>lua_gethook</code></a></h3><p>
6029 <hr><h3><a name="lua_gethookcount"><code>lua_gethookcount</code></a></h3><p>
6040 <hr><h3><a name="lua_gethookmask"><code>lua_gethookmask</code></a></h3><p>
6051 <hr><h3><a name="lua_getinfo"><code>lua_getinfo</code></a></h3><p>
6061 the parameter <code>ar</code> must be a valid activation record that was
6062 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
6063 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
6068 and start the <code>what</code> string with the character '<code>></code>'.
6070 <code>lua_getinfo</code> pops the function from the top of the stack.)
6071 For instance, to know in which line a function <code>f</code> was defined,
6072 you can write the following code:
6082 Each character in the string <code>what</code>
6083 selects some fields of the structure <code>ar</code> to be filled or
6088 <li><b>'<code>n</code>': </b> fills in the field <code>name</code> and <code>namewhat</code>;
6091 <li><b>'<code>S</code>': </b>
6092 fills in the fields <code>source</code>, <code>short_src</code>,
6093 <code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>;
6096 <li><b>'<code>l</code>': </b> fills in the field <code>currentline</code>;
6099 <li><b>'<code>t</code>': </b> fills in the field <code>istailcall</code>;
6102 <li><b>'<code>u</code>': </b> fills in the fields
6103 <code>nups</code>, <code>nparams</code>, and <code>isvararg</code>;
6106 <li><b>'<code>f</code>': </b>
6111 <li><b>'<code>L</code>': </b>
6114 (A <em>valid line</em> is a line with some associated code,
6120 If this option is given together with option '<code>f</code>',
6131 This function returns 0 to signal an invalid option in <code>what</code>;
6138 <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3><p>
6149 the parameter <code>ar</code> must be a valid activation record that was
6150 filled by a previous call to <a href="#lua_getstack"><code>lua_getstack</code></a> or
6151 given as argument to a hook (see <a href="#lua_Hook"><code>lua_Hook</code></a>).
6152 The index <code>n</code> selects which local variable to inspect;
6153 see <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for details about variable indices
6158 <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack
6163 In the second case, <code>ar</code> must be <code>NULL</code> and the function
6171 Returns <code>NULL</code> (and pushes nothing)
6179 <hr><h3><a name="lua_getstack"><code>lua_getstack</code></a></h3><p>
6188 This function fills parts of a <a href="#lua_Debug"><code>lua_Debug</code></a> structure with
6195 <a href="#lua_getstack"><code>lua_getstack</code></a> returns 0;
6202 <hr><h3><a name="lua_getupvalue"><code>lua_getupvalue</code></a></h3><p>
6207 Gets information about the <code>n</code>-th upvalue
6208 of the closure at index <code>funcindex</code>.
6211 Returns <code>NULL</code> (and pushes nothing)
6212 when the index <code>n</code> is greater than the number of upvalues.
6216 See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about up…
6222 <hr><h3><a name="lua_Hook"><code>lua_Hook</code></a></h3>
6230 Whenever a hook is called, its <code>ar</code> argument has its field
6231 <code>event</code> set to the specific event that triggered the hook.
6233 <a name="pdf-LUA_HOOKCALL"><code>LUA_HOOKCALL</code></a>, <a name="pdf-LUA_HOOKRET"><code>LUA_HOOKR…
6234 <a name="pdf-LUA_HOOKTAILCALL"><code>LUA_HOOKTAILCALL</code></a>, <a name="pdf-LUA_HOOKLINE"><code>…
6235 and <a name="pdf-LUA_HOOKCOUNT"><code>LUA_HOOKCOUNT</code></a>.
6236 Moreover, for line events, the field <code>currentline</code> is also set.
6237 To get the value of any other field in <code>ar</code>,
6238 the hook must call <a href="#lua_getinfo"><code>lua_getinfo</code></a>.
6242 For call events, <code>event</code> can be <code>LUA_HOOKCALL</code>,
6243 the normal value, or <code>LUA_HOOKTAILCALL</code>, for a tail call;
6255 that is, they cannot call <a href="#lua_yieldk"><code>lua_yieldk</code></a>,
6256 …a href="#lua_pcallk"><code>lua_pcallk</code></a>, or <a href="#lua_callk"><code>lua_callk</code></…
6263 calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero
6270 <hr><h3><a name="lua_setcstacklimit"><code>lua_setcstacklimit</code></a></h3><p>
6281 see <a href="#pdf-debug.setcstacklimit"><code>debug.setcstacklimit</code></a>,
6288 <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3><p>
6297 Argument <code>f</code> is the hook function.
6298 <code>mask</code> specifies on which events the hook will be called:
6300 <a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>,
6301 <a name="pdf-LUA_MASKRET"><code>LUA_MASKRET</code></a>,
6302 <a name="pdf-LUA_MASKLINE"><code>LUA_MASKLINE</code></a>,
6303 and <a name="pdf-LUA_MASKCOUNT"><code>LUA_MASKCOUNT</code></a>.
6304 The <code>count</code> argument is only meaningful when the mask
6305 includes <code>LUA_MASKCOUNT</code>.
6319 start the execution of a new line of code,
6320 or when it jumps back in the code (even to the same line).
6325 <code>count</code> instructions.
6332 Hooks are disabled by setting <code>mask</code> to zero.
6338 <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3><p>
6350 Returns <code>NULL</code> (and pops nothing)
6356 Parameters <code>ar</code> and <code>n</code> are as in the function <a href="#lua_getlocal"><code>…
6362 <hr><h3><a name="lua_setupvalue"><code>lua_setupvalue</code></a></h3><p>
6374 Returns <code>NULL</code> (and pops nothing)
6375 when the index <code>n</code> is greater than the number of upvalues.
6379 Parameters <code>funcindex</code> and <code>n</code> are as in
6380 the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>.
6386 <hr><h3><a name="lua_upvalueid"><code>lua_upvalueid</code></a></h3><p>
6391 Returns a unique identifier for the upvalue numbered <code>n</code>
6392 from the closure at index <code>funcindex</code>.
6404 Parameters <code>funcindex</code> and <code>n</code> are as in
6405 the function <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>,
6406 but <code>n</code> cannot be greater than the number of upvalues.
6412 <hr><h3><a name="lua_upvaluejoin"><code>lua_upvaluejoin</code></a></h3><p>
6418 Make the <code>n1</code>-th upvalue of the Lua closure at index <code>funcindex1</code>
6419 refer to the <code>n2</code>-th upvalue of the Lua closure at index <code>funcindex2</code>.
6443 are defined in header file <code>lauxlib.h</code> and
6444 have a prefix <code>luaL_</code>.
6452 more consistency to your code.
6467 (e.g., "<code>bad argument #1</code>"),
6472 Functions called <code>luaL_check*</code>
6487 <hr><h3><a name="luaL_addchar"><code>luaL_addchar</code></a></h3><p>
6492 Adds the byte <code>c</code> to the buffer <code>B</code>
6493 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6499 <hr><h3><a name="luaL_addgsub"><code>luaL_addgsub</code></a></h3><p>
6505 Adds a copy of the string <code>s</code> to the buffer <code>B</code> (see <a href="#luaL_Buffer"><…
6506 replacing any occurrence of the string <code>p</code>
6507 with the string <code>r</code>.
6513 <hr><h3><a name="luaL_addlstring"><code>luaL_addlstring</code></a></h3><p>
6518 Adds the string pointed to by <code>s</code> with length <code>l</code> to
6519 the buffer <code>B</code>
6520 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6527 <hr><h3><a name="luaL_addsize"><code>luaL_addsize</code></a></h3><p>
6532 Adds to the buffer <code>B</code>
6533 a string of length <code>n</code> previously copied to the
6534 buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>).
6540 <hr><h3><a name="luaL_addstring"><code>luaL_addstring</code></a></h3><p>
6545 Adds the zero-terminated string pointed to by <code>s</code>
6546 to the buffer <code>B</code>
6547 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6553 <hr><h3><a name="luaL_addvalue"><code>luaL_addvalue</code></a></h3><p>
6559 to the buffer <code>B</code>
6560 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6573 <hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3><p>
6581 Checks whether <code>cond</code> is true.
6582 …ses an error with a standard message (see <a href="#luaL_argerror"><code>luaL_argerror</code></a>).
6588 <hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3><p>
6593 Raises an error reporting a problem with argument <code>arg</code>
6596 that includes <code>extramsg</code> as a comment:
6607 <hr><h3><a name="luaL_argexpected"><code>luaL_argexpected</code></a></h3><p>
6615 Checks whether <code>cond</code> is true.
6616 If it is not, raises an error about the type of the argument <code>arg</code>
6617 with a standard message (see <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>).
6623 <hr><h3><a name="luaL_Buffer"><code>luaL_Buffer</code></a></h3>
6631 A string buffer allows C code to build Lua strings piecemeal.
6636 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code>…
6638 <li>Then initialize it with a call <code>luaL_buffinit(L, &b)</code>.</li>
6642 the <code>luaL_add*</code> functions.
6646 Finish by calling <code>luaL_pushresult(&b)</code>.
6658 <li>First declare a variable <code>b</code> of type <a href="#luaL_Buffer"><code>luaL_Buffer</code>…
6661 size <code>sz</code> with a call <code>luaL_buffinitsize(L, &b, sz)</code>.</li>
6666 Finish by calling <code>luaL_pushresultsize(&b, sz)</code>,
6667 where <code>sz</code> is the total size of the resulting string
6685 (The only exception to this rule is <a href="#luaL_addvalue"><code>luaL_addvalue</code></a>.)
6686 After calling <a href="#luaL_pushresult"><code>luaL_pushresult</code></a>,
6694 <hr><h3><a name="luaL_buffaddr"><code>luaL_buffaddr</code></a></h3><p>
6699 Returns the address of the current content of buffer <code>B</code>
6700 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6707 <hr><h3><a name="luaL_buffinit"><code>luaL_buffinit</code></a></h3><p>
6712 Initializes a buffer <code>B</code>
6713 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6721 <hr><h3><a name="luaL_bufflen"><code>luaL_bufflen</code></a></h3><p>
6726 Returns the length of the current content of buffer <code>B</code>
6727 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6733 <hr><h3><a name="luaL_buffinitsize"><code>luaL_buffinitsize</code></a></h3><p>
6739 <a href="#luaL_buffinit"><code>luaL_buffinit</code></a>, <a href="#luaL_prepbuffsize"><code>luaL_pr…
6745 <hr><h3><a name="luaL_buffsub"><code>luaL_buffsub</code></a></h3><p>
6750 Removes <code>n</code> bytes from the the buffer <code>B</code>
6751 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
6758 <hr><h3><a name="luaL_callmeta"><code>luaL_callmeta</code></a></h3><p>
6767 If the object at index <code>obj</code> has a metatable and this
6768 metatable has a field <code>e</code>,
6779 <hr><h3><a name="luaL_checkany"><code>luaL_checkany</code></a></h3><p>
6785 of any type (including <b>nil</b>) at position <code>arg</code>.
6791 <hr><h3><a name="luaL_checkinteger"><code>luaL_checkinteger</code></a></h3><p>
6796 Checks whether the function argument <code>arg</code> is an integer
6804 <hr><h3><a name="luaL_checklstring"><code>luaL_checklstring</code></a></h3><p>
6809 Checks whether the function argument <code>arg</code> is a string
6811 if <code>l</code> is not <code>NULL</code> fills its referent
6816 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
6823 <hr><h3><a name="luaL_checknumber"><code>luaL_checknumber</code></a></h3><p>
6828 Checks whether the function argument <code>arg</code> is a number
6829 and returns this number converted to a <code>lua_Number</code>.
6835 <hr><h3><a name="luaL_checkoption"><code>luaL_checkoption</code></a></h3><p>
6843 Checks whether the function argument <code>arg</code> is a string and
6844 searches for this string in the array <code>lst</code>
6852 If <code>def</code> is not <code>NULL</code>,
6853 the function uses <code>def</code> as a default value when
6854 there is no argument <code>arg</code> or when this argument is <b>nil</b>.
6866 <hr><h3><a name="luaL_checkstack"><code>luaL_checkstack</code></a></h3><p>
6871 Grows the stack size to <code>top + sz</code> elements,
6873 <code>msg</code> is an additional text to go into the error message
6874 (or <code>NULL</code> for no additional text).
6880 <hr><h3><a name="luaL_checkstring"><code>luaL_checkstring</code></a></h3><p>
6885 Checks whether the function argument <code>arg</code> is a string
6890 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
6897 <hr><h3><a name="luaL_checktype"><code>luaL_checktype</code></a></h3><p>
6902 Checks whether the function argument <code>arg</code> has type <code>t</code>.
6903 See <a href="#lua_type"><code>lua_type</code></a> for the encoding of types for <code>t</code>.
6909 <hr><h3><a name="luaL_checkudata"><code>luaL_checkudata</code></a></h3><p>
6914 Checks whether the function argument <code>arg</code> is a userdata
6915 of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>…
6916 …he userdata's memory-block address (see <a href="#lua_touserdata"><code>lua_touserdata</code></a>).
6922 <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p>
6927 Checks whether the code making the call and the Lua library being called
6934 <hr><h3><a name="luaL_dofile"><code>luaL_dofile</code></a></h3><p>
6945 It returns <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if there are no errors,
6946 or an error code in case of errors (see <a href="#4.4.1">§4.4.1</a>).
6952 <hr><h3><a name="luaL_dostring"><code>luaL_dostring</code></a></h3><p>
6963 It returns <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> if there are no errors,
6964 or an error code in case of errors (see <a href="#4.4.1">§4.4.1</a>).
6970 <hr><h3><a name="luaL_error"><code>luaL_error</code></a></h3><p>
6976 The error message format is given by <code>fmt</code>
6978 following the same rules of <a href="#lua_pushfstring"><code>lua_pushfstring</code></a>.
6987 as <code>return luaL_error(<em>args</em>)</code>.
6993 <hr><h3><a name="luaL_execresult"><code>luaL_execresult</code></a></h3><p>
7000 (<a href="#pdf-os.execute"><code>os.execute</code></a> and <a href="#pdf-io.close"><code>io.close</…
7006 <hr><h3><a name="luaL_fileresult"><code>luaL_fileresult</code></a></h3><p>
7013 …pdf-io.open"><code>io.open</code></a>, <a href="#pdf-os.rename"><code>os.rename</code></a>, <a hre…
7019 <hr><h3><a name="luaL_getmetafield"><code>luaL_getmetafield</code></a></h3><p>
7024 Pushes onto the stack the field <code>e</code> from the metatable
7025 of the object at index <code>obj</code> and returns the type of the pushed value.
7028 pushes nothing and returns <code>LUA_TNIL</code>.
7034 <hr><h3><a name="luaL_getmetatable"><code>luaL_getmetatable</code></a></h3><p>
7039 Pushes onto the stack the metatable associated with the name <code>tname</code>
7040 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>),
7048 <hr><h3><a name="luaL_getsubtable"><code>luaL_getsubtable</code></a></h3><p>
7053 Ensures that the value <code>t[fname]</code>,
7054 where <code>t</code> is the value at index <code>idx</code>,
7064 <hr><h3><a name="luaL_gsub"><code>luaL_gsub</code></a></h3><p>
7072 Creates a copy of string <code>s</code>,
7073 replacing any occurrence of the string <code>p</code>
7074 with the string <code>r</code>.
7081 <hr><h3><a name="luaL_len"><code>luaL_len</code></a></h3><p>
7088 it is equivalent to the '<code>#</code>' operator in Lua (see <a href="#3.4.7">§3.4.7</a>).
7096 <hr><h3><a name="luaL_loadbuffer"><code>luaL_loadbuffer</code></a></h3><p>
7104 …ent to <a href="#luaL_loadbufferx"><code>luaL_loadbufferx</code></a> with <code>mode</code> equal …
7110 <hr><h3><a name="luaL_loadbufferx"><code>luaL_loadbufferx</code></a></h3><p>
7120 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the
7121 buffer pointed to by <code>buff</code> with size <code>sz</code>.
7125 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
7126 <code>name</code> is the chunk name,
7128 The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.
7134 <hr><h3><a name="luaL_loadfile"><code>luaL_loadfile</code></a></h3><p>
7139 …valent to <a href="#luaL_loadfilex"><code>luaL_loadfilex</code></a> with <code>mode</code> equal t…
7145 <hr><h3><a name="luaL_loadfilex"><code>luaL_loadfilex</code></a></h3><p>
7152 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in the file
7153 named <code>filename</code>.
7154 If <code>filename</code> is <code>NULL</code>,
7156 The first line in the file is ignored if it starts with a <code>#</code>.
7160 The string <code>mode</code> works as in the function <a href="#lua_load"><code>lua_load</code></a>.
7164 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>
7165 or <a href="#pdf-LUA_ERRFILE"><code>LUA_ERRFILE</code></a> for file-related errors.
7169 As <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
7176 <hr><h3><a name="luaL_loadstring"><code>luaL_loadstring</code></a></h3><p>
7182 This function uses <a href="#lua_load"><code>lua_load</code></a> to load the chunk in
7183 the zero-terminated string <code>s</code>.
7187 This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>.
7191 Also as <a href="#lua_load"><code>lua_load</code></a>, this function only loads the chunk;
7198 <hr><h3><a name="luaL_newlib"><code>luaL_newlib</code></a></h3><p>
7204 the functions in the list <code>l</code>.
7213 The array <code>l</code> must be the actual array,
7220 <hr><h3><a name="luaL_newlibtable"><code>luaL_newlibtable</code></a></h3><p>
7226 to store all entries in the array <code>l</code>
7228 It is intended to be used in conjunction with <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></…
7229 (see <a href="#luaL_newlib"><code>luaL_newlib</code></a>).
7234 The array <code>l</code> must be the actual array,
7241 <hr><h3><a name="luaL_newmetatable"><code>luaL_newmetatable</code></a></h3><p>
7246 If the registry already has the key <code>tname</code>,
7250 adds to this new table the pair <code>__name = tname</code>,
7251 adds to the registry the pair <code>[tname] = new table</code>,
7258 with <code>tname</code> in the registry.
7264 <hr><h3><a name="luaL_newstate"><code>luaL_newstate</code></a></h3><p>
7270 It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an
7278 or <code>NULL</code> if there is a memory allocation error.
7284 <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p>
7295 <hr><h3><a name="luaL_opt"><code>luaL_opt</code></a></h3><p>
7305 In words, if the argument <code>arg</code> is nil or absent,
7306 the macro results in the default <code>dflt</code>.
7307 Otherwise, it results in the result of calling <code>func</code>
7308 with the state <code>L</code> and the argument index <code>arg</code> as
7310 Note that it evaluates the expression <code>dflt</code> only if needed.
7316 <hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3><p>
7323 If the function argument <code>arg</code> is an integer
7327 returns <code>d</code>.
7334 <hr><h3><a name="luaL_optlstring"><code>luaL_optlstring</code></a></h3><p>
7342 If the function argument <code>arg</code> is a string,
7345 returns <code>d</code>.
7350 If <code>l</code> is not <code>NULL</code>,
7352 If the result is <code>NULL</code>
7353 (only possible when returning <code>d</code> and <code>d == NULL</code>),
7358 This function uses <a href="#lua_tolstring"><code>lua_tolstring</code></a> to get its result,
7365 <hr><h3><a name="luaL_optnumber"><code>luaL_optnumber</code></a></h3><p>
7370 If the function argument <code>arg</code> is a number,
7371 returns this number as a <code>lua_Number</code>.
7373 returns <code>d</code>.
7380 <hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3><p>
7387 If the function argument <code>arg</code> is a string,
7390 returns <code>d</code>.
7397 <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p>
7402 Equivalent to <a href="#luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a>
7403 with the predefined size <a name="pdf-LUAL_BUFFERSIZE"><code>LUAL_BUFFERSIZE</code></a>.
7409 <hr><h3><a name="luaL_prepbuffsize"><code>luaL_prepbuffsize</code></a></h3><p>
7414 Returns an address to a space of size <code>sz</code>
7415 where you can copy a string to be added to buffer <code>B</code>
7416 (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>).
7418 <a href="#luaL_addsize"><code>luaL_addsize</code></a> with the size of the string to actually add
7425 <hr><h3><a name="luaL_pushfail"><code>luaL_pushfail</code></a></h3><p>
7436 <hr><h3><a name="luaL_pushresult"><code>luaL_pushresult</code></a></h3><p>
7441 Finishes the use of buffer <code>B</code> leaving the final string on
7448 <hr><h3><a name="luaL_pushresultsize"><code>luaL_pushresultsize</code></a></h3><p>
7453 …sequence <a href="#luaL_addsize"><code>luaL_addsize</code></a>, <a href="#luaL_pushresult"><code>l…
7459 <hr><h3><a name="luaL_ref"><code>luaL_ref</code></a></h3><p>
7465 in the table at index <code>t</code>,
7471 As long as you do not manually add integer keys into the table <code>t</code>,
7472 <a href="#luaL_ref"><code>luaL_ref</code></a> ensures the uniqueness of the key it returns.
7473 You can retrieve an object referred by the reference <code>r</code>
7474 by calling <code>lua_rawgeti(L, t, r)</code>.
7475 The function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference.
7480 <a href="#luaL_ref"><code>luaL_ref</code></a> returns the constant <a name="pdf-LUA_REFNIL"><code>L…
7481 The constant <a name="pdf-LUA_NOREF"><code>LUA_NOREF</code></a> is guaranteed to be different
7482 from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>.
7488 <hr><h3><a name="luaL_Reg"><code>luaL_Reg</code></a></h3>
7496 <a href="#luaL_setfuncs"><code>luaL_setfuncs</code></a>.
7497 <code>name</code> is the function name and <code>func</code> is a pointer to
7499 Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with a sentinel entry
7500 in which both <code>name</code> and <code>func</code> are <code>NULL</code>.
7506 <hr><h3><a name="luaL_requiref"><code>luaL_requiref</code></a></h3><p>
7512 If <code>package.loaded[modname]</code> is not true,
7513 calls the function <code>openf</code> with the string <code>modname</code> as an argument
7514 and sets the call result to <code>package.loaded[modname]</code>,
7515 as if that function has been called through <a href="#pdf-require"><code>require</code></a>.
7519 If <code>glb</code> is true,
7520 also stores the module into the global <code>modname</code>.
7530 <hr><h3><a name="luaL_setfuncs"><code>luaL_setfuncs</code></a></h3><p>
7535 Registers all functions in the array <code>l</code>
7536 (see <a href="#luaL_Reg"><code>luaL_Reg</code></a>) into the table on the top of the stack
7541 When <code>nup</code> is not zero,
7542 all functions are created with <code>nup</code> upvalues,
7543 initialized with copies of the <code>nup</code> values
7552 <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p>
7558 as the metatable associated with name <code>tname</code>
7559 in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
7565 <hr><h3><a name="luaL_Stream"><code>luaL_Stream</code></a></h3>
7578 with a metatable called <code>LUA_FILEHANDLE</code>
7579 (where <code>LUA_FILEHANDLE</code> is a macro with the actual metatable's name).
7581 (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
7585 This userdata must start with the structure <code>luaL_Stream</code>;
7587 The field <code>f</code> points to the corresponding C stream
7588 (or it can be <code>NULL</code> to indicate an incompletely created handle).
7589 The field <code>closef</code> points to a Lua function
7596 it changes the field value to <code>NULL</code>
7603 <hr><h3><a name="luaL_testudata"><code>luaL_testudata</code></a></h3><p>
7608 This function works like <a href="#luaL_checkudata"><code>luaL_checkudata</code></a>,
7610 it returns <code>NULL</code> instead of raising an error.
7616 <hr><h3><a name="luaL_tolstring"><code>luaL_tolstring</code></a></h3><p>
7625 If <code>len</code> is not <code>NULL</code>,
7626 the function also sets <code>*len</code> with the string length.
7630 If the value has a metatable with a <code>__tostring</code> field,
7631 then <code>luaL_tolstring</code> calls the corresponding metamethod
7639 <hr><h3><a name="luaL_traceback"><code>luaL_traceback</code></a></h3><p>
7645 Creates and pushes a traceback of the stack <code>L1</code>.
7646 If <code>msg</code> is not <code>NULL</code>, it is appended
7648 The <code>level</code> parameter tells at which level
7655 <hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p>
7662 Raises a type error for the argument <code>arg</code>
7665 <code>tname</code> is a "name" for the expected type.
7672 <hr><h3><a name="luaL_typename"><code>luaL_typename</code></a></h3><p>
7683 <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p>
7688 Releases the reference <code>ref</code> from the table at index <code>t</code>
7689 (see <a href="#luaL_ref"><code>luaL_ref</code></a>).
7692 The reference <code>ref</code> is also freed to be used again.
7696 If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a href="#pdf-LUA_REF…
7697 <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing.
7703 <hr><h3><a name="luaL_where"><code>luaL_where</code></a></h3><p>
7709 of the control at level <code>lvl</code> in the call stack.
7737 (e.g., <a href="#pdf-type"><code>type</code></a> and <a href="#pdf-getmetatable"><code>getmetatable…
7741 deserve an implementation in C (e.g., <a href="#pdf-table.sort"><code>table.sort</code></a>).
7750 For instance, a function documented as <code>foo(arg)</code>
7760 with <code>(not status)</code>, instead of <code>(status == nil)</code>.)
7796 the C host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> fun…
7800 <a href="#luaL_requiref"><code>luaL_requiref</code></a> to call
7801 <a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library),
7802 <a name="pdf-luaopen_package"><code>luaopen_package</code></a> (for the package library),
7803 <a name="pdf-luaopen_coroutine"><code>luaopen_coroutine</code></a> (for the coroutine library),
7804 <a name="pdf-luaopen_string"><code>luaopen_string</code></a> (for the string library),
7805 <a name="pdf-luaopen_utf8"><code>luaopen_utf8</code></a> (for the UTF-8 library),
7806 <a name="pdf-luaopen_table"><code>luaopen_table</code></a> (for the table library),
7807 <a name="pdf-luaopen_math"><code>luaopen_math</code></a> (for the mathematical library),
7808 <a name="pdf-luaopen_io"><code>luaopen_io</code></a> (for the I/O library),
7809 <a name="pdf-luaopen_os"><code>luaopen_os</code></a> (for the operating system library),
7810 and <a name="pdf-luaopen_debug"><code>luaopen_debug</code></a> (for the debug library).
7811 These functions are declared in <a name="pdf-lualib.h"><code>lualib.h</code></a>.
7827 <hr><h3><a name="pdf-assert"><code>assert (v [, message])</code></a></h3>
7832 the value of its argument <code>v</code> is false (i.e., <b>nil</b> or <b>false</b>);
7835 <code>message</code> is the error object;
7836 when absent, it defaults to "<code>assertion failed!</code>"
7842 <hr><h3><a name="pdf-collectgarbage"><code>collectgarbage ([opt [, arg]])</code></a></h3>
7847 It performs different functions according to its first argument, <code>opt</code>:
7851 <li><b>"<code>collect</code>": </b>
7856 <li><b>"<code>stop</code>": </b>
7862 <li><b>"<code>restart</code>": </b>
7866 <li><b>"<code>count</code>": </b>
7873 <li><b>"<code>step</code>": </b>
7875 The step "size" is controlled by <code>arg</code>.
7884 <li><b>"<code>isrunning</code>": </b>
7889 <li><b>"<code>incremental</code>": </b>
7898 <li><b>"<code>generational</code>": </b>
7914 <hr><h3><a name="pdf-dofile"><code>dofile ([filename])</code></a></h3>
7917 <code>dofile</code> executes the content of the standard input (<code>stdin</code>).
7919 In case of errors, <code>dofile</code> propagates the error
7921 (That is, <code>dofile</code> does not run in protected mode.)
7927 <hr><h3><a name="pdf-error"><code>error (message [, level])</code></a></h3>
7933 Usually, <code>error</code> adds some information about the error position
7935 The <code>level</code> argument specifies how to get the error position.
7937 <code>error</code> function was called.
7939 that called <code>error</code> was called; and so on.
7947 <hr><h3><a name="pdf-_G"><code>_G</code></a></h3>
7958 <hr><h3><a name="pdf-getmetatable"><code>getmetatable (object)</code></a></h3>
7962 If <code>object</code> does not have a metatable, returns <b>nil</b>.
7964 if the object's metatable has a <code>__metatable</code> field,
7972 <hr><h3><a name="pdf-ipairs"><code>ipairs (t)</code></a></h3>
7976 Returns three values (an iterator function, the table <code>t</code>, and 0)
7983 (<code>1,t[1]</code>), (<code>2,t[2]</code>), ...,
7990 <hr><h3><a name="pdf-load"><code>load (chunk [, chunkname [, mode [, env]]])</code></a></h3>
7998 If <code>chunk</code> is a string, the chunk is this string.
7999 If <code>chunk</code> is a function,
8000 <code>load</code> calls it repeatedly to get the chunk pieces.
8001 Each call to <code>chunk</code> must return a string that concatenates
8008 <code>load</code> returns the compiled chunk as a function;
8015 the <code>_ENV</code> variable (see <a href="#2.2">§2.2</a>).
8017 …binary chunk created from a function (see <a href="#pdf-string.dump"><code>string.dump</code></a>),
8020 the <code>_ENV</code> variable.
8021 (A non-main function may not even have an <code>_ENV</code> upvalue.)
8026 its first upvalue is set to the value of <code>env</code>,
8035 <code>chunkname</code> is used as the name of the chunk for error messages
8038 it defaults to <code>chunk</code>, if <code>chunk</code> is a string,
8039 or to "<code>=(load)</code>" otherwise.
8043 The string <code>mode</code> controls whether the chunk can be text or binary
8045 It may be the string "<code>b</code>" (only binary chunks),
8046 "<code>t</code>" (only text chunks),
8047 or "<code>bt</code>" (both binary and text).
8048 The default is "<code>bt</code>".
8053 <code>load</code> signals an appropriate error.
8055 Lua does not check the consistency of the code inside binary chunks;
8062 <hr><h3><a name="pdf-loadfile"><code>loadfile ([filename [, mode [, env]]])</code></a></h3>
8066 Similar to <a href="#pdf-load"><code>load</code></a>,
8067 but gets the chunk from file <code>filename</code>
8075 <hr><h3><a name="pdf-next"><code>next (table [, index])</code></a></h3>
8082 A call to <code>next</code> returns the next index of the table
8085 <code>next</code> returns an initial index
8089 <code>next</code> returns <b>nil</b>.
8092 you can use <code>next(t)</code> to check whether a table is empty.
8103 The behavior of <code>next</code> is undefined if,
8113 <hr><h3><a name="pdf-pairs"><code>pairs (t)</code></a></h3>
8117 If <code>t</code> has a metamethod <code>__pairs</code>,
8118 calls it with <code>t</code> as argument and returns the first three
8124 returns three values: the <a href="#pdf-next"><code>next</code></a> function, the table <code>t</co…
8130 will iterate over all key–value pairs of table <code>t</code>.
8134 See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying
8141 <hr><h3><a name="pdf-pcall"><code>pcall (f [, arg1, ···])</code></a></h3>
8145 Calls the function <code>f</code> with
8147 This means that any error inside <code>f</code> is not propagated;
8148 instead, <code>pcall</code> catches the error
8149 and returns a status code.
8150 Its first result is the status code (a boolean),
8152 In such case, <code>pcall</code> also returns all results from the call,
8154 In case of any error, <code>pcall</code> returns <b>false</b> plus the error object.
8155 Note that errors caught by <code>pcall</code> do not call a message handler.
8161 <hr><h3><a name="pdf-print"><code>print (···)</code></a></h3>
8163 and prints their values to <code>stdout</code>,
8165 following the same rules of <a href="#pdf-tostring"><code>tostring</code></a>.
8169 The function <code>print</code> is not intended for formatted output,
8173 use <a href="#pdf-string.format"><code>string.format</code></a> and <a href="#pdf-io.write"><code>i…
8179 <hr><h3><a name="pdf-rawequal"><code>rawequal (v1, v2)</code></a></h3>
8180 Checks whether <code>v1</code> is equal to <code>v2</code>,
8181 without invoking the <code>__eq</code> metamethod.
8188 <hr><h3><a name="pdf-rawget"><code>rawget (table, index)</code></a></h3>
8189 Gets the real value of <code>table[index]</code>,
8190 without using the <code>__index</code> metavalue.
8191 <code>table</code> must be a table;
8192 <code>index</code> may be any value.
8198 <hr><h3><a name="pdf-rawlen"><code>rawlen (v)</code></a></h3>
8199 Returns the length of the object <code>v</code>,
8201 without invoking the <code>__len</code> metamethod.
8208 <hr><h3><a name="pdf-rawset"><code>rawset (table, index, value)</code></a></h3>
8209 Sets the real value of <code>table[index]</code> to <code>value</code>,
8210 without using the <code>__newindex</code> metavalue.
8211 <code>table</code> must be a table,
8212 <code>index</code> any value different from <b>nil</b> and NaN,
8213 and <code>value</code> any Lua value.
8217 This function returns <code>table</code>.
8223 <hr><h3><a name="pdf-select"><code>select (index, ···)</code></a></h3>
8227 If <code>index</code> is a number,
8228 returns all arguments after argument number <code>index</code>;
8230 Otherwise, <code>index</code> must be the string <code>"#"</code>,
8231 and <code>select</code> returns the total number of extra arguments it received.
8237 <hr><h3><a name="pdf-setmetatable"><code>setmetatable (table, metatable)</code></a></h3>
8242 If <code>metatable</code> is <b>nil</b>,
8244 If the original metatable has a <code>__metatable</code> field,
8249 This function returns <code>table</code>.
8253 To change the metatable of other types from Lua code,
8260 <hr><h3><a name="pdf-tonumber"><code>tonumber (e [, base])</code></a></h3>
8264 When called with no <code>base</code>,
8265 <code>tonumber</code> tries to convert its argument to a number.
8268 then <code>tonumber</code> returns this number;
8279 When called with <code>base</code>,
8280 then <code>e</code> must be a string to be interpreted as
8283 In bases above 10, the letter '<code>A</code>' (in either upper or lower case)
8284 represents 10, '<code>B</code>' represents 11, and so forth,
8285 with '<code>Z</code>' representing 35.
8286 If the string <code>e</code> is not a valid numeral in the given base,
8293 <hr><h3><a name="pdf-tostring"><code>tostring (v)</code></a></h3>
8302 If the metatable of <code>v</code> has a <code>__tostring</code> field,
8303 then <code>tostring</code> calls the corresponding value
8304 with <code>v</code> as argument,
8306 Otherwise, if the metatable of <code>v</code> has a <code>__name</code> field
8308 <code>tostring</code> may use that string in its final result.
8313 use <a href="#pdf-string.format"><code>string.format</code></a>.
8319 <hr><h3><a name="pdf-type"><code>type (v)</code></a></h3>
8325 "<code>nil</code>" (a string, not the value <b>nil</b>),
8326 "<code>number</code>",
8327 "<code>string</code>",
8328 "<code>boolean</code>",
8329 "<code>table</code>",
8330 "<code>function</code>",
8331 "<code>thread</code>",
8332 and "<code>userdata</code>".
8338 <hr><h3><a name="pdf-_VERSION"><code>_VERSION</code></a></h3>
8344 The current value of this variable is "<code>Lua 5.4</code>".
8350 <hr><h3><a name="pdf-warn"><code>warn (msg1, ···)</code></a></h3>
8360 a one-piece message starting with '<code>@</code>'
8364 recognizes the control messages "<code>@off</code>",
8366 and "<code>@on</code>", to (re)start the emission;
8373 <hr><h3><a name="pdf-xpcall"><code>xpcall (f, msgh [, arg1, ···])</code></a></…
8377 This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>,
8378 except that it sets a new message handler <code>msgh</code>.
8390 which come inside the table <a name="pdf-coroutine"><code>coroutine</code></a>.
8395 <hr><h3><a name="pdf-coroutine.close"><code>coroutine.close (co)</code></a></h3>
8399 Closes coroutine <code>co</code>,
8412 <hr><h3><a name="pdf-coroutine.create"><code>coroutine.create (f)</code></a></h3>
8416 Creates a new coroutine, with body <code>f</code>.
8417 <code>f</code> must be a function.
8419 an object with type <code>"thread"</code>.
8425 <hr><h3><a name="pdf-coroutine.isyieldable"><code>coroutine.isyieldable ([co])</code></a></h3>
8429 Returns true when the coroutine <code>co</code> can yield.
8430 The default for <code>co</code> is the running coroutine.
8441 <hr><h3><a name="pdf-coroutine.resume"><code>coroutine.resume (co [, val1, ···…
8445 Starts or continues the execution of coroutine <code>co</code>.
8448 The values <code>val1</code>, ... are passed
8451 <code>resume</code> restarts it;
8452 the values <code>val1</code>, ... are passed
8458 <code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code>
8462 <code>resume</code> returns <b>false</b> plus the error message.
8468 <hr><h3><a name="pdf-coroutine.running"><code>coroutine.running ()</code></a></h3>
8479 <hr><h3><a name="pdf-coroutine.status"><code>coroutine.status (co)</code></a></h3>
8483 Returns the status of the coroutine <code>co</code>, as a string:
8484 <code>"running"</code>,
8486 (that is, it is the one that called <code>status</code>);
8487 <code>"suspended"</code>, if the coroutine is suspended in a call to <code>yield</code>,
8489 <code>"normal"</code> if the coroutine is active but not running
8491 and <code>"dead"</code> if the coroutine has finished its body function,
8498 <hr><h3><a name="pdf-coroutine.wrap"><code>coroutine.wrap (f)</code></a></h3>
8502 Creates a new coroutine, with body <code>f</code>;
8503 <code>f</code> must be a function.
8506 extra arguments to <code>resume</code>.
8507 The function returns the same values returned by <code>resume</code>,
8516 <hr><h3><a name="pdf-coroutine.yield"><code>coroutine.yield (···)</code></a></…
8521 Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>.
8535 <a href="#pdf-require"><code>require</code></a>.
8536 Everything else is exported in the table <a name="pdf-package"><code>package</code></a>.
8540 <hr><h3><a name="pdf-require"><code>require (modname)</code></a></h3>
8545 The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></…
8546 to determine whether <code>modname</code> is already loaded.
8547 If it is, then <code>require</code> returns the value stored
8548 at <code>package.loaded[modname]</code>.
8556 <code>require</code> is guided by the table <a href="#pdf-package.searchers"><code>package.searcher…
8560 we can change how <code>require</code> looks for a module.
8562 for <a href="#pdf-package.searchers"><code>package.searchers</code></a>.
8566 First <code>require</code> queries <code>package.preload[modname]</code>.
8569 Otherwise <code>require</code> searches for a Lua loader using the
8570 path stored in <a href="#pdf-package.path"><code>package.path</code></a>.
8572 path stored in <a href="#pdf-package.cpath"><code>package.cpath</code></a>.
8574 …m>all-in-one</em> loader (see <a href="#pdf-package.searchers"><code>package.searchers</code></a>).
8579 <code>require</code> calls the loader with two arguments:
8580 <code>modname</code> and an extra value,
8589 <code>require</code> assigns the returned value to <code>package.loaded[modname]</code>.
8591 has not assigned any value to <code>package.loaded[modname]</code>,
8592 then <code>require</code> assigns <b>true</b> to this entry.
8593 In any case, <code>require</code> returns the
8594 final value of <code>package.loaded[modname]</code>.
8595 Besides that value, <code>require</code> also returns as a second result
8597 which indicates how <code>require</code> found the module.
8603 then <code>require</code> raises an error.
8609 <hr><h3><a name="pdf-package.config"><code>package.config</code></a></h3>
8619 Default is '<code>\</code>' for Windows and '<code>/</code>' for all other systems.</li>
8622 Default is '<code>;</code>'.</li>
8626 Default is '<code>?</code>'.</li>
8630 Default is '<code>!</code>'.</li>
8633 when building the <code>luaopen_</code> function name.
8634 Default is '<code>-</code>'.</li>
8641 <hr><h3><a name="pdf-package.cpath"><code>package.cpath</code></a></h3>
8645 A string with the path used by <a href="#pdf-require"><code>require</code></a>
8650 Lua initializes the C path <a href="#pdf-package.cpath"><code>package.cpath</code></a> in the …
8651 it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code></a>,
8652 using the environment variable <a name="pdf-LUA_CPATH_5_4"><code>LUA_CPATH_5_4</code></a>,
8653 or the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a>,
8654 or a default path defined in <code>luaconf.h</code>.
8660 <hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3>
8664 A table used by <a href="#pdf-require"><code>require</code></a> to control which
8666 When you require a module <code>modname</code> and
8667 <code>package.loaded[modname]</code> is not false,
8668 <a href="#pdf-require"><code>require</code></a> simply returns the value stored there.
8674 table used by <a href="#pdf-require"><code>require</code></a>.
8680 <hr><h3><a name="pdf-package.loadlib"><code>package.loadlib (libname, funcname)</code></a></h3>
8684 Dynamically links the host program with the C library <code>libname</code>.
8688 If <code>funcname</code> is "<code>*</code>",
8693 it looks for a function <code>funcname</code> inside the library
8695 So, <code>funcname</code> must follow the <a href="#lua_CFunction"><code>lua_CFunction</code></a> p…
8696 (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
8702 Unlike <a href="#pdf-require"><code>require</code></a>,
8705 <code>libname</code> must be the complete file name of the C library,
8707 <code>funcname</code> must be the exact name exported by the C library
8715 plus other Unix systems that support the <code>dlfcn</code> standard).
8724 (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>).
8733 <hr><h3><a name="pdf-package.path"><code>package.path</code></a></h3>
8737 A string with the path used by <a href="#pdf-require"><code>require</code></a>
8743 the value of the environment variable <a name="pdf-LUA_PATH_5_4"><code>LUA_PATH_5_4</code></a> or
8744 the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or
8745 with a default path defined in <code>luaconf.h</code>,
8747 A "<code>;;</code>" in the value of the environment variable
8754 <hr><h3><a name="pdf-package.preload"><code>package.preload</code></a></h3>
8759 (see <a href="#pdf-require"><code>require</code></a>).
8765 table used by <a href="#pdf-require"><code>require</code></a>.
8771 <hr><h3><a name="pdf-package.searchers"><code>package.searchers</code></a></h3>
8775 A table used by <a href="#pdf-require"><code>require</code></a> to control how to find modules.
8781 <a href="#pdf-require"><code>require</code></a> calls each of these searchers in ascending order,
8782 with the module name (the argument given to <a href="#pdf-require"><code>require</code></a>) as its
8788 returned as a second result by <a href="#pdf-require"><code>require</code></a>.
8800 <a href="#pdf-package.preload"><code>package.preload</code></a> table.
8805 using the path stored at <a href="#pdf-package.path"><code>package.path</code></a>.
8806 …one as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8811 using the path given by the variable <a href="#pdf-package.cpath"><code>package.cpath</code></a>.
8813 …one as described in function <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8820 the searcher for module <code>foo</code>
8821 will try to open the files <code>./foo.so</code>, <code>./foo.dll</code>,
8822 and <code>/usr/local/foo/init.so</code>, in that order.
8828 The name of this C function is the string "<code>luaopen_</code>"
8833 For instance, if the module name is <code>a.b.c-v2.1</code>,
8834 the function name will be <code>luaopen_a_b_c</code>.
8841 For instance, when requiring <code>a.b.c</code>,
8842 it will search for a C library for <code>a</code>.
8845 in our example, that would be <code>luaopen_a_b_c</code>.
8854 as returned by <a href="#pdf-package.searchpath"><code>package.searchpath</code></a>.
8855 The first searcher always returns the string "<code>:preload:</code>".
8867 <hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep [, rep]])</cod…
8871 Searches for the given <code>name</code> in the given <code>path</code>.
8879 in the template with a copy of <code>name</code>
8880 wherein all occurrences of <code>sep</code>
8882 were replaced by <code>rep</code>
8893 the search for the name <code>foo.a</code>
8895 <code>./foo/a.lua</code>, <code>./foo/a.lc</code>, and
8896 <code>/usr/local/foo/a/init.lua</code>, in that order.
8927 <a name="pdf-string"><code>string</code></a>.
8929 where the <code>__index</code> field points to the <code>string</code> table.
8931 For instance, <code>string.byte(s,i)</code>
8932 can be written as <code>s:byte(i)</code>.
8940 <hr><h3><a name="pdf-string.byte"><code>string.byte (s [, i [, j]])</code></a></h3>
8941 Returns the internal numeric codes of the characters <code>s[i]</code>,
8942 <code>s[i+1]</code>, ..., <code>s[j]</code>.
8943 The default value for <code>i</code> is 1;
8944 the default value for <code>j</code> is <code>i</code>.
8946 following the same rules of function <a href="#pdf-string.sub"><code>string.sub</code></a>.
8956 <hr><h3><a name="pdf-string.char"><code>string.char (···)</code></a></h3>
8959 in which each character has the internal numeric code equal
8970 <hr><h3><a name="pdf-string.dump"><code>string.dump (function [, strip])</code></a></h3>
8977 so that a later <a href="#pdf-load"><code>load</code></a> on this string returns
8979 If <code>strip</code> is a true value,
8989 (See the <a href="#pdf-load"><code>load</code></a> function for details about
8999 <hr><h3><a name="pdf-string.find"><code>string.find (s, pattern [, init [, plain]])</code></a></h3>
9004 <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) in the string <code>s</code>.
9005 If it finds a match, then <code>find</code> returns the indices of <code>s</code>
9008 A third, optional numeric argument <code>init</code> specifies
9011 A value of <b>true</b> as a fourth, optional argument <code>plain</code>
9014 with no characters in <code>pattern</code> being considered magic.
9027 <hr><h3><a name="pdf-string.format"><code>string.format (formatstring, ···)</c…
9034 The format string follows the same rules as the ISO C function <code>sprintf</code>.
9036 <code>*</code>, <code>h</code>, <code>L</code>, <code>l</code>, and <code>n</code> are not supported
9037 and that there is an extra specifier, <code>q</code>.
9041 The specifier <code>q</code> formats booleans, nil, numbers, and strings
9042 in a way that the result is a valid constant in Lua source code.
9044 (<code>true</code>, <code>false</code>, <code>nil</code>).
9066 <code>A</code>, <code>a</code>, <code>E</code>, <code>e</code>, <code>f</code>,
9067 <code>G</code>, and <code>g</code> all expect a number as argument.
9068 The specifiers <code>c</code>, <code>d</code>,
9069 <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code>
9072 the specifiers <code>A</code> and <code>a</code> (hexadecimal floats)
9077 The specifier <code>s</code> expects a string;
9079 it is converted to one following the same rules of <a href="#pdf-tostring"><code>tostring</code></a…
9085 The specifier <code>p</code> formats the pointer
9086 returned by <a href="#lua_topointer"><code>lua_topointer</code></a>.
9091 the pointer <code>NULL</code>.
9097 <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern [, init])</code></a></h3>
9100 returns the next captures from <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>)
9101 over the string <code>s</code>.
9102 If <code>pattern</code> specifies no captures,
9104 A third, optional numeric argument <code>init</code> specifies
9111 will iterate over all the words from string <code>s</code>,
9120 The next example collects all pairs <code>key=value</code> from the
9132 For this function, a caret '<code>^</code>' at the start of a pattern does not
9139 <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3>
9140 Returns a copy of <code>s</code>
9141 in which all (or the first <code>n</code>, if given)
9142 occurrences of the <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) have been
9143 replaced by a replacement string specified by <code>repl</code>,
9145 <code>gsub</code> also returns, as its second value,
9147 The name <code>gsub</code> comes from <em>Global SUBstitution</em>.
9151 If <code>repl</code> is a string, then its value is used for replacement.
9152 The character <code>%</code> works as an escape character:
9153 any sequence in <code>repl</code> of the form <code>%<em>d</em></code>,
9156 the sequence <code>%0</code> stands for the whole match;
9157 the sequence <code>%%</code> stands for a single <code>%</code>.
9161 If <code>repl</code> is a table, then the table is queried for every match,
9166 If <code>repl</code> is a function, then this function is called every time a
9215 <hr><h3><a name="pdf-string.len"><code>string.len (s)</code></a></h3>
9220 The empty string <code>""</code> has length 0.
9222 so <code>"a\000bc\000"</code> has length 5.
9228 <hr><h3><a name="pdf-string.lower"><code>string.lower (s)</code></a></h3>
9241 <hr><h3><a name="pdf-string.match"><code>string.match (s, pattern [, init])</code></a></h3>
9246 the <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) in the string <code>s</code>.
9247 If it finds one, then <code>match</code> returns
9250 If <code>pattern</code> specifies no captures,
9252 A third, optional numeric argument <code>init</code> specifies
9260 <hr><h3><a name="pdf-string.pack"><code>string.pack (fmt, v1, v2, ···)</code><…
9264 Returns a binary string containing the values <code>v1</code>, <code>v2</code>, etc.
9266 according to the format string <code>fmt</code> (see <a href="#6.4.2">§6.4.2</a>).
9272 <hr><h3><a name="pdf-string.packsize"><code>string.packsize (fmt)</code></a></h3>
9276 Returns the size of a string resulting from <a href="#pdf-string.pack"><code>string.pack</code></a>
9279 '<code>s</code>' or '<code>z</code>' (see <a href="#6.4.2">§6.4.2</a>).
9285 <hr><h3><a name="pdf-string.rep"><code>string.rep (s, n [, sep])</code></a></h3>
9289 Returns a string that is the concatenation of <code>n</code> copies of
9290 the string <code>s</code> separated by the string <code>sep</code>.
9291 The default value for <code>sep</code> is the empty string
9293 Returns the empty string if <code>n</code> is not positive.
9304 <hr><h3><a name="pdf-string.reverse"><code>string.reverse (s)</code></a></h3>
9308 Returns a string that is the string <code>s</code> reversed.
9314 <hr><h3><a name="pdf-string.sub"><code>string.sub (s, i [, j])</code></a></h3>
9318 Returns the substring of <code>s</code> that
9319 starts at <code>i</code> and continues until <code>j</code>;
9320 <code>i</code> and <code>j</code> can be negative.
9321 If <code>j</code> is absent, then it is assumed to be equal to -1
9324 the call <code>string.sub(s,1,j)</code> returns a prefix of <code>s</code>
9325 with length <code>j</code>,
9326 and <code>string.sub(s, -i)</code> (for a positive <code>i</code>)
9327 returns a suffix of <code>s</code>
9328 with length <code>i</code>.
9333 <code>i</code> is less than 1,
9335 If <code>j</code> is greater than the string length,
9338 <code>i</code> is greater than <code>j</code>,
9345 <hr><h3><a name="pdf-string.unpack"><code>string.unpack (fmt, s [, pos])</code></a></h3>
9349 Returns the values packed in string <code>s</code> (see <a href="#pdf-string.pack"><code>string.pac…
9350 according to the format string <code>fmt</code> (see <a href="#6.4.2">§6.4.2</a>).
9351 An optional <code>pos</code> marks where
9352 to start reading in <code>s</code> (default is 1).
9354 this function also returns the index of the first unread byte in <code>s</code>.
9360 <hr><h3><a name="pdf-string.upper"><code>string.upper (s)</code></a></h3>
9382 <a href="#pdf-string.find"><code>string.find</code></a>,
9383 <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>,
9384 <a href="#pdf-string.gsub"><code>string.gsub</code></a>,
9385 and <a href="#pdf-string.match"><code>string.match</code></a>.
9401 <code>^$()%.[]*+-?</code>)
9405 <li><b><code>.</code>: </b> (a dot) represents all characters.</li>
9407 <li><b><code>%a</code>: </b> represents all letters.</li>
9409 <li><b><code>%c</code>: </b> represents all control characters.</li>
9411 <li><b><code>%d</code>: </b> represents all digits.</li>
9413 <li><b><code>%g</code>: </b> represents all printable characters except space.</li>
9415 <li><b><code>%l</code>: </b> represents all lowercase letters.</li>
9417 <li><b><code>%p</code>: </b> represents all punctuation characters.</li>
9419 <li><b><code>%s</code>: </b> represents all space characters.</li>
9421 <li><b><code>%u</code>: </b> represents all uppercase letters.</li>
9423 <li><b><code>%w</code>: </b> represents all alphanumeric characters.</li>
9425 <li><b><code>%x</code>: </b> represents all hexadecimal digits.</li>
9427 <li><b><code>%<em>x</em></code>: </b> (where <em>x</em> is any non-alphanumeric character)
9432 can be preceded by a '<code>%</code>' to represent itself in a pattern.
9435 <li><b><code>[<em>set</em>]</code>: </b>
9440 in ascending order, with a '<code>-</code>'.
9441 All classes <code>%</code><em>x</em> described above can also be used as
9444 For example, <code>[%w_]</code> (or <code>[_%w]</code>)
9446 <code>[0-7]</code> represents the octal digits,
9447 and <code>[0-7%l%-]</code> represents the octal digits plus
9448 the lowercase letters plus the '<code>-</code>' character.
9461 Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code>
9465 <li><b><code>[^<em>set</em>]</code>: </b>
9471 For all classes represented by single letters (<code>%a</code>, <code>%c</code>, etc.),
9473 For instance, <code>%S</code> represents all non-space characters.
9479 In particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</code>.
9496 a single character class followed by '<code>*</code>',
9502 a single character class followed by '<code>+</code>',
9508 a single character class followed by '<code>-</code>',
9510 Unlike '<code>*</code>',
9515 a single character class followed by '<code>?</code>',
9521 <code>%<em>n</em></code>, for <em>n</em> between 1 and 9;
9527 <code>%b<em>xy</em></code>, where <em>x</em> and <em>y</em> are two distinct characters;
9533 For instance, the item <code>%b()</code> matches expressions with
9538 <code>%f[<em>set</em>]</code>, a <em>frontier pattern</em>;
9544 they were the character '<code>\0</code>'.
9554 A caret '<code>^</code>' at the beginning of a pattern anchors the match at the
9556 A '<code>$</code>' at the end of a pattern anchors the match at the
9559 '<code>^</code>' and '<code>$</code>' have no special meaning and represent themselves.
9571 For instance, in the pattern <code>"(a*(.)%w(%s*))"</code>,
9572 the part of the string matching <code>"a*(.)%w(%s*)"</code> is
9574 the character matching "<code>.</code>" is captured with number 2,
9575 and the part matching "<code>%s*</code>" has number 3.
9579 As a special case, the capture <code>()</code> captures
9581 For instance, if we apply the pattern <code>"()aa()"</code> on the
9582 string <code>"flaaap"</code>, there will be two captures: 3 and 5.
9589 …a href="#pdf-string.gsub"><code>string.gsub</code></a> and the iterator <a href="#pdf-string.gmatc…
9597 consider the results of the following code:
9606 string after '<code>b</code>' and another one after '<code>c</code>'.
9607 Lua does not match an empty string after '<code>a</code>',
9619 The first argument to <a href="#pdf-string.pack"><code>string.pack</code></a>,
9620 …a href="#pdf-string.packsize"><code>string.packsize</code></a>, and <a href="#pdf-string.unpack"><…
9630 <li><b><code><</code>: </b>sets little endian</li>
9631 <li><b><code>></code>: </b>sets big endian</li>
9632 <li><b><code>=</code>: </b>sets native endian</li>
9633 <li><b><code>![<em>n</em>]</code>: </b>sets maximum alignment to <code>n</code>
9635 <li><b><code>b</code>: </b>a signed byte (<code>char</code>)</li>
9636 <li><b><code>B</code>: </b>an unsigned byte (<code>char</code>)</li>
9637 <li><b><code>h</code>: </b>a signed <code>short</code> (native size)</li>
9638 <li><b><code>H</code>: </b>an unsigned <code>short</code> (native size)</li>
9639 <li><b><code>l</code>: </b>a signed <code>long</code> (native size)</li>
9640 <li><b><code>L</code>: </b>an unsigned <code>long</code> (native size)</li>
9641 <li><b><code>j</code>: </b>a <code>lua_Integer</code></li>
9642 <li><b><code>J</code>: </b>a <code>lua_Unsigned</code></li>
9643 <li><b><code>T</code>: </b>a <code>size_t</code> (native size)</li>
9644 <li><b><code>i[<em>n</em>]</code>: </b>a signed <code>int</code> with <code>n</code> bytes
9646 <li><b><code>I[<em>n</em>]</code>: </b>an unsigned <code>int</code> with <code>n</code> bytes
9648 <li><b><code>f</code>: </b>a <code>float</code> (native size)</li>
9649 <li><b><code>d</code>: </b>a <code>double</code> (native size)</li>
9650 <li><b><code>n</code>: </b>a <code>lua_Number</code></li>
9651 <li><b><code>c<em>n</em></code>: </b>a fixed-sized string with <code>n</code> bytes</li>
9652 <li><b><code>z</code>: </b>a zero-terminated string</li>
9653 <li><b><code>s[<em>n</em>]</code>: </b>a string preceded by its length
9654 coded as an unsigned integer with <code>n</code> bytes
9655 (default is a <code>size_t</code>)</li>
9656 <li><b><code>x</code>: </b>one byte of padding</li>
9657 <li><b><code>X<em>op</em></code>: </b>an empty item that aligns
9658 according to option <code>op</code>
9660 <li><b>'<code> </code>': </b>(space) ignored</li>
9662 (A "<code>[<em>n</em>]</code>" means an optional integral numeral.)
9664 (options "<code>xX <=>!</code>"),
9665 each option corresponds to an argument in <a href="#pdf-string.pack"><code>string.pack</code></a>
9666 or a result in <a href="#pdf-string.unpack"><code>string.unpack</code></a>.
9670 For options "<code>!<em>n</em></code>", "<code>s<em>n</em></code>", "<code>i<em>n</em></code>", and…
9671 <code>n</code> can be any integer between 1 and 16.
9673 <a href="#pdf-string.pack"><code>string.pack</code></a> checks whether the given value fits in the …
9674 <a href="#pdf-string.unpack"><code>string.unpack</code></a> checks whether the read value fits in a…
9680 Any format string starts as if prefixed by "<code>!1=</code>",
9700 Options "<code>c</code>" and "<code>z</code>" are not aligned;
9701 option "<code>s</code>" follows the alignment of its starting integer.
9705 All padding is filled with zeros by <a href="#pdf-string.pack"><code>string.pack</code></a>
9706 and ignored by <a href="#pdf-string.unpack"><code>string.unpack</code></a>.
9718 It provides all its functions inside the table <a name="pdf-utf8"><code>utf8</code></a>.
9736 accept all values up to <code>0x7FFFFFFF</code>,
9745 that result in valid Unicode code points,
9746 rejecting values greater than <code>10FFFF</code> and surrogates.
9747 A boolean argument <code>lax</code>, when available,
9749 so that all values up to <code>0x7FFFFFFF</code> are accepted.
9754 <hr><h3><a name="pdf-utf8.char"><code>utf8.char (···)</code></a></h3>
9766 <hr><h3><a name="pdf-utf8.charpattern"><code>utf8.charpattern</code></a></h3>
9770 The pattern (a string, not a function) "<code>[\0-\x7F\xC2-\xFD][\x80-\xBF]*</code>"
9779 <hr><h3><a name="pdf-utf8.codes"><code>utf8.codes (s [, lax])</code></a></h3>
9788 will iterate over all UTF-8 characters in string <code>s</code>,
9789 with <code>p</code> being the position (in bytes) and <code>c</code> the code point
9797 <hr><h3><a name="pdf-utf8.codepoint"><code>utf8.codepoint (s [, i [, j [, lax]]])</code></a></h3>
9801 Returns the code points (as integers) from all characters in <code>s</code>
9802 that start between byte position <code>i</code> and <code>j</code> (both included).
9803 The default for <code>i</code> is 1 and for <code>j</code> is <code>i</code>.
9810 <hr><h3><a name="pdf-utf8.len"><code>utf8.len (s [, i [, j [, lax]]])</code></a></h3>
9814 Returns the number of UTF-8 characters in string <code>s</code>
9815 that start between positions <code>i</code> and <code>j</code> (both inclusive).
9816 The default for <code>i</code> is 1 and for <code>j</code> is -1.
9824 <hr><h3><a name="pdf-utf8.offset"><code>utf8.offset (s, n [, i])</code></a></h3>
9829 <code>n</code>-th character of <code>s</code>
9830 (counting from position <code>i</code>) starts.
9831 A negative <code>n</code> gets characters before position <code>i</code>.
9832 The default for <code>i</code> is 1 when <code>n</code> is non-negative
9833 and <code>#s + 1</code> otherwise,
9834 so that <code>utf8.offset(s, -n)</code> gets the offset of the
9835 <code>n</code>-th character from the end of the string.
9843 when <code>n</code> is 0 the function returns the start of the encoding
9844 of the character that contains the <code>i</code>-th byte of <code>s</code>.
9848 This function assumes that <code>s</code> is a valid UTF-8 string.
9860 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>.
9871 <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>
9876 returns the string <code>list[i]..sep..list[i+1] ··· sep..list[j]</code>.
9877 The default value for <code>sep</code> is the empty string,
9878 the default for <code>i</code> is 1,
9879 and the default for <code>j</code> is <code>#list</code>.
9880 If <code>i</code> is greater than <code>j</code>, returns the empty string.
9886 <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3>
9890 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>,
9892 <code>list[pos], list[pos+1], ···, list[#list]</code>.
9893 The default value for <code>pos</code> is <code>#list+1</code>,
9894 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end
9895 of the list <code>t</code>.
9901 <hr><h3><a name="pdf-table.move"><code>table.move (a1, f, e, t [,a2])</code></a></h3>
9905 Moves elements from the table <code>a1</code> to the table <code>a2</code>,
9908 <code>a2[t],··· = a1[f],···,a1[e]</code>.
9909 The default for <code>a2</code> is <code>a1</code>.
9915 Returns the destination table <code>a2</code>.
9921 <hr><h3><a name="pdf-table.pack"><code>table.pack (···)</code></a></h3>
9926 and with a field "<code>n</code>" with the total number of arguments.
9934 <hr><h3><a name="pdf-table.remove"><code>table.remove (list [, pos])</code></a></h3>
9938 Removes from <code>list</code> the element at position <code>pos</code>,
9940 When <code>pos</code> is an integer between 1 and <code>#list</code>,
9942 <code>list[pos+1], list[pos+2], ···, list[#list]</code>
9943 and erases element <code>list[#list]</code>;
9944 The index <code>pos</code> can also be 0 when <code>#list</code> is 0,
9945 or <code>#list + 1</code>.
9949 The default value for <code>pos</code> is <code>#list</code>,
9950 so that a call <code>table.remove(l)</code> removes the last element
9951 of the list <code>l</code>.
9957 <hr><h3><a name="pdf-table.sort"><code>table.sort (list [, comp])</code></a></h3>
9962 from <code>list[1]</code> to <code>list[#list]</code>.
9963 If <code>comp</code> is given,
9968 <code>i < j</code> implies <code>not comp(list[j],list[i])</code>).
9969 If <code>comp</code> is not given,
9970 then the standard Lua operator <code><</code> is used instead.
9974 Note that the <code>comp</code> function must define
9989 <hr><h3><a name="pdf-table.unpack"><code>table.unpack (list [, i [, j]])</code></a></h3>
9999 By default, <code>i</code> is 1 and <code>j</code> is <code>#list</code>.
10011 It provides all its functions and constants inside the table <a name="pdf-math"><code>math</code></…
10012 Functions with the annotation "<code>integer/float</code>" give
10016 …th.ceil"><code>math.ceil</code></a>, <a href="#pdf-math.floor"><code>math.floor</code></a>, and <a…
10022 <hr><h3><a name="pdf-math.abs"><code>math.abs (x)</code></a></h3>
10026 Returns the maximum value between <code>x</code> and <code>-x</code>. (integer/float)
10032 <hr><h3><a name="pdf-math.acos"><code>math.acos (x)</code></a></h3>
10036 Returns the arc cosine of <code>x</code> (in radians).
10042 <hr><h3><a name="pdf-math.asin"><code>math.asin (x)</code></a></h3>
10046 Returns the arc sine of <code>x</code> (in radians).
10052 <hr><h3><a name="pdf-math.atan"><code>math.atan (y [, x])</code></a></h3>
10057 Returns the arc tangent of <code>y/x</code> (in radians),
10060 It also handles correctly the case of <code>x</code> being zero.
10064 The default value for <code>x</code> is 1,
10065 so that the call <code>math.atan(y)</code>
10066 returns the arc tangent of <code>y</code>.
10072 <hr><h3><a name="pdf-math.ceil"><code>math.ceil (x)</code></a></h3>
10076 Returns the smallest integral value greater than or equal to <code>x</code>.
10082 <hr><h3><a name="pdf-math.cos"><code>math.cos (x)</code></a></h3>
10086 Returns the cosine of <code>x</code> (assumed to be in radians).
10092 <hr><h3><a name="pdf-math.deg"><code>math.deg (x)</code></a></h3>
10096 Converts the angle <code>x</code> from radians to degrees.
10102 <hr><h3><a name="pdf-math.exp"><code>math.exp (x)</code></a></h3>
10107 (where <code>e</code> is the base of natural logarithms).
10113 <hr><h3><a name="pdf-math.floor"><code>math.floor (x)</code></a></h3>
10117 Returns the largest integral value less than or equal to <code>x</code>.
10123 <hr><h3><a name="pdf-math.fmod"><code>math.fmod (x, y)</code></a></h3>
10127 Returns the remainder of the division of <code>x</code> by <code>y</code>
10134 <hr><h3><a name="pdf-math.huge"><code>math.huge</code></a></h3>
10138 The float value <code>HUGE_VAL</code>,
10145 <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3>
10149 Returns the logarithm of <code>x</code> in the given base.
10150 The default for <code>base</code> is <em>e</em>
10151 (so that the function returns the natural logarithm of <code>x</code>).
10157 <hr><h3><a name="pdf-math.max"><code>math.max (x, ···)</code></a></h3>
10162 according to the Lua operator <code><</code>.
10168 <hr><h3><a name="pdf-math.maxinteger"><code>math.maxinteger</code></a></h3>
10175 <hr><h3><a name="pdf-math.min"><code>math.min (x, ···)</code></a></h3>
10180 according to the Lua operator <code><</code>.
10186 <hr><h3><a name="pdf-math.mininteger"><code>math.mininteger</code></a></h3>
10193 <hr><h3><a name="pdf-math.modf"><code>math.modf (x)</code></a></h3>
10197 Returns the integral part of <code>x</code> and the fractional part of <code>x</code>.
10204 <hr><h3><a name="pdf-math.pi"><code>math.pi</code></a></h3>
10214 <hr><h3><a name="pdf-math.rad"><code>math.rad (x)</code></a></h3>
10218 Converts the angle <code>x</code> from degrees to radians.
10224 <hr><h3><a name="pdf-math.random"><code>math.random ([m [, n]])</code></a></h3>
10231 When called with two integers <code>m</code> and <code>n</code>,
10232 <code>math.random</code> returns a pseudo-random integer
10234 The call <code>math.random(n)</code>, for a positive <code>n</code>,
10235 is equivalent to <code>math.random(1,n)</code>.
10236 The call <code>math.random(0)</code> produces an integer with
10241 This function uses the <code>xoshiro256**</code> algorithm to produce
10250 a call to <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with no arguments,
10251 so that <code>math.random</code> should generate
10258 <hr><h3><a name="pdf-math.randomseed"><code>math.randomseed ([x [, y]])</code></a></h3>
10263 the integer parameters <code>x</code> and <code>y</code> are
10267 The default for <code>y</code> is zero.
10286 you should call <a href="#pdf-math.randomseed"><code>math.randomseed</code></a> with explicit argum…
10292 <hr><h3><a name="pdf-math.sin"><code>math.sin (x)</code></a></h3>
10296 Returns the sine of <code>x</code> (assumed to be in radians).
10302 <hr><h3><a name="pdf-math.sqrt"><code>math.sqrt (x)</code></a></h3>
10306 Returns the square root of <code>x</code>.
10307 (You can also use the expression <code>x^0.5</code> to compute this value.)
10313 <hr><h3><a name="pdf-math.tan"><code>math.tan (x)</code></a></h3>
10317 Returns the tangent of <code>x</code> (assumed to be in radians).
10323 <hr><h3><a name="pdf-math.tointeger"><code>math.tointeger (x)</code></a></h3>
10327 If the value <code>x</code> is convertible to an integer,
10335 <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3>
10339 Returns "<code>integer</code>" if <code>x</code> is an integer,
10340 "<code>float</code>" if it is a float,
10341 or <b>fail</b> if <code>x</code> is not a number.
10347 <hr><h3><a name="pdf-math.ult"><code>math.ult (m, n)</code></a></h3>
10352 true if and only if integer <code>m</code> is below integer <code>n</code> when
10374 all operations are supplied by table <a name="pdf-io"><code>io</code></a>.
10376 the operation <a href="#pdf-io.open"><code>io.open</code></a> returns a file handle
10382 for <code>__gc</code> and <code>__close</code> that try
10387 The table <code>io</code> also provides
10389 …f-io.stdin"><code>io.stdin</code></a>, <a name="pdf-io.stdout"><code>io.stdout</code></a>, and <a …
10397 a system-dependent error code as a third result,
10400 the computation of the error message and error code
10403 because they rely on the global C variable <code>errno</code>.
10407 <hr><h3><a name="pdf-io.close"><code>io.close ([file])</code></a></h3>
10411 Equivalent to <code>file:close()</code>.
10412 Without a <code>file</code>, closes the default output file.
10418 <hr><h3><a name="pdf-io.flush"><code>io.flush ()</code></a></h3>
10422 Equivalent to <code>io.output():flush()</code>.
10428 <hr><h3><a name="pdf-io.input"><code>io.input ([file])</code></a></h3>
10442 instead of returning an error code.
10448 <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename, ···])</code></a></h3>
10454 works like <code>file:lines(···)</code> over the opened file.
10458 <code>io.lines</code> returns three other values:
10467 The call <code>io.lines()</code> (with no file name) is equivalent
10468 to <code>io.input():lines("l")</code>;
10476 instead of returning an error code.
10482 <hr><h3><a name="pdf-io.open"><code>io.open (filename [, mode])</code></a></h3>
10487 in the mode specified in the string <code>mode</code>.
10493 The <code>mode</code> string can be any of the following:
10496 <li><b>"<code>r</code>": </b> read mode (the default);</li>
10497 <li><b>"<code>w</code>": </b> write mode;</li>
10498 <li><b>"<code>a</code>": </b> append mode;</li>
10499 <li><b>"<code>r+</code>": </b> update mode, all previous data is preserved;</li>
10500 <li><b>"<code>w+</code>": </b> update mode, all previous data is erased;</li>
10501 <li><b>"<code>a+</code>": </b> append update mode, previous data is preserved,
10504 The <code>mode</code> string can also have a '<code>b</code>' at the end,
10511 <hr><h3><a name="pdf-io.output"><code>io.output ([file])</code></a></h3>
10515 Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output …
10521 <hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3>
10530 Starts the program <code>prog</code> in a separated process and returns
10532 (if <code>mode</code> is <code>"r"</code>, the default)
10534 (if <code>mode</code> is <code>"w"</code>).
10540 <hr><h3><a name="pdf-io.read"><code>io.read (···)</code></a></h3>
10544 Equivalent to <code>io.input():read(···)</code>.
10550 <hr><h3><a name="pdf-io.tmpfile"><code>io.tmpfile ()</code></a></h3>
10563 <hr><h3><a name="pdf-io.type"><code>io.type (obj)</code></a></h3>
10567 Checks whether <code>obj</code> is a valid file handle.
10568 Returns the string <code>"file"</code> if <code>obj</code> is an open file handle,
10569 <code>"closed file"</code> if <code>obj</code> is a closed file handle,
10570 or <b>fail</b> if <code>obj</code> is not a file handle.
10576 <hr><h3><a name="pdf-io.write"><code>io.write (···)</code></a></h3>
10580 Equivalent to <code>io.output():write(···)</code>.
10586 <hr><h3><a name="pdf-file:close"><code>file:close ()</code></a></h3>
10590 Closes <code>file</code>.
10597 When closing a file handle created with <a href="#pdf-io.popen"><code>io.popen</code></a>,
10598 <a href="#pdf-file:close"><code>file:close</code></a> returns the same values
10599 returned by <a href="#pdf-os.execute"><code>os.execute</code></a>.
10605 <hr><h3><a name="pdf-file:flush"><code>file:flush ()</code></a></h3>
10609 Saves any written data to <code>file</code>.
10615 <hr><h3><a name="pdf-file:lines"><code>file:lines (···)</code></a></h3>
10623 uses "<code>l</code>" as a default.
10631 Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
10638 <hr><h3><a name="pdf-file:read"><code>file:read (···)</code></a></h3>
10642 Reads the file <code>file</code>,
10659 <li><b>"<code>n</code>": </b>
10666 (e.g., an empty string, "<code>0x</code>", or "<code>3.4e-</code>")
10671 <li><b>"<code>a</code>": </b>
10677 <li><b>"<code>l</code>": </b>
10683 <li><b>"<code>L</code>": </b>
10691 If <code>number</code> is zero,
10697 The formats "<code>l</code>" and "<code>L</code>" should be used only for text files.
10703 <hr><h3><a name="pdf-file:seek"><code>file:seek ([whence [, offset]])</code></a></h3>
10709 to the position given by <code>offset</code> plus a base
10710 specified by the string <code>whence</code>, as follows:
10713 <li><b>"<code>set</code>": </b> base is position 0 (beginning of the file);</li>
10714 <li><b>"<code>cur</code>": </b> base is current position;</li>
10715 <li><b>"<code>end</code>": </b> base is end of file;</li>
10717 In case of success, <code>seek</code> returns the final file position,
10719 If <code>seek</code> fails, it returns <b>fail</b>,
10724 The default value for <code>whence</code> is <code>"cur"</code>,
10725 and for <code>offset</code> is 0.
10726 Therefore, the call <code>file:seek()</code> returns the current
10728 the call <code>file:seek("set")</code> sets the position to the
10730 and the call <code>file:seek("end")</code> sets the position to the
10737 <hr><h3><a name="pdf-file:setvbuf"><code>file:setvbuf (mode [, size])</code></a></h3>
10745 <li><b>"<code>no</code>": </b> no buffering.</li>
10746 <li><b>"<code>full</code>": </b> full buffering.</li>
10747 <li><b>"<code>line</code>": </b> line buffering.</li>
10752 <code>size</code> is a hint for the size of the buffer, in bytes.
10758 check the underlying ISO C function <code>setvbuf</code> in your platform for
10765 <hr><h3><a name="pdf-file:write"><code>file:write (···)</code></a></h3>
10769 Writes the value of each of its arguments to <code>file</code>.
10774 In case of success, this function returns <code>file</code>.
10785 This library is implemented through table <a name="pdf-os"><code>os</code></a>.
10789 <hr><h3><a name="pdf-os.clock"><code>os.clock ()</code></a></h3>
10795 as returned by the underlying ISO C function <code>clock</code>.
10801 <hr><h3><a name="pdf-os.date"><code>os.date ([format [, time]])</code></a></h3>
10806 formatted according to the given string <code>format</code>.
10810 If the <code>time</code> argument is present,
10812 (see the <a href="#pdf-os.time"><code>os.time</code></a> function for a description of this value).
10813 Otherwise, <code>date</code> formats the current time.
10817 If <code>format</code> starts with '<code>!</code>',
10820 if <code>format</code> is the string "<code>*t</code>",
10821 then <code>date</code> returns a table with the following fields:
10822 <code>year</code>, <code>month</code> (1–12), <code>day</code> (1–31),
10823 <code>hour</code> (0–23), <code>min</code> (0–59),
10824 <code>sec</code> (0–61, due to leap seconds),
10825 <code>wday</code> (weekday, 1–7, Sunday is 1),
10826 <code>yday</code> (day of the year, 1–366),
10827 and <code>isdst</code> (daylight saving flag, a boolean).
10833 If <code>format</code> is not "<code>*t</code>",
10834 then <code>date</code> returns the date as a string,
10835 formatted according to the same rules as the ISO C function <code>strftime</code>.
10839 If <code>format</code> is absent, it defaults to "<code>%c</code>",
10847 because of its reliance on C function <code>gmtime</code> and C function <code>localtime<…
10853 <hr><h3><a name="pdf-os.difftime"><code>os.difftime (t2, t1)</code></a></h3>
10858 from time <code>t1</code> to time <code>t2</code>
10859 (where the times are values returned by <a href="#pdf-os.time"><code>os.time</code></a>).
10861 this value is exactly <code>t2</code><em>-</em><code>t1</code>.
10867 <hr><h3><a name="pdf-os.execute"><code>os.execute ([command])</code></a></h3>
10871 This function is equivalent to the ISO C function <code>system</code>.
10872 It passes <code>command</code> to be executed by an operating system shell.
10882 <li><b>"<code>exit</code>": </b>
10887 <li><b>"<code>signal</code>": </b>
10895 When called without a <code>command</code>,
10896 <code>os.execute</code> returns a boolean that is true if a shell is available.
10902 <hr><h3><a name="pdf-os.exit"><code>os.exit ([code [, close]])</code></a></h3>
10906 Calls the ISO C function <code>exit</code> to terminate the host program.
10907 If <code>code</code> is <b>true</b>,
10908 the returned status is <code>EXIT_SUCCESS</code>;
10909 if <code>code</code> is <b>false</b>,
10910 the returned status is <code>EXIT_FAILURE</code>;
10911 if <code>code</code> is a number,
10913 The default value for <code>code</code> is <b>true</b>.
10917 If the optional second argument <code>close</code> is true,
10924 <hr><h3><a name="pdf-os.getenv"><code>os.getenv (varname)</code></a></h3>
10928 Returns the value of the process environment variable <code>varname</code>
10935 <hr><h3><a name="pdf-os.remove"><code>os.remove (filename)</code></a></h3>
10942 plus a string describing the error and the error code.
10949 <hr><h3><a name="pdf-os.rename"><code>os.rename (oldname, newname)</code></a></h3>
10953 Renames the file or directory named <code>oldname</code> to <code>newname</code>.
10955 plus a string describing the error and the error code.
10962 <hr><h3><a name="pdf-os.setlocale"><code>os.setlocale (locale [, category])</code></a></h3>
10967 <code>locale</code> is a system-dependent string specifying a locale;
10968 <code>category</code> is an optional string describing which category to change:
10969 <code>"all"</code>, <code>"collate"</code>, <code>"ctype"</code>,
10970 <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>;
10971 the default category is <code>"all"</code>.
10977 If <code>locale</code> is the empty string,
10979 If <code>locale</code> is the string "<code>C</code>",
10991 because of its reliance on C function <code>setlocale</code>.
10997 <hr><h3><a name="pdf-os.time"><code>os.time ([table])</code></a></h3>
11003 This table must have fields <code>year</code>, <code>month</code>, and <code>day</code>,
11005 <code>hour</code> (default is 12),
11006 <code>min</code> (default is 0),
11007 <code>sec</code> (default is 0),
11008 and <code>isdst</code> (default is <b>nil</b>).
11010 For a description of these fields, see the <a href="#pdf-os.date"><code>os.date</code></a> function.
11016 For instance, if <code>sec</code> is -10,
11018 if <code>hour</code> is 1000,
11028 and the number returned by <code>time</code> can be used only as an argument to
11029 <a href="#pdf-os.date"><code>os.date</code></a> and <a href="#pdf-os.difftime"><code>os.difftime</c…
11034 <code>os.time</code> also normalizes all the fields
11035 documented in the <a href="#pdf-os.date"><code>os.date</code></a> function,
11043 <hr><h3><a name="pdf-os.tmpname"><code>os.tmpname ()</code></a></h3>
11065 you may prefer to use <a href="#pdf-io.tmpfile"><code>io.tmpfile</code></a>,
11081 violate basic assumptions about Lua code
11084 that userdata metatables cannot be changed by Lua code;
11086 and therefore can compromise otherwise secure code.
11092 inside the <a name="pdf-debug"><code>debug</code></a> table.
11100 <hr><h3><a name="pdf-debug.debug"><code>debug.debug ()</code></a></h3>
11109 A line containing only the word <code>cont</code> finishes this function,
11114 Note that commands for <code>debug.debug</code> are not lexically nested
11121 <hr><h3><a name="pdf-debug.gethook"><code>debug.gethook ([thread])</code></a></h3>
11128 as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function.
11138 <hr><h3><a name="pdf-debug.getinfo"><code>debug.getinfo ([thread,] f [, what])</code></a></h3>
11144 or you can give a number as the value of <code>f</code>,
11145 which means the function running at level <code>f</code> of the call stack
11147 level 0 is the current function (<code>getinfo</code> itself);
11148 level 1 is the function that called <code>getinfo</code>
11151 If <code>f</code> is a number greater than the number of active functions,
11152 then <code>getinfo</code> returns <b>fail</b>.
11156 …d table can contain all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>,
11157 with the string <code>what</code> describing which fields to fill in.
11158 The default for <code>what</code> is to get all information available,
11161 the option '<code>f</code>'
11162 adds a field named <code>func</code> with the function itself.
11164 the option '<code>L</code>'
11165 adds a field named <code>activelines</code> with the table of
11170 For instance, the expression <code>debug.getinfo(1,"n").name</code> returns
11173 and the expression <code>debug.getinfo(print)</code>
11175 about the <a href="#pdf-print"><code>print</code></a> function.
11181 <hr><h3><a name="pdf-debug.getlocal"><code>debug.getlocal ([thread,] f, local)</code></a></h3>
11186 with index <code>local</code> of the function at level <code>f</code> of the stack.
11193 following the order that they are declared in the code,
11203 (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the leve…
11207 Variable names starting with '<code>(</code>' (open parenthesis)
11214 The parameter <code>f</code> may also be a function.
11215 In that case, <code>getlocal</code> returns only the name of function parameters.
11221 <hr><h3><a name="pdf-debug.getmetatable"><code>debug.getmetatable (value)</code></a></h3>
11225 Returns the metatable of the given <code>value</code>
11232 <hr><h3><a name="pdf-debug.getregistry"><code>debug.getregistry ()</code></a></h3>
11242 <hr><h3><a name="pdf-debug.getupvalue"><code>debug.getupvalue (f, up)</code></a></h3>
11247 with index <code>up</code> of the function <code>f</code>.
11259 For C functions, this function uses the empty string <code>""</code>
11264 Variable name '<code>?</code>' (interrogation mark)
11272 <hr><h3><a name="pdf-debug.getuservalue"><code>debug.getuservalue (u, n)</code></a></h3>
11276 Returns the <code>n</code>-th user value associated
11277 to the userdata <code>u</code> plus a boolean,
11284 <hr><h3><a name="pdf-debug.setcstacklimit"><code>debug.setcstacklimit (limit)</code></a></h3>
11298 Each call made from Lua code counts one unit.
11309 <li><code>limit</code> must be less than 40000;</li>
11310 <li><code>limit</code> cannot be less than the amount of C stack in use.</li>
11321 <hr><h3><a name="pdf-debug.sethook"><code>debug.sethook ([thread,] hook, mask [, count])</code></a>…
11326 The string <code>mask</code> and the number <code>count</code> describe
11332 <li><b>'<code>c</code>': </b> the hook is called every time Lua calls a function;</li>
11333 <li><b>'<code>r</code>': </b> the hook is called every time Lua returns from a function;</li>
11334 <li><b>'<code>l</code>': </b> the hook is called every time Lua enters a new line of code.</li>
11337 with a <code>count</code> different from zero,
11338 the hook is called also after every <code>count</code> instructions.
11343 <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> turns off the hook.
11349 <code>"call"</code>, <code>"tail call"</code>, <code>"return"</code>,
11350 <code>"line"</code>, and <code>"count"</code>.
11354 you can call <code>getinfo</code> with level 2 to get more information about
11356 (Level 0 is the <code>getinfo</code> function,
11363 <hr><h3><a name="pdf-debug.setlocal"><code>debug.setlocal ([thread,] level, local, value)</code></a…
11367 This function assigns the value <code>value</code> to the local variable
11368 with index <code>local</code> of the function at level <code>level</code> of the stack.
11371 and raises an error when called with a <code>level</code> out of range.
11372 (You can call <code>getinfo</code> to check whether the level is valid.)
11377 See <a href="#pdf-debug.getlocal"><code>debug.getlocal</code></a> for more information about
11384 <hr><h3><a name="pdf-debug.setmetatable"><code>debug.setmetatable (value, table)</code></a></h3>
11388 Sets the metatable for the given <code>value</code> to the given <code>table</code>
11390 Returns <code>value</code>.
11396 <hr><h3><a name="pdf-debug.setupvalue"><code>debug.setupvalue (f, up, value)</code></a></h3>
11400 This function assigns the value <code>value</code> to the upvalue
11401 with index <code>up</code> of the function <code>f</code>.
11408 See <a href="#pdf-debug.getupvalue"><code>debug.getupvalue</code></a> for more information about up…
11414 <hr><h3><a name="pdf-debug.setuservalue"><code>debug.setuservalue (udata, value, n)</code></a></h3>
11418 Sets the given <code>value</code> as
11419 the <code>n</code>-th user value associated to the given <code>udata</code>.
11420 <code>udata</code> must be a full userdata.
11424 Returns <code>udata</code>,
11431 <hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message [, level]])</code><…
11435 If <code>message</code> is present but is neither a string nor <b>nil</b>,
11436 this function returns <code>message</code> without further processing.
11439 The optional <code>message</code> string is appended
11441 An optional <code>level</code> number tells at which level
11443 (default is 1, the function calling <code>traceback</code>).
11449 <hr><h3><a name="pdf-debug.upvalueid"><code>debug.upvalueid (f, n)</code></a></h3>
11454 for the upvalue numbered <code>n</code>
11469 <hr><h3><a name="pdf-debug.upvaluejoin"><code>debug.upvaluejoin (f1, n1, f2, n2)</code></a></h3>
11473 Make the <code>n1</code>-th upvalue of the Lua closure <code>f1</code>
11474 refer to the <code>n2</code>-th upvalue of the Lua closure <code>f2</code>.
11489 called simply <code>lua</code>,
11501 <li><b><code>-e <em>stat</em></code>: </b> execute string <em>stat</em>;</li>
11502 <li><b><code>-i</code>: </b> enter interactive mode after running <em>script</em>;</li>
11503 <li><b><code>-l <em>mod</em></code>: </b> "require" <em>mod</em> and assign the
11505 <li><b><code>-v</code>: </b> print version information;</li>
11506 <li><b><code>-E</code>: </b> ignore environment variables;</li>
11507 <li><b><code>-W</code>: </b> turn warnings on;</li>
11508 <li><b><code>--</code>: </b> stop handling options;</li>
11509 <li><b><code>-</code>: </b> execute <code>stdin</code> as a file and stop handling options.</li>
11511 After handling its options, <code>lua</code> runs the given <em>script</em>.
11513 <code>lua</code> behaves as <code>lua -v -i</code>
11514 when the standard input (<code>stdin</code>) is a terminal,
11515 and as <code>lua -</code> otherwise.
11519 When called without the option <code>-E</code>,
11520 …rpreter checks for an environment variable <a name="pdf-LUA_INIT_5_4"><code>LUA_INIT_5_4</code></a>
11521 (or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if the versioned name is not defined)
11523 If the variable content has the format <code>@<em>filename</em></code>,
11524 then <code>lua</code> executes the file.
11525 Otherwise, <code>lua</code> executes the string itself.
11529 When called with the option <code>-E</code>,
11532 … of <a href="#pdf-package.path"><code>package.path</code></a> and <a href="#pdf-package.cpath"><co…
11533 are set with the default paths defined in <code>luaconf.h</code>.
11537 The options <code>-e</code>, <code>-l</code>, and <code>-W</code> are handled in
11544 will first set <code>a</code> to 1, then require the library <code>lib1</code>,
11545 and finally run the file <code>script.lua</code> with no arguments.
11546 (Here <code>$</code> is the shell prompt. Your prompt may be different.)
11550 Before running any code,
11551 <code>lua</code> collects all command-line arguments
11552 in a global table called <code>arg</code>.
11579 will print "<code>-e</code>".
11582 <code>arg[1]</code>, ···, <code>arg[#arg]</code>.
11600 If the global variable <a name="pdf-_PROMPT"><code>_PROMPT</code></a> contains a string,
11602 Similarly, if the global variable <a name="pdf-_PROMPT2"><code>_PROMPT2</code></a> contains a strin…
11611 has a metamethod <code>__tostring</code>,
11622 (see <a href="#lua_close"><code>lua_close</code></a>).
11624 calling <a href="#pdf-os.exit"><code>os.exit</code></a> to terminate.
11630 Lua skips the first line of a file chunk if it starts with <code>#</code>.
11632 by using <code>chmod +x</code> and the <code>#!</code> form,
11640 If <code>lua</code> is in your <code>PATH</code>,
11661 appropriate options (see file <code>luaconf.h</code>).
11668 you should try to test your code with a version of Lua compiled
11675 do not imply source-code changes in a program,
11712 For instance, the result of <code>"1" + "2"</code> now is an integer,
11725 The use of the <code>__lt</code> metamethod to emulate <code>__le</code>
11744 Lua does not ignore <code>__gc</code> metamethods that are not functions.
11759 The function <a href="#pdf-print"><code>print</code></a> does not call <a href="#pdf-tostring"><cod…
11762 You should use <code>__tostring</code> to modify how values are printed.
11766 …andom number generator used by the function <a href="#pdf-math.random"><code>math.random</code></a>
11772 By default, the decoding functions in the <a href="#pdf-utf8"><code>utf8</code></a> library
11773 do not accept surrogates as valid code points.
11778 The options "<code>setpause</code>" and "<code>setstepmul</code>"
11779 of the function <a href="#pdf-collectgarbage"><code>collectgarbage</code></a> are deprecated.
11780 You should use the new option "<code>incremental</code>" to set them.
11784 The function <a href="#pdf-io.lines"><code>io.lines</code></a> now returns four values,
11788 such as in <code>load(io.lines(filename, "L"))</code>.
11806 Therefore, the functions <code>lua_newuserdata</code>,
11807 <code>lua_setuservalue</code>, and <code>lua_getuservalue</code> were
11808 replaced by <a href="#lua_newuserdatauv"><code>lua_newuserdatauv</code></a>,
11809 … href="#lua_setiuservalue"><code>lua_setiuservalue</code></a>, and <a href="#lua_getiuservalue"><c…
11821 The function <a href="#lua_resume"><code>lua_resume</code></a> has an extra parameter.
11829 The function <a href="#lua_version"><code>lua_version</code></a> returns the version number,
11838 The constant <code>LUA_ERRGCMM</code> was removed.
11844 The options <code>LUA_GCSETPAUSE</code> and <code>LUA_GCSETSTEPMUL</code>
11845 of the function <a href="#lua_gc"><code>lua_gc</code></a> are deprecated.
11846 You should use the new option <code>LUA_GCINC</code> to set them.