io.output()

io.output ([file]) Similar to io.input, but operates over the default output file.

io.open()

io.open (filename [, mode]) This function opens a file, in the mode specified in the string mode. In case of success, it returns a new file handle. The mode string can be any of the following: "r": read mode (the default); "w": write mode; "a": append mode; "r+": update mode, all previous data is preserved; "w+": update mode, all previous data is erased; "a+": append update mode, previous data is preserved, writing is only allowed at the end of file. The mode string can also

io.lines()

io.lines ([filename, ···]) Opens the given file name in read mode and returns an iterator function that works like file:lines(···) over the opened file. 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.lines() (with no file name) is equivalent to io.input():lines("*l"); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends. In case

io.input()

io.input ([file]) When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file. In case of errors this function raises the error, instead of returning an error code.

io.flush()

io.flush () Equivalent to io.output():flush().

io.close()

io.close ([file]) Equivalent to file:close(). Without a file, closes the default output file.

getmetatable()

getmetatable (object) If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a __metatable field, returns the associated value. Otherwise, returns the metatable of the given object.

Garbage-Collection Metamethods

2.5.1 – Garbage-Collection Metamethods You can set garbage-collector metamethods for tables and, using the C API, for full userdata (see §2.4). 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). For an object (table or userdata) to be finalized when collected, you must mark it for finalization. You mark an object for fi

Function Definitions

3.4.11 – Function Definitions The syntax for function definition is functiondef ::= function funcbody funcbody ::= ‘(’ [parlist] ‘)’ block end The following syntactic sugar simplifies function definitions: stat ::= function funcname funcbody stat ::= local function Name funcbody funcname ::= Name {‘.’ Name} [‘:’ Name] The statement function f () body end translates to f = function () body end The statement function t.a.b.c.f () body end translates to t.a.b.c.f = function () body end

Function Calls as Statements

3.3.6 – Function Calls as Statements To allow possible side-effects, function calls can be executed as statements: stat ::= functioncall In this case, all returned values are thrown away. Function calls are explained in §3.4.10.