aboutsummaryrefslogtreecommitdiff
path: root/src/lua_globs.c
diff options
context:
space:
mode:
authordacctal <donotcontactmevia@email.invalid>2026-07-01 07:50:01 +0000
committerdacctal <donotcontactmevia@email.invalid>2026-07-01 07:50:01 +0000
commit166b788d61a443a1576f8b56abdf06fea5a2178e (patch)
treee6f4760d01f83d0865fecdd097fca51e521a1376 /src/lua_globs.c
parentfcfb6ac21651e286092bcc92309e89c8fa2e87fd (diff)
ezntek: checkpoint!
Diffstat (limited to 'src/lua_globs.c')
-rw-r--r--src/lua_globs.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/src/lua_globs.c b/src/lua_globs.c
index f030acb..5a8e51c 100644
--- a/src/lua_globs.c
+++ b/src/lua_globs.c
@@ -18,12 +18,11 @@
*/
-#include <stdio.h>
-
#include "lua_globs.h"
-
-#include "globs.h"
#include "files.h"
+#include "globs.h"
+#include "log.h"
+#include "str.h"
lua_State *L = NULL;
lua_State *B = NULL;
@@ -34,7 +33,8 @@ void push_lua_path(lua_State *L, const char *new_path) {
lua_getglobal(L, "package");
lua_getfield(L, -1, "path");
const char *current_path = lua_tostring(L, -1);
- if (!current_path) current_path = "";
+ if (!current_path)
+ current_path = "";
lua_pop(L, 1);
lua_pushfstring(L, "%s;%s", current_path, new_path);
lua_setfield(L, -2, "path");
@@ -42,47 +42,37 @@ void push_lua_path(lua_State *L, const char *new_path) {
}
void init_lua_state(void) {
- if (L != NULL) return;
+ if (L != NULL)
+ return;
L = luaL_newstate();
luaL_openlibs(L);
- char lua_path[MAX_PATH_LEN + 20];
- snprintf(lua_path, sizeof(lua_path), "%s/?.lua", config_dir.data);
- push_lua_path(L, lua_path);
- if (luaL_loadfile(L, config_file.data) || lua_pcall(L, 0, 0, 0)) {
- printf(
- "%s cannot run configuration script: %s\n",
- PRINT_ERROR, lua_tostring(L, -1)
- );
- printf(
- "%s to generate a configuration file, head into the",
- PRINT_PKGIT
- );
- printf(
- " root directory of the pkgit source and run `make defconfig`\n"
- );
+ str lua_path = str_format("%.*s/?.lua", str_fmt(&cfg.dir));
+ push_lua_path(L, lua_path.data);
+ if (luaL_loadfile(L, cfg.name.data) || lua_pcall(L, 0, 0, 0)) {
+ log_error("cannot run configuration script: %s", lua_tostring(L, -1));
+ log_pkgit("to generate a configuration file, head into the");
+ log_pkgit(
+ "root directory of the pkgit source and run `make defconfig`");
exit(EXIT_FAILURE);
}
- if (file_exists(repos_file.data)) {
- if (luaL_loadfile(L, repos_file.data) || lua_pcall(L, 0, 0, 0)) {
- printf(
- "%s cannot load repository file: %s\n",
- PRINT_ERROR, lua_tostring(L, -1)
- );
+ if (file_exists(cfg.repos.data)) {
+ if (luaL_loadfile(L, cfg.repos.data) || lua_pcall(L, 0, 0, 0)) {
+ log_warn("cannot load repository file: %s", lua_tostring(L, -1));
lua_pop(L, 1);
}
}
+ str_free(&lua_path);
config_loaded = true;
}
void init_bldit(void) {
- if (B != NULL) return;
+ if (B != NULL)
+ return;
B = luaL_newstate();
luaL_openlibs(B);
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
- if (is_verbose) printf(
- "%s cannot run bldit script: %s\n",
- PRINT_WARNING, lua_tostring(B, -1)
- );
+ if (flags.verbose)
+ log_warn("cannot run bldit: %s", lua_tostring(B, -1));
return;
}
bldit_loaded = true;
@@ -96,11 +86,11 @@ void free_lua_state(void) {
config_loaded = false;
}
-lua_State *get_lua_state(void) { return L; }
+lua_State *get_lua_state(void) {
+ return L;
+}
-void lua_isnt_type(char* variable, char* type) {
- if (is_verbose) printf(
- "%s init.lua: '%s' is not a %s.\n",
- PRINT_ERROR, variable, type
- );
+void lua_isnt_type(char *variable, char *type) {
+ if (flags.verbose)
+ log_error("init.lua: '%s' is not a %s.", variable, type);
}