feat: add programs directory in path

This commit is contained in:
Guillaume ARM 2022-07-18 18:25:24 +02:00
parent 12278f72e9
commit 88ce07859d
5 changed files with 67 additions and 9 deletions

View File

@ -1,16 +1,26 @@
local _VERSION = '1.0.0'
local _VERSION = '1.1.0'
local LIST_FILES = {
-- startup
'startup/servers.lua',
-- servers
'servers/ping-server.lua',
'ping.lua',
'router.lua',
'servers/cube-server.lua',
'servers/cube-startup.lua',
-- programs
'programs/router.lua', -- router is not in servers folder because he's not ran on every machines
'programs/ping.lua',
'programs/cube.lua',
-- apis
'apis/net.lua',
'apis/eventloop.lua',
};
-- remove old files
fs.delete('ping-server.lua')
fs.delete('ping-server.lua');
fs.delete('ping.lua')
fs.delete('cube.lua')
fs.delete('router.lua')
local REPO_PREFIX = 'https://raw.githubusercontent.com/guillaumearm/cc-libs/master/'
@ -18,6 +28,7 @@ local previousDir = shell.dir()
shell.setDir('/')
fs.makeDir('/programs');
fs.makeDir('/apis');
fs.makeDir('/startup');

View File

@ -5,6 +5,38 @@ local net = require('/apis/net')();
local cubeCommand, firstArg, secondArg = ...;
--- Pads str to length len with char from right
local leftPad = function(str, len, char)
if char == nil then char = ' ' end
local nbRepetition = len - #str;
if nbRepetition > 0 then
return str .. string.rep(char, len - #str)
end
return str;
end
--- Pads str to length len with char from left
local rightPad = function(str, len, char)
if char == nil then char = ' ' end
local nbRepetition = len - #str;
if nbRepetition > 0 then
return string.rep(char, len - #str) .. str
end
return str;
end
local function getRow(str1, str2, str3)
local row1 = leftPad(tostring(str1 or ''), 6, ' ')
local row2 = leftPad(tostring(str2 or ''), 16, ' ')
local row3 = leftPad(tostring(str3 or ''), 6, ' ')
return row1 .. row2 .. row3;
end
local function isFlag(name)
return function(arg)
return arg == '-' .. name or arg == '--' .. name;
@ -138,15 +170,24 @@ local COMMANDS = {
error(results);
end
-- print('ID LABEL\t\t\t\tSTARTUP');
print(getRow('ID', 'LABEL', 'STARTUP'))
for k in ipairs(results) do
local result = results[k];
local packet = packets[k];
print("=> " .. tostring(packet.sourceId)
..
(
packet.sourceLabel and " (label=" .. tostring(packet.sourceLabel) .. ")" or
"") .. ": startup='" .. result.startup .. "'");
-- local row1 = leftPad(tostring(packet.sourceId or ''), 8, ' ')
-- local row2 = leftPad(tostring(packet.sourceLabel or ''), 12, ' ')
-- local row3 = leftPad(tostring(result.startup or ''), 12, ' ')
-- print(packet.sourceId, packet.sourceLabel or '', result.startup)
print(getRow(packet.sourceId, packet.sourceLabel, result.startup))
-- print("=> " .. tostring(packet.sourceId)
-- ..
-- (
-- packet.sourceLabel and " (label=" .. tostring(packet.sourceLabel) .. ")" or
-- "") .. ": startup='" .. result.startup .. "'");
end
end,
configure = function()

View File

@ -6,6 +6,12 @@ local SERVERS = {
"servers/cube-startup.lua",
};
local function init()
shell.setPath(shell.path() .. ':/programs');
end
init();
local periphEmulation = function()
-- attach modem
periphemu.create('top', 'modem');