Module xSandbox

xSandbox allows you to execute code in a controlled environment .

How to use

-- create instance
sandbox = xSandbox()

-- supply function
sandbox.callback_str =
  "print('hello world')"

-- and call it...
sandback.callback()

Arguments and return values

-- if you need to supply arguments and define return value,
-- one approach is to define a 'prefix' and 'suffix'
-- (always added to the generated code)

-- define arguments
sandbox.str_prefix = "local some_arg = select(1, ...)"

-- define return value
sandbox.str_suffix = "return some_arg"

-- supply function
sandbox.callback_str =
  "some_arg = some_arg + 'foo'"..
  "print(some_arg)"

-- now call the function like this:
local result = sandback.callback('my_arg')

Custom properties

TODO how to ...

Functions

compile () call method to evaluate function (ensure that it's safe to run)
test_syntax (str_fn) check for syntax errors (assert provides better error messages)

Fields

self.callback function, compiled function (when set, always valid)
self.str_prefix string, code to insert into all generated functions
self.compile_at_once boolean, set to true for instant compilation of callback string
self.callback_str string, text representation of the function
self.properties properties can contain custom get/set methods
self.modified_observable invoked when callback has changed
self.env table, sandbox environment


Functions

compile ()
call method to evaluate function (ensure that it's safe to run)

Returns:

  1. boolean, true when method passed
  2. string, error message when failed
test_syntax (str_fn)
check for syntax errors (assert provides better error messages)

Parameters:

  • str_fn (string) function as string

Returns:

  1. boolean, true when passed
  2. string, when failed

Fields

self.callback
function, compiled function (when set, always valid)
self.str_prefix
string, code to insert into all generated functions
self.compile_at_once
boolean, set to true for instant compilation of callback string
self.callback_str
string, text representation of the function
self.properties
properties can contain custom get/set methods
self.modified_observable
invoked when callback has changed
self.env
table, sandbox environment
generated by LDoc 1.4.2