LUA(4) | Device Drivers Manual | LUA(4) |
lua
— control
in-kernel Lua states
lua*
#include <sys/types.h>
#include <sys/lua.h>
The lua
device allows to create, control,
and delete Lua states in the kernel through an
ioctl(2) interface. Moreover,
lua
can be used to load Lua scripts into a Lua state
and to assign modules to an existing state, i.e. perform the equivalent of
the Lua command require. lua
is
also used to retrieve information about currently active Lua states.
Lua modules are used to provide functionality to Lua scripts not
available in the language itself, e.g. to access core kernel functionality
like printing text on the console. Unlike in user space Lua, where Lua
modules are files in the filesystem, modules must be provided to
lua
in the form of loadable kernel modules that
register their functionality with lua
. Modules are
loaded using the require
Lua command; whether this
command is available or not is controlled by a
sysctl(8) variable.
lua
by default tries to load a kernel module named
luafoo.kmod
when it encounters the Lua command require 'foo'.
The operation of lua
can be controlled by
means of the following
sysctl(8) variables:
kern.lua.autoload
lua
tries to autoload kernel
modules.
The default value is 1.
kern.lua.bytecode
The default value is 0.
kern.lua.maxcount
lua
limits the number
of instructions executed to this number.
The default value is 0.
kern.lua.require
The default value is 1.
kern.lua.verbose
The default value is 0.
The following structures and constants are defined in the
<sys/lua.h>
header file:
LUAINFO(struct
lua_info)
lua
states in the
lua_info structure:
#define MAX_LUA_NAME 16 #define MAX_LUA_DESC 64 struct lua_state_info { char name[MAX_LUA_NAME]; char desc[MAX_LUA_DESC]; bool user; }; struct lua_info { int num_states; /* total number of Lua states */ struct lua_state_info *states; };
LUACREATE(struct
lua_create)
struct lua_create { char name[MAX_LUA_NAME]; char desc[MAX_LUA_DESC]; };
LUADESTROY(struct
lua_create)
LUAREQUIRE(struct
lua_require)
#define LUA_MAX_MODNAME 32 struct lua_require { char state[MAX_LUA_NAME]; char module[LUA_MAX_MODNAME]; };
LUALOAD(struct
lua_load)
struct lua_load { char state[MAX_LUA_NAME]; char path[MAXPATHLEN]; };
The path element of the lua_load structure must contain at least one ‘/’ character.
The lua
device first appeared in
NetBSD 7.0.
The lua
driver was written by
Marc Balmer
<mbalmer@NetBSD.org>.
The lua
device is experimental.
Incompatible changes might be made in the future.
July 25, 2014 | NetBSD 10.99 |