Add optional Lua scripting module, examples, and validation
This commit is contained in:
@@ -7,10 +7,33 @@ namespace fs = std::filesystem;
|
||||
using namespace faset;
|
||||
int tool_main(int argc, char** argv) {
|
||||
try {
|
||||
if (argc == 3 && std::string_view(argv[1]) == "--output") {
|
||||
if (argc >= 3 && std::string_view(argv[1]) == "--output") {
|
||||
if (argc == 5 && std::string_view(argv[3]) == "--project") {
|
||||
const auto snapshot = path_from_utf8(argv[4]);
|
||||
const auto project = read_json(snapshot / "project.faset.json");
|
||||
for (const auto& name : project.at("scripting").at("lua").at("scripts"))
|
||||
if (!fs::is_regular_file(snapshot / path_from_utf8(name.get<std::string>())))
|
||||
throw std::runtime_error(
|
||||
"Schema exporter did not receive captured sources");
|
||||
atomic_write_json("exporter-project-fixture.json", project);
|
||||
if (fs::exists("mutate-lua-during-build"))
|
||||
atomic_write("Scripts/main.lua", "-- changed while schema was exporting\n");
|
||||
if (fs::exists("mutate-lua-snapshot"))
|
||||
atomic_write(snapshot / "Scripts/main.lua", "-- corrupt snapshot\n");
|
||||
}
|
||||
atomic_write_json(path_from_utf8(argv[2]), read_json("schema-fixture.json"));
|
||||
return 0;
|
||||
}
|
||||
if (argc >= 2 && std::string_view(argv[1]) == "--validate") {
|
||||
if (fs::exists("project.faset.json")) {
|
||||
const auto manifest = read_json("project.faset.json");
|
||||
for (const auto& name : manifest.at("scripting").at("lua").at("scripts"))
|
||||
if (!fs::is_regular_file(path_from_utf8(name.get<std::string>())))
|
||||
throw std::runtime_error("Packaged Player is missing a Lua entry source");
|
||||
}
|
||||
std::cout << "Native packaging fixture validated\n";
|
||||
return 0;
|
||||
}
|
||||
if (argc > 2 && std::string_view(argv[1]) == "--build")
|
||||
return 0;
|
||||
fs::path build;
|
||||
@@ -19,8 +42,15 @@ int tool_main(int argc, char** argv) {
|
||||
build = path_from_utf8(argv[i + 1]);
|
||||
if (build.empty())
|
||||
throw std::runtime_error("Fixture expects CMake configure or SchemaExporter arguments");
|
||||
Json arguments = Json::array();
|
||||
for (int i = 1; i < argc; ++i)
|
||||
arguments.push_back(argv[i]);
|
||||
atomic_write_json("configure-fixture.json", arguments);
|
||||
fs::create_directories(build / "shaders");
|
||||
atomic_write(build / "CMakeCache.txt", "Native schema publication fixture\n");
|
||||
for (const auto* name : {"sdl3", "entt", "box2d", "box3d", "json", "stb"})
|
||||
atomic_write(build / "_deps" / (std::string(name) + "-src") / "LICENSE.txt",
|
||||
"Synthetic dependency notice for packaging tests only.\n");
|
||||
const auto self = fs::absolute(path_from_utf8(argv[0]));
|
||||
#ifdef _WIN32
|
||||
constexpr auto suffix = ".exe";
|
||||
|
||||
Reference in New Issue
Block a user