summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md20
-rw-r--r--src/tests/hs_parse_args_tests.c17
2 files changed, 19 insertions, 18 deletions
diff --git a/README.md b/README.md
index 9a63e74..432100b 100644
--- a/README.md
+++ b/README.md
@@ -61,8 +61,8 @@ These constants are used when honeysuckle needs to know a type to
expect.
- `HS_BOOL` - booleans
-- `HS_INT` - integers
-- `HS_NUM` - numbers (double by default)
+- `HS_INT` - lua_Integer (aka long int)
+- `HS_NUM` - lua_Number (aka double)
- `HS_STR` - strings
- `HS_TBL` - tables
- `HS_FUNC` - any function
@@ -100,7 +100,7 @@ only parse up to 255 arguments.
int some_lua_binding(lua_State *L)
{
bool b;
- int i;
+ lua_Integer i;
int tbl_index;
lua_Number n;
char *str;
@@ -135,19 +135,19 @@ function throws an error.
```c
int overloaded_lua_binding(lua_State *L)
{
- int i;
- float f;
+ long int i;
+ double n;
char *str;
int choice = hs_parse_overloaded(L,
hs_overload( hs_int(i) ),
- hs_overload( hs_str(str), hs_num(f) )
+ hs_overload( hs_str(str), hs_num(n) )
);
if (choice == 0) {
// do something with i
- // str and f remain unassigned!!
+ // str and n remain unassigned!!
}
else {
- // choice == 1, do something with str and f
+ // choice == 1, do something with str and n
// i remains unassigned!!
}
return 0;
@@ -163,7 +163,7 @@ struct hs_tbl_entry`s. These can either be constructed by hand, or
via function-like macros identified by lowercase versions of the
typenames shown above (e.g. `hs_str_int` would create a string key
with integer value). Most of the type constants expect their
-associated type (e.g. `HS_INT` expects an `int`, `HS_CFUNC` expects `
+associated type (e.g. `HS_INT` expects a `long int`, `HS_CFUNC` expects `
lua_CFunction`, etc.) but `HS_FUNC`, `HS_USER`, and `HS_TBL` expect
an integer stack index. You cannot use `HS_NIL` or `HS_ANY` with
this function.
@@ -221,7 +221,7 @@ void open_logfile(const char *logfile, void *settings) {
struct settings {
bool debug;
- int verbosity;
+ long int verbosity;
float epsilon;
};
diff --git a/src/tests/hs_parse_args_tests.c b/src/tests/hs_parse_args_tests.c
index a6aa475..300a519 100644
--- a/src/tests/hs_parse_args_tests.c
+++ b/src/tests/hs_parse_args_tests.c
@@ -48,7 +48,8 @@ static int testfunc(lua_State *L) { return 0; }
lua_pop(L, 1);
#define CHECK_FAIL_FUNC(name) \
- lua_pushcfunction(L, name ## _testfunc); lua_getglobal(L, "print"); \
+ lua_pushcfunction(L, name ## _testfunc); \
+ luaL_loadstring(L, "print('hello, world!')"); \
mu_assert("incorrectly succeeded in parsing function!", \
lua_pcall(L, 1, 0, 0) != 0); \
lua_pop(L, 1);
@@ -191,7 +192,7 @@ PARSE_TYPECHECK_TEST(parse_func_typecheck, int, hs_func)
CHECK_FAIL_TABLE(parse_func_typecheck);
lua_pushcfunction(L, parse_func_typecheck_testfunc);
- lua_getglobal(L, "print");
+ luaL_loadstring(L, "print('hello, world!')");
mu_assert("typecheck for function failed!",
lua_pcall(L, 1, 0, 0) == 0);
@@ -199,7 +200,7 @@ PARSE_TYPECHECK_TEST(parse_func_typecheck, int, hs_func)
lua_pushvalue(L, -1);
mu_assert("typecheck for C function failed!",
lua_pcall(L, 1, 0, 0) == 0);
-
+
CHECK_FAIL_USER(parse_func_typecheck);
CHECK_FAIL_LIGHT(parse_func_typecheck);
CHECK_FAIL_NIL(parse_func_typecheck);
@@ -318,7 +319,7 @@ PARSE_TYPECHECK_TEST(parse_any_typecheck, int, hs_any)
lua_pcall(L, 1, 0, 0) == 0);
lua_pushcfunction(L, parse_func_typecheck_testfunc);
- lua_getglobal(L, "test");
+ luaL_loadstring(L, "print('hello, world!')");
mu_assert("typecheck for function failed!",
lua_pcall(L, 1, 0, 0) == 0);
@@ -429,7 +430,7 @@ int should_fail(lua_State *L)
TEST(fail_parse_noncfunc)
{
lua_pushcfunction(L, should_fail);
- lua_getglobal(L, "print");
+ luaL_loadstring(L, "print('hello, world!')");
mu_assert("incorrectly parsed non-C function!",
lua_pcall(L, 1, 0, 0) != 0);
return 0;
@@ -548,7 +549,8 @@ TEST(parse_readme_example)
lua_pushstring(L, "c: c: c:");
void *userdata = lua_newuserdata(L, sizeof(char));
- bool b; int i; int table_index; float f; char *str; void *user;
+ bool b; long int i; int table_index;
+ double f; char *str; void *user;
hs_parse_args
(L, hs_bool(b), hs_int(i), hs_tbl(table_index),
hs_num(f), hs_str(str), hs_user(user));
@@ -571,7 +573,7 @@ TEST(parse_readme_example)
void hs_parse_args_tests()
{
- printf("running hs_parse_args() typechecking tests...\n");
+ printf("running hs_parse_args() tests...\n");
mu_run_test("parse bool typecheck", parse_bool_typecheck);
mu_run_test("parse int typecheck", parse_int_typecheck);
mu_run_test("parse num typecheck", parse_num_typecheck);
@@ -584,7 +586,6 @@ void hs_parse_args_tests()
mu_run_test("parse nil typecheck", parse_nil_typecheck);
mu_run_test("parse any typecheck", parse_any_typecheck);
- printf("running hs_parse_args() parsing tests...\n");
mu_run_test("parse bool", parse_bool);
mu_run_test("parse int", parse_int);
mu_run_test("parse num", parse_num);