LUA(4)
π LUA(4) β like, the kernel Lua device, bestie
okay so this is from the Kernel Interfaces Manual, and it's literally all about lua β the thing that lets you boss around Lua states inside the kernel. buckle up π¦
β¨ NAME β¨
lua β control in-kernel Lua states π
πΈ SYNOPSIS πΈ
lua*
#include <sys/types.h>
#include <sys/lua.h>
π DESCRIPTION π
The lua device is your main character. it lets you create, control, and delete Lua states in the kernel through an ioctl(2) interface. no cap.
but wait, there's more β lua can also:
- load Lua scripts into a Lua state π§
- assign modules to an existing state, which is literally the equivalent of doing the Lua command
require - retrieve info about the Lua states that are currently active π
β LUA MODULES β
so, Lua modules exist to give Lua scripts functionality that the language itself just doesn't have β like, for example, accessing core kernel functionality such as printing text on the console. slay.
here's the tea though π: in user space Lua, modules are just files in the filesystem. but unlike that, with lua the modules have to be handed over in the form of loadable kernel modules that register their functionality with lua.
modules get loaded with the require Lua command. whether that command is even available is controlled by a sysctl(8) variable (iykyk, more on that below).
by default, lua tries to load a kernel module named luafoo.kmod when it encounters the Lua command require 'foo'. π«Ά
π¦ SYSCTL VARIABLES π¦
you can steer how lua behaves with these sysctl(8) variables:
kern.lua.autoloadβ when it's set to1,luatries to autoload kernel modules. the default value is1. β¨kern.lua.bytecodeβ when it's set to1, loading of Lua bytecode is allowed. the default value is0. πkern.lua.maxcountβ when it's set to a value> 0,lualimits the number of instructions executed to this number. the default value is0.kern.lua.requireβ when it's set to1, it enables therequirecommand in Lua. the default value is1. πkern.lua.verboseβ when it's set to a value> 0, verbosity is increased. the default value is0. π₯
π₯ IOCTL INTERFACE π₯
these structures and constants live in the <sys/lua.h> header file:
π LUAINFO(struct lua_info)
returns information about the lua states, all wrapped up 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)
creates a new named Lua state, with the name and description living in the lua_create structure:
struct lua_create {
char name[MAX_LUA_NAME];
char desc[MAX_LUA_DESC];
};
π LUADESTROY(struct lua_create)
destroys a named Lua state. bye bestie π
πΈ LUAREQUIRE(struct lua_require)
does the equivalent of the Lua command require inside a named state. the name of the state and the module name both get 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)
loads Lua code from the filesystem into a named Lua state. the name of the state and the path to the Lua code get passed in the lua_load structure:
struct lua_load {
char state[MAX_LUA_NAME];
char path[MAXPATHLEN];
};
β οΈ thepathelement of thelua_loadstructure must contain at least one/character. no cap, it's required.
π FILES π
/dev/luaβ the Lua device file. π
π SEE ALSO π
ioctl(2), luactl(8)
π HISTORY π
The lua device first appeared in NetBSD 7.0. iconic behavior.
π AUTHORS π
the lua driver was written by Marc Balmer <mbalmer@NetBSD.org>. give them their flowers π
π«Ά CAVEATS π«Ά
β οΈ The lua device is experimental. incompatible changes might be made in the future. so likeβ¦ don't get too attached to how it works today, bestie π
k that's the whole thing! mwah π this page came from the Debian edition of the manual, dated July 25, 2014 β logging off now, ily πβ¨
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2013 Marc Balmer <marc@msys.ch>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms