diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -61,8 +61,8 @@ These constants are used when honeysuckle needs to know a type to expect. - `HS_BOOL` - booleans -- `HS_INT` - lua_Integer (aka long int) -- `HS_NUM` - lua_Number (aka double) +- `HS_INT` - lua_Integer (DO NOT use int, long int, or other types!) +- `HS_NUM` - lua_Number (DO NOT use float, double, or other types!) - `HS_STR` - strings - `HS_TBL` - tables - `HS_FUNC` - any function @@ -75,6 +75,9 @@ expect. `hs_type_to_string()` takes as argument a single type constant and returns a const string representing the type. +For the numeric types (`HS_INT` and `HS_NUM`, using variables other +than `lua_Integer` and `lua_Number` may result in undefined behavior. + ### Argument parsing [(Back to top)](#table-of-contents) @@ -109,7 +112,7 @@ int some_lua_binding(lua_State *L) void* user; hs_parse_args(L, // explicit initializer for struct - { HS_BOOL, ptr.bool = &b }, + { HS_BOOL, .ptr.bool = &b }, // macro initialization (recommended) hs_int(i), hs_tbl(tbl_index), @@ -131,6 +134,11 @@ in the macro `hs_overload()`. This function returns an integer containing the zero-indexed index of the overload option that was actually used. +Please note that because of Lua's type system, overloads that differ +only in an integer/number pair, function/c function pair, or +userdata/light userdata pair in the same position may not work as +expected. + If none of the argument lists match the provided arguments, this function throws an error. @@ -140,8 +148,8 @@ store arguments. ```c int overloaded_lua_binding(lua_State *L) { - long int i; - double n; + lua_Integer i; + lua_Number n; char *str; int choice = hs_parse_overloaded(L, hs_overload( hs_int(i) ), @@ -168,7 +176,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 a `long int`, `HS_CFUNC` expects ` +associated type (e.g. `HS_INT` expects a `lua_Integer`, `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. @@ -181,15 +189,14 @@ int *ptr; // some pointer hs_create_table(L, // manual struct initialization - { HS_STR, key.string="intVal", HS_INT, value.integer=4 }, + { HS_STR, .key.string="intVal", HS_INT, .value.integer=4 }, // macro initialization (recommended) hs_str_num("numVal", 6.0f), hs_int_tbl(12, hs_create_table(L, hs_str_cfunc("subTableCFunc", some_lua_binding), hs_int_bool(15, true), - ), - "lightUserdataVal", HS_LIGHT, (void *)ptr, - HS_END); + ) +); ``` ### Table processing @@ -226,7 +233,7 @@ void open_logfile(const char *logfile, void *settings) { struct settings { bool debug; - long int verbosity; + lua_Integer verbosity; float epsilon; }; |