Module literal

A library for safe evaluation of Lua literal expressions.

Info:

  • License: Public Domain
  • Author: Peter Melnichenko

Functions

eval (str [, grammar [, filename]]) Tries to evaluate a given string as a Lua literal.
peval (str [, grammar [, filename]]) Protected version of eval.
eval_config (str [, grammar [, filename]]) Tries to evaluate a given string as a config file.
peval_config (str [, grammar [, filename]]) Protected version of eval_config.

Fields

grammar Default grammar to be used by evaluation functions.
max_nesting Maximum nesting level of table literals.
max_repr_length Maximum length of string representation in error messages.


Functions

eval (str [, grammar [, filename]])
Tries to evaluate a given string as a Lua literal. Correct literals are "nil", "true", "false", decimal and hexadecimal numerical constants, short and long strings, and tables of other literals.

Comments are considered whitespace. Non-whitespace after a correct literal is an error.

Parameters:

  • str string the string.
  • grammar string the grammar to be used. Must be either "5.1" or "5.2". Default grammar is the grammar of Lua version used to run the module.
  • filename string the filename to be used in error messages.

Returns:

    nil, boolean, number, string or table Result of evaluation.

Raises:

Errors similar to those of Lua compiler.
peval (str [, grammar [, filename]])
Protected version of eval. Acts as eval, but instead of raising errors returns false and error message.

Parameters:

  • str string the string.
  • grammar string the grammar to be used. Must be either "5.1" or "5.2". Default grammar is the grammar of Lua version used to run the module.
  • filename string the filename to be used in error messages.

Returns:

  1. boolean True if there were no errors, false otherwise.
  2. nil, boolean, number, string or table Result of evaluation or error message.
eval_config (str [, grammar [, filename]])
Tries to evaluate a given string as a config file. Config is a string consisting of pairs "<string> = <literal>", separated by whitespace and optional semicolons. <string> must be a valid Lua name or keyword. Config is interpreted as a table with these strings as keys and corresponding literals as values.

Parameters:

  • str string the string.
  • grammar string the grammar to be used. Must be either "5.1" or "5.2". Default grammar is the grammar of Lua version used to run the module.
  • filename string the filename to be used in error messages.

Returns:

    table Result of evaluation.

Raises:

Errors similar to those of Lua compiler.
peval_config (str [, grammar [, filename]])
Protected version of eval_config. Acts as eval_config, but instead of raising errors returns false and error message.

Parameters:

  • str string the string.
  • grammar string the grammar to be used. Must be either "5.1" or "5.2". Default grammar is the grammar of Lua version used to run the module.
  • filename string the filename to be used in error messages.

Returns:

  1. boolean True if there were no errors, false otherwise.
  2. string or table Result of evaluation or error message.

Fields

grammar
Default grammar to be used by evaluation functions. Set to the version of Lua used to run the module.
max_nesting
Maximum nesting level of table literals. Default is 200.
max_repr_length
Maximum length of string representation in error messages. Default is 45.
generated by LDoc 1.3.12