Lua module

Evaluating Lua at runtime: a string of code, or a file on disk. Both run in the same state as every other script.

Structures

  • trx.lua.Error

    What went wrong while running Lua.

    Properties:

    • kind: string. Either "syntax" or "runtime".
    • message: string. The error text.

Functions

  • trx.lua.eval_expr(code)
    Evaluates a string of Lua code, as the /lua console command does.

    Parameters:

    • code (string). Any chunk of Lua, not only an expression.

    Returns: trx.lua.Error or nil. nil when the code ran to completion, and what went wrong otherwise. A failure comes back as a value rather than raising, so the caller decides what it means.

    Example:

    trx.lua.eval_expr("trx.console.log('hello')")
    
  • trx.lua.eval_file(path)
    Runs a Lua file, the way a level script is run. A file that cannot be read reports as a "runtime" failure.

    Parameters:

    • path (string). Path of the file.

    Returns: trx.lua.Error or nil.

    Example:

    trx.lua.eval_file("data/ship/scripts/extra.lua")