LuaSandbox::loadString

Load Lua code into the Lua environment

&reftitle.description; public `LuaSandboxFunction` `LuaSandbox::loadString` `string` `code` `string` `chunkName`''

Loads Lua code into the Lua environment.

This is the equivalent of standard Lua's `loadstring()` function.

&reftitle.parameters;

`code`

- Lua code.

`chunkName`

- Name for the loaded chunk, for use in error traces.

&reftitle.returnvalues;

Returns a `LuaSandboxFunction` which, when executed, will execute the passed `$code`.

&reftitle.examples;

### Loading code into Lua

    <?php

    // create a new LuaSandbox
    $sandbox = new LuaSandbox();

    // Load the code
    $function = $sandbox->loadString(
    <<<CODE
        return "Hello, world"
    CODE
    );

    // Execute the loaded code
    var_dump( $function->call() );

    ?>

&example.outputs;

    array(1) {
      [0]=>
      string(12) "Hello, world"
    }

&reftitle.seealso;

- `LuaSandbox::registerLibrary`
- `LuaSandbox::wrapPhpFunction`