#include "reflex/ruby/application.h" #include #include "defs.h" using namespace Rucy; RUCY_DEFINE_WRAPPER_VALUE_FROM_TO(Reflex::Application) #define THIS to(self) #define CHECK RUCY_CHECK_OBJECT(Reflex::Application, self) #define CALL(fun) RUCY_WRAPPER_CALL(Reflex::Application, THIS, fun) static VALUE alloc(VALUE klass) { return value(new Reflex::RubyApplication, klass); } static VALUE start(VALUE self) { CHECK; CALL(start()); return self; } static VALUE quit(VALUE self) { CHECK; CALL(quit()); return self; } static VALUE set_name(VALUE self, VALUE name) { CHECK; THIS->set_name(name.c_str()); return name; } static VALUE get_name(VALUE self) { CHECK; return value(THIS->name()); } static VALUE on_start(VALUE self, VALUE event) { CHECK; RUCY_SYM(call_start_block); self.call(call_start_block); CALL(on_start(to(event))); } static VALUE on_quit(VALUE self, VALUE event) { CHECK; CALL(on_quit(to(event))); } static VALUE on_preference(VALUE self, VALUE event) { CHECK; CALL(on_preference(to(event))); } static VALUE on_about(VALUE self, VALUE event) { CHECK; CALL(on_about(to(event))); } static VALUE instance(VALUE self) { return value(Reflex::app()); } static Class cApplication; void Init_application () { Module mReflex = rb_define_module("Reflex"); cApplication = rb_define_class_under(mReflex, "Application", rb_cObject); rb_define_alloc_func(cApplication, alloc); rb_define_method(cApplication, "start", RUBY_METHOD_FUNC(start), 0); rb_define_method(cApplication, "quit", RUBY_METHOD_FUNC(quit), 0); rb_define_method(cApplication, "name=", RUBY_METHOD_FUNC(set_name), 1); rb_define_method(cApplication, "name", RUBY_METHOD_FUNC(get_name), 0); rb_define_method(cApplication, "on_start", RUBY_METHOD_FUNC(on_start), 1); rb_define_method(cApplication, "on_quit", RUBY_METHOD_FUNC(on_quit), 1); rb_define_method(cApplication, "on_preference", RUBY_METHOD_FUNC(on_preference), 1); rb_define_method(cApplication, "on_about", RUBY_METHOD_FUNC(on_about), 1); rb_define_singleton_method(cApplication, "instance", RUBY_METHOD_FUNC(instance), 0); } namespace Reflex { Class application_class () { return cApplication; } }// Reflex