LUA(4)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… 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 to 1, lua tries to autoload kernel modules. the default value is 1. ✨
  • kern.lua.bytecode β€” when it's set to 1, loading of Lua bytecode is allowed. the default value is 0. πŸ™ˆ
  • kern.lua.maxcount β€” when it's set to a value > 0, lua limits the number of instructions executed to this number. the default value is 0.
  • kern.lua.require β€” when it's set to 1, it enables the require command in Lua. the default value is 1. πŸ’œ
  • kern.lua.verbose β€” when it's set to a value > 0, verbosity is increased. the default value is 0. πŸ”₯

πŸ”₯ 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];
};
⚠️ the path element of the lua_load structure 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