Version 0.84

Class Overview


Class (v9.0)


ClassOverview : Class /

This module implements inheritance and the creation of objects from classes.


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.


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 =[, 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.


Changes the class of an object or the super class of a class.

CGI (v5.2)


ClassOverview : Class / CGI


continue = beginPost(req)

Signals that a POST request has begun. Parameters are known, but data is yet to be read.

fh = beginUpload(req, fname, argname)

Begin upload


Function called when a request can be processed.

continue = endPost(req, s)

Signals that all data belonging to a POST request have arrived.

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.

is_valid = endUpload(req, fname, fh)

Complete upload

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.

success = updateUpload(req, fname, fh, buf)

Update upload

HTTPD (v2.1)


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 listed

  • DocumentRoot [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"


success = HTTPD:bind()

Bind server to Address and Port.


Unbinds server, frees server socket.

HTTPRequest (v3.1)


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


decoded = decodeURL(url)

Decode URL-encoded string

args = getArgs()

Get table of request arguments

document = getDocument()

Get table of document properties, containing e.g. the keys ScriptPath and ScriptFile

val = getEnv(key)

Get server environment variable

global = getGlobal()

Get HTTP Request global state, containing e.g. internals of the server application.


Insert raw arguments string, e.g. from QUERY_STRING


Write data to output stream

Markup (v3.3)


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().


This function starts the conversion.

Server (v2.6)


ClassOverview : Class / Server /

This class implements a server. If copas is used, this server provides nonblocking multiplexed I/O.



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

id = registerClient(fd, name, func[, data[, ...]])

Register client

id = registerInterval(interval_in_seconds, func)

Register interval

registerOnce(delay, func[, data])

Register a function to be called in the server main loop once, after the given delay

id = registerServer(fd, name, func[, data[, ...]])

Register server socket


Remove an interval by id

status = run()

Run server

setServerState(state[, delay])

Supported are "break", "restart", ...

SessionRequest (v3.0)


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


cookie = createSessionCookie([expire])

Create session cookie string


Delete the current 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.

session, sid = getSession()

Find session by session Id in cookie

sid = newSession(sessiondata[, sid])

Place sessiondata table in a new session

WTF (v3.2)


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)
      return env

Args (v2.5)


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:


This template requires one or more arguments to satisfy SOURCE, and exactly one argument to satisfy DEST. Neither can be omitted. Either -d (or its alias DEST) 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.

  • - Parses a string or table through an argument template

Backslashes for escaping quotes, spaces and themselves

res, msg =, 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 (v6.1)


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.INFO

The default debug output stream is stderr. To override it globally, e.g.:

db = require "tek.lib.debug"
db.out ="logfile", "w")
  • level - Debug level, default 5 (WARN)
  • out - Output stream, default io.stderr


Enters debug console.

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.error(msg, ...)

Prints formatted debug info with ERROR debug level

debug.execute(lvl, func, ...)

Executes the specified function if the global debug level is less or equal the specified level., ...)

Prints formatted debug info with FAIL debug level

debug.format(lvl, msg, ...)

Format error message, ...)

Prints formatted debug info with INFO debug level

debug.note(msg, ...)

Prints formatted debug info with NOTE debug 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.

debug.trace(msg, ...)

Prints formatted debug info with TRACE debug level

debug.warn(msg, ...)

Prints formatted debug info with WARN debug level

debug.wrout(lvl, ...)

Debug output function, by default

function(...) out:write(...) end

Exec (v0.83)



Sends the task the abortion signal "a" and synchronizes on its completion.

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.

name = Exec.getname()

Returns the own task's name.

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

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 If successful, return values from the child task will be converted to strings and returned as additional return values.

child =[, 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:

Optional keys in the table:

Additional arguments are passed to the script, in their given order. Methods on the returned child task handle:

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