Built-in Functions

Moontale's standard library



All functions in this section do not return a value.


Broadly, an Entity is a non-text object that the Host is capable of handling.


A 'changer' is something that modifies a block of content - for example hiding/showing it, wrapping it with some formatting, or rendering it multiple times. Behind the scenes, changers are higher-order functions; they can be called with a single argument, which itself is a parameter-less function that renders the attached content. This means that $Color.red[Text] is functionally equivalent to $Color.red(function() Text('Text') end), and $Link('Passage')[Text] is the same as $Link('Passage')(function() Text('Text') end)

As a convenience, built-in changers will convert a single string argument to a content rendering function. So instead of Style.em(function Text('Text') end) you could write Style.em('Text').

All functions in this section are themselves Changers, or return a Changer function.

If an entry is listed without parentheses, it should be used as such: for example, $Else[ Text ], not $Else()[ Text ]


The capitalization is required to avoid conflicting with Lua keywords


Note that these functions are written as table indexers, allowing the 'dot' syntax where the index is a string literal (the most common use case).


When nesting interactivity changers, the resulting callbacks will all be applied to the outer-most block. This means that if you have a 'link within a link', the outer link will perform both actions when clicked on.





These are the low-level functions that produce user-visible text, and need to be implemented by the Host. You probably won't call these from Moontale directly (but you can, if you know what you're doing!)

Moontale overrides some of these functions on start-up to facilitate proper event handling. In general, once the Host registers these functions it should not change them for the lifetime of the Lua VM

Note that any tag can be given as an argument to Push and Object; the list of valid tags will ultimately depend on the Host. The browser host, for instance, will faithfully emit all tags as HTML.

Most tags do not take any additional arguments. Notable exceptions are color(color) and a(id). When developing custom tag conventions, you should use simple arguments (string, number etc.) rather than complex tables.


While the Host can call any library-defined or user-defined Moontale function, the following should be called solely by the Host (unless your intention is to simulate user actions):

Interactive content is indicated with Push('a', id), where id is a sequential integer. The Host is then responsible for calling RaiseEvent with the ID for that span when an event occurs. Interactivity tags will never be nested.

The following is a non-exhaustive list of event names, a subset of the HTML DOM events:

The Host should note that raising an event can call one or more of the Output functions, resulting in the content on screen changing and the mapping of IDs to user-visible content changing. If Clear() is called as a result of an event, the Host should ignore any other events until the new content is on screen. This may result in e.g. mouseover and mouseout being un-balanced.

Last updated