diff options
| -rw-r--r-- | include/raylib/core.h | 15 | ||||
| -rw-r--r-- | src/core.c | 51 | ||||
| -rw-r--r-- | src/raylib.c | 48 |
3 files changed, 69 insertions, 45 deletions
diff --git a/include/raylib/core.h b/include/raylib/core.h new file mode 100644 index 0000000..b327cec --- /dev/null +++ b/include/raylib/core.h @@ -0,0 +1,15 @@ +#ifndef MRUBY_RAYLIB_CORE_H +#define MRUBY_RAYLIB_CORE_H +#include <raylib.h> +#include <mruby.h> +#include <mruby/string.h> +#include <mruby/numeric.h> +#include <stdlib.h> +#if defined(PLATFORM_WEB) +#include <emscripten/emscripten.h> +#endif + +void mrb_raylib_core_init(mrb_state*); + +#endif /* end of include guard MRUBY_RAYLIB_CORE_H */ + diff --git a/src/core.c b/src/core.c new file mode 100644 index 0000000..a301ed0 --- /dev/null +++ b/src/core.c @@ -0,0 +1,51 @@ +#include "raylib/core.h" + +/* + * @overload init_window(screen_width, screen_height, title) + * + * Initialize window and OpenGL context. + * + * *Parameters:* + * + * * *screen_width* (+Integer+) + * + * * *screen_height* (+Integer+) + * + * * *title* (+String+) + */ +static mrb_value +mrb_init_window(mrb_state* mrb, mrb_value self) { + mrb_int screenWidth = 800; + mrb_int screenHeight = 600; + char* title = "Hello World from FelFlame!"; + + 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(); +} + +void +mrb_raylib_core_init(mrb_state* mrb) { + struct RClass *raylib = mrb_define_module(mrb, "Raylib"); + mrb_define_module_function(mrb, raylib, "init_window", mrb_init_window, MRB_ARGS_OPT(3)); +} diff --git a/src/raylib.c b/src/raylib.c index 595493f..6af8179 100644 --- a/src/raylib.c +++ b/src/raylib.c @@ -6,6 +6,7 @@ #include <mruby/numeric.h> #include <mruby/string.h> #include <stdlib.h> +#include "raylib/core.h" #if defined(PLATFORM_WEB) #include <emscripten/emscripten.h> #endif @@ -806,50 +807,6 @@ mrb_set_master_volume(mrb_state* mrb, mrb_value self) { } /* - * @overload init_window(screen_width, screen_height, title) - * - * Initialize window and OpenGL context. - * - * *Parameters:* - * - * * *screen_width* (+Integer+) - * - * * *screen_height* (+Integer+) - * - * * *title* (+String+) - */ -static mrb_value -mrb_init_window(mrb_state* mrb, mrb_value self) { - mrb_int screenWidth = 800; - mrb_int screenHeight = 600; - char* title = "Hello World from FelFlame!"; - - 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(); -} - -/* * Returns a string telling if the platform is web or desktop. * * *Returns:* @@ -1055,8 +1012,9 @@ mrb_Rectangle_draw_rectangle_lines_ex(mrb_state* mrb, mrb_value self) { void mrb_mruby_raylib_gem_init(mrb_state* mrb) { + mrb_raylib_core_init(mrb); + struct RClass *raylib = mrb_define_module(mrb, "Raylib"); - mrb_define_module_function(mrb, raylib, "init_window", mrb_init_window, MRB_ARGS_OPT(3)); mrb_define_module_function(mrb, raylib, "platform", mrb_platform, MRB_ARGS_NONE()); mrb_define_module_function(mrb, raylib, "_draw_text", mrb_draw_text, MRB_ARGS_OPT(5)); mrb_define_module_function(mrb, raylib, "begin_drawing", mrb_begin_drawing, MRB_ARGS_NONE()); |
