Updated: 2022/Sep/29

Please read Privacy Policy. It's for your privacy.


LUA(4)                       Device Drivers Manual                      LUA(4)

NAME
     lua - control in-kernel Lua states

SYNOPSIS
     lua*

     #include <sys/types.h>
     #include <sys/lua.h>

DESCRIPTION
     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
     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'.

SYSCTL VARIABLES
     The operation of lua can be controlled by means of the following
     sysctl(8) variables:

     kern.lua.autoload
           When set to 1, lua tries to autoload kernel modules.

           The default value is 1.

     kern.lua.bytecode
           When set to 1, loading of Lua bytecode is allowed.

           The default value is 0.

     kern.lua.maxcount
           When set to a value > 0, lua limits the number of instructions
           executed to this number.

           The default value is 0.

     kern.lua.require
           When set to 1, enables the require command in Lua.

           The default value is 1.

     kern.lua.verbose
           When set to a value > 0, verbosity is increased.

           The default value is 0.

IOCTL INTERFACE
     The following structures and constants are defined in the <sys/lua.h>
     header file:

     LUAINFO(struct lua_info)
           Returns information about the 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)
           Create a new named Lua state with name and description in the
           lua_create structure:

           struct lua_create {
                   char    name[MAX_LUA_NAME];
                   char    desc[MAX_LUA_DESC];
           };

     LUADESTROY(struct lua_create)
           Destroy a named Lua state.

     LUAREQUIRE(struct lua_require)
           Perform the equivalent of the Lua command require in a named state.
           The name of the state and of the module name is passed in the
           lua_require structure:

           #define LUA_MAX_MODNAME         32

           struct lua_require {
                   char    state[MAX_LUA_NAME];
                   char    module[LUA_MAX_MODNAME];
           };

     LUALOAD(struct lua_load)
           Load Lua code from the filesystem into a named Lua state.  The name
           of the state and the path to the Lua code are passed in the
           lua_load structure:

           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.

FILES
     /dev/lua  Lua device file.

SEE ALSO
     ioctl(2), luactl(8)

HISTORY
     The lua device first appeared in NetBSD 7.0.

AUTHORS
     The lua driver was written by Marc Balmer <mbalmer@NetBSD.org>.

CAVEATS
     The lua device is experimental.  Incompatible changes might be made in
     the future.

NetBSD 10.99                     July 25, 2014                    NetBSD 10.99