Function Calls

3.4.10 – Function Calls A function call in Lua has the following syntax: functioncall ::= prefixexp args In a function call, first prefixexp and args are evaluated. If the value of prefixexp has type function, then this function is called with the given arguments. Otherwise, the prefixexp "call" metamethod is called, having as first parameter the value of prefixexp, followed by the original call arguments (see §2.4). The form functioncall ::= prefixexp ‘:’ Name args can be used to call "

Format Strings for Pack and Unpack

6.4.2 – Format Strings for Pack and Unpack The first argument to string.pack, string.packsize, and string.unpack is a format string, which describes the layout of the structure being created or read. A format string is a sequence of conversion options. The conversion options are as follows: <: sets little endian >: sets big endian =: sets native endian ![n]: sets maximum alignment to n (default is native alignment) b: a signed byte (char) B: an unsigned byte (char) h: a signed

For Statement

3.3.5 – For Statement The for statement has two forms: one numerical and one generic. The numerical for loop repeats a block of code while a control variable runs through an arithmetic progression. It has the following syntax: stat ::= for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end The block is repeated for name starting at the value of the first exp, until it passes the second exp by steps of the third exp. More precisely, a for statement like for v = e1, e2, e3 do block end is equival

file:write()

file:write (···) Writes the value of each of its arguments to file. The arguments must be strings or numbers. In case of success, this function returns file. Otherwise it returns nil plus a string describing the error.

file:setvbuf()

file:setvbuf (mode [, size]) Sets the buffering mode for an output file. There are three available modes: "no": no buffering; the result of any output operation appears immediately. "full": full buffering; output operation is performed only when the buffer is full or when you explicitly flush the file (see io.flush). "line": line buffering; output is buffered until a newline is output or there is any input from some special files (such as a terminal device). For the last two case

file:seek()

file:seek ([whence [, offset]]) Sets and gets the file position, measured from the beginning of the file, to the position given by offset plus a base specified by the string whence, as follows: "set": base is position 0 (beginning of the file); "cur": base is current position; "end": base is end of file; In case of success, seek returns the final file position, measured in bytes from the beginning of the file. If seek fails, it returns nil, plus a string describing the error. The

file:read()

file:read (···) Reads the file file, according to the given formats, which specify what to read. 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": reads a numeral and returns it as a float or an integer, fol

file:lines()

file:lines (···) Returns an iterator function that, each time it is called, reads the file according to the given formats. When no format is given, uses "l" as a default. As an example, the construction for c in file:lines(1) do body end will iterate over all characters of the file, starting at the current position. Unlike io.lines, this function does not close the file when the loop ends. In case of errors this function raises the error, instead of returning an error code.

file:flush()

file:flush () Saves any written data to file.

file:close()

file:close () Closes file. 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.popen, file:close returns the same values returned by os.execute.