Updated: 2022/Sep/29

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


KLUA_MOD_REGISTER(9)       Kernel Developer's Manual      KLUA_MOD_REGISTER(9)

NAME
     klua_mod_register, klua_mod_unregister - Lua kernel bindings

SYNOPSIS
     #include <sys/lua.h>

     void
     klua_mod_register(const char *name, lua_CFunction open);

     void
     klua_mod_unregister(const char *name);

DESCRIPTION
     The Lua kernel bindings are designed to provide functionality to Lua
     scripts normally not available in the language itself, e.g. to access
     core kernel functionality.  This is achieved by utilizing the lua_modules
     functionality.

     The lua_module structure is declared as follows:

     struct lua_module {
             char                    mod_name[LUA_MAX_MODNAME];
             lua_CFunction           open;
             int                     refcount;
             LIST_ENTRY(lua_module)  mod_next;
     };

     The mod_name defines the unique name of a module.  A C function must use
     the standard Lua protocol in order to communicate with Lua, this part is
     maintained with the open element in the standard Lua way.  refcount
     protects the module from being unloaded whilst still in use.  The last
     parameter, mod_next, is used for the standard container LIST(3).

     The klua_mod_register() function registers a new function which is made
     available to the lua(9) device and Lua code using the require directive.
     The require directive can be called from luactl(8) and the kernel Lua
     version.  The name parameter is a unique identifier of the kernel Lua
     module.  open points to a function used in the C to Lua binding, defined
     with the appropriate standard Lua API.

     Once registered, a C function can be unregistered with the
     klua_mod_unregister() function.  This function takes as its parameter the
     unique literal identifier of the extending module.

EXAMPLES
     A set of example modules is available in the src/sys/modules/examples
     directory hierarchy.

SEE ALSO
     lua(1), luac(1), intro(3lua), lua(4), klua_close(9), klua_lock(9),
     klua_newstate(9), klua_unlock(9), kluaL_newstate(9), intro(9lua)

AUTHORS
     Kamil Rytarowski <kamil@NetBSD.org>.

NetBSD 10.99                    April 15, 2017                    NetBSD 10.99