diff --git a/binding-sandbox/audio-binding.h b/binding-sandbox/audio-binding.h index a60c6fee..092dd403 100644 --- a/binding-sandbox/audio-binding.h +++ b/binding-sandbox/audio-binding.h @@ -28,9 +28,9 @@ namespace mkxp_sandbox { static VALUE audio_module; - SANDBOX_COROUTINE(audio_binding_init, + struct audio_binding_init : boost::asio::coroutine { static VALUE bgm_play(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t filename; int32_t volume; int32_t pitch; @@ -69,7 +69,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -80,7 +80,7 @@ namespace mkxp_sandbox { } static VALUE bgm_fade(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t time; int32_t track; @@ -96,13 +96,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE bgm_pos(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t track; double pos; VALUE value; @@ -119,13 +119,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE bgm_volume(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t track; int32_t volume; VALUE value; @@ -142,13 +142,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE bgm_set_volume(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t volume; int32_t track; @@ -164,13 +164,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE bgs_play(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t filename; int32_t volume; int32_t pitch; @@ -198,7 +198,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -209,7 +209,7 @@ namespace mkxp_sandbox { } static VALUE bgs_fade(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t time; VALUE operator()(VALUE self, VALUE value) { @@ -220,13 +220,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } static VALUE bgs_pos(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { double pos; VALUE value; @@ -238,13 +238,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self); } static VALUE me_play(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t filename; int32_t volume; int32_t pitch; @@ -267,7 +267,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -278,7 +278,7 @@ namespace mkxp_sandbox { } static VALUE me_fade(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t time; VALUE operator()(VALUE self, VALUE value) { @@ -289,13 +289,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } static VALUE se_play(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t filename; int32_t volume; int32_t pitch; @@ -318,7 +318,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -360,7 +360,7 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_module_function, audio_module, "__reset__", (VALUE (*)(ANYARGS))reset, 0); } } - ) + }; } #endif // MKXPZ_SANDBOX_AUDIO_BINDING_H diff --git a/binding-sandbox/binding-base.h b/binding-sandbox/binding-base.h index a930f181..dc1b6013 100644 --- a/binding-sandbox/binding-base.h +++ b/binding-sandbox/binding-base.h @@ -26,9 +26,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -122,7 +124,15 @@ namespace mkxp_sandbox { return bind.fibers[key]; } - static wasm_ptr_t init_inner(struct binding_base &bind, struct fiber &fiber) { + template static typename boost::enable_if, void>::type construct_frame_at(void *ptr, struct binding_base &bind) { + new(ptr) U(bind); + } + + template static typename boost::disable_if, void>::type construct_frame_at(void *ptr, struct binding_base &bind) { + new(ptr) U; + } + + static wasm_ptr_t init_frame(struct binding_base &bind, struct fiber &fiber) { uint32_t state = w2c_ruby_asyncify_get_state(&bind.instance()); if (fiber.stack_ptr > fiber.stack.size()) { @@ -151,12 +161,12 @@ namespace mkxp_sandbox { ); assert(sp % sizeof(VALUE) == 0); assert(sp % WASMSTACKALIGN == 0); - new(*bind + sp) T(bind); + construct_frame_at(*bind + sp, bind); w2c_ruby_rb_wasm_set_stack_pointer(&bind.instance(), sp); return sp; } - stack_frame_guard(struct binding_base &b) : bind(&b), fiber(&init_fiber(b)), ptr(init_inner(b, *fiber)) {} + stack_frame_guard(struct binding_base &b) : bind(&b), fiber(&init_fiber(b)), ptr(init_frame(b, *fiber)) {} public: stack_frame_guard(const stack_frame_guard &frame) = delete; diff --git a/binding-sandbox/binding-sandbox.h b/binding-sandbox/binding-sandbox.h index 20bd6e69..056888ec 100644 --- a/binding-sandbox/binding-sandbox.h +++ b/binding-sandbox/binding-sandbox.h @@ -47,10 +47,10 @@ extern const char module_rpg3[]; namespace mkxp_sandbox { // Evaluates a script, returning the exception if it encountered an exception or `SANDBOX_UNDEF` otherwise. - SANDBOX_COROUTINE(eval_script, + struct eval_script : boost::asio::coroutine { private: static VALUE func(VALUE arg) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE string; VALUE filename; ID id; @@ -63,18 +63,18 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_funcall, SANDBOX_NIL, id, 3, string, SANDBOX_NIL, filename); } } - ) + }; sb()->bind()()(arg); return SANDBOX_UNDEF; } static VALUE rescue(VALUE arg, VALUE exception) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE operator()(VALUE exception) { return exception; } - ) + }; return sb()->bind()()(exception); } @@ -92,10 +92,10 @@ namespace mkxp_sandbox { return value; } - ) + }; // Runs the game scripts. - SANDBOX_COROUTINE(run_rmxp_scripts, + struct run_rmxp_scripts : boost::asio::coroutine { VALUE value; VALUE scripts; wasm_size_t script_count; @@ -225,11 +225,11 @@ namespace mkxp_sandbox { std::free(decode_buffer); } } - ) + }; - SANDBOX_COROUTINE(sandbox_binding_init, + struct sandbox_binding_init : boost::asio::coroutine { static VALUE load_data(VALUE self, VALUE path) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE value; VALUE file; wasm_ptr_t ptr; @@ -254,15 +254,15 @@ namespace mkxp_sandbox { delete path_str; } } - ) + }; return sb()->bind()()(path); } static VALUE rgss_main(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { static VALUE func(VALUE block) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { ID id; VALUE operator()(VALUE block) { @@ -273,7 +273,7 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(block); } @@ -297,13 +297,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self); } static VALUE rgss_stop(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE operator()(VALUE self) { BOOST_ASIO_CORO_REENTER (this) { while (true) { @@ -313,7 +313,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self); } @@ -360,7 +360,7 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(run_rmxp_scripts); } } - ) + }; } #endif // MKXPZ_BINDING_SANDBOX_H diff --git a/binding-sandbox/binding-util.h b/binding-sandbox/binding-util.h index 0716aa34..dbef947d 100644 --- a/binding-sandbox/binding-util.h +++ b/binding-sandbox/binding-util.h @@ -29,42 +29,46 @@ #define SANDBOX_DEF_ALLOC(rbtype) \ static VALUE alloc(VALUE _klass) { \ - SANDBOX_COROUTINE(alloc, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE _obj; \ VALUE operator()(VALUE _klass) { \ BOOST_ASIO_CORO_REENTER (this) { \ - SANDBOX_AWAIT_AND_SET(_obj, mkxp_sandbox::rb_data_typed_object_wrap, _klass, 0, rbtype); \ + SANDBOX_AWAIT_AND_SET(_obj, rb_data_typed_object_wrap, _klass, 0, rbtype); \ } \ return _obj; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(_klass); \ + }; \ + return sb()->bind()()(_klass); \ } #define SANDBOX_DEF_ALLOC_WITH_INIT(rbtype, initializer) \ static VALUE alloc(VALUE _klass) { \ - SANDBOX_COROUTINE(alloc, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE _obj; \ VALUE operator()(VALUE _klass) { \ BOOST_ASIO_CORO_REENTER (this) { \ - SANDBOX_AWAIT_AND_SET(_obj, mkxp_sandbox::rb_data_typed_object_wrap, _klass, 0, rbtype); \ - mkxp_sandbox::set_private_data(_obj, initializer); /* TODO: free when sandbox is deallocated */ \ + SANDBOX_AWAIT_AND_SET(_obj, rb_data_typed_object_wrap, _klass, 0, rbtype); \ + set_private_data(_obj, initializer); /* TODO: free when sandbox is deallocated */ \ } \ return _obj; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(_klass); \ + }; \ + return sb()->bind()()(_klass); \ } #define SANDBOX_DEF_DFREE(T) \ static void dfree(wasm_ptr_t _buf) { \ - delete *(T **)(**mkxp_sandbox::sb() + _buf); \ - mkxp_sandbox::sb()->sandbox_free(_buf); \ + using namespace ::mkxp_sandbox; \ + delete *(T **)(**sb() + _buf); \ + sb()->sandbox_free(_buf); \ } #define SANDBOX_DEF_LOAD(T) \ static VALUE load(VALUE _self, VALUE _serialized) { \ - SANDBOX_COROUTINE(load, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE _obj; \ wasm_ptr_t _ptr; \ wasm_size_t _len; \ @@ -73,19 +77,21 @@ SANDBOX_AWAIT_AND_SET(_obj, rb_obj_alloc, _self); \ SANDBOX_AWAIT_AND_SET(_ptr, rb_string_value_ptr, &_serialized); \ SANDBOX_AWAIT_AND_SET(_len, get_bytesize, _serialized); \ - set_private_data(_obj, T::deserialize((const char *)(**mkxp_sandbox::sb() + _ptr), _len)); /* TODO: free when sandbox is deallocated */ \ + set_private_data(_obj, T::deserialize((const char *)(**sb() + _ptr), _len)); /* TODO: free when sandbox is deallocated */ \ } \ return _obj; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(_self, _serialized); \ + }; \ + return sb()->bind()()(_self, _serialized); \ } #define SANDBOX_DEF_CLASS_PROP_B(S, prop, name) \ static VALUE get_##name(VALUE self) { \ + using namespace ::mkxp_sandbox; \ return SANDBOX_BOOL_TO_VALUE(S::get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ bool v = SANDBOX_VALUE_TO_BOOL(value); \ S::set##prop(v); \ return value; \ @@ -93,10 +99,12 @@ #define SANDBOX_DEF_CLASS_PROP(V, num2val, val2num, S, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(S::get##prop()); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(S::get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ V v; \ BOOST_ASIO_CORO_REENTER (this) { \ @@ -105,8 +113,8 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_CLASS_PROP_I(S, prop, name) SANDBOX_DEF_CLASS_PROP(int32_t, rb_ll2inum, rb_num2int, S, prop, name) @@ -115,10 +123,12 @@ #define SANDBOX_DEF_CLASS_PROP_OBJ_REF(S, V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ BOOST_ASIO_CORO_REENTER (this) { \ { \ @@ -129,15 +139,17 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_CLASS_PROP_OBJ_VAL(S, V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ V *v = get_private_data(value); \ S::set##prop(*v); \ return value; \ @@ -145,10 +157,12 @@ #define SANDBOX_DEF_PROP_B(S, prop, name) \ static VALUE get_##name(VALUE self) { \ + using namespace ::mkxp_sandbox; \ S *s = get_private_data(self); \ return SANDBOX_BOOL_TO_VALUE(s->get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ S *s = get_private_data(self); \ bool v = SANDBOX_VALUE_TO_BOOL(value); \ s->set##prop(v); \ @@ -157,10 +171,12 @@ #define SANDBOX_DEF_PROP(V, num2val, val2num, S, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(get_private_data(self)->get##prop()); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(get_private_data(self)->get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ V v; \ BOOST_ASIO_CORO_REENTER (this) { \ @@ -170,8 +186,8 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_PROP_I(S, prop, name) SANDBOX_DEF_PROP(int32_t, rb_ll2inum, rb_num2int, S, prop, name) @@ -180,10 +196,12 @@ #define SANDBOX_DEF_PROP_OBJ_REF(S, V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ BOOST_ASIO_CORO_REENTER (this) { \ { \ @@ -195,15 +213,17 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_PROP_OBJ_VAL(S, V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ S *s = get_private_data(self); \ V *v = get_private_data(value); \ s->set##prop(*v); \ @@ -212,10 +232,12 @@ #define SANDBOX_DEF_GFX_PROP_B(S, prop, name) \ static VALUE get_##name(VALUE self) { \ + using namespace ::mkxp_sandbox; \ S *s = get_private_data(self); \ return SANDBOX_BOOL_TO_VALUE(s->get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ S *s = get_private_data(self); \ bool v = SANDBOX_VALUE_TO_BOOL(value); \ GFX_GUARD_EXC(s->set##prop(v);); \ @@ -224,10 +246,12 @@ #define SANDBOX_DEF_GFX_PROP(V, num2val, val2num, S, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(get_private_data(self)->get##prop()); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(get_private_data(self)->get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ V v; \ BOOST_ASIO_CORO_REENTER (this) { \ @@ -237,8 +261,8 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_GFX_PROP_I(S, prop, name) SANDBOX_DEF_GFX_PROP(int32_t, rb_ll2inum, rb_num2int, S, prop, name) @@ -247,10 +271,12 @@ #define SANDBOX_DEF_GFX_PROP_OBJ_REF(S, V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ BOOST_ASIO_CORO_REENTER (this) { \ { \ @@ -262,15 +288,17 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_GFX_PROP_OBJ_VAL(S, V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ S *s = get_private_data(self); \ V *v = get_private_data(value); \ GFX_GUARD_EXC(s->set##prop(*v);); \ @@ -279,9 +307,11 @@ #define SANDBOX_DEF_GRA_PROP_B(prop, name) \ static VALUE get_##name(VALUE self) { \ + using namespace ::mkxp_sandbox; \ return SANDBOX_BOOL_TO_VALUE(shState->graphics().get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ bool v = SANDBOX_VALUE_TO_BOOL(value); \ GFX_LOCK; \ shState->graphics().set##prop(v); \ @@ -291,10 +321,12 @@ #define SANDBOX_DEF_GRA_PROP(V, num2val, val2num, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(shState->graphics().get##prop()); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(shState->graphics().get##prop()); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ V v; \ BOOST_ASIO_CORO_REENTER (this) { \ @@ -305,8 +337,8 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_GRA_PROP_I(prop, name) SANDBOX_DEF_GRA_PROP(int32_t, rb_ll2inum, rb_num2int, prop, name) @@ -315,10 +347,12 @@ #define SANDBOX_DEF_GRA_PROP_OBJ_REF(V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ - SANDBOX_COROUTINE(coro, \ + using namespace ::mkxp_sandbox; \ + struct coro : boost::asio::coroutine { \ VALUE operator()(VALUE self, VALUE value) { \ BOOST_ASIO_CORO_REENTER (this) { \ { \ @@ -331,15 +365,17 @@ } \ return value; \ } \ - ) \ - return mkxp_sandbox::sb()->bind()()(self, value); \ + }; \ + return sb()->bind()()(self, value); \ } #define SANDBOX_DEF_GRA_PROP_OBJ_VAL(V, prop, name) \ static VALUE get_##name(VALUE self) { \ - return mkxp_sandbox::sb()->bind()()(self, #name); \ + using namespace ::mkxp_sandbox; \ + return sb()->bind()()(self, #name); \ } \ static VALUE set_##name(VALUE self, VALUE value) { \ + using namespace ::mkxp_sandbox; \ V *v = get_private_data(value); \ GFX_LOCK; \ shState->graphics().set##prop(*v); \ @@ -366,7 +402,7 @@ namespace mkxp_sandbox { } // Gets the length of a Ruby object. - SANDBOX_COROUTINE(get_length, + struct get_length : boost::asio::coroutine { ID id; VALUE length_value; wasm_size_t result; @@ -380,10 +416,10 @@ namespace mkxp_sandbox { return result; } - ) + }; // Gets the bytesize of a Ruby object. - SANDBOX_COROUTINE(get_bytesize, + struct get_bytesize : boost::asio::coroutine { ID id; VALUE length_value; wasm_size_t result; @@ -397,9 +433,9 @@ namespace mkxp_sandbox { return result; } - ) + }; - SANDBOX_COROUTINE(wrap_property, + struct wrap_property : boost::asio::coroutine { VALUE obj; VALUE operator()(VALUE self, void *ptr, const char *iv, VALUE klass) { @@ -411,10 +447,10 @@ namespace mkxp_sandbox { return obj; } - ) + }; // Prints the backtrace of a Ruby exception to the log. - SANDBOX_COROUTINE(log_backtrace, + struct log_backtrace : boost::asio::coroutine { ID id; VALUE backtrace; VALUE separator; @@ -432,7 +468,7 @@ namespace mkxp_sandbox { mkxp_retro::log_printf(RETRO_LOG_ERROR, "%s\n", **sb() + backtrace_str); } } - ) + }; } #endif // MKXPZ_SANDBOX_BINDING_UTIL_H diff --git a/binding-sandbox/bitmap-binding.h b/binding-sandbox/bitmap-binding.h index c13d6f77..0a74aec0 100644 --- a/binding-sandbox/bitmap-binding.h +++ b/binding-sandbox/bitmap-binding.h @@ -32,7 +32,7 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type bitmap_type; static VALUE bitmap_class; - SANDBOX_COROUTINE(bitmap_init_props, + struct bitmap_init_props : boost::asio::coroutine { VALUE font; VALUE hires; VALUE hires_font; @@ -55,14 +55,14 @@ namespace mkxp_sandbox { bitmap->setInitFont(get_private_data(font)); } } - ) + }; - SANDBOX_COROUTINE(bitmap_binding_init, + struct bitmap_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(bitmap_type) SANDBOX_DEF_DFREE(Bitmap) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; wasm_ptr_t filename; wasm_size_t width; @@ -85,13 +85,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE initialize_copy(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; Bitmap *orig; @@ -113,7 +113,7 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, value); } @@ -142,7 +142,7 @@ namespace mkxp_sandbox { SANDBOX_DEF_GFX_PROP_OBJ_REF(Bitmap, Bitmap, Hires, hires); static VALUE rect(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE obj; VALUE operator()(VALUE self) { @@ -153,13 +153,13 @@ namespace mkxp_sandbox { return obj; } - ) + }; return sb()->bind()()(self); } static VALUE blt(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int x; int y; VALUE srcObj; @@ -189,13 +189,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE stretch_blt(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE destRectObj; VALUE srcObj; VALUE srcRectObj; @@ -224,13 +224,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE fill_rect(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; int x; int y; @@ -254,7 +254,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -265,7 +265,7 @@ namespace mkxp_sandbox { } static VALUE get_pixel(VALUE self, VALUE xval, VALUE yval) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; int x; int y; @@ -295,13 +295,13 @@ namespace mkxp_sandbox { return obj; } - ) + }; return sb()->bind()()(self, xval, yval); } static VALUE set_pixel(VALUE self, VALUE xval, VALUE yval, VALUE colorObj) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; int x; int y; @@ -319,13 +319,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, xval, yval, colorObj); } static VALUE hue_change(VALUE self, VALUE hueval) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; int hue; @@ -340,13 +340,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, hueval); } static VALUE draw_text(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; wasm_ptr_t str; VALUE obj; @@ -395,13 +395,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE text_size(VALUE self, VALUE text) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t str; VALUE obj; @@ -419,13 +419,13 @@ namespace mkxp_sandbox { return obj; } - ) + }; return sb()->bind()()(self, text); } static VALUE get_raw_data(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE value; wasm_ptr_t str; @@ -442,13 +442,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self); } static VALUE set_raw_data(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t str; wasm_size_t size; @@ -462,13 +462,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, value); } static VALUE to_file(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t str; VALUE operator()(VALUE self, VALUE value) { @@ -480,13 +480,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } static VALUE snap_to_bitmap(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; VALUE obj; int32_t pos; @@ -509,13 +509,13 @@ namespace mkxp_sandbox { return obj; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE gradient_fill_rect(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t x; int32_t y; int32_t w; @@ -547,13 +547,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE clear_rect(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t x; int32_t y; int32_t w; @@ -574,7 +574,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -585,7 +585,7 @@ namespace mkxp_sandbox { } static VALUE radial_blur(VALUE self, VALUE angle, VALUE divisions) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t a; int32_t d; @@ -598,7 +598,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, angle, divisions); } @@ -636,7 +636,7 @@ namespace mkxp_sandbox { } static VALUE goto_and_play(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t frame; VALUE operator()(VALUE self, VALUE value) { @@ -648,13 +648,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } static VALUE goto_and_stop(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t frame; VALUE operator()(VALUE self, VALUE value) { @@ -666,7 +666,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } @@ -680,7 +680,7 @@ namespace mkxp_sandbox { } static VALUE add_frame(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE value; int32_t pos; @@ -705,13 +705,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE remove_frame(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t pos; VALUE operator()(int32_t argc, wasm_ptr_t argv, VALUE self) { @@ -730,7 +730,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -755,7 +755,7 @@ namespace mkxp_sandbox { } static VALUE set_font(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE f; VALUE prop; @@ -790,7 +790,7 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, value); } @@ -851,7 +851,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_PROP_BIND(bitmap_class, font); } } - ) + }; } #endif // MKXPZ_SANDBOX_BITMAP_BINDING_H diff --git a/binding-sandbox/etc-binding.h b/binding-sandbox/etc-binding.h index 7b135522..1e504fcc 100644 --- a/binding-sandbox/etc-binding.h +++ b/binding-sandbox/etc-binding.h @@ -36,14 +36,14 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type rect_type; static VALUE rect_class; - SANDBOX_COROUTINE(etc_binding_init, - SANDBOX_COROUTINE(color_binding_init, + struct etc_binding_init : boost::asio::coroutine { + struct color_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC_WITH_INIT(color_type, new Color) SANDBOX_DEF_DFREE(Color) SANDBOX_DEF_LOAD(Color) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Color *color; double red; double green; @@ -71,13 +71,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE initialize_copy(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE operator()(VALUE self, VALUE value) { BOOST_ASIO_CORO_REENTER (this) { if (self != value) { @@ -88,13 +88,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, value); } static VALUE set(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { double red; double green; double blue; @@ -119,7 +119,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -130,7 +130,7 @@ namespace mkxp_sandbox { SANDBOX_DEF_PROP_D(Color, Alpha, alpha); static VALUE equal(VALUE self, VALUE other) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE value; VALUE operator()(VALUE self, VALUE other) { @@ -146,7 +146,7 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, other); } @@ -177,15 +177,15 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_method, color_class, "inspect", (VALUE (*)(ANYARGS))stringify, 0); } } - ) + }; - SANDBOX_COROUTINE(tone_binding_init, + struct tone_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC_WITH_INIT(tone_type, new Tone) SANDBOX_DEF_DFREE(Tone) SANDBOX_DEF_LOAD(Tone) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Tone *tone; double red; double green; @@ -213,13 +213,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE initialize_copy(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE operator()(VALUE self, VALUE value) { BOOST_ASIO_CORO_REENTER (this) { if (self != value) { @@ -230,13 +230,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, value); } static VALUE set(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { double red; double green; double blue; @@ -261,7 +261,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -272,7 +272,7 @@ namespace mkxp_sandbox { SANDBOX_DEF_PROP_D(Tone, Gray, gray); static VALUE equal(VALUE self, VALUE other) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE value; VALUE operator()(VALUE self, VALUE other) { @@ -288,7 +288,7 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, other); } @@ -319,15 +319,15 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_method, tone_class, "inspect", (VALUE (*)(ANYARGS))stringify, 0); } } - ) + }; - SANDBOX_COROUTINE(rect_binding_init, + struct rect_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC_WITH_INIT(rect_type, new Rect) SANDBOX_DEF_DFREE(Rect) SANDBOX_DEF_LOAD(Rect) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Rect *rect; int x; int y; @@ -351,13 +351,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE initialize_copy(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE operator()(VALUE self, VALUE value) { BOOST_ASIO_CORO_REENTER (this) { if (self != value) { @@ -368,13 +368,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, value); } static VALUE set(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int x; int y; int width; @@ -395,7 +395,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -411,7 +411,7 @@ namespace mkxp_sandbox { SANDBOX_DEF_PROP_D(Rect, Height, height); static VALUE equal(VALUE self, VALUE other) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE value; VALUE operator()(VALUE self, VALUE other) { @@ -427,7 +427,7 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, other); } @@ -459,7 +459,7 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_method, rect_class, "inspect", (VALUE (*)(ANYARGS))stringify, 0); } } - ) + }; void operator()() { BOOST_ASIO_CORO_REENTER (this) { @@ -468,7 +468,7 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rect_binding_init); } } - ) + }; } #endif // MKXPZ_SANDBOX_ETC_BINDING_H diff --git a/binding-sandbox/font-binding.h b/binding-sandbox/font-binding.h index 084b936e..d05a7b39 100644 --- a/binding-sandbox/font-binding.h +++ b/binding-sandbox/font-binding.h @@ -33,7 +33,7 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type font_type; static VALUE font_class; - SANDBOX_COROUTINE(font_binding_init, + struct font_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(font_type) SANDBOX_DEF_DFREE(Font) @@ -41,7 +41,7 @@ namespace mkxp_sandbox { VALUE default_name; wasm_size_t default_name_index; - SANDBOX_COROUTINE(collect_strings, + struct collect_strings : boost::asio::coroutine { VALUE value; VALUE entry; wasm_ptr_t str; @@ -72,10 +72,10 @@ namespace mkxp_sandbox { } } } - ) + }; static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Font *font; std::vector *names; VALUE names_obj; @@ -120,13 +120,13 @@ namespace mkxp_sandbox { ~coro() { delete names; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE initialize_copy(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Font *font; VALUE operator()(VALUE self, VALUE value) { @@ -150,7 +150,7 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, value); } @@ -160,7 +160,7 @@ namespace mkxp_sandbox { } static VALUE set_name(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { std::vector *names; VALUE operator()(VALUE self, VALUE value) { @@ -177,7 +177,7 @@ namespace mkxp_sandbox { ~coro() { delete names; } - ) + }; return sb()->bind()()(self, value); } @@ -195,7 +195,7 @@ namespace mkxp_sandbox { } static VALUE set_default_name(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { std::vector *names; VALUE operator()(VALUE self, VALUE value) { @@ -212,7 +212,7 @@ namespace mkxp_sandbox { ~coro() { delete names; } - ) + }; return sb()->bind()()(self, value); } @@ -226,7 +226,7 @@ namespace mkxp_sandbox { SANDBOX_DEF_CLASS_PROP_OBJ_VAL(Font, Color, DefaultOutColor, default_out_color); static VALUE exist(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t str; VALUE is_string; @@ -243,7 +243,7 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, value); } @@ -309,7 +309,7 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_singleton_method, font_class, "exist?", (VALUE (*)(ANYARGS))exist, 1); } } - ) + }; } #endif // MKXPZ_SANDBOX_FONT_BINDING_H diff --git a/binding-sandbox/graphics-binding.h b/binding-sandbox/graphics-binding.h index 060f3bff..20c50bf3 100644 --- a/binding-sandbox/graphics-binding.h +++ b/binding-sandbox/graphics-binding.h @@ -32,9 +32,9 @@ namespace mkxp_sandbox { static VALUE graphics_module; - SANDBOX_COROUTINE(graphics_binding_init, + struct graphics_binding_init : boost::asio::coroutine { static VALUE delta(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE value; VALUE operator()(VALUE self) { @@ -46,13 +46,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self); } static VALUE update(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE operator()(VALUE self) { BOOST_ASIO_CORO_REENTER (this) { if (shState->graphics().update()) { @@ -62,7 +62,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self); } @@ -73,7 +73,7 @@ namespace mkxp_sandbox { } static VALUE transition(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *trans_map; wasm_ptr_t str; int32_t duration; @@ -125,7 +125,7 @@ namespace mkxp_sandbox { delete trans_map; } } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -138,7 +138,7 @@ namespace mkxp_sandbox { } static VALUE screenshot(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t str; VALUE operator()(VALUE self, VALUE value) { @@ -149,7 +149,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } @@ -183,7 +183,7 @@ namespace mkxp_sandbox { } static VALUE wait(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t duration; int32_t i; @@ -199,13 +199,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } static VALUE fadeout(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t duration; int32_t i; int32_t brightness; @@ -223,13 +223,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } static VALUE fadein(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t duration; int32_t i; int32_t brightness; @@ -247,13 +247,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, value); } static VALUE snap_to_bitmap(VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Bitmap *bitmap; VALUE obj; @@ -267,13 +267,13 @@ namespace mkxp_sandbox { return obj; } - ) + }; return sb()->bind()()(self); } static VALUE resize_screen(VALUE self, VALUE width, VALUE height) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t w; int32_t h; @@ -288,13 +288,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, width, height); } static VALUE resize_window(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t w; int32_t h; @@ -314,7 +314,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -327,7 +327,7 @@ namespace mkxp_sandbox { SANDBOX_DEF_GRA_PROP_I(Brightness, brightness); static VALUE play_movie(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { wasm_ptr_t str; int32_t volume; @@ -347,7 +347,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -405,7 +405,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_MODULE_PROP_BIND(graphics_module, threadsafe); } } - ) + }; } #endif // MKXPZ_SANDBOX_GRAPHICS_BINDING_H diff --git a/binding-sandbox/input-binding.h b/binding-sandbox/input-binding.h index 38eaf078..7e8e8f25 100644 --- a/binding-sandbox/input-binding.h +++ b/binding-sandbox/input-binding.h @@ -62,8 +62,8 @@ namespace mkxp_sandbox { {"MOUSEX2", Input::MouseX2}, }; - SANDBOX_COROUTINE(input_binding_init, - SANDBOX_COROUTINE(get_button_arg, + struct input_binding_init : boost::asio::coroutine { + struct get_button_arg : boost::asio::coroutine { VALUE value; int32_t button; @@ -88,7 +88,7 @@ namespace mkxp_sandbox { return button; } - ) + }; static VALUE delta(VALUE self) { return sb()->bind()()(mkxp_retro::input->getDelta()); @@ -100,7 +100,7 @@ namespace mkxp_sandbox { } static VALUE press(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -111,13 +111,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE trigger(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -128,13 +128,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE repeat(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -145,13 +145,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE release(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -162,13 +162,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE count(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; int32_t count; VALUE value; @@ -182,13 +182,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, code); } static VALUE time(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; double time; VALUE value; @@ -202,13 +202,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, code); } static VALUE pressex(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -219,13 +219,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE triggerex(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -236,13 +236,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE repeatex(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -253,13 +253,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE releaseex(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; VALUE operator()(VALUE self, VALUE code) { @@ -270,13 +270,13 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(self, code); } static VALUE repeatcount(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; int32_t count; VALUE value; @@ -290,13 +290,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, code); } static VALUE timeex(VALUE self, VALUE code) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t button; double time; VALUE value; @@ -310,7 +310,7 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, code); } @@ -394,7 +394,7 @@ namespace mkxp_sandbox { } } } - ) + }; } #endif // MKXPZ_SANDBOX_INPUT_BINDING_H diff --git a/binding-sandbox/plane-binding.h b/binding-sandbox/plane-binding.h index 93a1341d..9e09b614 100644 --- a/binding-sandbox/plane-binding.h +++ b/binding-sandbox/plane-binding.h @@ -31,12 +31,12 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type plane_type; static VALUE plane_class; - SANDBOX_COROUTINE(plane_binding_init, + struct plane_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(plane_type) SANDBOX_DEF_DFREE(Plane) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Plane *plane; VALUE viewport_obj; Viewport *viewport; @@ -73,7 +73,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -126,7 +126,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_PROP_BIND(plane_class, blend_type); } } - ) + }; } #endif // MKXPZ_SANDBOX_PLANE_BINDING_H diff --git a/binding-sandbox/sandbox.h b/binding-sandbox/sandbox.h index f82ba655..112f4e4b 100644 --- a/binding-sandbox/sandbox.h +++ b/binding-sandbox/sandbox.h @@ -27,12 +27,11 @@ #include #include "types.h" -#define SANDBOX_COROUTINE(name, definition) struct name : boost::asio::coroutine { inline name(struct mkxp_sandbox::binding_base &bind) {} definition }; - #define SANDBOX_AWAIT(coroutine, ...) \ do { \ { \ - struct mkxp_sandbox::bindings::stack_frame_guard _frame = mkxp_sandbox::sb()->bind(); \ + using namespace ::mkxp_sandbox; \ + struct bindings::stack_frame_guard _frame = sb()->bind(); \ _frame()(__VA_ARGS__); \ if (_frame().is_complete()) break; \ } \ @@ -42,7 +41,8 @@ #define SANDBOX_AWAIT_AND_SET(variable, coroutine, ...) \ do { \ { \ - struct mkxp_sandbox::bindings::stack_frame_guard _frame = mkxp_sandbox::sb()->bind(); \ + using namespace ::mkxp_sandbox; \ + struct bindings::stack_frame_guard _frame = sb()->bind(); \ auto ret = _frame()(__VA_ARGS__); \ if (_frame().is_complete()) { \ variable = ret; \ @@ -54,6 +54,7 @@ #define SANDBOX_YIELD \ do { \ + using namespace ::mkxp_sandbox; \ sb()._begin_yield(); \ BOOST_ASIO_CORO_YIELD; \ sb()._end_yield(); \ diff --git a/binding-sandbox/sprite-binding.h b/binding-sandbox/sprite-binding.h index 63e47359..4b2f797f 100644 --- a/binding-sandbox/sprite-binding.h +++ b/binding-sandbox/sprite-binding.h @@ -31,12 +31,12 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type sprite_type; static VALUE sprite_class; - SANDBOX_COROUTINE(sprite_binding_init, + struct sprite_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(sprite_type) SANDBOX_DEF_DFREE(Sprite) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Sprite *sprite; VALUE viewport_obj; Viewport *viewport; @@ -69,7 +69,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -88,7 +88,7 @@ namespace mkxp_sandbox { } static VALUE flash(VALUE self, VALUE obj, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int duration; VALUE operator()(VALUE self, VALUE obj, VALUE value) { @@ -99,7 +99,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, obj, value); } @@ -173,7 +173,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_PROP_BIND(sprite_class, blend_type); } } - ) + }; } #endif // MKXPZ_SANDBOX_SPRITE_BINDING_H diff --git a/binding-sandbox/table-binding.h b/binding-sandbox/table-binding.h index 3ee9997d..fa3dc835 100644 --- a/binding-sandbox/table-binding.h +++ b/binding-sandbox/table-binding.h @@ -31,13 +31,13 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type table_type; static VALUE table_class; - SANDBOX_COROUTINE(table_binding_init, + struct table_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC_WITH_INIT(table_type, new Table(0, 0, 0)) SANDBOX_DEF_DFREE(Table) SANDBOX_DEF_LOAD(Table) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int32_t x; int32_t y; int32_t z; @@ -69,13 +69,13 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE initialize_copy(VALUE self, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE operator()(VALUE self, VALUE value) { BOOST_ASIO_CORO_REENTER (this) { if (self != value) { @@ -86,13 +86,13 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, value); } static VALUE resize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Table *table; int32_t x; int32_t y; @@ -119,7 +119,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -137,7 +137,7 @@ namespace mkxp_sandbox { } static VALUE get(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Table *table; VALUE value; int32_t x; @@ -167,13 +167,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(argc, argv, self); } static VALUE set(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Table *table; int32_t x; int32_t y; @@ -203,7 +203,7 @@ namespace mkxp_sandbox { return SANDBOX_UNDEF; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -224,7 +224,7 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_method, table_class, "[]=", (VALUE (*)(ANYARGS))set, -1); } } - ) + }; } #endif // MKXPZ_SANDBOX_TABLE_BINDING_H diff --git a/binding-sandbox/tilemap-binding.h b/binding-sandbox/tilemap-binding.h index f0381159..cdc93f53 100644 --- a/binding-sandbox/tilemap-binding.h +++ b/binding-sandbox/tilemap-binding.h @@ -33,12 +33,12 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type tilemap_autotiles_type; static VALUE tilemap_autotiles_class; - SANDBOX_COROUTINE(tilemap_binding_init, - SANDBOX_COROUTINE(tilemap_autotiles_binding_init, + struct tilemap_binding_init : boost::asio::coroutine { + struct tilemap_autotiles_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(tilemap_autotiles_type) static VALUE get(VALUE self, VALUE i) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE ary; wasm_size_t index; VALUE value; @@ -52,13 +52,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, i); } static VALUE set(VALUE self, VALUE i, VALUE obj) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Tilemap::Autotiles *autotiles; Bitmap *bitmap; VALUE ary; @@ -84,7 +84,7 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, i, obj); } @@ -98,13 +98,13 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_method, tilemap_autotiles_class, "[]=", (VALUE (*)(ANYARGS))set, 2); } } - ) + }; SANDBOX_DEF_ALLOC(tilemap_type) SANDBOX_DEF_DFREE(Tilemap) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Tilemap *tilemap; VALUE viewport_obj; Viewport *viewport; @@ -162,7 +162,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -228,7 +228,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_PROP_BIND(tilemap_class, blend_type); } } - ) + }; } #endif // MKXPZ_SANDBOX_TILEMAP_BINDING_H diff --git a/binding-sandbox/tilemapvx-binding.h b/binding-sandbox/tilemapvx-binding.h index 87162c4e..eb9c19cd 100644 --- a/binding-sandbox/tilemapvx-binding.h +++ b/binding-sandbox/tilemapvx-binding.h @@ -32,12 +32,12 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type bitmap_array_type; static VALUE bitmap_array_class; - SANDBOX_COROUTINE(tilemapvx_binding_init, - SANDBOX_COROUTINE(bitmap_array_binding_init, + struct tilemapvx_binding_init : boost::asio::coroutine { + struct bitmap_array_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(bitmap_array_type) static VALUE get(VALUE self, VALUE i) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { VALUE ary; wasm_size_t index; VALUE value; @@ -51,13 +51,13 @@ namespace mkxp_sandbox { return value; } - ) + }; return sb()->bind()()(self, i); } static VALUE set(VALUE self, VALUE i, VALUE obj) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { TilemapVX::BitmapArray *bitmap_array; Bitmap *bitmap; VALUE ary; @@ -83,7 +83,7 @@ namespace mkxp_sandbox { return self; } - ) + }; return sb()->bind()()(self, i, obj); } @@ -97,13 +97,13 @@ namespace mkxp_sandbox { SANDBOX_AWAIT(rb_define_method, bitmap_array_class, "[]=", (VALUE (*)(ANYARGS))set, 2); } } - ) + }; SANDBOX_DEF_ALLOC(tilemapvx_type) SANDBOX_DEF_DFREE(TilemapVX) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { TilemapVX *tilemap; VALUE viewport_obj; Viewport *viewport; @@ -156,7 +156,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -217,7 +217,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_PROP_BIND(tilemapvx_class, oy); } } - ) + }; } #endif // MKXPZ_SANDBOX_TILEMAPVX_BINDING_H diff --git a/binding-sandbox/viewport-binding.h b/binding-sandbox/viewport-binding.h index cf0dc2b5..4bb48037 100644 --- a/binding-sandbox/viewport-binding.h +++ b/binding-sandbox/viewport-binding.h @@ -31,12 +31,12 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type viewport_type; static VALUE viewport_class; - SANDBOX_COROUTINE(viewport_binding_init, + struct viewport_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(viewport_type) SANDBOX_DEF_DFREE(Viewport) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Viewport *viewport; int32_t x; int32_t y; @@ -74,7 +74,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -93,7 +93,7 @@ namespace mkxp_sandbox { } static VALUE flash(VALUE self, VALUE obj, VALUE value) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { int duration; VALUE operator()(VALUE self, VALUE obj, VALUE value) { @@ -104,7 +104,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, obj, value); } @@ -141,7 +141,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_PROP_BIND(viewport_class, z); } } - ) + }; } #endif // MKXPZ_SANDBOX_VIEWPORT_BINDING_H diff --git a/binding-sandbox/window-binding.h b/binding-sandbox/window-binding.h index fd8567de..386cc9df 100644 --- a/binding-sandbox/window-binding.h +++ b/binding-sandbox/window-binding.h @@ -31,12 +31,12 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type window_type; static VALUE window_class; - SANDBOX_COROUTINE(window_binding_init, + struct window_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(window_type) SANDBOX_DEF_DFREE(Window) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { Window *window; VALUE viewport_obj; Viewport *viewport; @@ -67,7 +67,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -138,7 +138,7 @@ namespace mkxp_sandbox { SANDBOX_INIT_PROP_BIND(window_class, contents_opacity); } } - ) + }; } #endif // MKXPZ_SANDBOX_WINDOW_BINDING_H diff --git a/binding-sandbox/windowvx-binding.h b/binding-sandbox/windowvx-binding.h index 80f75678..a0e93f9c 100644 --- a/binding-sandbox/windowvx-binding.h +++ b/binding-sandbox/windowvx-binding.h @@ -34,12 +34,12 @@ namespace mkxp_sandbox { static struct mkxp_sandbox::bindings::rb_data_type windowvx_type; static VALUE windowvx_class; - SANDBOX_COROUTINE(windowvx_binding_init, + struct windowvx_binding_init : boost::asio::coroutine { SANDBOX_DEF_ALLOC(windowvx_type) SANDBOX_DEF_DFREE(WindowVX) static VALUE initialize(int32_t argc, wasm_ptr_t argv, VALUE self) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { WindowVX *window; VALUE viewport_obj; Viewport *viewport; @@ -97,7 +97,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(argc, argv, self); } @@ -140,7 +140,7 @@ namespace mkxp_sandbox { SANDBOX_DEF_GFX_PROP_I(WindowVX, Openness, openness); static VALUE move(VALUE self, VALUE xv, VALUE yv, VALUE wv, VALUE hv) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { WindowVX *window; int32_t x; int32_t y; @@ -160,7 +160,7 @@ namespace mkxp_sandbox { return SANDBOX_NIL; } - ) + }; return sb()->bind()()(self, xv, yv, wv, hv); } @@ -217,7 +217,7 @@ namespace mkxp_sandbox { } } } - ) + }; } #endif // MKXPZ_SANDBOX_WINDOWVX_BINDING_H diff --git a/libretro/sandbox-bindgen.rb b/libretro/sandbox-bindgen.rb index e3cbf76d..90e2ce9c 100644 --- a/libretro/sandbox-bindgen.rb +++ b/libretro/sandbox-bindgen.rb @@ -616,11 +616,10 @@ File.readlines('tags', chomp: true).each do |line| coroutine_declaration = <<~HEREDOC struct #{func_name} : boost::asio::coroutine { - friend struct bindings::stack_frame_guard; #{coroutine_ret} operator()(#{declaration_args.join(', ')}); + #{func_name}(struct binding_base &b); #{coroutine_destructor.empty? ? '' : "~#{func_name}();\n "}private: struct binding_base &bind; - #{func_name}(struct binding_base &b); #{fields.empty? ? '' : fields.map { |field| " #{field};\n" }.join}}; HEREDOC diff --git a/src/core.cpp b/src/core.cpp index 454ba9da..abe7fb2f 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -223,13 +223,13 @@ static void audio_render(size_t samples) { } static VALUE func(VALUE arg) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { void operator()() { BOOST_ASIO_CORO_REENTER (this) { SANDBOX_AWAIT(sandbox_binding_init); } } - ) + }; sb()->bind()()(); @@ -237,27 +237,27 @@ static VALUE func(VALUE arg) { } static VALUE rescue(VALUE arg, VALUE exception) { - SANDBOX_COROUTINE(coro, + struct coro : boost::asio::coroutine { void operator()(VALUE exception) { BOOST_ASIO_CORO_REENTER (this) { SANDBOX_AWAIT(rb_eval_string, "puts 'Entered rescue()'"); SANDBOX_AWAIT(rb_p, exception); } } - ) + }; sb()->bind()()(exception); return arg; } -SANDBOX_COROUTINE(main, +struct main : boost::asio::coroutine { void operator()() { BOOST_ASIO_CORO_REENTER (this) { SANDBOX_AWAIT(rb_rescue2, func, SANDBOX_NIL, rescue, SANDBOX_NIL, sb()->rb_eException(), 0); } } -) +}; static void deinit_sandbox() { shared_state_initialized = false;