feat(cli): add a run mode that compiles and executes a Lua script

Writing C++ or CMake to try a Lua file makes the compiler hard to evaluate, so
one command now transpiles the script and its sibling modules, links them and
runs the result. Literal require calls resolve against the compiled modules.
This commit is contained in:
BlackAngelTV committed 2026-11-18 08:48:05 +01:00
1 parent d32f73006e
commit f140f30348
3 files changed
+348 -64

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
-- Script à lancer directement avec le compilateur :
-- ./build/luacpp run Demo/hello.lua
-- Aucun C++ nécessaire : luacpp traduit ce fichier en C++, le compile et l'exécute.
print("Bonjour depuis du Lua compile en C++ !")
local function fib(n)
if n < 2 then
return n
end
return fib(n - 1) + fib(n - 2)
end
local suite = {}
for i = 0, 12 do
suite[#suite + 1] = tostring(fib(i))
end
print("fibonacci : " .. table.concat(suite, " "))
local langs = { "Lua", "C++" }
for i, name in ipairs(langs) do
print(string.format("%d. %s", i, name))
end
local t = { sum = 0 }
for _, v in ipairs({ 3, 4, 5 }) do
t.sum = t.sum + v
end
print("somme = " .. t.sum)