LuaSandboxFunction::call
(PECL luasandbox >= 1.0.0)
LuaSandboxFunction::call — Call a Lua function
Description
...$args
): array|boolCalls a Lua function.
Errors considered to be the fault of the PHP code will result in the
function returning false
and E_WARNING
being raised, for example, a resource type being used as an
argument. Lua errors will result in a LuaSandboxRuntimeError
exception being thrown.
PHP and Lua types are converted as follows:
-
PHP
null
is Luanil
, and vice versa. -
PHP ints and floats are converted to Lua numbers. Infinity and
NAN
are supported. -
Lua numbers without a fractional part between approximately
-2**53
and2**53
are converted to PHP ints, with others being converted to PHP floats. -
PHP bools are Lua booleans, and vice versa.
-
PHP strings are Lua strings, and vice versa.
-
Lua functions are PHP LuaSandboxFunction objects, and vice versa. General PHP callables are not supported.
-
PHP arrays are converted to Lua tables, and vice versa.
-
Note that Lua typically indexes arrays from 1, while PHP indexes arrays from 0. No adjustment is made for these differing conventions.
-
Self-referential arrays are not supported in either direction.
-
PHP references are dereferenced.
-
Lua
__pairs
and__ipairs
are processed.__index
is ignored. -
When converting from PHP to Lua, integer keys between
-2**53
and2**53
are represented as Lua numbers. All other keys are represented as Lua strings. -
When converting from Lua to PHP, keys other than strings and numbers will result in an error, as will collisions when converting numbers to strings or vice versa (since PHP considers things like
$a[0]
and$a["0"]
as being equivalent).
-
-
All other types are unsupported and will raise an error/exception, including general PHP objects and Lua userdata and thread types.
Lua functions inherently return a list of results. So on success, this method returns an array containing all of the values returned by Lua, with int keys starting from zero. Lua may return no results, in which case an empty array is returned.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-luasandboxcall.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.