bettola/assets/scripts/bin/echo.lua
Ritchie Cunningham e06d6eec37 [Refactor] Implement scriptable Lua API
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.
2025-09-27 21:18:05 +01:00

26 lines
545 B
Lua

-- /bin/echo - Display contents of a text file.
local content_parts = {}
local filename = nil
local found_redirect = false
for i, v in ipairs(arg) do
if v == ">" then
found_redirect = true
filename = arg[i+1]
break
else
table.insert(content_parts, v)
end
end
if found_redirect then
if not filename then
return "echo: syntax error: expected filename after '>'"
end
local content = table.concat(content_parts, " ")
return bettola.write_file(context, filename, content)
else
return table.concat(arg, " ")
end