feat: add events program
This commit is contained in:
parent
dff6af0666
commit
efc7e88b9b
@ -9,6 +9,7 @@ local LIST_FILES = {
|
||||
'servers/ping-server.lua',
|
||||
-- programs
|
||||
'programs/router.lua', -- router is not in servers folder because he's not ran on every machines
|
||||
'programs/events.lua',
|
||||
'programs/ping.lua',
|
||||
'programs/upgrade.lua',
|
||||
-- apis
|
||||
|
||||
47
programs/events.lua
Normal file
47
programs/events.lua
Normal file
@ -0,0 +1,47 @@
|
||||
local _VERSION = '1.0.0';
|
||||
|
||||
local command = ...;
|
||||
|
||||
local function printUsage()
|
||||
print('events usage:');
|
||||
print();
|
||||
print('\t\t\tevents');
|
||||
print('\t\t\tevents version');
|
||||
print('\t\t\tevents help');
|
||||
end
|
||||
|
||||
local function valueToString(value)
|
||||
if type(value) == 'string' then
|
||||
return value;
|
||||
end
|
||||
|
||||
return textutils.serialize(value, { compact = true });
|
||||
end
|
||||
|
||||
if command == 'version' or command == '-version' or command == '--version' then
|
||||
print('events v' .. _VERSION);
|
||||
return;
|
||||
end
|
||||
|
||||
if command == 'help' or command == '-help' or command == '--help' then
|
||||
printUsage();
|
||||
return;
|
||||
end
|
||||
|
||||
if command ~= nil and command ~= '' then
|
||||
printUsage();
|
||||
return;
|
||||
end
|
||||
|
||||
print('Listening events... Press Ctrl+T to stop.');
|
||||
|
||||
while true do
|
||||
local event = table.pack(os.pullEventRaw());
|
||||
local parts = {};
|
||||
|
||||
for i = 1, event.n do
|
||||
parts[i] = valueToString(event[i]);
|
||||
end
|
||||
|
||||
print(table.concat(parts, ' '));
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user