refactor(demo): keep the demo Lua-only
Calling the compiled modules required a CMake project and a C++ main, which contradicted the point of the compiler. A Lua entry script now prints the same report, and the modules sit next to it so require resolves without any flag.
This commit is contained in:
8 files changed
+37
-70
No files matched your search
@@ -0,0 +1,51 @@
|
||||
-- Small demo package: a toy todo list, compiled into the C++ package demo::todo.
|
||||
local M = {}
|
||||
|
||||
local items = {}
|
||||
local next_id = 0
|
||||
|
||||
function M.add(text, priority)
|
||||
next_id = next_id + 1
|
||||
local item = {
|
||||
id = next_id,
|
||||
text = text,
|
||||
done = false,
|
||||
priority = priority or 2,
|
||||
}
|
||||
items[#items + 1] = item
|
||||
return item.id
|
||||
end
|
||||
|
||||
function M.done(id)
|
||||
for _, item in ipairs(items) do
|
||||
if item.id == id then
|
||||
item.done = true
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function M.count()
|
||||
return #items
|
||||
end
|
||||
|
||||
function M.pending()
|
||||
local n = 0
|
||||
for _, item in ipairs(items) do
|
||||
if not item.done then
|
||||
n = n + 1
|
||||
end
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
function M.list()
|
||||
return items
|
||||
end
|
||||
|
||||
function M.version()
|
||||
return "1.0"
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user