From 3535f754ab82a0193d5a03a5a6df5f500d74a966 Mon Sep 17 00:00:00 2001 From: Lourival Vieira Neto Date: Tue, 4 Apr 2023 22:40:23 +0000 Subject: [PATCH] add README.md * few adjustments to improve the documentation * update lua/ submodule --- README.md | 390 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/luadevice.c | 12 +- lib/lualinux.c | 39 +++++ lua | 2 +- lunatik.h | 4 +- lunatik_core.c | 18 +-- sbin/lunatik | 17 ++- 7 files changed, 453 insertions(+), 29 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..c15917df --- /dev/null +++ b/README.md @@ -0,0 +1,390 @@ +# Lunatik + +Lunatik is a framework for scripting the Linux kernel with [Lua](https://www.lua.org/). +It is composed by the Lua interpreter modified to run in the kernel; +a [device driver](lunatik.lua) (written in Lua =)) and a [command line tool](sbin/lunatik) +to load and run scripts and manage runtime environments from the user space; +a [C API](#lunatik-c-api) to load and run scripts and manage runtime environments from the kernel; +and [Lua APIs](#lunatik-lua-apis) for binding kernel facilities to Lua scripts. +Lunatik also offers a [shell script](sbin/lunatik.sh) as a helper for managing its kernel modules. + +Here is an example of a character device driver written in Lua using Lunatik +to generate random ASCII printable characters: +```Lua +-- /lib/modules/lua/passwd.lua +-- +-- implements /dev/passwd for generate passwords +-- usage: $ sudo sbin/lunatik --run passwd +-- $ head -c /dev/passwd + +local device = require("device") +local linux = require("linux") + +local function nop() end -- do nothing + +local s = linux.stat +local driver = {name = "passwd", open = nop, release = nop, mode = s.IRUGO} + +function driver:read() -- read(2) callback + -- generate random ASCII printable characters + return string.char(linux.random(32, 126)) +end + +-- creates a new character device +device.new(driver) +``` + +## Usage + +``` +make +sudo sbin/lunatik.sh install # copy lunatik.lua to /lib/modules/lua +sudo sbin/lunatik.sh start # load Lunatik kernel modules +sudo sbin/lunatik.sh run # execute sbin/lunatik REPL +Lunatik 3.0 Copyright (C) 2023 ring-0 Ltda. +> return 42 -- execute this line in the kernel +42 +``` + +### sbin/lunatik + +```Shell +usage: sbin/lunatik [[--run]