13 changed files with 127 additions and 23 deletions
@ -1,4 +1,9 @@ |
|||
#ifndef LUARES_H |
|||
#define LUARES_H |
|||
extern char lua_boot[]; |
|||
extern char lua_component[]; |
|||
extern char lua_computer[]; |
|||
extern char lua_init[]; |
|||
extern char lua_sandbox[]; |
|||
extern char lua_util_random[]; |
|||
#endif |
|||
|
@ -0,0 +1,9 @@ |
|||
#include <lua.h> |
|||
#include <lualib.h> |
|||
#include <lauxlib.h> |
|||
#ifndef LUPI_H |
|||
#define LUPI_H |
|||
|
|||
void run_init(); |
|||
void setup_modules(lua_State *L); |
|||
#endif |
@ -0,0 +1,22 @@ |
|||
#include "luares.h" |
|||
#include "lupi.h" |
|||
#include <lua.h> |
|||
#include <lualib.h> |
|||
#include <lauxlib.h> |
|||
#include <stdlib.h> |
|||
|
|||
//TODO: move to utils
|
|||
#define pushtuple(state, name, value) lua_pushstring((state), (name)); lua_pushstring((state), (value)); lua_settable((state), -3) |
|||
|
|||
|
|||
void setup_modules(lua_State *L) { |
|||
lua_createtable (L, 0, 1); |
|||
|
|||
pushtuple(L, "boot", lua_boot); |
|||
pushtuple(L, "component", lua_component); |
|||
pushtuple(L, "computer", lua_computer); |
|||
pushtuple(L, "sandbox", lua_sandbox); |
|||
pushtuple(L, "random", lua_util_random); |
|||
|
|||
lua_setglobal(L, "moduleCode"); |
|||
} |
@ -0,0 +1,9 @@ |
|||
local boot = {} |
|||
|
|||
function boot.boot() |
|||
print("LuPI L2 INIT") |
|||
print("FIXME: boot stub") |
|||
error("Unable to boot") |
|||
end |
|||
|
|||
return boot |
@ -0,0 +1,9 @@ |
|||
local component = {} |
|||
local api = {} |
|||
component.api = api |
|||
|
|||
function component.prepare() |
|||
print("Assembling initial component tree") |
|||
end |
|||
|
|||
return component |
@ -0,0 +1 @@ |
|||
|
@ -1 +1,24 @@ |
|||
print("hello") |
|||
print("LuPI L1 INIT") |
|||
modules = {} |
|||
|
|||
local function loadModule(name) |
|||
print("LuPI L1 INIT > Load module > " .. name) |
|||
--TODO: PRERELEASE: Module sandboxing, preferably secure-ish |
|||
--TODO: ASAP: Handle load errors |
|||
if not moduleCode[name] then |
|||
error("No code for module " .. tostring(name)) |
|||
end |
|||
modules[name] = load(moduleCode[name])() |
|||
end |
|||
|
|||
--Load modules |
|||
loadModule("random") |
|||
loadModule("component") |
|||
loadModule("computer") |
|||
loadModule("sandbox") |
|||
loadModule("boot") |
|||
|
|||
--Setup core modules |
|||
modules.component.prepare() |
|||
|
|||
modules.boot.boot() |
|||
|
@ -0,0 +1 @@ |
|||
|
@ -0,0 +1,11 @@ |
|||
local random = {} |
|||
|
|||
function random.uuid() |
|||
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' |
|||
return string.gsub(template, '[xy]', function (c) |
|||
local v = (c == 'x') and random(0, 0xf) or random(8, 0xb) |
|||
return string.format('%x', v) |
|||
end) |
|||
end |
|||
|
|||
return random |
Loading…
issues.context.reference_issue