summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-03-21 11:22:52 -0500
committersanine-a <sanine.not@pm.me>2023-03-21 11:22:52 -0500
commit78eb15d59190c079b1edb405eeae6696724f1b2e (patch)
tree19341cac36443766950d1483952074068d0609b4
parent184a9517a619c0052aabd8ad6ab00ed0d2607e97 (diff)
move modules.h -> common.h and add version numbers
-rw-r--r--src/common.h (renamed from src/modules.h)8
-rw-r--r--src/main.c18
-rw-r--r--src/options/options.c23
-rw-r--r--src/util/util.h2
4 files changed, 49 insertions, 2 deletions
diff --git a/src/modules.h b/src/common.h
index 69e5900..31ff856 100644
--- a/src/modules.h
+++ b/src/common.h
@@ -3,6 +3,11 @@
#include <lua.h>
+#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) \
@@ -11,9 +16,10 @@
X(image) \
X(import) \
X(logging) \
+ X(nvg) \
X(ode) \
X(util) \
- X(nvg) \
+ X(version) \
#define X(module) \
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 <lualib.h>
#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/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 <stdio.h>
#include <cargs.h>
+#include <common.h>
#include "options.h"
static struct cag_option opts[] = {
@@ -11,6 +12,13 @@ static struct cag_option opts[] = {
.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",
.access_name = "help",
@@ -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 }