From 78eb15d59190c079b1edb405eeae6696724f1b2e Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 21 Mar 2023 11:22:52 -0500 Subject: move modules.h -> common.h and add version numbers --- src/common.h | 31 +++++++++++++++++++++++++++++++ src/main.c | 18 +++++++++++++++++- src/modules.h | 25 ------------------------- src/options/options.c | 23 +++++++++++++++++++++++ src/util/util.h | 2 ++ 5 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 src/common.h delete mode 100644 src/modules.h (limited to 'src') diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..31ff856 --- /dev/null +++ b/src/common.h @@ -0,0 +1,31 @@ +#ifndef HONEY_COMMON_H +#define HONEY_COMMON_H + +#include + +#define HONEY_VERSION_MAJOR 0 +#define HONEY_VERSION_MINOR 0 +#define HONEY_VERSION_PATCH 0 +#define HONEY_VERSION_STR "intermissia [pre-alpha]" + +#define HONEY_MODULES \ + X(audio) \ + X(gl) \ + X(glfw) \ + X(glm) \ + X(image) \ + X(import) \ + X(logging) \ + X(nvg) \ + X(ode) \ + X(util) \ + X(version) \ + + +#define X(module) \ + void setup_ ## module (lua_State *L, int honey_index); +HONEY_MODULES +#undef X + + +#endif diff --git a/src/main.c b/src/main.c index db348b8..90e829e 100644 --- a/src/main.c +++ b/src/main.c @@ -3,10 +3,11 @@ #include #include "options/options.h" #include "util/util.h" -#include "modules.h" +#include "common.h" void print_load_error(lua_State *L, const char *script_file, int error_type); +void setup_version(lua_State *L, int honey_tbl); int main(int argc, char **argv) { @@ -69,3 +70,18 @@ void print_load_error(lua_State *L, const char *script_file, int error_type) break; }; } + + +void setup_version(lua_State *L, int honey_tbl) +{ + struct honey_tbl_t tbl[] = { + H_INT("major", HONEY_VERSION_MAJOR), + H_INT("minor", HONEY_VERSION_MINOR), + H_INT("patch", HONEY_VERSION_PATCH), + H_STR("string", HONEY_VERSION_STR), + + H_END + }; + create_table(L, tbl); + lua_setfield(L, honey_tbl, "version"); +} diff --git a/src/modules.h b/src/modules.h deleted file mode 100644 index 69e5900..0000000 --- a/src/modules.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef HONEY_COMMON_H -#define HONEY_COMMON_H - -#include - -#define HONEY_MODULES \ - X(audio) \ - X(gl) \ - X(glfw) \ - X(glm) \ - X(image) \ - X(import) \ - X(logging) \ - X(ode) \ - X(util) \ - X(nvg) \ - - -#define X(module) \ - void setup_ ## module (lua_State *L, int honey_index); -HONEY_MODULES -#undef X - - -#endif diff --git a/src/options/options.c b/src/options/options.c index 4488837..7ac35c7 100644 --- a/src/options/options.c +++ b/src/options/options.c @@ -1,5 +1,6 @@ #include #include +#include #include "options.h" static struct cag_option opts[] = { @@ -10,6 +11,13 @@ static struct cag_option opts[] = { .value_name = "SCRIPT_FILE", .description = "The filename of the main script. (default: main.lua)" }, + { + .identifier = 'e', + .access_letters = NULL, + .access_name = "version", + .value_name = NULL, + .description = "Show the honey version" + }, { .identifier = 'h', .access_letters = "h", @@ -29,6 +37,12 @@ void print_help(char *program_name) enum outcomes_t parse_options(struct honey_options *options, int argc, char **argv) { + /* check if we even need to parse at all */ + if (argc == 1) { + print_help(argv[0]); + return EXIT_SUCCESS; + } + /* default values */ options->script_file = "main.lua"; @@ -47,6 +61,15 @@ enum outcomes_t parse_options(struct honey_options *options, int argc, char **ar case 'h': print_help(argv[0]); return EXIT_SUCCESS; + case 'e': + printf( + "honey v%d.%d.%d -- %s\n", + HONEY_VERSION_MAJOR, + HONEY_VERSION_MINOR, + HONEY_VERSION_PATCH, + HONEY_VERSION_STR + ); + return EXIT_SUCCESS; default: return EXIT_FAILURE; } diff --git a/src/util/util.h b/src/util/util.h index ab68330..293397c 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -10,12 +10,14 @@ struct honey_tbl_t { union { lua_Integer integer; lua_CFunction function; + const char *string; } value; }; #define H_INT(k, v) { .key=k, .type=LUA_TNUMBER, .value.integer=v } #define H_ENUM(v) { .key=#v, .type=LUA_TNUMBER, .value.integer=v } #define H_FUNC(k, v) { .key=k, .type=LUA_TFUNCTION, .value.function=v } +#define H_STR(k, v) { .key=k, .type=LUA_TSTRING, .value.string=v } #define H_END { .key=NULL, .type=LUA_TNIL, .value.integer=0 } -- cgit v1.2.1