SymfonyWorld Online 2022 Winter Edition

LuaSandbox::loadString

(PECL luasandbox >= 1.0.0)

LuaSandbox::loadStringLoad Lua code into the Lua environment

Description

public LuaSandbox::loadString(string $code, string $chunkName = ''): LuaSandboxFunction

Loads Lua code into the Lua environment.

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

Liste de paramètres

code

Lua code.

chunkName

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

Valeurs de retour

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

Exemples

Exemple #1 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() );

?>

L'exemple ci-dessus va afficher :

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

Voir aussi

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top