summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/honeysuckle.h370
-rw-r--r--src/tests/hs_create_table_tests.c13
2 files changed, 226 insertions, 157 deletions
diff --git a/src/honeysuckle.h b/src/honeysuckle.h
index f54a261..69c29a3 100644
--- a/src/honeysuckle.h
+++ b/src/honeysuckle.h
@@ -103,157 +103,229 @@ struct hs_tbl_entry {
} value;
};
-#define hs_bool_bool(key, value) \
- { HS_BOOL, .key.boolean=key, HS_BOOL, .value.boolean=value }
-#define hs_bool_int(key, value) \
- { HS_BOOL, .key.boolean=key, HS_INT, .value.integer=value }
-#define hs_bool_num(key, value) \
- { HS_BOOL, .key.boolean=key, HS_NUM, .value.number=value }
-#define hs_bool_str(key, value) \
- { HS_BOOL, .key.boolean=key, HS_STR, .value.string=value }
-#define hs_bool_tbl(key, value) \
- { HS_BOOL, .key.boolean=key, HS_TBL, .value.stack_index=value }
-#define hs_bool_func(key, value) \
- { HS_BOOL, .key.boolean=key, HS_FUNC, .value.stack_index=value }
-#define hs_bool_cfunc(key, value) \
- { HS_BOOL, .key.boolean=key, HS_CFUNC, .value.function=value }
-#define hs_bool_user(key, value) \
- { HS_BOOL, .key.boolean=key, HS_USER, .value.stack_index=value }
-#define hs_bool_light(key, value) \
- { HS_BOOL, .key.boolean=key, HS_LIGHT, .value.userdata=value }
-
-#define hs_int_bool(key, value) \
- { HS_INT, .key.integer=key, HS_BOOL, .value.boolean=value }
-#define hs_int_int(key, value) \
- { HS_INT, .key.integer=key, HS_INT, .value.integer=value }
-#define hs_int_num(key, value) \
- { HS_INT, .key.integer=key, HS_NUM, .value.number=value }
-#define hs_int_str(key, value) \
- { HS_INT, .key.integer=key, HS_STR, .value.string=value }
-#define hs_int_tbl(key, value) \
- { HS_INT, .key.integer=key, HS_TBL, .value.stack_index=value }
-#define hs_int_func(key, value) \
- { HS_INT, .key.integer=key, HS_FUNC, .value.stack_index=value }
-#define hs_int_cfunc(key, value) \
- { HS_INT, .key.integer=key, HS_CFUNC, .value.function=value }
-#define hs_int_user(key, value) \
- { HS_INT, .key.integer=key, HS_USER, .value.stack_index=value }
-#define hs_int_light(key, value) \
- { HS_INT, .key.integer=key, HS_LIGHT, .value.userdata=value }
+#define hs_bool_bool(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_BOOL, .value.boolean=v }
+#define hs_bool_int(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_INT, .value.integer=v }
+#define hs_bool_num(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_NUM, .value.number=v }
+#define hs_bool_str(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_STR, .value.string=v }
+#define hs_bool_tbl(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_TBL, .value.stack_index=v }
+#define hs_bool_func(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_FUNC, .value.stack_index=v }
+#define hs_bool_cfunc(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_CFUNC, .value.function=v }
+#define hs_bool_user(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_USER, .value.stack_index=v }
+#define hs_bool_light(k, v) \
+ { .key_type=HS_BOOL, .key.boolean=k, \
+ .value_type=HS_LIGHT, .value.userdata=v }
+
+#define hs_int_bool(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ .value_type=HS_BOOL, .value.boolean=v }
+#define hs_int_int(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ .value_type=HS_INT, .value.integer=v }
+#define hs_int_num(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ .value_type=HS_NUM, .value.number=v }
+#define hs_int_str(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ HS_STR, .value.string=v }
+#define hs_int_tbl(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ HS_TBL, .value.stack_index=v }
+#define hs_int_func(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ HS_FUNC, .value.stack_index=v }
+#define hs_int_cfunc(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ HS_CFUNC, .value.function=v }
+#define hs_int_user(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ HS_USER, .value.stack_index=v }
+#define hs_int_light(k, v) \
+ { .key_type=HS_INT, .key.integer=k, \
+ HS_LIGHT, .value.userdata=v }
-#define hs_num_bool(key, value) \
- { HS_NUM, .key.number=key, HS_BOOL, .value.boolean=value }
-#define hs_num_int(key, value) \
- { HS_NUM, .key.number=key, HS_INT, .value.integer=value }
-#define hs_num_num(key, value) \
- { HS_NUM, .key.number=key, HS_NUM, .value.number=value }
-#define hs_num_str(key, value) \
- { HS_NUM, .key.number=key, HS_STR, .value.string=value }
-#define hs_num_tbl(key, value) \
- { HS_NUM, .key.number=key, HS_TBL, .value.stack_index=value }
-#define hs_num_func(key, value) \
- { HS_NUM, .key.number=key, HS_FUNC, .value.stack_index=value }
-#define hs_num_cfunc(key, value) \
- { HS_NUM, .key.number=key, HS_CFUNC, .value.function=value }
-#define hs_num_user(key, value) \
- { HS_NUM, .key.number=key, HS_USER, .value.stack_index=value }
-#define hs_num_light(key, value) \
- { HS_NUM, .key.number=key, HS_LIGHT, .value.userdata=value }
-
-#define hs_tbl_bool(key, value) \
- { HS_TBL, .key.stack_index=key, HS_BOOL, .value.boolean=value }
-#define hs_tbl_int(key, value) \
- { HS_TBL, .key.stack_index=key, HS_INT, .value.integer=value }
-#define hs_tbl_num(key, value) \
- { HS_TBL, .key.stack_index=key, HS_NUM, .value.number=value }
-#define hs_tbl_str(key, value) \
- { HS_TBL, .key.stack_index=key, HS_STR, .value.string=value }
-#define hs_tbl_tbl(key, value) \
- { HS_TBL, .key.stack_index=key, HS_TBL, .value.stack_index=value }
-#define hs_tbl_func(key, value) \
- { HS_TBL, .key.stack_index=key, HS_FUNC, .value.stack_index=value }
-#define hs_tbl_cfunc(key, value) \
- { HS_TBL, .key.stack_index=key, HS_CFUNC, .value.function=value }
-#define hs_tbl_user(key, value) \
- { HS_TBL, .key.stack_index=key, HS_USER, .value.stack_index=value }
-#define hs_tbl_light(key, value) \
- { HS_TBL, .key.stack_index=key, HS_LIGHT, .value.userdata=value }
-
-#define hs_func_bool(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_BOOL, .value.boolean=value }
-#define hs_func_int(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_INT, .value.integer=value }
-#define hs_func_num(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_NUM, .value.number=value }
-#define hs_func_str(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_STR, .value.string=value }
-#define hs_func_tbl(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_TBL, .value.stack_index=value }
-#define hs_func_func(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_FUNC, .value.stack_index=value }
-#define hs_func_cfunc(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_CFUNC, .value.function=value }
-#define hs_func_user(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_USER, .value.stack_index=value }
-#define hs_func_light(key, value) \
- { HS_FUNC, .key.stack_index=key, HS_LIGHT, .value.userdata=value }
-
-#define hs_cfunc_bool(key, value) \
- { HS_CFUNC, .key.function=key, HS_BOOL, .value.boolean=value }
-#define hs_cfunc_int(key, value) \
- { HS_CFUNC, .key.function=key, HS_INT, .value.integer=value }
-#define hs_cfunc_num(key, value) \
- { HS_CFUNC, .key.function=key, HS_NUM, .value.number=value }
-#define hs_cfunc_str(key, value) \
- { HS_CFUNC, .key.function=key, HS_STR, .value.string=value }
-#define hs_cfunc_tbl(key, value) \
- { HS_CFUNC, .key.function=key, HS_TBL, .value.stack_index=value }
-#define hs_cfunc_func(key, value) \
- { HS_CFUNC, .key.function=key, HS_FUNC, .value.stack_index=value }
-#define hs_cfunc_cfunc(key, value) \
- { HS_CFUNC, .key.function=key, HS_CFUNC, .value.function=value }
-#define hs_cfunc_user(key, value) \
- { HS_CFUNC, .key.function=key, HS_USER, .value.stack_index=value }
-#define hs_cfunc_light(key, value) \
- { HS_CFUNC, .key.function=key, HS_LIGHT, .value.userdata=value }
+#define hs_num_bool(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_BOOL, .value.boolean=v }
+#define hs_num_int(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_INT, .value.integer=v }
+#define hs_num_num(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_NUM, .value.number=v }
+#define hs_num_str(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_STR, .value.string=v }
+#define hs_num_tbl(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_TBL, .value.stack_index=v }
+#define hs_num_func(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_FUNC, .value.stack_index=v }
+#define hs_num_cfunc(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_CFUNC, .value.function=v }
+#define hs_num_user(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_USER, .value.stack_index=v }
+#define hs_num_light(k, v) \
+ { .key_type=HS_NUM, .key.number=k, \
+ HS_LIGHT, .value.userdata=v }
+
+#define hs_tbl_bool(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_BOOL, .value.boolean=v }
+#define hs_tbl_int(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_INT, .value.integer=v }
+#define hs_tbl_num(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_NUM, .value.number=v }
+#define hs_tbl_str(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_STR, .value.string=v }
+#define hs_tbl_tbl(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_TBL, .value.stack_index=v }
+#define hs_tbl_func(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_FUNC, .value.stack_index=v }
+#define hs_tbl_cfunc(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_CFUNC, .value.function=v }
+#define hs_tbl_user(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_USER, .value.stack_index=v }
+#define hs_tbl_light(k, v) \
+ { .key_type=HS_TBL, .key.stack_index=k, \
+ HS_LIGHT, .value.userdata=v }
+
+#define hs_func_bool(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_BOOL, .value.boolean=v }
+#define hs_func_int(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_INT, .value.integer=v }
+#define hs_func_num(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_NUM, .value.number=v }
+#define hs_func_str(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_STR, .value.string=v }
+#define hs_func_tbl(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_TBL, .value.stack_index=v }
+#define hs_func_func(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_FUNC, .value.stack_index=v }
+#define hs_func_cfunc(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_CFUNC, .value.function=v }
+#define hs_func_user(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_USER, .value.stack_index=v }
+#define hs_func_light(k, v) \
+ { .key_type=HS_FUNC, .key.stack_index=k, \
+ HS_LIGHT, .value.userdata=v }
+
+#define hs_cfunc_bool(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_BOOL, .value.boolean=v }
+#define hs_cfunc_int(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_INT, .value.integer=v }
+#define hs_cfunc_num(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_NUM, .value.number=v }
+#define hs_cfunc_str(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_STR, .value.string=v }
+#define hs_cfunc_tbl(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_TBL, .value.stack_index=v }
+#define hs_cfunc_func(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_FUNC, .value.stack_index=v }
+#define hs_cfunc_cfunc(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_CFUNC, .value.function=v }
+#define hs_cfunc_user(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_USER, .value.stack_index=v }
+#define hs_cfunc_light(k, v) \
+ { .key_type=HS_CFUNC, .key.function=k, \
+ HS_LIGHT, .value.userdata=v }
-#define hs_user_bool(key, value) \
- { HS_USER, .key.stack_index=key, HS_BOOL, .value.boolean=value }
-#define hs_user_int(key, value) \
- { HS_USER, .key.stack_index=key, HS_INT, .value.integer=value }
-#define hs_user_num(key, value) \
- { HS_USER, .key.stack_index=key, HS_NUM, .value.number=value }
-#define hs_user_str(key, value) \
- { HS_USER, .key.stack_index=key, HS_STR, .value.string=value }
-#define hs_user_tbl(key, value) \
- { HS_USER, .key.stack_index=key, HS_TBL, .value.stack_index=value }
-#define hs_user_func(key, value) \
- { HS_USER, .key.stack_index=key, HS_FUNC, .value.stack_index=value }
-#define hs_user_cfunc(key, value) \
- { HS_USER, .key.stack_index=key, HS_CFUNC, .value.function=value }
-#define hs_user_user(key, value) \
- { HS_USER, .key.stack_index=key, HS_USER, .value.stack_index=value }
-#define hs_user_light(key, value) \
- { HS_USER, .key.stack_index=key, HS_LIGHT, .value.userdata=value }
-
-#define hs_light_bool(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_BOOL, .value.boolean=value }
-#define hs_light_int(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_INT, .value.integer=value }
-#define hs_light_num(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_NUM, .value.number=value }
-#define hs_light_str(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_STR, .value.string=value }
-#define hs_light_tbl(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_TBL, .value.stack_index=value }
-#define hs_light_func(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_FUNC, .value.stack_index=value }
-#define hs_light_cfunc(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_CFUNC, .value.function=value }
-#define hs_light_user(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_USER, .value.stack_index=value }
-#define hs_light_light(key, value) \
- { HS_LIGHT, .key.userdata=key, HS_LIGHT, .value.userdata=value }
+#define hs_user_bool(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_BOOL, .value.boolean=v }
+#define hs_user_int(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_INT, .value.integer=v }
+#define hs_user_num(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_NUM, .value.number=v }
+#define hs_user_str(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_STR, .value.string=v }
+#define hs_user_tbl(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_TBL, .value.stack_index=v }
+#define hs_user_func(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_FUNC, .value.stack_index=v }
+#define hs_user_cfunc(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_CFUNC, .value.function=v }
+#define hs_user_user(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_USER, .value.stack_index=v }
+#define hs_user_light(k, v) \
+ { .key_type=HS_USER, .key.stack_index=k, \
+ HS_LIGHT, .value.userdata=v }
+
+#define hs_light_bool(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_BOOL, .value.boolean=v }
+#define hs_light_int(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_INT, .value.integer=v }
+#define hs_light_num(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_NUM, .value.number=v }
+#define hs_light_str(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_STR, .value.string=v }
+#define hs_light_tbl(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_TBL, .value.stack_index=v }
+#define hs_light_func(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_FUNC, .value.stack_index=v }
+#define hs_light_cfunc(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_CFUNC, .value.function=v }
+#define hs_light_user(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_USER, .value.stack_index=v }
+#define hs_light_light(k, v) \
+ { .key_type=HS_LIGHT, .key.userdata=k, \
+ HS_LIGHT, .value.userdata=v }
int hs_create_table_(lua_State *L, int n_elements, struct hs_tbl_entry *elements);
diff --git a/src/tests/hs_create_table_tests.c b/src/tests/hs_create_table_tests.c
index e2c8ca8..b2b3f3c 100644
--- a/src/tests/hs_create_table_tests.c
+++ b/src/tests/hs_create_table_tests.c
@@ -11,9 +11,11 @@ static int testfunc(lua_State *L) { return 0; }
TEST(table_correct_index)
{
- int index = hs_create_table(L);
- mu_assert("returned incorrect index!", index == lua_gettop(L));
- return 0;
+ int top_old = lua_gettop(L);
+ int index = hs_create_table(L);
+ mu_assert("the stack is unchanged!", lua_gettop(L) != top_old);
+ mu_assert("returned incorrect index!", index == lua_gettop(L));
+ return 0;
}
#define load_key(index, value, pushf) do { \
@@ -56,11 +58,6 @@ TEST(table_correct_index)
lua_pop(L, 1); /* remove key */ \
} while(0)
-static inline compare_ptrs(lua_State *L, int index0, int index1)
-{
- return lua_topointer(L, index0) == lua_topointer(L, index1);
-}
-
#define checkval_bool(expected) \
check_value(lua_isboolean, "boolean", bool, lua_toboolean, value==expected)
#define checkval_int(expected) \