From 6cd1e5c0d9f4a72ed52bc9843b15cf5c722c5e41 Mon Sep 17 00:00:00 2001 From: Arnold <27396817+arngo@users.noreply.github.com> Date: Thu, 3 Feb 2022 20:57:10 -0500 Subject: implement kwargs for init_window use regular args if keyword not given, or use defaults if neither given --- src/raylib.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/raylib.c b/src/raylib.c index c4bb483..595493f 100644 --- a/src/raylib.c +++ b/src/raylib.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #if defined(PLATFORM_WEB) #include @@ -822,9 +823,28 @@ mrb_init_window(mrb_state* mrb, mrb_value self) { mrb_int screenWidth = 800; mrb_int screenHeight = 600; char* title = "Hello World from FelFlame!"; - mrb_get_args(mrb, "|iiz", &screenWidth, &screenHeight, &title); - InitWindow(screenWidth, screenHeight, title); + uint32_t kw_num = 3; + const mrb_sym kw_names[] = { + mrb_intern_lit(mrb, "width"), + mrb_intern_lit(mrb, "height"), + mrb_intern_lit(mrb, "title"), + }; + mrb_value kw_values[kw_num]; + const mrb_kwargs kwargs = { kw_num, 0, kw_names, kw_values, NULL }; + mrb_get_args(mrb, "|iiz:", &screenWidth, &screenHeight, &title, &kwargs); + + if (mrb_undef_p(kw_values[0])) { + kw_values[0] = mrb_fixnum_value(screenWidth); + } + if (mrb_undef_p(kw_values[1])) { + kw_values[1] = mrb_fixnum_value(screenHeight); + } + if (mrb_undef_p(kw_values[2])) { + kw_values[2] = mrb_str_new_cstr(mrb, title); + } + + InitWindow(mrb_fixnum(kw_values[0]), mrb_fixnum(kw_values[1]), mrb_str_to_cstr(mrb, kw_values[2])); return mrb_nil_value(); } -- cgit v1.2.3