Download the PHP package quasilyte/klua without Composer
On this page you can find all versions of the php package quasilyte/klua. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download quasilyte/klua
More information about quasilyte/klua
Files in quasilyte/klua
Package klua
Short Description FFI-based Lua5 library that can be used in both PHP and KPHP
License MIT
Informations about the package klua
KLua
KLua is a FFI-based Lua5 library that can be used in both PHP and KPHP.
Installation
Since this is a FFI library, it needs a dynamic library available during the run time.
Installation steps:
- Install liblua5 in your system (if you don't have it already)
- Locate the library file and place in under
./ffilibs/liblua5
- Install this composer package to use KLua classes inside your code
Depending on your system, you need to find liblua.so
, liblua.dylib
or liblua.dll
file. Then you can copy it to the application root ffilibs
folder
under the liblua5
name (note: no extension suffixes).
If you're having difficulties locating the library file, use a helper script:
Then install the composer library itself:
Notes:
- If you want to place library files/links globally, make
./ffilibs
a symlink - You'll probably want to add
ffilibs/
to your gitignore
Examples
- simple.php - a simple overview of the API basics
- phpfunc.php - how to bind PHP functions to Lua
- override_print.php - override Lua
print()
stdlib function - limited_stdlib.php - how to limit the stdlib access in Lua scripts
- plugin_sandbox.php - how to load several plugins without conflicts
- phpfunc_table.php - how to create module-like native libraries
- light userdata
- memory_limit.php - how to limit the amount of memory Lua scripts can use
- time_limit.php - how to limit the amount of time Lua scripts can run
Running examples with PHP:
Running examples with KPHP:
Quick start
Running with PHP:
Running with KPHP:
Value conversion
PHP Type | Lua Type | Operation Cost |
---|---|---|
bool | boolean | free |
int | number | free |
float | number | free |
string | string | string data is copied |
map-like array | table | expensive conversion |
list-like array | sequence table | expensive conversion |
All conversions are symmetrical, except for the Lua->PHP case of sequence tables.
If KLuaConfig::pack_lua_tables
is set to false
, Lua tables will be returned "as is".
If that option is set to true
(the default), then KLua will try to return Lua sequence
tables as list-like PHP arrays.
Not every PHP value can be converted to a Lua value and vice versa. Both languages should communicate to each other using the simpler protocols.
If some value can't be converted properly, a special error-like value is produced instead.
The light userdata is a special case. It can't be auto-converted from a PHP value, but there are KLua::setVarUserData
and call builder API pushUserData
functions to pass user data from PHP to Lua. When Lua->PHP conversion is performed, the user data address is stored as PHP int
value. You can convert that int
addr to the CData void*
by using KLua::userDataPtr
. See userdata.php for the complete example.
API reference
See api_reference.md for full documentation.
All KLua
class methods are static.
KLua
initialization methods:
loadFFI()
init($config)
close()
KLua
main methods:
eval($code)
evalScript($filename)
setVar($var_name, $value)
setVarUserData($var_name, $ptr)
getVar($var_name)
registerFunction($func_name, $php_func)
userDataPtr($addr)
call($func_name, ...$args)
callStaticMethod($table_name, $table_key, ...$args)
callMethod($table_name, $table_key, ...$args)
KLua
call builder methods:
callBuilder($func_name)
staticMethodCallBuilder($table_name, $table_key)
methodCallBuilder($table_name, $table_key)
KLua
utility methods:
getStats()
All versions of klua with dependencies
vkcom/kphp-polyfills Version ^1.0
quasilyte/kfinalize Version ^1.0
vkcom/ktest-script Version ^0.7.4