Skip to content

SaferLua

Joachim Stolberg edited this page Jan 30, 2019 · 20 revisions

SaferLua [safer_lua] is a programming mod/library with a subset of the language Lua for safe and secure Lua sandboxes with:

  • limited code length
  • limited execution time
  • limited memory use
  • limited possibilities to call functions

All these limits should prevent any server damage or crashes and thus allow Lua sandboxes for ingame Lua computers and robots, like the SaferLua Controller.

SaferLua follows the standard Lua syntax with the following restrictions:

  • no while and repeat loops
  • for loops only for Data Structures elements or via range(from, to) Examples
  • no table constructor {..}, see Data Structures for comfortable alternatives
  • limited runtime environment

SaferLua directly supports the following standard functions:

  • math.floor
  • math.abs
  • math.max
  • math.min
  • math.random
  • tonumber
  • tostring
  • unpack
  • type
  • string.byte
  • string.char
  • string.find
  • string.format
  • string.gmatch
  • string.gsub
  • string.len
  • string.lower
  • string.match
  • string.rep
  • string.sub
  • string.upper
  • string.split
  • string.trim

Each SaferLua program has access to the following system variables:

  • ticks - a counter increment for each call of loop(). See Examples.
  • elapsed - the amount of seconds since the last call of loop()
  • event - a boolean flag (true/false) to signal the execution of loop() based on an event. See Loops and Events.

SaferLua allows to write and call Lua functions. See Examples#idle-function.

Further functions and commands may be available by the mod using SaferLua. Commands are functions to control the game environment like for TechPack nodes. All Commands start with the character '$', like $print().

Further reading:

See also: