diff --git a/assets/scripts/bin/cat.lua b/assets/scripts/bin/cat.lua new file mode 100644 index 0000000..befe959 --- /dev/null +++ b/assets/scripts/bin/cat.lua @@ -0,0 +1,18 @@ +-- /bin/cat - Concatenate files and print on stdout. +local filename = arg[1] +if not filename then + return "" -- No arguments, return nothing. +end + +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 diff --git a/common/src/lua_processor.cpp b/common/src/lua_processor.cpp index 0acdffb..cc587d6 100644 --- a/common/src/lua_processor.cpp +++ b/common/src/lua_processor.cpp @@ -12,7 +12,8 @@ LuaProcessor::LuaProcessor(void) { "name", &vfs_node::name, "type", &vfs_node::type, "children", &vfs_node::children, - "read_only", &vfs_node::read_only); } + "read_only", &vfs_node::read_only, + "content", &vfs_node::content); } LuaProcessor::~LuaProcessor(void) {}