The Lua Language (V5.1) Cheat Sheet Page 4

ADVERTISEMENT

--
stops parsing options
Time formatting directives (most used, portable features):
Recognized environment variables
%c
date/time (locale)
%x
date only (locale)
%X
time only (locale)
LUA_INIT
if this holds a string in the form @filename loads and executes filename, else executes the string itself
%y
year (nn)
%Y
year (yyyy)
LUA_PATH
defines search path for Lua modules, with "?" replaced by the module name
%j
day of year (001..366)
LUA_CPATH
defines search path for dynamic libraries (e.g. .so or .dll files), with "?" replaced by the module name
%m
month (01..12)
_PROMPT[2]
set the prompts for interactive mode
%b
abbreviated month name (locale)
%B
full name of month (locale)
Special Lua variables
%d
day of month (01..31)
arg
nil if no arguments on the command line, else a table containing command line arguments starting from
week number (01..53), Sunday-based
week number (01..53), Monday-based
%U
%W
arg[1] while #arg is the number of arguments; arg[0] holds the script name as given on the command line;
weekday (0..6), 0 is Sunday
%w
arg[-1] and lower indexes contain the fields of the command line preceding the script name.
%a
abbreviated weekday name (locale)
%A
full weekday name (locale)
_PROMPT[2]
contain the prompt for interactive mode; can be changed by assigning a new value.
%H
hour (00..23)
%I
hour (01..12)
%p
either AM or PM
T h e c o m p i l e r
%M
minute (00..59)
Command line syntax
%S
second (00..61)
luac [options] [filenames]
time zone name, if any
%Z
Options
T h e d e b u g l i b r a r y [ d e b u g ]
-
compiles from standard input
Basic functions
-l
produces a listing of the compiled bytecode
debug.debug ()
enters interactive debugging shell (type cont to exit); local variables cannot be accessed
-o filename
sends output to filename [default: luac.out]
directly.
-p
performs syntax and integrity checking only, does not output bytecode
debug.getinfo (f [, w])
returns a table with information for function f or for function at level f [1 = caller], or nil if
-s
strips debug information; line numbers and local names are lost.
invalid level (see Result fields for getinfo below); characters in string w select one or more
prints version information
-v
groups of fields [default: all] (see Options for getinfo below).
--
stops parsing options
debug.getlocal (n, i)
returns name and value of local variable at index i (from 1, in order of appearance) of the
Note: compiled chunks are portable between machines having the same word size.
function at stack level n (1= caller); returns nil if i is out of range, raises error if n is out of
range.
Lua is a language designed and implemented by Roberto Ierusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes; for details see .
Drafts of this reference card (for Lua 5.0) were produced by Enrico Colombini <erix@erix.it> in 2004 and updated by Thomas Lauer
debug.getupvalue (f, i)
returns name and value of upvalue at index i (from 1, in order of appearance) of function f;
<thomas.lauer@gmail.com> in 2007, 2008 and 2009. Comments, praise or blame please to the lua-l mailing list.
returns nil if i is out of range.
This reference card can be used and distributed according to the terms of the Lua 5.1 license.
debug.traceback ([msg])
returns a string with traceback of call stack, prepended by msg
debug.setlocal (n, i, v)
assigns value v to the local variable at index i (from 1, in order of appearance) of the function
at stack level n (1= caller); returns nil if i is out of range, raises error if n is out of range.
debug.setupvalue (f, i, v)
assigns value v to the upvalue at index i (from 1, in order of appearance) of function f; returns
nil if i is out of range.
debug.sethook ([h, m [, n]])
sets function h as hook, called for events given in string (mask) m: "c" = function call, "r" =
function return, "l" = new code line; also, a number n will call h() every n instructions; h() will
receive the event type as first argument: "call", "return", "tail return", "line" (line number as
second argument) or "count"; use debug.getinfo(2) inside h() for info (not for "tail_return").
debug.gethook ()
returns current hook function, mask and count set with debug.sethook()
Note: the debug library functions are not optimised for efficiency and should not be used in normal operation.
Result fields for debug.getinfo
source
name of file (prefixed by '@') or string where the function was defined
short_src
short version of source, up to 60 characters
linedefined
line of source where the function was defined
what
"Lua" = Lua function, "C" = C function, "main" = part of main chunk
name
name of function, if available, or a reasonable guess if possible
namewhat
meaning of name: "global", "local", "method", "field" or ""
nups
number of upvalues of the function
the function itself
func
Options for debug.getinfo (character codes for argument w)
returns fields name and namewhat
returns field currentline
n
l
returns field func
returns field nup
f
u
S
returns fields source, short_src, what and linedefined
T h e s t a n d - a l o n e i n t e r p r e t e r
Command line syntax
lua [options] [script [arguments]]
Options
-
loads and executes script from standard input (no args allowed)
-e stats
executes the Lua statements in the literal string stats, can be used multiple times on the same line
-l filename
requires filename (loads and executes if not already done)
-i
enters interactive mode after loading and executing script
-v
prints version information
4

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 4