From 2526f9e419923fdd871c7065523dcd2cf80cec72 Mon Sep 17 00:00:00 2001 From: sanine Date: Thu, 26 Aug 2021 11:30:22 -0500 Subject: add first-pass implementation of hs_parse_overloaded --- src/hs_parse_args.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') 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); } -- cgit v1.2.1