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,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.
Reference in new issue
Block a user