summaryrefslogtreecommitdiff
path: root/src/honeysuckle.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/honeysuckle.h')
-rw-r--r--src/honeysuckle.h85
1 files changed, 63 insertions, 22 deletions
diff --git a/src/honeysuckle.h b/src/honeysuckle.h
index 1890c40..9aecddf 100644
--- a/src/honeysuckle.h
+++ b/src/honeysuckle.h
@@ -7,28 +7,66 @@
#include <lualib.h>
#include <lauxlib.h>
-#define HS_END 0
+#include "va_nargs.h"
/* type constants */
-#define HS_BOOL 1
-#define HS_INT 2
-#define HS_NUM 3
-#define HS_STR 4
-#define HS_TBL 5
-#define HS_FUNC 6
-#define HS_CFUNC 7
-#define HS_USER 8
-#define HS_LIGHT 9
-#define HS_NIL 10
-#define HS_ANY 11
-
-const char* hs_type_to_string(int type);
-
-void hs_parse_args(lua_State *L, ...);
-int hs_parse_overloaded(lua_State *L, ...);
+typedef enum
+ { HS_BOOL,
+ HS_INT,
+ HS_NUM,
+ HS_STR,
+ HS_TBL,
+ HS_FUNC,
+ HS_CFUNC,
+ HS_USER,
+ HS_LIGHT,
+ HS_NIL,
+ HS_ANY,
+ } hs_type;
+
+const char* hs_type_to_string(hs_type type);
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * hs_parse_args and hs_parse_overloaded
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+struct hs_arg {
+ hs_type type;
+ union {
+ bool *boolean;
+ lua_Integer *integer;
+ lua_Number *number;
+ char **string;
+ int *stack_index;
+ lua_CFunction *function;
+ void **userdata;
+ } ptr;
+};
+
+#define hs_bool(x) { .type=HS_BOOL, .ptr.boolean = &(x) }
+#define hs_int(x) { .type=HS_INT, .ptr.integer = &(x) }
+#define hs_num(x) { .type=HS_NUM, .ptr.number = &(x) }
+#define hs_str(x) { .type=HS_STR, .ptr.string = &(x) }
+#define hs_tbl(x) { .type=HS_TBL, .ptr.stack_index = &(x) }
+#define hs_func(x) { .type=HS_FUNC, .ptr.stack_index = &(x) }
+#define hs_cfunc(x) { .type=HS_CFUNC, .ptr.function = &(x) }
+#define hs_user(x) { .type=HS_USER, .ptr.userdata = &(x) }
+#define hs_light(x) { .type=HS_LIGHT, .ptr.userdata = &(x) }
+#define hs_nil(x) { .type=HS_NIL, .ptr.stack_index = &(x) }
+#define hs_any(x) { .type=HS_ANY, .ptr.stack_index = &(x) }
+
+void hs_parse_args_(lua_State *L, int n_args, struct hs_arg *arguments);
+
+#define hs_parse_args(L, ...) \
+ hs_parse_args_(L, VA_NARGS(__VA_ARGS__)/2, (struct hs_arg[]) { __VA_ARGS__ })
+
+
+//int hs_parse_overloaded_(lua_State *L, ...);
int hs_create_table(lua_State *L, ...);
-int hs_create_enum(lua_State *L, ...);
void hs_process_table(lua_State *L, int table_index, void *data, ...);
// default processors
@@ -37,12 +75,15 @@ void hs_pt_set_integer(lua_Integer value, void *data);
void hs_pt_set_number(lua_Number value, void *data);
void hs_pt_set_string(const char *value, void *data);
+void hs_vpushstring(lua_State *L, const char *format_string, va_list args);
+void hs_pushstring(lua_State *L, const char *format_string, ...);
+
+
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
void hs_throw_error(lua_State *L, const char *format_string, ...);
int hs_traceback(lua_State *L);
-int hs_call(lua_State *L);
-int hs_call_args(lua_State *L, ...);
-
-void hs_pushstring(lua_State *L, const char *format_string, ...);
+int hs_call(lua_State *L, int nargs, int nret);
#define hs_rstore(L) luaL_ref(L, LUA_REGISTRYINDEX);
#define hs_rload(L, ref) lua_rawgeti(L, LUA_REGISTRYINDEX, ref)