From 14e27593d1f9ea1a93b73a528e866c61fc441153 Mon Sep 17 00:00:00 2001 From: ZakatTeamI2P Date: Mon, 4 May 2026 13:11:44 +0400 Subject: [PATCH] Added aval helper --- binding-mri/sunshine-binding.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/binding-mri/sunshine-binding.cpp b/binding-mri/sunshine-binding.cpp index db14af4..30c09ac 100644 --- a/binding-mri/sunshine-binding.cpp +++ b/binding-mri/sunshine-binding.cpp @@ -8,14 +8,42 @@ static VALUE string_clone(VALUE self){ return rb_obj_clone(self); } +static VALUE ruby_eval(VALUE self, VALUE code){ + if (!RB_TYPE_P(code, T_STRING)) { + rb_raise(rb_eTypeError, "wrong argument type (expected String)"); + } + + #ifdef HAVE_RB_EVAL_STRING_PROTECT + int error = 0; + VALUE result = rb_eval_string_protect(RSTRING_PTR(code), &error); + + if (error) { + rb_clear_exception(); + return Qnil; + } + return result; + #else + // Fallback + return rb_eval_string(RSTRING_PTR(code)); + #endif +} + void SunshineBindingInit(){ printf("[SunshineBindingInit] Initializing Sunshine binding\n"); VALUE module = rb_define_module("Sunshine"); rb_const_set(module, rb_intern("SDLVersion_major"), INT2NUM(SDL_MAJOR_VERSION)); rb_const_set(module, rb_intern("SDLVersion_minor"), INT2NUM(SDL_MINOR_VERSION)); rb_const_set(module, rb_intern("SDLVersion_micro"), INT2NUM(SDL_MICRO_VERSION)); - rb_define_method(rb_cObject, "class", rb_obj_class, 0); - rb_define_method(rb_cString, "clone", RUBY_METHOD_FUNC(string_clone), 0); printf("[SunshineBindingInit] SDL version: %i.%i.%i\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION); + + printf("[SunshineBindingInit] Initializing helpers\n"); + rb_define_method(rb_cObject, "class", rb_obj_class, 0); + rb_define_method(rb_cString, "clone", RUBY_METHOD_FUNC(string_clone), 0); + + if (!rb_respond_to(rb_mKernel, rb_intern("eval"))) { + printf("[SunshineBindingInit] Well, the standard eval is not available, let's try a custom one...\n"); + rb_define_method(rb_mKernel, "eval", RUBY_METHOD_FUNC(ruby_eval), 1); + } + printf("[SunshineBindingInit] Done\n"); }