The core module keeps the functionality of the following standard Lua libraries:
dofile
;coroutine
- replaced with co
library to resolve conflicts with the multithreading engine;package
- not implemented, use require
;string
- all funcions;table
- all funcions;math
- all funcions;bit32
- all funcions;io
- replaced with file
module;os
- replaced with similar functions and file
module;debug
- not implemented, use graphical interface.after(t, func)
func
in a new thread after t
seconds. Returns the new (paused) thread.
clock()
dump(...)
exit([code])
include(filename)
iskindof(v, name)
v
is a userdata of type name
or a type derived from it. Returns the actual type or nil
.
keepalive()
load(filename)
objtype(v)
v
.
print(...)
require(name)
sleep(t)
t
seconds (can be a real number).
Paused threads have higher priority so calling sleep(0)
in a loop can block other threads.
wipe(t)
t
(in-place).
os.execute(cmd)
os.execfile(filename[, action[, args]])
"open"
) on a file.
os.getenv(name) os.setenv(name, value)
os.environ
year
- 4 digits;month
- 1-12;day
- 1-31;wday
- day of week, 1-7 (7 for Sunday);hour
- 0-23;min
- 0-59;sec
- 0-59;ms
- 0-999.time.time()
time.tolocal([t])
time.toutc([t])
time.fromlocal(ts)
time.time()
.
time.fromutc(ts)
time.time()
.
time.format([fmt, [t]])
strftime
.
time.formatutc([fmt, [t]])
strftime
.
thread.create(func, ...)
thread.current()
thread.lock() thread.unlock()
thread.yield()
thread:state()
thread:suspend() thread:resume()
thread:terminate()
These functions replace the original coroutine
module to avoid conflicts with the multithreading engine. The library
is intended for making python-like generator functions.
co.create(func, ...)
func
, optionally saving arguments for the first call. The coroutine is initially suspended.
co.resume(state, ...)
co.create
,
if any), or passed as return values from co.yield
call. Returns the values passed to the next co.yield
call or values returned
from the function if it finishes execution. Returns nil
immediately if the coroutine is already completed.
co.yield(...)
co.resume
call. Returns the values passed to the next
co.resume
call.
co.wrap(func, ...)
func
and optional initial arguments, and returns a wrapper function that is equivalent to calling
co.resume
on the coroutine.
co.status(state)
"running"
if called from inside the coroutine, "suspended"
if the coroutine is in suspended
state (has not been started yet or yielded, or if it is running in a different thread from the one that called co.status
),
"normal"
if the coroutine is is active but not running (it called co.resume
), or "dead"
if it finished
execution or an error occured.
sync.wait(obj1, ..., objn[, t])
objk:state()
return true (obj
can be any type with a state()
method,
such as sync.event
or thread
). Optionally specify a timeout in seconds. Returns true unless
the timeout was exceeded.
sync.newsection()
sync.section
object.
sync.newevent([state])
sync.event
object with a specified initial state (default is false
)
sync.section:enter() sync.section:leave()
sync.event:state()
sync.event:set() sync.event:reset()
string.concat(...)
string.hex(str)
string.pad(str, len)
str
resized to len
characters, shortening the string or appending nil characters as required.
string.unpack(str)
utf8.byte(s[, i[, j]])
string.byte
,
but are specified in UTF-8 characters).
utf8.char(...)
utf8.fromoffset(str, pos)
pos
.
utf8.len(str)
utf8.lower(str)
utf8.offset(str, pos)
pos
.
utf8.reverse(str)
utf8.sub(str, i[, j])
utf8.unpack(str)
utf8.upper(str)
utf8.valid(str)
re.compile(pattern[, flags])
re.LIST
. Compilation results are cached (lifetime defined by garbage collection).
re.I re.IGNORECASE
re.M re.MULTILINE
^
and $
metacharacters match beginning/end of line instead of just the beginning/end of string.
re.S re.DOTALL
.
) metacharacter matches all characters, including newline (by default, newline is not matched).
re.X re.VERBOSE
#
symbol until the end of line.
re.L re.LIST
re.search(pattern, string[, flags])
nil
if no matches were found.
re.match(pattern, string[, flags])
string
; return a match object or nil
.
re.split(pattern, string[, maxsplit[, flags]])
pattern
, return a list of strings. If pattern
matches the
beginning/end of string
, the list will start/end with an empty string. If pattern
contains capturing
groups, they will be included in the list. Optionally, maxsplit
limits the number of splits made.
re.findall(pattern, string[, flags])
pattern
in string
. If the pattern conains captures, return
captures instead of the entire matches. If more than one capture group is present, return a list of tables instead.
re.finditer(pattern, string[, flags])
for
loop that will iterate through all matches of pattern
in the
string
. Each iteration returns a match object or a list of captures if re.LIST
flag was specified.
re.sub(pattern, repl, string[, count[, flags]])
pattern
in string
with repl
, which can be either a string or a
function. The repl
string may contain references to capture groups in the form of \4
or \g<name>
.
Optionally, up to count
replacements are made. Returns the resulting string and number of replacements made.
re.escape(string)
string
with all non-alphanumerics escaped (resulting string is a pattern equivalent to searching for string
).
re.expand(string, match)
string
with capture references expanded according to a given match object or a list of captures.
re.prog:search(string[, pos])
re.search
but allows specifying starting position to search from.
re.prog:match(string[, pos])
re.match
but allows specifying starting position to match from.
re.prog:split(string[, maxsplit])
re.split
.
re.prog:findall(string[, pos])
re.findall
but allows specifying starting position to search from.
re.prog:finditer(string[, pos])
re.finditer
but allows specifying starting position to search from.
re.prog:sub(repl, string[, count])
re.sub
.
re.prog.flags
re.compile
and inline flags in the pattern.
re.prog.groups
re.prog.groupindex
re.prog.pattern
re.compile
.
re.match:expand(string)
string
with capture references expanded.
re.match:group(...)
re.match:groups([default])
default
.
re.match:groupdict([default])
default
.
re.match:left([group]) re.match:right([group])
re.match:span([group])
-1,-1
if the group wasn't matched.
re.match.pos
re.prog:search()
or re.prog:match()
.
re.match.re
re.match.string
stream:read(...)
stream:write(...)
stream:seek(pos[, orig])
pos
from orig
, which can be stream.SEEK_SET
(absolute position),
stream.SEEK_CUR
(current position) or stream.SEEK_END
(end of data). String values can be used instead:
"set"
, "cur"
, "end"
.
stream:tell()
stream:size()
stream:resize()
stream:eof()
tell() >= size()
).
stream:read8() stream:read16([big]) stream:read32([big]) stream:readfloat([big]) stream:readdouble([big])
stream:write8(val) stream:write16(val[, big]) stream:write32(val[, big]) stream:writefloat(val[, big]) stream:writedouble(val[, big])
stream:readstr() stream:writestr(str)
stream:readbuf()
stream:writebuf(buf)
stream:serialize(...) stream:deserialize([count])
count
objects. Accepts a nil
, number, string,
Lua function or a table containing listed types. Supports recursive tables and metatables. Note that it does not check
Lua functions for validity, do not use on untrusted data (see Lua manual).
stream:copy(source[, length])
length
bytes from source
stream (or all remaining bytes).
stream:printf(fmt, ...)
stream:getline()
stream:lines()
for
loop, iterating over all lines in a stream.
stream:flush()
stream.SEEK_SET stream.SEEK_CUR stream.SEEK_END
stream.seek
.
buffer.create([str])
stream
.
Buffers support the concatenation (..
) and length (#
) operations.
buffer:tostring()