Version 0.84
ClassOverview : Class /
This module implements inheritance and the creation of objects from classes.
object:getClass()
- Returns the class of an object, or the super class of a classobject:getClassName()
- Returns the class name of an object or classobject:getSuper()
- Returns the super class of an object or classobject:instanceOf()
- Checks if an object descends from a classClass.module()
- Creates a new class from a superclassClass.new()
- Creates and returns a new objectClass.newClass()
- Creates a child class from a super classobject:setClass()
- Changes the class of an object, or the super class of a class
class = object:getClass()
This function returns the class of an object
. If applied to a
class instead of an object, it returns its super class, e.g.:
superclass = Class.getClass(class)
name = object:getClassName()
This function returns the _NAME
attribute of the object
's class. It is also possible to apply this
function to a class instead of an object.
object:getSuper()
Gets the super class of an object or class.
For example, to forward a call to a method
to its super class,
without knowing its class:
self:getSuper().method(self, ...)
is_descendant = object:instanceOf(class)
Returns true if object
is an instance of or descends from the
specified class
. It is also possible to apply this function to a class
instead of an object, e.g.:
Class.instanceOf(Button, Area)
class, superclass = Class.module(classname, superclassname)
Creates a new
class from the specified superclass. superclassname
is being loaded
and its method Class:newClass()
invoked with the _NAME
field set to
classname
. Both class and superclass will be returned.
object = Class.new(class[, object])
Creates and returns a new object of the given class
. Optionally,
it just prepares the specified object
(a table) for inheritance and
attaches the class
' methods and data.
class = Class.newClass(superclass[, class])
Derives a new class from the specified superclass
. Optionally,
an existing class
(a table) can be specified. If a _NAME
field
exists in this class, it will be used. Otherwise, or if a new class is
created, class._NAME
will be composed from superclass._NAME
and
an unique identifier. The same functionality can be achieved by calling
a class like a function, so the following invocations are equivalent:
class = Class.newClass(superclass) class = superclass()
The second notation allows a super class to be passed as the second
argument to Lua's module
function, which will set up a child class
inheriting from superclass
in the module table.
continue = beginPost(req)
Signals that a POST request has begun. Parameters are known, but data is yet to be read.
success, msg = endRequest(request[, protstatus[, appstatus]])
Confirms the end of a CGI request. Optionally, the application can signify a protocol status (e.g., FCGI_REQUEST_COMPLETE) and an application status (by default, 0). The result will be true, indicating success, or nil followed by an error message.
continue = haveParams(req)
Signals the arrival of all parameters that belong to the request. The return value is a boolean indicating success and whether processing should continue.
continue = updatePost(req, s)
Signals that new data is available on the stream that belongs to a POST request. The return value indicates whether processing should continue.
ClassOverview : Class / Server / HTTPD
This class implements a HTTP server.
Address [IG]
(string)Host/address to bind to, default
"localhost"
DefaultIndex [ISG]
(table)Numerically indexed table of filenames accepted for default index documents. Default
"index.lhtml"
,"index.lua"
,"index.html"
DirList [ISG]
(string or boolean)Directory listing options, boolean or the key
"l"
. Default"l"
, directories will be listedDocumentRoot [ISG]
(string)Document root path, default
"htdocs"
ExtraWebEnvironment [IG]
(table)Table to be mixed into default web environment
Handlers [ISG]
(table)Table keyed by filename extensions that invoke a Lua handler. The value is a table of additional arguments to the handler. Default
"%.lua"
,"%.lhtml"
Listen [IG]
(string)Combined Host and port specification, e.g.
localhost:8080
Port [IG]
(number)Port to bind to, default
8080
RequestArgs [ISG]
(table)Table of arguments to be mixed into requests
RequestClassName [ISG]
(string)Name of the class that provides requests. Default
"tek.class.httprequest"
ServerName [IG]
(string)Name under which the server will be registered, default
"server-http"
HTTPD:bind()
- binds toAddress
andPort
HTTPD:unbind()
- unbinds server
ClassOverview : Class / HTTPRequest /
Environment [ISG]
(table)Initial environment of server variables
MaxContentLength [ISG]
(number)Maximum size allowed for POST, in bytes. Default: 1000000
RequestsGlobal [ISG]
(table)Global variables shared by all requests
HTTPRequest.decodeURL()
- Decodes an URL-encoded stringHTTPRequest:getArgs()
- Gets table of request argumentsHTTPRequest:getDocument()
- Gets table of document propertiesHTTPRequest:getEnv()
- Gets a server environment variableHTTPRequest:getGlobal()
- Gets persistent, global data from serverHTTPRequest:insertArgString()
- Insert QUERY_STRING arguments- HTTPRequest:write(s) - Sets an server environment variable
document = getDocument()
Get table of document properties, containing e.g. the keys ScriptPath and ScriptFile
global = getGlobal()
Get HTTP Request global state, containing e.g. internals of the server application.
ClassOverview : Class / Markup
This class implements a markup parser and converter for producing feature-rich XHTML 1.0 from plain text with special formattings.
parser = Markup:new(args)
Creates a new markup parser. args
can be a
table of initial arguments that constitute its behavior. Supported fields
in args
are:
indentchar
|
Character recognized for indentation, default "\t"
|
input
|
Filehandle or string, default io.stdin
|
rdfunc
|
Line reader, by default reads using args.input:lines
|
wrfunc
|
Writer func, by default io.stdout.write
|
docname
|
Name of document, default "Manual"
|
features
|
Feature codes, default "hespcadlint"
|
The parser supports the following features, which can be combined into
a string and passed to the constructor in args.features
:
Code | Description | rough HTML equivalent |
h
|
Heading |
<h1> , <h2> , ...
|
e
|
Emphasis |
<strong>
|
s
|
Separator |
<hr>
|
p
|
Preformatted block |
<pre>
|
c
|
Code |
<code>
|
a
|
Anchor, link |
<a href="...">
|
d
|
Definition |
<dfn>
|
l
|
List |
<ul> , <li>
|
i
|
Image |
<img>
|
n
|
Node header |
<a name="...">
|
t
|
Table |
<table>
|
f
|
Function | (undocumented, internal use only) |
After creation of the parser, conversion starts by calling Markup:run()
.
ClassOverview : Class / Server /
This class implements a server. If copas is used, this server provides nonblocking multiplexed I/O.
Server:registerClient()
- Register a client socketServer:registerInterval()
- Register an interval functionServer:registerOnce()
- Register a one-shot functionServer:registerServer()
- Register a server socketServer:removeInterval()
- Remove an interval functionServer:run()
- Run server (mainloop)Server:setServerState()
- Sets server stateServer:shutdown()
- Tries to shut down services, protectedServer:startup()
- Checks configuration and starts up servicesServer:unregister()
- Unregisters a socket
checkAbort()
Override this function to check for termination of the server. Since we cannot suspend in I/O and signals or messages at the same time, we must check for termination periodically. A pity
registerOnce(delay, func[, data])
Register a function to be called in the server main loop once, after the given delay
ClassOverview : Class / HTTPRequest / SessionRequest
CookieName [ISG]
(string)Default basename for cookies, default
"luawtf"
SessionExpirationTime [ISG]
(number)Number of seconds before a session expires, default: 600
Sessions [ISG]
(table)Table of sessions, indexed by session Id. Must be provided during initialization so that session states can be held and found later
SessionRequest.getRawId()
- Get binary data for unique session IdSessionRequest:createSessionCookie()
- Create session cookie stringSessionRequest:deleteSession()
- Delete current sessionSessionRequest:getSession()
- Find session (by session Id in cookie)SessionRequest:newSession()
- Create new session
getRawId([len[, rlen]])
Get unique binary data of given length to be
used for a session Id. rlen
is the desired number of bytes of entropy,
the regular length (default 6) is usually made up of pseudo random data.
ClassOverview : Class / WTF - Lua Web Tiny Framework
Buffered [ISG]
(boolean)Specifies whether the output stream should be collected in a buffer by default. Default:
false
Environment [IG]
(table)The function environment passed to scripts. Default: an empty environment
env = createEnvironment(request)
Creates a request-specific HTML environment derived from the Environment property; can be overridden if the combined environment needs to be intercepted for passing it back to the request, f.ex.:
WTF:new { Environment = _G, createEnvironment = function(self, req) local env = WTF.createEnvironment(self, req) req:setHTMLEnvironment(env) return env end }:doRequest(req)
This library implements an argument parser.
A string is parsed into an array of arguments according to a format template. Arguments in the template are separated by commas. Each argument in the template consists of a keyword, optionally followed by one or more aliases delimited by equal signs, and an optional set of modifiers delimited by slashes. Modifiers denote the expected data type, if the argument is mandatory and whether a keyword must precede its value to form a valid argument. Example argument template:
SOURCE=-s/A/M,DEST=-d/A/KThis template requires one or more arguments to satisfy
SOURCE
, and exactly one argument to satisfyDEST
. Neither can be omitted. Either-d
(or its aliasDEST
) must precede the value to be accepted as the second argument. Example command lines:
SOURCE one two three DEST foo
valid DEST foo -s one
valid DEST foo
rejected; source argument missing one two three foo
rejected; keyword missing one two dest foo
valid, keys are case insensitive one two three -d="foo" four
valid, "four" added to SOURCE
An option without modifiers represents an optional string argument. Available modifiers are:
/S
- Switch; considered a boolean value. When the keyword is present, true will be written into the respective slot in the results array./N
- Number; the value will be converted to a number./K
- Keyword; the keyword (or an alias) must precede its value./A
- Always required; This argument cannot be omitted./M
- Multiple; Any number of strings will be accepted, and all values that cannot be assigned to other arguments will show up in this argument. No more than one/M
modifier may appear in a template./F
- Fill; literal rest of line. If present, this must be the last argument.Quoting and escaping: Double quotes can be used to enclose arguments containing equal signs and spaces.
args.read()
- Parses a string or table through an argument template
Backslashes for escaping quotes, spaces and themselves
res, msg = args.read(template, args)
Parses args
according to
template
. args
can be a string or a table of strings. If the
arguments can be successfully matched against the template, the result
will be a table of parsed arguments, indexed by both keywords and
numerical order in which they appear in template
, and the second
argument will be set to the number of arguments in the template. If the
arguments cannot be matched against the template, the result will be
nil followed by an error message.
Debug library - implements debug output and debug levels:
2 TRACE used for trace messages 3 INFO informational messages, notices 4 NOTE important notices 5 WARN something unexpected happened 10 ERROR something went wrong, e.g. resource unavailable 20 FAIL something went wrong that cannot be coped with The default debug level is
WARN
. To set the debug level globally, e.g.:db = require "tek.lib.debug" db.level = db.INFOThe default debug output stream is
stderr
. To override it globally, e.g.:db = require "tek.lib.debug" db.out = io.open("logfile", "w")
debug.console()
- Enters the debug consoledebug.dump()
- Dumps a table recursivelydebug.error()
- Prints a text in theERROR
debug leveldebug.execute()
- Executes a function in the specified debug leveldebug.fail()
- Prints a text in theFAIL
debug leveldebug.info()
- Prints a text in theINFO
debug leveldebug.note()
- Prints a text in theNOTE
debug leveldebug.print()
- Prints a text in the specified debug leveldebug.stacktrace()
- Prints a stacktrace in the specified debug leveldebug.trace()
- Prints a text in theTRACE
debug leveldebug.warn()
- Prints a text in theWARN
debug leveldebug.wrout()
- Output function
level
- Debug level, default 5 (WARN
)out
- Output stream, defaultio.stderr
debug.dump(table[, outfunc])
Dumps a table as Lua source using
outfunc
. Cyclic references are silently dropped. The default output
function is debug.wrout()
.
debug.execute(lvl, func, ...)
Executes the specified function if the global debug level is less or equal the specified level.
debug.print(lvl, msg, ...)
Prints formatted text if the global debug level is less or equal the specified level.
debug.stacktrace(debuglevel[, stacklevel])
Prints a stacktrace starting at
the function of the given level on the stack (excluding the
stracktrace
function itself) if the global debug level is less
or equal the specified debuglevel
.
Exec.getmsg()
- Get next message from own task's message queueExec.getname()
- Get the own task's nameExec.getsignals()
- Get and clear own task's signalsExec.run()
- Run a Lua function, file, or chunk, returning a taskExec.sendmsg()
- Send a message to a named taskExec.sendport()
- Send a message to a named task and portExec.signal()
- Send signals to a named taskExec.sleep()
- Suspend own task for a period of timeExec.wait()
- Suspend own task waiting for signalsExec.waitmsg()
- Suspend own rask waiting for a message or timeoutExec.waittime()
- Suspend own task waiting for signals and timeout
child:abort()
- Send abortion signal and wait for task completionchild:join()
- Wait for task completion- child:sendmsg(msg) - Send a message to a task, see
Exec.sendmsg()
- child:sendport(port, msg) - Send a message to a named port in the task, see
Exec.sendport()
- child:signal([sigs]) - Send signals to a task, see
Exec.signal()
child:terminate()
- Send termination signal and wait for completion of a task
msg, sender = Exec.getmsg()
Unlinks and returns the next message from the task's message queue, or nil if no messages are present. If a message is returned, then the second argument is the name of the task sending the message.
sig = Exec.getsignals([sigset])
Gets and clears the signals in sigset
from the own task's signal state, and returns the present signals, one
character per signal, concatenated to a string. If no signals are present,
returns nil. Possible signals and their meanings are
"a"
- abort, the Lua program stops due to an error"t"
- terminate, the task is asked to quit"c"
- child, a child task has finished"m"
- message, a message is present at the task
The default for sigset
is "tcm"
. Notes: The abortion signal cannot
be cleared from a task. The termination signal is a request that a task
may handle, but it is not enforced.
success, res1, ... = child:join()
Synchronizes the caller on completion
of the child task. The first return value is boolean and indicative of
whether the task completed successfully. While suspended in this function
and if an error occurs in the child task, an error is propagated to the
caller also, unless error propagation is suppressed - see Exec.run()
. If
successful, return values from the child task will be converted to
strings and returned as additional return values.
child = Exec.run(what[, arg1[, ...]])
Tries to launch a Lua script, function, or chunk, and returns a handle on a child task if successful. The first argument can be a string denoting the filename of a Lua script, a Lua function, or a table. If a table is given, either of the following keys in the table is mandatory:
"func"
, a function value to run,"filename"
, a string denoting the filename of a Lua script,"chunk"
, a string value containing a Lua chunk to run.
Optional keys in the table:
"taskname"
, a string denoting the name of the task to run. Task names are immutable during runtime and must be unique; the top-level task's implicit name is"main"
."abort"
, a boolean to indicate whether errors in the child should be propagated to the parent task. Default: true
Additional arguments are passed to the script, in their given order. Methods on the returned child task handle:
child:abort()
- sends abortion signal and synchronizes on completion of the taskchild:join()
- synchronizes on completion of the task- child:sendmsg(msg) - sends a message to a task, see
Exec.sendmsg()
- child:sendport(port, msg) - Sends a message to a named port in the task, see
Exec.sendport()
- child:signal([sigs]) - sends signals to a task, see
Exec.signal()
child:terminate()
- sends termination signal and synchronizes on completion of the task
Note that the returned child handle is subject to garbage collection. If it gets collected (at the latest when the parent task is ending) and the child task is still running, the child will be sent the abortion signal, causing it to raise an error. This error, like any child error, also gets propagated back to the parent task, unless error propagation is suppressed (see above).
success = Exec.sendmsg(taskname, msg)
Sends a message to a named task.
The special name "*p"
addresses the parent task. Returns true
if the task was found and the message sent.
success = Exec.sendport(taskname, portname, msg)
Sends the message to the named message port in the named task. Returns true if the task and port could be found and the message was sent.
success = Exec.signal(taskname[, sigs])
Sends signals to a named task,
by default the termination signal "t"
. The special name "*p"
addresses the parent task. Returns true if the task was found and
the signals sent. See Exec.getsignals()
for details on the signal format.
sig = Exec.sleep([millisecs])
Suspends the task for the given number of
1/1000th seconds. If no timeout is specified, sleeps indefinitely. Returns
nil when the timeout has expired, or "a"
when an abortion signal
occurred or was already present at the task.
success, res1, ... = child:terminate()
This function is equivalent to
child:join()
, except for that it sends the child task the termination
signal "t"
before joining.
sig = Exec.wait([sigset])
Suspends the task waiting for any signals from
the specified set. The signals from sigset
that occured (or were
already present at the task) are returned to the caller - see
Exec.getsignals()
for their format. The default signal set to wait for is
"tc"
. Note: The abortion signal "a"
is always included in the set.
msg, sender, sig = Exec.waitmsg([millisecs])
Suspends the task waiting
for the given number of 1/1000th seconds or for a message, and returns the
next message to the caller. If no timeout is specified, waits indefinitely.
Returns nil when no message arrives in the given time, or when the
cause for returning was that only a signal showed up in the task. The
second return value is the name of the sender task, see Exec.getmsg()
for
details. The third return value contains the possible signals ("m"
and "a"
) that caused this function to return, or nil if a
timeout occurred.
sig = Exec.waittime(millisecs[, sigset])
Suspends the task waiting for
the given number of 1/1000th seconds, or for any signals from the specified
set. Signals from sigset
that occured (or were already present at
the task) are returned to the caller - see Exec.getsignals()
for details.
The default signal set to wait for is "tc"
. Note: The abortion signal
"a"
is always included in the signal set.
Document generated on Sat Mar 14 11:01:26 2015 using gendoc.lua version 1.5