Large architecture refactor of the scripting system. Previous implementation required Lua scripts to return "action tables" which were interpreted by a large and not very flexible at all if-else ladder in C++. While fine for the initial implementation, it's not scalable, and it makes it impossible for players to write their own meaningful tools.
20 lines
499 B
Lua
20 lines
499 B
Lua
-- /bin/cat - Concatenate files and print on stdout.
|
|
local filename = arg[1]
|
|
if not filename then
|
|
return "" -- No arguments, return nothing.
|
|
end
|
|
|
|
local current_dir = bettola.get_current_dir(context)
|
|
local target_node = current_dir.children[filename]
|
|
|
|
if not target_node then
|
|
return "cat: " .. filename .. ": No such file or directory."
|
|
end
|
|
|
|
if target_node.type == 1 then
|
|
return "cat: " .. filename .. ": Is a directory"
|
|
end
|
|
|
|
-- It's a file, return it's contents. :)
|
|
return target_node.content
|