build: add build script and CMake helper for compiled packages
Compiling the compiler, the example and the demo by hand is error prone, so a single script keeps the whole flow reproducible and ignores build outputs.
This commit is contained in:
6 files changed
+161
No files matched your search
@@ -0,0 +1,14 @@
|
||||
-- Example module that requires another compiled module.
|
||||
local mathx = require("demo.mathx")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.hello(name)
|
||||
return "Bonjour " .. name .. " !"
|
||||
end
|
||||
|
||||
function M.double_factorial(n)
|
||||
return mathx.factorial(n) * 2
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,29 @@
|
||||
-- Example Lua module compiled into the C++ package demo::mathx.
|
||||
local M = {}
|
||||
|
||||
function M.add(a, b)
|
||||
return a + b
|
||||
end
|
||||
|
||||
function M.factorial(n)
|
||||
local result = 1
|
||||
for i = 2, n do
|
||||
result = result * i
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function M.summarise(values)
|
||||
local total = 0
|
||||
local count = #values
|
||||
for _, v in ipairs(values) do
|
||||
total = total + v
|
||||
end
|
||||
return {
|
||||
sum = total,
|
||||
count = count,
|
||||
average = count > 0 and total / count or 0,
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user