Menu
CoddyTech

Recap: Dispatch Reports

Lesson 42 of 48 in Coddy's Lua for GDScript Developers course.

challenge icon

Challenge

Medium

Implement two modules, short.lua and full.lua, each providing format(self,name,n). Short returns name:n; full returns name has n. Input has name, integer n, and style short or full. App selects the module and returns its format result.

Edit app.lua, short.lua, full.lua. The visible locked main.lua reads stdin into a sequence of lines, calls app.run(lines), and prints its returned value with one final newline. Do not print diagnostics or change the module names. Empty input gives an empty sequence. All numeric inputs are small enough to avoid overflow.

Public API checks: Both formatter modules must implement their public format(self, name, n) method independently. The locked driver checks this behavior before calling app.run. These checks print nothing when successful.

Try it yourself

-- Public API checks
do
local short,full=require("short"),require("full")
assert(short:format("pen",3)=="pen:3","short module format")
assert(full:format("book",0)=="book has 0","full module format")
assert(short:format("x",-1)=="x:-1","signed values are formatted unchanged")
end
local app = require("app")
local lines = {}
for line in io.lines() do lines[#lines + 1] = line end
print(app.run(lines))

All lessons in Lua for GDScript Developers

Practice on your own: Online Lua compiler