mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Moved mrbgems examples
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
C and Ruby Extension Example
|
||||
=========
|
||||
|
||||
This is an example gem which implements a C and Ruby extension.
|
||||
@@ -0,0 +1,20 @@
|
||||
MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby developers'
|
||||
|
||||
# Add compile flags
|
||||
# spec.cc.flags << ''
|
||||
|
||||
# Add cflags to all
|
||||
# spec.mruby.cc.flags << '-g'
|
||||
|
||||
# Add libraries
|
||||
# spec.linker.libraries << 'external_lib'
|
||||
|
||||
# Default building fules
|
||||
# spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb")
|
||||
# spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
|
||||
# spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb")
|
||||
# spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
|
||||
# spec.test_preload = 'test/assert.rb'
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
module CRubyExtension
|
||||
def CRubyExtension.ruby_method
|
||||
puts "A Ruby Extension"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <mruby.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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) {
|
||||
struct RClass *class_cextension = mrb_define_module(mrb, "CRubyExtension");
|
||||
mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, ARGS_NONE());
|
||||
}
|
||||
|
||||
void
|
||||
mrb_c_and_ruby_extension_example_gem_final(mrb_state* mrb) {
|
||||
// finalizer
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
C Extension Example
|
||||
=========
|
||||
|
||||
This is an example gem which implements a C extension.
|
||||
@@ -0,0 +1,20 @@
|
||||
MRuby::Gem::Specification.new('c_extension_example') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby developers'
|
||||
|
||||
# Add compile flags
|
||||
# spec.cc.flags << '-g'
|
||||
|
||||
# Add cflags to all
|
||||
# spec.mruby.cc.flags << '-g'
|
||||
|
||||
# Add libraries
|
||||
# spec.linker.libraries << 'external_lib'
|
||||
|
||||
# Default building fules
|
||||
# spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb")
|
||||
# spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
|
||||
# spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb")
|
||||
# spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
|
||||
# spec.test_preload = 'test/assert.rb'
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <mruby.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static mrb_value
|
||||
mrb_c_method(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
puts("A C Extension");
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
mrb_c_extension_example_gem_init(mrb_state* mrb) {
|
||||
struct RClass *class_cextension = mrb_define_module(mrb, "CExtension");
|
||||
mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, ARGS_NONE());
|
||||
}
|
||||
|
||||
void
|
||||
mrb_c_extension_example_gem_final(mrb_state* mrb) {
|
||||
// finalizer
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <mruby.h>
|
||||
|
||||
void
|
||||
mrb_c_extension_example_gem_test(mrb_state *mrb)
|
||||
{
|
||||
/* test initializer in C */
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
assert('C Extension Example') do
|
||||
CExtension.respond_to? :c_method
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
Pure Ruby Extension Example
|
||||
=========
|
||||
|
||||
This is an example gem which implements a pure Ruby extension.
|
||||
@@ -0,0 +1,20 @@
|
||||
MRuby::Gem::Specification.new('ruby_extension_example') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby developers'
|
||||
|
||||
# Add compile flags
|
||||
# spec.cc.flags << ''
|
||||
|
||||
# Add cflags to all
|
||||
# spec.mruby.cc.flags << '-g'
|
||||
|
||||
# Add libraries
|
||||
# spec.linker.libraries << 'external_lib'
|
||||
|
||||
# Default building fules
|
||||
# spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb")
|
||||
# spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
|
||||
# spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb")
|
||||
# spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) }
|
||||
# spec.test_preload = 'test/assert.rb'
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RubyExtension
|
||||
def RubyExtension.ruby_method
|
||||
puts "A Ruby Extension"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
assert('Ruby Extension Example') do
|
||||
RubyExtension.respond_to? :ruby_method
|
||||
end
|
||||
Reference in New Issue
Block a user