From 306e6cca8e49638779b111d66852877416971a59 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Sun, 29 Nov 2020 22:38:45 -0600 Subject: add camera functions and fix bug in argument parsing --- src/honey_lua.c | 142 ++++++++++++++++++++++++++------------------------------ 1 file changed, 66 insertions(+), 76 deletions(-) (limited to 'src/honey_lua.c') diff --git a/src/honey_lua.c b/src/honey_lua.c index 2469d37..72624be 100644 --- a/src/honey_lua.c +++ b/src/honey_lua.c @@ -25,8 +25,7 @@ struct argument_list { */ /* string must be able to hold at least 16 characters. */ -static int type_to_string(char* string, - honey_lua_type type); +static const char* type_to_string(honey_lua_type type); static bool check_argument(lua_State* L, honey_lua_type type, @@ -100,34 +99,6 @@ void honey_lua_throw_error(lua_State* L, * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -static void honey_lua_arg_error(lua_State* L, - honey_lua_type type, - int position) -{ - char expected_type[16]; - type_to_string(expected_type, type); - - char* error_message; - honey_result result; - char* got_type = (char*) lua_typename(L, lua_type(L, position)); - result = honey_format_string(&error_message, - "bad argument in position %d: " - "expected %s, but got %s instead.", - position, - expected_type, - got_type); - if (result != HONEY_OK) { - lua_pushstring(L, "error allocating memory for error message :("); - } - else { - lua_pushstring(L, error_message); - free(error_message); - } - lua_error(L); -} - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - static bool check_arg_list(lua_State* L, struct argument_list arg_list) { @@ -141,28 +112,22 @@ static bool check_arg_list(lua_State* L, /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -static int arg_list_to_string(char* string, - int start_index, +static void arg_list_to_string(char** string, struct argument_list arg_list) { struct argument_pair* args = arg_list.args; - string[start_index] = '('; + size_t size = sizeof(char) * (18*arg_list.length + 5); + *string = malloc(size); + + memcpy(*string, "(", 2); - int index = start_index + 1; - for (int i=0; i