A separate CMake project using the compiler as a subproject shows the real workflow: namespaced facades, require between compiled modules and dynamic access from C++.
33 lines
941 B
C++
33 lines
941 B
C++
// 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;
|
|
}
|