BearLibTerminal / Using / Lua

Using BearLibTerminal with Lua is very straightforward. The library binary file itself is a Lua binary module which may be imported by a simple require instruction:

terminal = require 'BearLibTerminal'

-- Initialize the library
terminal.open()

-- Print something
terminal.print(2, 1, 'Hello, world')
terminal.refresh()

-- The usual 'Press any key to exit...'
terminal.read()

-- Clean up
terminal.close()

For this to work, you must:

  • Place the library binary file in a folder searched by Lua module loader, e. g. in the same directory as the script file.
  • Make sure the binary is named BearLibTerminal.dll/.so/.dylib – meaning under Linux and OS X you'll have to symlink or rename the file to remove its usual 'lib' prefix.
    This is just how Lua module loader works, it looks for a file without prefixes.

API

Similar to other bindings, functions and constants names and their behavior are mostly the same as described at API reference page. The fact that most of library configuration is text-based helps this a lot.

The only noticeable difference is that read str function returns two values instead of one:

rc, str = terminal.read_str(x, y, prompt_str, max_length)