summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-08-26 11:30:22 -0500
committersanine <sanine.not@pm.me>2021-08-26 11:30:22 -0500
commit2526f9e419923fdd871c7065523dcd2cf80cec72 (patch)
tree481c88a934838bf47f50e5fa5941c3a36b9bcd47 /src
parent9d4fa04c41ce44ad8bfaa9cce65e2b26d8b642d1 (diff)
add first-pass implementation of hs_parse_overloaded
Diffstat (limited to 'src')
-rw-r--r--src/hs_parse_args.c25
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);
}