mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Add C and Ruby Extension Example Mixed
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
include ../../Makefile4gem
|
||||
|
||||
GEM := c_and_ruby_extension_example
|
||||
|
||||
GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c)
|
||||
GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES))
|
||||
|
||||
GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb)
|
||||
|
||||
gem-all : $(GEM_OBJECTS) gem-c-and-rb-files
|
||||
|
||||
gem-clean : gem-clean-c-and-rb-files
|
||||
@@ -0,0 +1,4 @@
|
||||
C and Ruby Extension Example
|
||||
=========
|
||||
|
||||
This is an example gem which implements a C and Ruby extension.
|
||||
@@ -0,0 +1,5 @@
|
||||
class RubyExtension
|
||||
def CRubyExtension.ruby_method
|
||||
puts "A Ruby Extension"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <mruby.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static struct RClass *_class_cextension;
|
||||
|
||||
static mrb_value
|
||||
mrb_c_method(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
puts("A C Extension");
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
mrb_c_and_ruby_extension_example_gem_init(mrb_state* mrb) {
|
||||
_class_cextension = mrb_define_module(mrb, "CRubyExtension");
|
||||
mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE());
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
assert('C and Ruby Extension Example 1') do
|
||||
CRubyExtension.respond_to? :c_method
|
||||
end
|
||||
|
||||
assert('C and Ruby Extension Example 2') do
|
||||
CRubyExtension.respond_to? :ruby_method
|
||||
end
|
||||
Reference in New Issue
Block a user