ELTN For Lua (Work in Progress)

Frank Mitchell

Posted: 2023-04-12
Last Modified: 2025-05-31
Word Count: 305
Tags: eltn lua programming

Table of Contents

Summary

As indicated in ELTN-C, we intend to keep the Lua API for ELTN as simple as possible. We therefore will implement only the following functions:

Documentation

eltn.parse

eltn.parse(eltn_string) => eltn_table | nil, error

Converts a string of ELTN text into (usually) nested tables. If the ELTN text is malformed or invalid, returns nil with an error string.

eltn.parse_file

eltn.parse_file(filename) => eltn_table | nil, error

Opens a file of ELTN text and parses it into (usually) nested tables. If the ELTN text is malformed or invalid, returns nil with an error string.

eltn.emit

eltn.emit(eltn_table [, options]) => eltn_string | nil, error

Accepts a structure of nested tables and converts it into a string of ELTN text. If the table structure cannot be converted, returns nil and an error string.

options is a table with the following keys:

eltn.error

eltn.error(error) => error_table | *error*

Parses an error string into a table. The table may contain the following fields:

If the function cannot parse the error string, it will return the original string.

Implementation Details

Parsing

The parser will use the lpeg or lpeglabel libraries to parse the code and construct a structure of tables.

Emitting

The emitter uses ordinary recursive code.

The emitter is not a general Lua table pretty-printer. In particular, if the emitter encounters the same table twice, or finds a key that is not a string, number, boolean, or printable userdata,it will halt with an error.