summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md7
-rw-r--r--src/hs_parse_args.c25
2 files changed, 31 insertions, 1 deletions
diff --git a/README.md b/README.md
index 432100b..ad32264 100644
--- a/README.md
+++ b/README.md
@@ -94,7 +94,9 @@ with helpful error messages.
integer that will be filled with the stack index of the argument.
Please note that, due to technical limitations, this function can
-only parse up to 255 arguments.
+only parse up to 255 arguments. This function may mutate any
+preexisting contents of the variables passed to contain the
+arguments.
```c
int some_lua_binding(lua_State *L)
@@ -132,6 +134,9 @@ actually used.
If none of the argument lists match the provided arguments, this
function throws an error.
+This function may mutate preexisting data in the variables passed to
+store arguments.
+
```c
int overloaded_lua_binding(lua_State *L)
{
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);
}