ecogenenergy.info Laws Lua Manual Pdf

LUA MANUAL PDF

Sunday, December 15, 2019


Nov 25, Lua Reference Manual. Roberto Ierusalimschy. Luiz Henrique de Figueiredo. Waldemar Celes [email protected] Tecgraf — Computer. Jul 28, The official definition of the Lua language is its reference manual, which These manuals are also available here in PostScript and PDF. Jun 26, The implementation described in this manual is available at Lua's official web site , ecogenenergy.info Like any other reference manual, this.


Lua Manual Pdf

Author:SYBLE GILBRIDE
Language:English, Spanish, Arabic
Country:Ecuador
Genre:Religion
Pages:677
Published (Last):03.10.2015
ISBN:780-9-56025-536-3
ePub File Size:24.40 MB
PDF File Size:8.44 MB
Distribution:Free* [*Regsitration Required]
Downloads:34008
Uploaded by: ROSENA

Nov 13, The implementation described in this manual is available at Lua's official web site , ecogenenergy.info Like any other reference manual, this. Complete manual with pages. • Mechanisms Lua is also quite Efficient. • Several independent benchmarks show. Lua as the most efficient in the realm of. Jan 13, The reference manual is a must for anyone who wants to really learn a language. This book does not replace the Lua reference manual.

The semantics of these operations is better explained by a Lua function describing how the interpreter executes the operation. The code shown here in Lua is only illustrative; the real behavior is hard coded in the interpreter and it is much more efficient than this simulation.

Index of /pdf/Gentoomen Library/Programming/Lua/

All functions used in these descriptions rawget , tonumber , etc. The function getbinhandler below defines how Lua chooses a handler for a binary operation. First, Lua tries the first operand. If its type does not define a handler for the operation, then Lua tries the second operand. Behavior similar to the "add" operation. The function getcomphandler defines how Lua chooses a metamethod for comparison operators. A metamethod only is selected when both objects being compared have the same type and the same metamethod for the selected operation.

Like metatables, environments are regular tables and multiple objects can share the same environment. Threads are created sharing the environment of the creating thread. Non-nested Lua functions created by loadfile , loadstring or load are created sharing the environment of the creating thread. Nested Lua functions are created sharing the environment of the creating Lua function. Environments associated with userdata have no meaning for Lua.

CHDK Lua Reference Card

It is only a convenience feature for programmers to associate a table to a userdata. Environments associated with threads are called global environments. They are used as the default environment for nested Lua functions created by the function. You can change the environment of a Lua function or the running thread by calling setfenv.

You can get the environment of a Lua function or the running thread by calling getfenv. This means that you have to worry neither about allocating memory for new objects nor about freeing it when the objects are no longer needed. Lua manages memory automatically by running a garbage collector from time to time to collect all dead objects that is, objects that are no longer accessible from Lua.

All memory used by Lua is subject to automatic management: tables, userdata, functions, threads, strings, etc. Lua implements an incremental mark-and-sweep collector. It uses two numbers to control its garbage-collection cycles: the garbage-collector pause and the garbage-collector step multiplier.

Both use percentage points as units so that a value of means an internal value of 1. The garbage-collector pause controls how long the collector waits before starting a new cycle. Larger values make the collector less aggressive. Values smaller than mean the collector will not wait to start a new cycle.

A value of means that the collector waits for the total memory in use to double before starting a new cycle. The step multiplier controls the relative speed of the collector relative to memory allocation. Larger values make the collector more aggressive but also increase the size of each incremental step. Values smaller than make the collector too slow and can result in the collector never finishing a cycle.

The default, , means that the collector runs at "twice" the speed of memory allocation. With these functions you can also control the collector directly e. These metamethods are also called finalizers. Finalizers allow you to coordinate Lua's garbage collection with external resource management such as closing files, network or database connections, or freeing your own memory.

Instead, Lua puts them in a list. That is, the first finalizer to be called is the one associated with the userdata created last in the program. The userdata itself is freed only in the next garbage-collection cycle. A weak reference is ignored by the garbage collector. In other words, if the only references to an object are weak references, then the garbage collector will collect this object.

A weak table can have weak keys, weak values, or both. A table with weak keys allows the collection of its keys, but prevents the collection of its values. A table with both weak keys and weak values allows the collection of both keys and values. In any case, if either the key or the value is collected, the whole pair is removed from the table. Otherwise, the weak behavior of the tables controlled by this metatable is undefined.

A coroutine in Lua represents an independent thread of execution. Unlike threads in multithread systems, however, a coroutine only suspends its execution by explicitly calling a yield function. You create a coroutine with a call to coroutine. Its sole argument is a function that is the main function of the coroutine.

The create function only creates a new coroutine and returns a handle to it an object of type thread ; it does not start the coroutine execution. When you first call coroutine.

Lua scripting

Extra arguments passed to coroutine. After the coroutine starts running, it runs until it terminates or yields. A coroutine can terminate its execution in two ways: normally, when its main function returns explicitly or implicitly, after the last instruction ; and abnormally, if there is an unprotected error.

In the first case, coroutine. In case of errors, coroutine. A coroutine yields by calling coroutine. When a coroutine yields, the corresponding coroutine. In the case of a yield, coroutine. The next time you resume the same coroutine, it continues its execution from the point where it yielded, with the call to coroutine. Like coroutine. Besides the Lua state, the continuation function has two other parameters: Lua does not use this context value; it only passes this value from the original function to the continuation function.

For these two functions, Lua will not call the continuation in case of errors, because they do not handle errors. Lua treats the continuation function as if it were the original function. The continuation function receives the same Lua stack from the original function, in the same state it would be if the callee function had returned. It also has the same upvalues. Whatever it returns is handled by Lua as if it were the return of the original function. Each function has an indicator like this: The second field, p , is how many elements the function pushes onto the stack.

Any function always pushes its results after popping its arguments. A field in the form x y means the function can push or pop x or y elements, depending on the situation; an interrogation mark '? The third field, x , tells whether the function may raise errors: The allocator function must provide a functionality similar to realloc , but not exactly the same. When ptr is not NULL , osize is the size of the block pointed by ptr , that is, the size given when it was allocated or reallocated.

When osize is some other value, Lua is allocating memory for something else. Lua assumes the following behavior from the allocator function: When nsize is zero, the allocator must behave like free and return NULL. When nsize is not zero, the allocator must behave like realloc. The allocator returns NULL if and only if it cannot fulfill the request. Here is a simple implementation for the allocator function.

This code assumes that realloc does not fail when shrinking a block. The function follows the semantics of the corresponding Lua operator that is, it may call metamethods. The value of op must be one of the following constants: To call a function you must use the following protocol: All arguments and the function value are popped from the stack when the function is called.

The function results are pushed onto the stack when the function returns. In this case, all results from the function are pushed; Lua takes care that the returned values fit into the stack space, but it does not ensure any extra space in the stack. The function results are pushed onto the stack in direct order the first result is pushed first , so that after the call the last result is on the top of the stack. Any error inside the called function is propagated upwards with a longjmp. The following example shows how the host program can do the equivalent to this Lua code: This is considered good programming practice.

Any other value in the stack below the results will be properly discarded by Lua. As an example, the following function receives a variable number of numeric arguments and returns their average and their sum: It returns false if it cannot fulfill the request, either because it would cause the stack to be larger than a fixed maximum size typically at least several thousand elements or because it cannot allocate memory for the extra space. This function never shrinks the stack; if the stack already has space for the extra slots, it is left unchanged.

In several platforms, you may not need to call this function, because all resources are naturally released when the host program ends.

On the other hand, long-running programs that create multiple states, such as daemons or web servers, will probably need to close states as soon as they are not needed. Returns 1 if the value at index index1 satisfies op when compared with the value at index index2 , following the semantics of the corresponding Lua operator that is, it may call metamethods.

Values at other positions are not affected. Parameter narr is a hint for how many elements the table will have as a sequence; parameter nrec is a hint for how many other elements the table will have.

Lua may use these hints to preallocate memory for the new table. This preallocation is useful for performance when you know in advance how many elements the table will have. Receives a Lua function on the top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped.

If strip is true, the binary representation may not include all debug information about the function, to save space. This function does not pop the Lua function from the stack. This function performs several tasks, according to the value of the parameter what: For more details about these options, see collectgarbage.

Returns the type of the pushed value. The application can use this area for any purpose; Lua does not use it for anything. Each new thread has this area initialized with a copy of the area of the main thread. By default, this area has the size of a pointer to void, but you can recompile Lua with a different size for this area. Returns the type of that value. This function pops the key from the stack, pushing the resulting value in its place. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.

By default this type is long long , usually a bit two-complement integer , but that can be changed to long or int usually a bit two-complement integer. It must be a numeric type. The result is pushed on the stack. Otherwise, it pushes an error message. This error has no relation with the chunk being loaded.

It is generated by the garbage collector. The data argument is an opaque value passed to the reader function. The string mode works as in function load , with the addition that a NULL value is equivalent to the string " bt ". Other upvalues are initialized with nil. Returns NULL if it cannot create the thread or the state due to lack of memory. The second argument, ud , is an opaque pointer that Lua passes to the allocator in every call.

The new thread returned by this function shares with the original thread its global environment, but has an independent execution stack. There is no explicit function to close or to destroy a thread. Threads are subject to garbage collection, like any Lua object. The host program can freely use this memory. A typical traversal looks like this: See function next for the caveats of modifying the table during its traversal.

By default this type is double, but that can be changed to a single float or a long double. This macro assumes that n has an integral value.

The macro results in a boolean indicating whether the conversion was successful. Note that this range test can be tricky to do correctly without this macro, due to roundings. This macro may evaluate its arguments more than once. If msgh is 0, then the error object returned on the stack is exactly the original error object. Otherwise, msgh is the stack index of a message handler. This index cannot be a pseudo-index. Typically, the message handler is used to add more debug information to the error object, such as a stack traceback.

For such errors, Lua does not call the message handler. For such errors, Lua does not call the message handler as this kind of error typically has no relation with the function being called. The maximum value for n is In that case, it never raises a memory error. You do not have to allocate space for the result: The conversion specifiers are quite restricted. There are no flags, widths, or precisions. Unlike other push functions, this function checks for the stack space it needs, including the slot for its result.

It is a value like a number: Lua makes or reuses an internal copy of the given string, so the memory at s can be freed or reused immediately after the function returns.

The string can contain any binary data, including embedded zeros. Returns a pointer to the internal copy of the string. Returns 1 if this thread is the main thread of its state. This function pops the value from the stack. The reader must return a pointer to a block of memory with a new piece of the chunk and set size to the block size. The block must exist until the reader function is called again. To signal the end of the chunk, the reader must return NULL or set size to zero.

The reader function may return pieces of any size greater than zero. It is defined as a macro: This call returns when the coroutine suspends or finishes its execution. In case of errors, the stack is not unwound, so you can use the debug API over it. The error object is on the top of the stack. The parameter from represents the coroutine that is resuming L. If there is no such coroutine, this parameter can be NULL. The elements are rotated n positions in the direction of the top, for a positive n , or -n positions in the direction of the bottom, for a negative n.

The absolute value of n must not be greater than the size of the slice being rotated. This function pops both the key and the value from the stack.

If the new top is larger than the old one, then the new elements are filled with nil. All information about a state is accessible through this structure. The string may have leading and trailing spaces and a sign. If the string is not a valid numeral, returns 0 and pushes nothing. Note that the result can be used as a boolean, true if the conversion succeeds.

If isnum is not NULL , its referent is assigned a boolean value that indicates whether the operation succeeded. Different objects will give different pointers. There is no way to convert the pointer back to its original value. Typically this function is used only for hashing and debug information. This value must be a thread; otherwise, the function returns NULL. If the value is a light userdata, returns its pointer. Otherwise, returns NULL. When called with NULL , returns the address of the version running the call.

The writer returns an error code: This function pops n values from the stack from , and pushes them onto the stack to. Usually, this function does not return; when the coroutine eventually resumes, it continues executing the continuation function.

Lua will yield and, when the coroutine resumes again, it will continue the normal execution of the Lua function that triggered the hook. This function can raise an error if it is called from a thread with a pending C call with no continuation function, or it is called from a thread that is not running inside a resume e. Instead, it offers a special interface by means of functions and hooks.

This interface allows the construction of different kinds of debuggers, profilers, and other tools that need "inside information" from the interpreter. If source starts with a ' ', it means that the function was defined in a file where the file name follows the ' '. Otherwise, the function was defined in a string where source is that string. When no line information is available, currentline is set to Because functions in Lua are first-class values, they do not have a fixed name: If it cannot find a name, then name is set to NULL.

The value of namewhat can be "global" , "local" , "method" , "field" , "upvalue" , or "" the empty string , according to how the function was called. Lua uses the empty string when no other option seems to apply. In this case, the caller of this level is not in the stack. For instance, to know in which line a function f was defined, you can write the following code: A valid line is a line with some associated code, that is, a line where you can put a break point.

Non-valid lines include empty lines and comments. If this option is given together with option ' f ', its table is pushed after the function. This function returns 0 on error for instance, an invalid option in what.

The index n selects which local variable to inspect; see debug. In the second case, ar must be NULL and the function to be inspected must be at the top of the stack. In this case, only parameters of Lua functions are visible as there is no information about what variables are active and no values are pushed onto the stack. Returns NULL and pushes nothing when the index is greater than the number of active local variables.

It pushes the upvalue's value onto the stack and returns its name. Returns NULL and pushes nothing when the index n is greater than the number of upvalues. For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure. Upvalues have no particular order, as they are active through the whole function. They are numbered in an arbitrary order.

Whenever a hook is called, its ar argument has its field event set to the specific event that triggered the hook. Lua identifies these events with the following constants: Moreover, for line events, the field currentline is also set. While Lua is running a hook, it disables other calls to hooks. Therefore, if a hook calls back Lua to execute a function or a chunk, this execution occurs without any calls to hooks.

Hook functions can yield under the following conditions: Argument f is the hook function. For each event, the hook is called as explained below: The call hook: The hook is called just after Lua enters the new function, before the function gets its arguments. The return hook: The hook is called just before Lua leaves the function. There is no standard way to access the values to be returned by the function.

The line hook: This event only happens while Lua is executing a Lua function. The count hook: A hook is disabled by setting mask to zero.

It assigns the value at the top of the stack to the variable and returns its name. It also pops the value from the stack.

Returns NULL and pops nothing when the index is greater than the number of active local variables. It assigns the value at the top of the stack to the upvalue and returns its name. Returns NULL and pops nothing when the index n is greater than the number of upvalues. These unique identifiers allow a program to check whether different closures share upvalues. Lua closures that share an upvalue that is, that access a same external local variable will return identical ids for those upvalue indices.

While the basic API provides the primitive functions for all interactions between C and Lua, the auxiliary library provides higher-level functions for some common tasks. All functions and types from the auxiliary library are defined in header file lauxlib. All functions in the auxiliary library are built on top of the basic API, and so they provide nothing that cannot be done with that API.

Nevertheless, the use of the auxiliary library ensures more consistency to your code. Several functions in the auxiliary library use internally some extra stack slots. When a function in the auxiliary library uses less than five slots, it does not check the stack size; it simply assumes that there are enough slots. Because the error message is formatted for arguments e.

The string can contain embedded zeros. Pops the value.

Laser Fundamentals

This is the only function on string buffers that can and must be called with an extra element on the stack, which is the value to be added to the buffer. Its pattern of use is as follows: This call leaves the final string on the top of the stack. If you know beforehand the total size of the resulting string, you can use the buffer like this: Then copy the string into that space.

During its normal operation, a string buffer uses a variable number of stack slots. So, while using a buffer, you cannot assume that you know where the top of the stack is. You can use the stack between successive calls to buffer operations as long as that use is balanced; that is, when you call a buffer operation, the stack is at the same level it was immediately after the previous buffer operation. If the object at index obj has a metatable and this metatable has a field e , this function calls this field passing the object as its only argument.

In this case this function returns true and pushes onto the stack the value returned by the call. If there is no metatable or no metamethod, this function returns false without pushing any value on the stack. Returns the index in the array where the string was found. Raises an error if the argument is not a string or if the string cannot be found.

If def is not NULL , the function uses def as a default value when there is no argument arg or when this argument is nil. The usual convention in Lua libraries is to use strings instead of numbers to select options. Also checks whether the core running the call and the core that created the Lua state are using the same address space. It is defined as the following macro: It also adds at the beginning of the message the file name and the line number where the error occurred, if this information is available.

Returns true if it finds a previous table there and false if it creates a new table. Pushes the resulting string on the stack and returns it. Raises an error if the result of the operation is not an integer. This case only can happen through metamethods.

If filename is NULL , then it loads from the standard input. The first line in the file is ignored if it starts with a. It is implemented as the following macro: It is implemented as a macro. The array l must be the actual array, not a pointer to it.

In both cases pushes onto the stack the final value associated with tname in the registry. Returns the new state, or NULL if there is a memory allocation error. Otherwise, it results in the result of calling func with the state L and the argument index arg as arguments.

Related Post: GTA 5 MANUAL PDF

Note that it evaluates the expression dflt only if needed. If this argument is absent or is nil , returns d. Otherwise, raises an error. A reference is a unique integer key. If glb is true, also stores the module into global modname. Leaves a copy of the module on the stack. When nup is not zero, all functions are created sharing nup upvalues, which must be previously pushed on the stack on top of the library table. These values are popped from the stack after the registration.

Field f points to the corresponding C stream or it can be NULL to indicate an incompletely created handle. Field closef points to a Lua function that will be called to close the stream when the handle is closed or collected; this function receives the file handle as its sole argument and must return either true in case of success or nil plus an error message in case of error. The resulting string is pushed onto the stack and also returned by the function.

If msg is not NULL it is appended at the beginning of the traceback. The level parameter tells at which level to start the traceback. The entry is removed from the table, so that the referred object can be collected. The reference ref is also freed to be used again. Typically this string has the following format: This function is used to build a prefix for error messages. Some of these functions provide essential services to the language e. Currently, Lua has the following standard libraries: Except for the basic and the package libraries, each library provides all its functions as fields of a global table or as methods of its objects.

These functions are declared in lualib. If you do not include this library in your application, you should check carefully whether you need to provide implementations for some of its facilities. In case of error, message is the error object; when absent, it defaults to " assertion failed! It performs different functions according to its first argument, opt: This is the default option.

The collector will run only when explicitly invoked, until a call to restart it. The value has a fractional part, so that it multiplied by gives the exact number of bytes in use by Lua except for overflows. The step "size" is controlled by arg. With a zero value, the collector will perform one basic indivisible step. For non-zero values, the collector will perform as if that amount of memory in KBytes had been allocated by Lua.

Returns true if the step finished a collection cycle. Returns the previous value for pause. Returns the previous value for step. When called without arguments, dofile executes the contents of the standard input stdin. Returns all values returned by the chunk. In case of errors, dofile propagates the error to its caller that is, dofile does not run in protected mode.

Function error never returns. Usually, error adds some information about the error position at the beginning of the message, if the message is a string. The level argument specifies how to get the error position.

Keyboard Shortcuts

Lua itself does not use this variable; changing its value does not affect any environment, nor vice versa. Otherwise, returns the metatable of the given object. If chunk is a string, the chunk is this string.

If chunk is a function, load calls it repeatedly to get the chunk pieces. Each call to chunk must return a string that concatenates with previous results. A return of an empty string, nil , or no value signals the end of the chunk. If there are no syntactic errors, returns the compiled chunk as a function; otherwise, returns nil plus the error message. If the resulting function has upvalues, the first upvalue is set to the value of env , if that parameter is given, or to the value of the global environment.

However, when you load a binary chunk created from a function see string. All upvalues are fresh, that is, they are not shared with any other function. The string mode controls whether the chunk can be text or binary that is, a precompiled chunk. It may be the string " b " only binary chunks , " t " only text chunks , or " bt " both binary and text.

The default is " bt ". Lua does not check the consistency of binary chunks. Maliciously crafted binary chunks can crash the interpreter. Its first argument is a table and its second argument is an index in this table.

When called with nil as its second argument, next returns an initial index and its associated value. When called with the last index, or with nil in an empty table, next returns nil. If the second argument is absent, then it is interpreted as nil. In particular, you can use next t to check whether a table is empty. The order in which the indices are enumerated is not specified, even for numeric indices. To traverse a table in numerical order, use a numerical for.

The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields.

Otherwise, returns three values: Its first result is the status code a boolean , which is true if the call succeeds without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false plus the error message.

For complete control over the output, use string. Returns a boolean. Returns an integer. This function returns table.

Otherwise, index must be the string " " , and select returns the total number of extra arguments it received. If metatable is nil , removes the metatable of the given table. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.

When called with base , then e must be a string to be interpreted as an integer numeral in that base. The base may be any integer between 2 and 36, inclusive. If the string e is not a valid numeral in the given base, the function returns nil. For complete control of how numbers are converted, use string.

The possible results of this function are " nil " a string, not the value nil , " number ", " string ", " boolean ", " table ", " function ", " thread ", and " userdata ". The current value of this variable is " Lua 5. Returns this new coroutine, an object with type "thread".

The first time you resume a coroutine, it starts running its body. The values val1 , If the coroutine has yielded, resume restarts it; the values val1 , If the coroutine runs without any errors, resume returns true plus any values passed to yield when the coroutine yields or any values returned by the body function when the coroutine terminates.

If there is any error, resume returns false plus the error message. Returns a function that resumes the coroutine each time it is called. Any arguments passed to the function behave as the extra arguments to resume. Returns the same values returned by resume , except the first boolean. In case of error, propagates the error. Any arguments to yield are passed as extra results to resume.

It exports one function directly in the global environment: Everything else is exported in a table package. The function starts by looking into the package. If it is, then require returns the value stored at package.

Otherwise, it tries to find a loader for the module. To find a loader, require is guided by the package. By changing this sequence, we can change how require looks for a module. The following explanation is based on the default configuration for package.

First require queries package. If it has a value, this value which must be a function is the loader. Otherwise require searches for a Lua loader using the path stored in package. If that also fails, it tries an all-in-one loader see package. Once a loader is found, require calls the loader with two arguments: If the loader came from a file, this extra value is the file name. If the loader returns any non-nil value, require assigns the returned value to package.

If the loader does not return a non-nil value and has not assigned any value to package. In any case, require returns the final value of package. If there is any error loading or running the module, or if it cannot find any loader for the module, then require raises an error. This string is a sequence of lines: The first line is the directory separator string. The second line is the character that separates templates in a path. Default is ' ; '.

The third line is the string that marks the substitution points in a template. Default is '? The fourth line is a string that, in a path in Windows, is replaced by the executable's directory. Default is '! Default is ' - '. When you require a module modname and package. This variable is only a reference to the real table; assignments to this variable do not change the table used by require.

This is a low-level function. It completely bypasses the package and module system. Unlike require , it does not perform any path searching and does not automatically adds extensions.

Any " ;; " in the value of the environment variable is replaced by the default path. Each entry in this table is a searcher function. When looking for a module, require calls each of these searchers in ascending order, with the module name the argument given to require as its sole parameter.

The function can return another function the module loader plus an extra value that will be passed to that loader, or a string explaining why it did not find that module or nil if it has nothing to say. Lua initializes this table with four searcher functions. The first searcher simply looks for a loader in the package. The second searcher looks for a loader as a Lua library, using the path stored at package.

The search is done as described in function package. Again, the search is done as described in function package. Moreover, if the module name has a hyphen, its suffix after and including the first hyphen is removed.

For instance, if the module name is a. The fourth searcher tries an all-in-one loader. For instance, when requiring a. All searchers except the first one preload return as the extra value the file name where the module was found, as returned by package.

The first searcher returns no extra value. A path is a string containing a sequence of templates separated by semicolons. For each template, the function replaces each interrogation mark if any in the template with a copy of name wherein all occurrences of sep a dot, by default were replaced by rep the system's directory separator, by default , and then tries to open the resulting file name.

For instance, if the path is the string ". Returns the resulting name of the first file that it can open in read mode after closing the file , or nil plus an error message if none succeeds.

This error message lists all file names it tried to open. Indices are allowed to be negative and are interpreted as indexing backwards, from the end of the string. Thus, the last character is at position -1, and so on. The string library provides all its functions inside the table string. Therefore, you can use the string functions in object-oriented style.

For instance, string. The string library assumes one-byte character encodings. These indices are corrected following the same rules of function string. Numeric codes are not necessarily portable across platforms. Returns a string with length equal to the number of arguments, in which each character has the internal numeric code equal to its corresponding argument.

If strip is a true value, the binary representation may not include all debug information about the function, to save space. Functions with upvalues have only their number of upvalues saved. When re loaded, those upvalues receive fresh instances containing nil. You can use the debug library to serialize and reload the upvalues of a function in a way adequate to your needs. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered magic.

Note that if plain is given, then init must be given as well. If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.

The q option formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter. For instance, the call string. When Lua is compiled with a C89 compiler, options A and a hexadecimal floats do not support any modifier flags, width, length. Option s expects a string; if its argument is not a string, it is converted to one following the same rules of tostring.

If the option has any modifier flags, width, length , the string argument should not contain embedded zeros. If pattern specifies no captures, then the whole match is produced in each call. As an example, the following loop will iterate over all the words from string s , printing one per line: The name gsub comes from Global SUBstitution.

If repl is a string, then its value is used for replacement. If repl is a table, then the table is queried for every match, using the first capture as the key. If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order. In any case, if the pattern specifies no captures, then it behaves as if the whole pattern was inside a capture. If the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is false or nil , then there is no replacement that is, the original match is kept in the string.

The empty string "" has length 0. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale. If it finds one, then match returns the captures from the pattern; otherwise it returns nil.

If pattern specifies no captures, then the whole match is returned. The default value for sep is the empty string that is, no separator. Returns the empty string if n is not positive. Note that it is very easy to exhaust the memory of your machine with a single call to this function.

If j is absent, then it is assumed to be equal to -1 which is the same as the string length. In particular, the call string.

If, after the translation of negative indices, i is less than 1, it is corrected to 1. If j is greater than the string length, it is corrected to that length.

If, after these corrections, i is greater than j , the function returns the empty string. An optional pos marks where to start reading in s default is 1. After the read values, this function also returns the index of the first unread byte in s. The definition of what a lowercase letter is depends on the current locale.

This section describes the syntax and the meaning that is, what they match of these strings. Character Class: A character class is used to represent a set of characters. The following combinations are allowed in describing a character class: This is the standard way to escape the magic characters. A range of characters can be specified by separating the end characters of the range, in ascending order, with a ' - '.

All other characters in set represent themselves.

You can put a closing square bracket in a set by positioning it as the first character in the set. You can put a hyphen in a set by positioning it as the first or the last character in the set. You can also use an escape for both cases. The interaction between ranges and classes is not defined.

The definitions of letter, space, and other character groups depend on the current locale. Pattern Item: These repetition items will always match the longest possible sequence; a single character class followed by ' - ', which also matches zero or more repetitions of characters in the class.

The set set is interpreted as previously described. A pattern is a sequence of pattern items. A pattern can contain sub-patterns enclosed in parentheses; they describe captures. When a match succeeds, the substrings of the subject string that match captures are stored captured for future use. Captures are numbered according to their left parentheses.

As a special case, the empty capture captures the current string position a number. For instance, if we apply the pattern " aa " on the string "flaaap" , there will be two captures: A format string is a sequence of conversion options. The conversion options are as follows: For options "!

All integral options check overflows; string. Any format string starts as if prefixed by "! Alignment works as follows: For each option, the format gets extra padding until the data starts at an offset that is a multiple of the minimum between the option size and the maximum alignment; this minimum must be a power of 2.

Options " c " and " z " are not aligned; option " s " follows the alignment of its starting integer. All padding is filled with zeros by string. It provides all its functions inside the table utf8. This library does not provide any support for Unicode other than the handling of the encoding.

Any operation that needs the meaning of a character, such as character classification, is outside its scope. Unless stated otherwise, all functions that expect a byte position as a parameter assume that the given position is either the start of a byte sequence or one plus the length of the subject string. As in the string library, negative indices count from the end of the string. It raises an error if it meets any invalid byte sequence.

The default for i is 1 and for j is i. The default for i is 1 and for j is If it finds any invalid byte sequence, returns a false value plus the position of the first invalid byte. A negative n gets characters before position i. If the specified character is neither in the subject nor right after its end, the function returns nil. As a special case, when n is 0 the function returns the start of the encoding of the character that contains the i -th byte of s.

This function assumes that s is a valid UTF-8 string. It provides all its functions inside the table table. All functions ignore non-numeric keys in the tables given as arguments. The default value for sep is the empty string, the default for i is 1, and the default for j is list.

If i is greater than j , returns the empty string. The default for a2 is a1. The destination range can overlap with the source range. The number of elements to be moved must fit in a Lua integer. Returns the destination table a2. Note that the resulting table may not be a sequence. The default value for pos is list , so that a call table.

Note that the comp function must define a strict partial order over the elements in the list; that is, it must be asymmetric and transitive. Otherwise, no valid sort may be possible. The sort algorithm is not stable: It provides all its functions and constants inside the table math. Rounding functions math. It also handles correctly the case of x being zero. The default value for x is 1, so that the call math. The default for base is e so that the function returns the natural logarithm of x.

Its second result is always a float. When called with two integers m and n , math. The value n-m cannot be negative and must fit in a Lua integer.

The call math. This function is an interface to the underling pseudo-random generator function provided by C. Otherwise, returns nil.

The second style uses explicit file handles. When using implicit file handles, all operations are supplied by table io. When using explicit file handles, the operation io. The table io also provides three predefined file handles with their usual meanings from C: In non-POSIX systems, the computation of the error message and error code in case of errors may be not thread safe, because they rely on the global C variable errno.

Without a file , closes the default output file. When called with a file handle, it simply sets this file handle as the default input file.

When called without arguments, it returns the current default input file. In case of errors this function raises the error, instead of returning an error code. When the iterator function detects the end of file, it returns no values to finish the loop and automatically closes the file. The call io. In this case, the iterator does not close the file when the loop ends. In case of success, it returns a new file handle.

The mode string can be any of the following: The mode string can also have a ' b ' at the end, which is needed in some systems to open the file in binary mode. Starts program prog in a separated process and returns a file handle that you can use to read data from this program if mode is "r" , the default or to write data to this program if mode is "w".

This file is opened in update mode and it is automatically removed when the program ends. Returns the string "file" if obj is an open file handle, "closed file" if obj is a closed file handle, or nil if obj is not a file handle.

Note that files are automatically closed when their handles are garbage collected, but that takes an unpredictable amount of time to happen. When closing a file handle created with io. When no format is given, uses " l " as a default. As an example, the construction for c in file: Unlike io. For each format, the function returns a string or a number with the characters read, or nil if it cannot read data with the specified format.

In this latter case, the function does not read subsequent formats. When called without formats, it uses a default format that reads the next line see below.

The available formats are " n ": The numeral may have leading spaces and a sign. This format always reads the longest input sequence that is a valid prefix for a numeral; if that prefix does not form a valid numeral e.

On end of file, it returns the empty string. This is the default format. If number is zero, it reads nothing and returns an empty string, or nil on end of file.All results of the call are the result of the operation. All upvalues are fresh, that is, they are not shared with any other function. The names shown here are for explanatory purposes only. Rounding functions math.

If there is no such coroutine, this parameter can be NULL. Lua initializes this table with four searcher functions.

BROOKS from Sterling Heights
I relish exploring ePub and PDF books far . Review my other posts. I have a variety of hobbies, like kelly pool.