Пример #1
0
        public void DefineStaticMethod(string name, RubyDLL.RubyCSFunction receiver, rb_args aspec)
        {
            // 防止被C#端GC
            state.MethodDelegates.Add(receiver);

            RubyDLL.r_define_class_method(state, class_ptr, name, receiver, aspec);
        }
Пример #2
0
        public void DefineMethod(string name, RubyDLL.RubyCSFunction receiver, rb_args aspec)
        {
            // 防止被C#端GC
            state.MethodDelegates.Add(receiver);

            RubyDLL.r_define_module_function(state.rb_state, module_ptr, name, receiver, aspec);
        }
Пример #3
0
        /// <summary>
        /// 在mruby全局中定义方法
        /// </summary>
        /// <param name="name"></param>
        /// <param name="delegate">实例方法/静态方法</param>
        /// <param name="aspec"></param>
        public void DefineMethod(string name, Delegate @delegate, rb_args aspec)
        {
            var function = CallbackFunction.FromDelegate(@delegate, RubyState.ObjectDataTypePtr);
            var method   = new RubyDLL.RubyCSFunction((state, self) => function.Invoke(this, self));

            // 防止被C#端GC
            MethodDelegates.Add(method);

#if MRUBY
            RubyDLL.r_define_module_function(rb_state, rb_kernel_module, name, method, aspec);
#else
            RubyDLL.r_define_module_function(rb_kernel_module, name, method, aspec);
#endif
        }
Пример #4
0
        /// <summary>
        /// 在mruby全局中定义方法
        /// </summary>
        /// <param name="name"></param>
        /// <param name="receiver"></param>
        /// <param name="aspec"></param>
        public void DefineMethod(string name, RubyDLL.RubyCSFunction receiver, rb_args aspec)
        {
            // 防止被C#端GC
            MethodDelegates.Add(receiver);

#if MRUBY
            RubyDLL.r_define_module_function(rb_state, rb_kernel_module, name, receiver, aspec);
#else
            // RubyDLL.RubyCSFunction receiverDelegate = receiver;
            // GCHandle gch = GCHandle.Alloc(receiverDelegate);
            // IntPtr intptr_delegate = Marshal.GetFunctionPointerForDelegate(receiverDelegate);
            RubyDLL.r_define_module_function(rb_kernel_module, name, receiver, aspec.value);
#endif
        }