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
@@ -1,6 +1,5 @@
|
||||
# Build output
|
||||
build/
|
||||
Demo/build/
|
||||
luacpp-build/
|
||||
|
||||
# Compiled objects
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(luacpp_demo LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Reuse the compiler from the repository root as a subproject.
|
||||
set(LUACPP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/.." "${CMAKE_CURRENT_BINARY_DIR}/luacpp")
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/lua-package.cmake")
|
||||
|
||||
add_lua_package(demo_lua
|
||||
ROOT "${CMAKE_CURRENT_SOURCE_DIR}/lua"
|
||||
MODULES todo.lua report.lua
|
||||
NAMESPACE demo)
|
||||
|
||||
add_executable(luacpp_demo main.cpp)
|
||||
target_link_libraries(luacpp_demo PRIVATE demo_lua)
|
||||
@@ -1,32 +0,0 @@
|
||||
// Demo program: uses Lua modules compiled into C++ packages.
|
||||
#include <iostream>
|
||||
|
||||
#include <luacpp/rt.hpp>
|
||||
|
||||
#include "report.hpp"
|
||||
#include "todo.hpp"
|
||||
|
||||
int main() {
|
||||
luacpp::State state;
|
||||
|
||||
auto todo = demo::todo::bind(state);
|
||||
auto report = demo::report::bind(state);
|
||||
|
||||
todo.add("Ecrire le compilateur Lua -> C++", 1);
|
||||
todo.add("Compiler les modules en packages C++", 1);
|
||||
todo.add("Ajouter les tests de conformite", 3);
|
||||
todo.done(2);
|
||||
|
||||
std::cout << report.summary().as_string() << "\n\n";
|
||||
std::cout << report.render().as_string() << "\n\n";
|
||||
|
||||
luacpp::Value stats = report.stats();
|
||||
std::cout << "termines : " << stats.get("finished").to_string() << "/"
|
||||
<< stats.get("total").to_string() << "\n";
|
||||
|
||||
// Dynamic access, without the generated facade.
|
||||
luacpp::Value items = demo::todo::module(state).get("list").call();
|
||||
std::cout << "premier item : " << items.at(1).get("text").as_string() << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Démo à lancer directement, sans écrire de C++ :
|
||||
-- ./build/luacpp run Demo/main.lua
|
||||
--
|
||||
-- luacpp compile ce script ET les modules du dossier, puis exécute le résultat.
|
||||
-- report.lua fait require("todo") : les modules compilés s'appellent entre eux
|
||||
-- exactement comme en Lua normal.
|
||||
|
||||
local todo = require("todo")
|
||||
local report = require("report")
|
||||
|
||||
todo.add("Ecrire le compilateur Lua -> C++", 1)
|
||||
todo.add("Compiler les modules en packages C++", 1)
|
||||
todo.add("Ajouter les tests de conformite", 3)
|
||||
todo.done(2)
|
||||
|
||||
print(report.summary())
|
||||
print()
|
||||
print(report.render())
|
||||
print()
|
||||
|
||||
local stats = report.stats()
|
||||
print(string.format("termines : %d/%d", stats.finished, stats.total))
|
||||
print("premier item : " .. todo.list()[1].text)
|
||||
@@ -1,5 +1,5 @@
|
||||
-- Demo module that requires another compiled module (demo.todo).
|
||||
local todo = require("demo.todo")
|
||||
-- Demo module that requires another compiled module (todo).
|
||||
local todo = require("todo")
|
||||
|
||||
local M = {}
|
||||
|
||||
File renamed without changes.
@@ -103,18 +103,16 @@ avec `pcall`.
|
||||
|
||||
## Demo
|
||||
|
||||
`Demo/` contient deux choses :
|
||||
`Demo/` ne contient que du Lua, aucun C++ :
|
||||
|
||||
- `Demo/hello.lua` : script pur Lua, sans aucun C++, à lancer avec
|
||||
`./build/luacpp run Demo/hello.lua` ;
|
||||
- un projet autonome (sa propre `CMakeLists.txt`) qui teste l'intégration C++ :
|
||||
`Demo/lua/todo.lua` (tables, closures, méthodes, `for` génériques),
|
||||
`Demo/lua/report.lua` (`require("demo.todo")` + statistiques) et
|
||||
`Demo/main.cpp` (façade générée et API dynamique).
|
||||
- `Demo/hello.lua` : script seul (fonctions, boucles, `table.concat`) ;
|
||||
- `Demo/todo.lua` : module — tables, closures, `ipairs` ;
|
||||
- `Demo/report.lua` : module qui fait `require("todo")` et calcule des stats ;
|
||||
- `Demo/main.lua` : utilise les deux modules et affiche le rapport.
|
||||
|
||||
```bash
|
||||
./build/luacpp run Demo/hello.lua
|
||||
cmake -S Demo -B build/demo && cmake --build build/demo -j && build/demo/luacpp_demo
|
||||
./build/luacpp run Demo/hello.lua # un fichier, aucun require
|
||||
./build/luacpp run Demo/main.lua # plusieurs modules compilés ensemble
|
||||
```
|
||||
|
||||
## Tests de conformité
|
||||
@@ -162,6 +160,6 @@ src/codegen.* analyse (captures/upvalues) + génération C++
|
||||
src/main.cpp CLI luacpp
|
||||
include/luacpp/ runtime C++ (State, Value, Module, helpers de la VM)
|
||||
cmake/ add_lua_package()
|
||||
Demo/ script Lua autonome + petit projet C++ de test
|
||||
Demo/ scripts Lua uniquement (aucun C++)
|
||||
tests/ suite de conformité comparée à lua5.4
|
||||
```
|
||||
@@ -6,7 +6,7 @@
|
||||
# cd build && ./luacpp run ../script.lua # même chose depuis le dossier build
|
||||
#
|
||||
# Options:
|
||||
# ./build.sh --full # + Demo et tests
|
||||
# ./build.sh --full # + tests de conformité et démo Lua
|
||||
#
|
||||
# Environment:
|
||||
# BUILD_DIR build directory (default: build)
|
||||
@@ -38,15 +38,12 @@ if [[ "${1:-}" != "--full" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "==> building the Demo and the tests"
|
||||
echo "==> building the tests"
|
||||
cmake --build "$BUILD_DIR" -j "$JOBS"
|
||||
|
||||
echo
|
||||
echo "==> Demo project"
|
||||
cmake -S Demo -B "$BUILD_DIR/demo" -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build "$BUILD_DIR/demo" -j "$JOBS"
|
||||
echo
|
||||
"$BUILD_DIR/demo/luacpp_demo"
|
||||
echo "==> Demo (Lua only, compiled and run by luacpp)"
|
||||
( cd "$BUILD_DIR" && ./luacpp run ../Demo/main.lua )
|
||||
|
||||
echo
|
||||
echo "==> conformance test (compiled modules vs. plain Lua 5.4)"
|
||||
|
||||
Reference in new issue
Block a user