lux.macro a LUX module

A module that provides a macro processor

Functions

process (str, env)

Processes the given string expanding the macros. There are two kinds of expanded macros:

  1. Lines starting with #: the whole line is inserted in the generator code
  2. Expressions wrapped in $(…): the expression is inserted into that part of the string

The implementation is based on this article.

Parameters:

  • string str

    String to be processed.

  • table env

    The Lua environment used to process the string.

Returns:

    string

    The expanded string

Usage:

      local macro = require 'lux.macro'
      local expanded = macro.process("the answer is $(6*x)", { x = 7 })
      assert(expanded == "the answer is 42")