diff options
| -rw-r--r-- | include/pkg.h | 16 | ||||
| -rw-r--r-- | include/state.h | 6 | ||||
| -rw-r--r-- | src/lua_state.c | 42 | ||||
| -rw-r--r-- | src/main.c | 1 | ||||
| -rw-r--r-- | src/state.c | 2 |
5 files changed, 34 insertions, 33 deletions
diff --git a/include/pkg.h b/include/pkg.h index 47d1918..2410710 100644 --- a/include/pkg.h +++ b/include/pkg.h @@ -4,21 +4,21 @@ #include "str.h" struct package_t; -typedef bool (*package_hook_cb_t)(struct package_t *self); -typedef str (*package_version_cb_t)(struct package_t *self); +typedef bool (*package_hook_cb_t)(struct package_t *pkg); +typedef str (*package_version_cb_t)(struct package_t *pkg); typedef struct package_t { str name, version, url, src; unsigned int dep_count; bool is_local; - package_hook_cb_t setup, build, install, rem, on_update, fetch_sources; + package_hook_cb_t setup, build, install, rm, on_update, fetch_sources; package_version_cb_t fetch_latest_version; } package_t; -bool setup(package_t *self), build(package_t *self), - install(package_t *self), rem(package_t *self), - on_update(package_t *self), - fetch_sources(package_t *self); -str fetch_latest_version(package_t *self); +bool setup(package_t *pkg), build(package_t *pkg), + install(package_t *pkg), rm(package_t *pkg), + on_update(package_t *pkg), + fetch_sources(package_t *pkg); +str fetch_latest_version(package_t *pkg); #endif diff --git a/include/state.h b/include/state.h index 9075270..a1c09d7 100644 --- a/include/state.h +++ b/include/state.h @@ -36,10 +36,6 @@ typedef struct config_t { bool is_root; } user_config_t; -typedef struct { - str prefix, bin, lib, include, src; -} install_dirs_t; - extern cli_flags_t flags; extern user_config_t config; -extern install_dirs_t inst_dirs; +extern inst_dirs_t inst_dirs; diff --git a/src/lua_state.c b/src/lua_state.c index 7e9dd18..aa5247f 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -25,6 +25,13 @@ static void lua_path_push(const char *new_path) { lua_pop(L, 1); } +#define HANDLE_LUA_ERROR \ + do { \ + log_error("lua: %s", lua_tostring(L, -1)); \ + lua_pop(L, 1); \ + return false; \ + } while (0) + bool init_lua_state(void) { if (L_is_loaded) return true; @@ -73,18 +80,16 @@ static void setup_base_dirs(void) { } } - config.init_path = str_concat_cstr(&config.dir, "/init.lua"); - config.autogenerated_path = - str_concat_cstr(&config.dir, "/autogenerated.lua"); + config.init_path = str_format( + "%.*s/init.lua", + str_fmt(&config.dir) + ); + config.autogenerated_path = str_format( + "%.*s/autogenerated.lua", + str_fmt(&config.dir) + ); } -#define HANDLE_LUA_ERROR \ - do { \ - log_error("lua: %s", lua_tostring(L, -1)); \ - lua_pop(L, 1); \ - return false; \ - } while (0) - #define lua_get_field_type(name, type, file) \ do { \ lua_getfield(L, -1, name); \ @@ -97,19 +102,16 @@ static void setup_base_dirs(void) { } while (0) static bool load_init_lua(void) { - if (luaL_loadfile(L, config.init_path.data)) - HANDLE_LUA_ERROR; - lua_setglobal(L, "__PkgitUserConfig"); - lua_getglobal(L, "__PkgitUserConfig"); + lua_get_field_type("dirs", table, &config.init_path); #define X(field) \ do { \ lua_get_field_type(#field, string, &config.init_path); \ config.inst_dirs.field = str_adopt((char *)lua_tostring(L, -1)); \ - lua_pop(L, -1); \ + lua_pop(L, 1); \ } while (0) X(prefix); @@ -120,17 +122,15 @@ static bool load_init_lua(void) { #undef X - lua_getfield(L, -1, "prefix"); - return true; } bool init_lua_config(void) { + setup_base_dirs(); + if (!init_lua_state()) return false; - setup_base_dirs(); - if (!load_init_lua()) return false; @@ -144,3 +144,7 @@ void free_lua_state(void) { } L_is_loaded = false; } + +void free_lua_config(void) { + free_lua_state(); +} @@ -33,6 +33,7 @@ int main(int argc, char **argv) { } if (result != CLI_HELP_CALLED) { + init_lua_config(); init_lua_state(); // if (!init_vars()) // return 1; diff --git a/src/state.c b/src/state.c index ec05250..e109628 100644 --- a/src/state.c +++ b/src/state.c @@ -24,4 +24,4 @@ cli_flags_t flags = {0}; user_config_t config = {0}; -install_dirs_t inst_dirs = {0}; +inst_dirs_t inst_dirs = {0}; |
