Bindings for Lua 5.5's public C API and auxiliary and standard libraries. They require the default Lua numeric configuration: 64-bit lua_Integer and double lua_Number. Lua 5.1 through 5.4 libraries are not ABI-compatible with these bindings.
The library identifier for typed aliases is liblua5.5. Platform library names are lua55.dll on Windows, liblua5.5.dylib on macOS, liblua5.5.so.0 on Linux, and liblua-5.5.so on other Unix systems. The library must be on the system's dynamic-library search path. For an Apple Silicon Homebrew installation, set DYLD_LIBRARY_PATH to /opt/homebrew/lib when launching Factor.
Running Lua code
USING: continuations kernel locals lua prettyprint ;
[let
luaL_newstate :> L
[
L luaL_openlibs
L "return 6 * 7" luaL_dostring .
L -1 lua_tointeger .
] [ L lua_close ] finally
]
Changes from the former Lua 5.1 bindings
•
lua_newstate now takes an unsigned random seed after the allocator and user data. lua_resume takes the originating state and an int* result count. lua_load takes a mode; lua_dump takes a strip flag.
•
Get operations such as lua_getglobal, lua_getfield and lua_rawgeti return the pushed value's type. lua_pushstring and lua_pushlstring return the pushed string. lua_sethook returns no value.
•
The registry index, registry entries, hook masks, GC options, lua_Debug and luaL_Buffer follow the 5.5 headers. Hook masks are constants. lua_gc is variadic and its extra argument types depend on the selected option.
•
Removed 5.1 environment indices and functions, lua_cpcall, lua_setlevel, luaI_openlib, luaL_register and luaL_findtable are no longer declared as exports. Use globals, upvalues, luaL_setfuncs and luaL_requiref as appropriate.
•
Operations that became C macros, including lua_call, lua_pcall, lua_tonumber, lua_insert and luaL_openlibs, are Factor wrappers around current exported functions.
Strings and native storage Text parameters and copied string results use UTF-8. Lua strings may also hold arbitrary bytes: use lua_tolstring-raw and its size_t output for a borrowed pointer and exact byte length. lua_pushlstring, lua_pushexternalstring, luaL_addlstring and luaL_loadbufferx accept raw buffers and explicit byte lengths.
Allocate luaL_Buffer with malloc-struct and release it with free after finishing the buffer operation. Its internal pointer can refer to the struct's own embedded storage, so it must not move with Factor's garbage collector. External strings likewise need stable native storage that remains valid for as long as Lua retains it.
Lua errors and yields must not unwind through a Factor callback. Use a C shim for callbacks that can raise Lua errors or yield; keep the protected call and the nonlocal jump inside C. Lua 5.5 variadic formatting