From 59ecab36f634a00cc6e2c4194bf2d5ebc4ec70eb Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 19 Apr 2017 19:34:05 +0200 Subject: First lua app --- src/syslua/lx/shell.lua | 61 +++++++++++++++++++++++++++++++++++------------- src/syslua/lx/sysdef.lua | 31 +++++++++++++++++++++++- 2 files changed, 75 insertions(+), 17 deletions(-) (limited to 'src/syslua/lx') diff --git a/src/syslua/lx/shell.lua b/src/syslua/lx/shell.lua index 62f210f..e736e24 100644 --- a/src/syslua/lx/shell.lua +++ b/src/syslua/lx/shell.lua @@ -3,28 +3,29 @@ local sysdef = require 'lx.sysdef' local _cwd = 'root:/' +function explode_path(path) + local _, _, dr, p = string.find(path, '^(%w+):(.*)$') + if not dr or not p then + dr, p = nil, path + end + local pp = string.split(p, '/') + if #pp > 1 and pp[#pp] == '' then + table.remove(pp) + end + return dr, pp +end + +function implode_path(dr, p) + assert(p[1] == '', 'bad first path component') + return dr .. ':' .. table.concat(p, '/') +end + function pathcat(path1, path2) assert(path1, "invalid argument") if not path2 then return path1 end - function explode_path(path) - local _, _, dr, p = string.find(path, '^(%w+):(.*)$') - if not dr or not p then - dr, p = nil, path - end - local pp = string.split(p, '/') - if #pp > 1 and pp[#pp] == '' then - table.remove(pp) - end - return dr, pp - end - - function implode_path(dr, p) - assert(p[1] == '', 'bad first path component') - return dr .. ':' .. table.concat(p, '/') - end local dr2, p2 = explode_path(path2) if dr2 then @@ -86,3 +87,31 @@ function ls(path) end end +function run(path) + path = pathcat(_cwd, path) + + local s = sys.stat(path) + if not s then + print("not found: " .. path) + elseif s.type & sysdef.FT_DIR == 0 then + print("not a directory: " .. s) + else + local mainlua = pathcat(path, 'main.lua') + local s2 = sys.stat(mainlua) + if not s2 then + print("not found: " .. mainlua) + else + local pid = sys.new_proc() + sys.bind_fs(pid, "sys", "sys") + + local _, _, dr, p = string.find(path, '^(%w+):(.*)$') + sys.bind_subfs(pid, "app", dr, p, sysdef.FM_READ | sysdef.FM_READDIR) + sys.bind_fd(pid, sysdef.STD_FD_TTY_STDIO, sysdef.STD_FD_TTY_STDIO) + + sys.proc_exec(pid, "sys:/bin/lx.bin") + local st = sys.proc_wait(pid, true) + + print(st) + end + end +end diff --git a/src/syslua/lx/sysdef.lua b/src/syslua/lx/sysdef.lua index 7c0d14f..43015e2 100644 --- a/src/syslua/lx/sysdef.lua +++ b/src/syslua/lx/sysdef.lua @@ -1,6 +1,7 @@ --- Constant definitions based on common/include/proto/fs.h return { + -- Definitions from proto/fs.h + -- FILE TYPES FT_REGULAR = 0, FT_DIR = 0x01, @@ -33,4 +34,32 @@ return { SEL_READ = 0x01, SEL_WRITE = 0x02, SEL_ERROR = 0x04, + + + -- Definitions from proto/launch.h + + -- STANDARD FILE DESCRIPTORS + STD_FD_TTY_STDIO = 1, + STD_FD_STDIN = 2, + STD_FD_STDOUT = 3, + STD_FD_STDERR = 4, + STD_FD_GIP = 5, + STD_FD_GIOSRV = 10, + STD_FD_TTYSRV = 11, + + -- Definitions from proto/fb.h + + -- FRAMEBUFFER TYPES : TODO + + -- FRAMEBUFFER IOCTLs + IOCTL_FB_GET_INFO = 1, + IOCTL_FBDEV_GET_MODE_INFO = 10, + IOCTL_FBDEV_SET_MODE = 11, + + -- Definitions from proto/proc.h + PS_LOADING = 1, + PS_RUNNING = 2, + PS_FINISHED = 3, + PS_FAILURE = 4, + PS_KILLED = 5, } -- cgit v1.2.3