diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hs_parse_args.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/hs_parse_args.c b/src/hs_parse_args.c index 685561e..d6d3b3c 100644 --- a/src/hs_parse_args.c +++ b/src/hs_parse_args.c @@ -112,6 +112,16 @@ void hs_parse_args_(lua_State *L, int n_args, struct hs_arg *arguments) } } + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +static void hs_overloaded_error(lua_State *L, va_list args) +{ + lua_pushstring(L, "hs_overloaded failed"); + lua_error(L); +} + + int hs_parse_overloaded_(lua_State *L, ...) { va_list args, args_error; @@ -119,6 +129,21 @@ int hs_parse_overloaded_(lua_State *L, ...) va_copy(args_error, args); int choice = 0; + + while(true) { + int n_args = va_arg(args, int); + if (n_args == -1) + break; + else { + struct hs_arg *arguments = va_arg(args, struct hs_arg *); + if (try_parse_args(L, n_args, arguments)) + return choice; + } + choice++; + } + + hs_overloaded_error(L, args_error); + va_end(args); va_end(args_error); } |