aboutsummaryrefslogtreecommitdiff
path: root/src/lua_build.cc
diff options
context:
space:
mode:
authordacctal <120422854+dacctal@users.noreply.github.com>2026-03-14 12:11:52 +0000
committerdacctal <120422854+dacctal@users.noreply.github.com>2026-03-14 12:11:52 +0000
commit2a6b92ed130ade1ea7542ee210e6957427a0aa81 (patch)
tree1e235b2116feddd3dcde0db9135ce9871801e2f3 /src/lua_build.cc
parent97d70a6f8252b15928ca7f51386df791dedf0067 (diff)
lua build system integration
Diffstat (limited to 'src/lua_build.cc')
-rw-r--r--src/lua_build.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/lua_build.cc b/src/lua_build.cc
new file mode 100644
index 0000000..b75e2f3
--- /dev/null
+++ b/src/lua_build.cc
@@ -0,0 +1,58 @@
+#include <iostream>
+#include <filesystem>
+#include <map>
+#include <lua5.1/lua.h>
+#include <lua5.1/lauxlib.h>
+#include <lua5.1/lualib.h>
+
+#include "vars.cc"
+
+std::map<std::string, int> build_files;
+
+void lua_build (const char *path) {
+ lua_State *L = lua_open();
+ luaL_openlibs(L);
+
+ if (luaL_loadfile(L, config_file.c_str()) || lua_pcall(L, 0, 0, 0)){
+ std::cout << print_error << "cannot run configuration script: " << lua_tostring(L, -1) << "\n";
+ }
+
+ lua_getglobal(L, "build_systems");
+
+ if (!lua_istable(L, -1)) {
+ std::cout << print_error << "lua variable 'build_systems' is not a table.\n";
+ }
+
+ lua_pushnil(L);
+
+ bool build_found = false;
+ while (lua_next(L, -2) != 0) {
+ const char *key = lua_tostring(L, -2);
+ int value = lua_type(L, -1);
+
+ if (lua_isfunction(L, -1) == 0) {
+ std::cout << print_error << "build value is not a function\n";
+ lua_pop(L, 1);
+ continue;
+ }
+
+ build_files[key] = value;
+
+ for (auto const& dir_entry : std::filesystem::directory_iterator(std::filesystem::current_path().string())) {
+ std::string string_key = key;
+ if (dir_entry.path().filename() != string_key) { continue; }
+ build_found = true;
+ lua_pushvalue(L, -1);
+ lua_pushstring(L, std::filesystem::current_path().string().c_str());
+ std::cout << "calling lua build function according to key filename '"<< key << "'...\n";
+ if (lua_pcall(L, 1, 0, 0) != 0) {
+ std::cout << print_error << "lua build function failed to run\n";
+ }
+ if (build_found) { break; }
+ }
+ lua_pop(L, 1);
+ }
+ if (!build_found) {
+ std::cout << print_error << "no usable build system was found\n";
+ }
+}