略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: LuaSandbox::loadString

2024-11-15

LuaSandbox::loadString

(PECL luasandbox >= 1.0.0)

LuaSandbox::loadStringLoad Lua code into the Lua environment

说明

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.

参数

code

Lua code.

chunkName

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

返回值

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

范例

示例 #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() );

?>

以上例程会输出:

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

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/luasandbox.loadstring.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3