Files
Lua-compilateur/Demo/hello.lua
T
BlackAngelTV 274daa7b1d 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.
2026-11-18 08:48:05 +01:00

29 lines
670 B
Lua

-- 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)