From 62b652c2925b2f71972b201a8134cf22183102b0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 22 Sep 2012 15:42:29 +0800 Subject: Catch some corner cases --- doc/mrbgems/README.md | 54 ++++++++++++++++++++++ doc/mrbgems/c_extension_example/Makefile | 12 +++++ doc/mrbgems/c_extension_example/README.md | 4 ++ doc/mrbgems/c_extension_example/src/example.c | 17 +++++++ doc/mrbgems/c_extension_example/test/example.rb | 3 ++ doc/mrbgems/ruby_extension_example/Makefile | 7 +++ doc/mrbgems/ruby_extension_example/README.md | 4 ++ .../ruby_extension_example/mrblib/example.rb | 5 ++ doc/mrbgems/ruby_extension_example/test/example.rb | 3 ++ 9 files changed, 109 insertions(+) create mode 100644 doc/mrbgems/README.md create mode 100644 doc/mrbgems/c_extension_example/Makefile create mode 100644 doc/mrbgems/c_extension_example/README.md create mode 100644 doc/mrbgems/c_extension_example/src/example.c create mode 100644 doc/mrbgems/c_extension_example/test/example.rb create mode 100644 doc/mrbgems/ruby_extension_example/Makefile create mode 100644 doc/mrbgems/ruby_extension_example/README.md create mode 100644 doc/mrbgems/ruby_extension_example/mrblib/example.rb create mode 100644 doc/mrbgems/ruby_extension_example/test/example.rb (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md new file mode 100644 index 000000000..e23ffdcf2 --- /dev/null +++ b/doc/mrbgems/README.md @@ -0,0 +1,54 @@ +# mrbgems + +mrbgems is a library manager to integrate C and Ruby extension in an easy and +standardized way into mruby. + +## GEM Structure + ++- GEM_NAME <- Name of Gem + | + +- mrblib/ <- Source for Ruby extension + | + +- src/ <- Source for C extension + | + +- test/ <- Test code (Ruby) + | + +- Makefile <- Makefile for Gem + | + +- README.md <- Readme for Gem + +## C Extension + +### Example + ++- c_extension_example/ + | + +- src/ + | | + | +- example.c <- C extension source + | + +- test/ + | | + | +- example.rb <- Test code for C extension + | + +- Makefile <- Build rules for C extension + | + +- README.md + +## Ruby Extension + +### Example + ++- ruby_extension_example/ + | + +- mrblib/ + | | + | +- example.rb <- Ruby extension source + | + +- test/ + | | + | +- example.rb <- Test code for Ruby extension + | + +- Makefile + | + +- README.md diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile new file mode 100644 index 000000000..b245e9696 --- /dev/null +++ b/doc/mrbgems/c_extension_example/Makefile @@ -0,0 +1,12 @@ +include ../../Makefile4gem + +GEM := c_extension_example + +GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) +GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) + +gem-all : $(GEM_OBJECTS) + $(AR) rs $(LIBR) $< + +gem-clean : + -$(RM) $(GEM_OBJECTS) diff --git a/doc/mrbgems/c_extension_example/README.md b/doc/mrbgems/c_extension_example/README.md new file mode 100644 index 000000000..3803c2065 --- /dev/null +++ b/doc/mrbgems/c_extension_example/README.md @@ -0,0 +1,4 @@ +C Extension Example +========= + +This is an example gem which implements a C extension. diff --git a/doc/mrbgems/c_extension_example/src/example.c b/doc/mrbgems/c_extension_example/src/example.c new file mode 100644 index 000000000..9f0b07839 --- /dev/null +++ b/doc/mrbgems/c_extension_example/src/example.c @@ -0,0 +1,17 @@ +#include +#include + +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_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} diff --git a/doc/mrbgems/c_extension_example/test/example.rb b/doc/mrbgems/c_extension_example/test/example.rb new file mode 100644 index 000000000..367d18029 --- /dev/null +++ b/doc/mrbgems/c_extension_example/test/example.rb @@ -0,0 +1,3 @@ +assert('C Extension Example') do + CExtension.respond_to? :c_method +end diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile new file mode 100644 index 000000000..7ebec4f09 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -0,0 +1,7 @@ +include ../../Makefile4gem + +GEM := ruby_extension_example + +gem-all : + +gem-clean : diff --git a/doc/mrbgems/ruby_extension_example/README.md b/doc/mrbgems/ruby_extension_example/README.md new file mode 100644 index 000000000..906a0d8f2 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/README.md @@ -0,0 +1,4 @@ +Pure Ruby Extension Example +========= + +This is an example gem which implements a pure Ruby extension. diff --git a/doc/mrbgems/ruby_extension_example/mrblib/example.rb b/doc/mrbgems/ruby_extension_example/mrblib/example.rb new file mode 100644 index 000000000..b07a2b580 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/mrblib/example.rb @@ -0,0 +1,5 @@ +class RubyExtension + def RubyExtension.ruby_method + puts "A Ruby Extension" + end +end diff --git a/doc/mrbgems/ruby_extension_example/test/example.rb b/doc/mrbgems/ruby_extension_example/test/example.rb new file mode 100644 index 000000000..0c1b63469 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/test/example.rb @@ -0,0 +1,3 @@ +assert('Ruby Extension Example') do + RubyExtension.respond_to? :ruby_method +end -- cgit v1.2.3 From a7cb9737df8de92a75eddadca01d5227acd60632 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 00:47:29 +0800 Subject: Improve Gem Readme file --- doc/mrbgems/README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index e23ffdcf2..919568a0c 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -5,6 +5,8 @@ standardized way into mruby. ## GEM Structure +The maximal Gem structure looks like this: + +- GEM_NAME <- Name of Gem | +- mrblib/ <- Source for Ruby extension @@ -17,8 +19,40 @@ standardized way into mruby. | +- README.md <- Readme for Gem +The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* +contains C files to extend mruby. The folder *test* contains pure Ruby files +for testing purposes which will be used by mrbtest. The *Makefile* contains +rules to build all C files and integrates them into the normal mruby +build process. +README.md+ is a short description for the Gem. + ## C Extension +mruby can be extended with C. It is possible by using the C API to integrate C +libraries into mruby. You need to use the folder *src* for all C files. Pay +attention that your *Makefile* has to build the source and also add the object +files to libmruby.a + +### Pre-Conditions + +mrbgems will automatically call the +gem-all+ make target of your Gem. Make +sure that you build all files in this target and that you add you object +files to libmruby.a + +mrbgems expects that you have implemented a C method called +*mrb_YOURGEMNAME_gem_init(mrb_state* mrb)*. YOURGEMNAME will be replaced +by the name of you Gem. The directory name of your Gem is considered also +as the name! If you call your Gem directory *c_extension_example*, your +initialisation method could look like this: + + void + mrb_c_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); + } + +mrbgems will also use the *gem-clean* make target to clean up your Gem. Implement +this target with the necessary rules! + ### Example +- c_extension_example/ @@ -37,6 +71,16 @@ standardized way into mruby. ## Ruby Extension +mruby can be extended with pure Ruby. It is possible to override existing +classes or add new ones in this way. Put all Ruby files into the *mrblib* +folder. At the moment only one directory layer is supported. So don't +use a deeper structure for now! + +The *Makefile* is not used for building a Ruby extension. But you still +should maintain this file so that during the build process the progress +can be visualized. If you want to do additional things during the build +process of your Ruby extension you can use the *Makefile* too. + ### Example +- ruby_extension_example/ -- cgit v1.2.3 From 96afe4bad92fe7820c8716763dc942ac53939c18 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 00:49:31 +0800 Subject: Improve Gem Readme Source --- doc/mrbgems/README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 919568a0c..f46c392ce 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -7,6 +7,7 @@ standardized way into mruby. The maximal Gem structure looks like this: +``` +- GEM_NAME <- Name of Gem | +- mrblib/ <- Source for Ruby extension @@ -18,6 +19,7 @@ The maximal Gem structure looks like this: +- Makefile <- Makefile for Gem | +- README.md <- Readme for Gem +``` The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files @@ -44,17 +46,20 @@ by the name of you Gem. The directory name of your Gem is considered also as the name! If you call your Gem directory *c_extension_example*, your initialisation method could look like this: - void - mrb_c_extension_example_gem_init(mrb_state* mrb) { - _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_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} +``` mrbgems will also use the *gem-clean* make target to clean up your Gem. Implement this target with the necessary rules! ### Example +``` +- c_extension_example/ | +- src/ @@ -68,6 +73,7 @@ this target with the necessary rules! +- Makefile <- Build rules for C extension | +- README.md +``` ## Ruby Extension @@ -83,6 +89,7 @@ process of your Ruby extension you can use the *Makefile* too. ### Example +``` +- ruby_extension_example/ | +- mrblib/ @@ -96,3 +103,4 @@ process of your Ruby extension you can use the *Makefile* too. +- Makefile | +- README.md +``` -- cgit v1.2.3 From ad37ddd823eb7edf3c7908f93fd40167d0562c1c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:00:11 +0800 Subject: Improve documentation for Gem and add limitations --- doc/mrbgems/README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index f46c392ce..d17547b3d 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -25,7 +25,7 @@ The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files for testing purposes which will be used by mrbtest. The *Makefile* contains rules to build all C files and integrates them into the normal mruby -build process. +README.md+ is a short description for the Gem. +build process. *README.md* is a short description of your Gem. ## C Extension @@ -36,12 +36,12 @@ files to libmruby.a ### Pre-Conditions -mrbgems will automatically call the +gem-all+ make target of your Gem. Make -sure that you build all files in this target and that you add you object +mrbgems will automatically call the *gem-all* make target of your Gem. Make +sure that you build all files in this target and that you add your object files to libmruby.a mrbgems expects that you have implemented a C method called -*mrb_YOURGEMNAME_gem_init(mrb_state* mrb)*. YOURGEMNAME will be replaced +*mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced by the name of you Gem. The directory name of your Gem is considered also as the name! If you call your Gem directory *c_extension_example*, your initialisation method could look like this: @@ -104,3 +104,16 @@ process of your Ruby extension you can use the *Makefile* too. | +- README.md ``` + +## Current Limitations + +The following limitations are currently existing: + +* Gem _MUST NOT_ have a *src* folder in case it doesn't have a + C extension +* Gem _MUST NOT_ have a *mrblib* folder in case it doesn't have a + Ruby extension +* Only Ruby files in the root directory of *mrblib* will be integrated + +If you have ideas how to fix these issues without implementing to much +complexity into the code please provide your code or idea. -- cgit v1.2.3 From d4631f29a2de3da19382dd6331706574cc5ceaa0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:16:50 +0800 Subject: Spell fix in mrbgems Readme --- doc/mrbgems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index d17547b3d..3082c0df0 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -1,7 +1,7 @@ # mrbgems mrbgems is a library manager to integrate C and Ruby extension in an easy and -standardized way into mruby. +standardised way into mruby. ## GEM Structure -- cgit v1.2.3 From 78a053a1ea5927caa62e3d815a8e6eeb27669935 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:18:10 +0800 Subject: Add location of gem to readme --- doc/mrbgems/README.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 3082c0df0..ad4b5d5e6 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -27,6 +27,8 @@ for testing purposes which will be used by mrbtest. The *Makefile* contains rules to build all C files and integrates them into the normal mruby build process. *README.md* is a short description of your Gem. +All Gems have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. + ## C Extension mruby can be extended with C. It is possible by using the C API to integrate C -- cgit v1.2.3 From 81bff9aac28d324ab0f1108a57267d54f006f3c7 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:30:48 +0800 Subject: Add a limitation for object files with C Extension --- doc/mrbgems/README.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index ad4b5d5e6..7eef38222 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -116,6 +116,8 @@ The following limitations are currently existing: * Gem _MUST NOT_ have a *mrblib* folder in case it doesn't have a Ruby extension * Only Ruby files in the root directory of *mrblib* will be integrated +* C files in the directory of *src* are overriding object files with + the same name. If you have ideas how to fix these issues without implementing to much complexity into the code please provide your code or idea. -- cgit v1.2.3 From 83fdc3d78e59e1c87ba8ba75445b65ff2f146ae3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:54:54 +0800 Subject: Add C and Ruby Extension Example Mixed --- doc/mrbgems/c_and_ruby_extension_example/Makefile | 12 ++++++++++++ doc/mrbgems/c_and_ruby_extension_example/README.md | 4 ++++ .../c_and_ruby_extension_example/mrblib/example.rb | 5 +++++ doc/mrbgems/c_and_ruby_extension_example/src/example.c | 17 +++++++++++++++++ .../c_and_ruby_extension_example/test/example.rb | 7 +++++++ 5 files changed, 45 insertions(+) create mode 100644 doc/mrbgems/c_and_ruby_extension_example/Makefile create mode 100644 doc/mrbgems/c_and_ruby_extension_example/README.md create mode 100644 doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb create mode 100644 doc/mrbgems/c_and_ruby_extension_example/src/example.c create mode 100644 doc/mrbgems/c_and_ruby_extension_example/test/example.rb (limited to 'doc') diff --git a/doc/mrbgems/c_and_ruby_extension_example/Makefile b/doc/mrbgems/c_and_ruby_extension_example/Makefile new file mode 100644 index 000000000..1744d73c3 --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/Makefile @@ -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 diff --git a/doc/mrbgems/c_and_ruby_extension_example/README.md b/doc/mrbgems/c_and_ruby_extension_example/README.md new file mode 100644 index 000000000..0b428b0b6 --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/README.md @@ -0,0 +1,4 @@ +C and Ruby Extension Example +========= + +This is an example gem which implements a C and Ruby extension. diff --git a/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb b/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb new file mode 100644 index 000000000..0c2d3c7d1 --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb @@ -0,0 +1,5 @@ +class RubyExtension + def CRubyExtension.ruby_method + puts "A Ruby Extension" + end +end diff --git a/doc/mrbgems/c_and_ruby_extension_example/src/example.c b/doc/mrbgems/c_and_ruby_extension_example/src/example.c new file mode 100644 index 000000000..178514ffe --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/src/example.c @@ -0,0 +1,17 @@ +#include +#include + +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()); +} diff --git a/doc/mrbgems/c_and_ruby_extension_example/test/example.rb b/doc/mrbgems/c_and_ruby_extension_example/test/example.rb new file mode 100644 index 000000000..fffad710f --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/test/example.rb @@ -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 -- cgit v1.2.3 From bc26a482d880a1c89bd685d4745f71009686d544 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:55:15 +0800 Subject: Modify C Extension --- doc/mrbgems/c_extension_example/Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile index b245e9696..615557aca 100644 --- a/doc/mrbgems/c_extension_example/Makefile +++ b/doc/mrbgems/c_extension_example/Makefile @@ -5,8 +5,6 @@ GEM := c_extension_example GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) -gem-all : $(GEM_OBJECTS) - $(AR) rs $(LIBR) $< +gem-all : $(GEM_OBJECTS) gem-c-files -gem-clean : - -$(RM) $(GEM_OBJECTS) +gem-clean : gem-clean-c-files -- cgit v1.2.3 From f591d116b0f2c0952aa63aaf28df1f2574b0e7a3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:55:29 +0800 Subject: Modify Ruby Extension --- doc/mrbgems/ruby_extension_example/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile index 7ebec4f09..33eee97e9 100644 --- a/doc/mrbgems/ruby_extension_example/Makefile +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -2,6 +2,8 @@ include ../../Makefile4gem GEM := ruby_extension_example -gem-all : +GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb) -gem-clean : +gem-all : gem-rb-files + +gem-clean : gem-clean-rb-files -- cgit v1.2.3 From 1c8bc4d9a1b27e4beadb02709185a49053d050ed Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 20:22:26 +0800 Subject: Improve README --- doc/mrbgems/README.md | 114 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 35 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 7eef38222..e799448f4 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -5,10 +5,10 @@ standardised way into mruby. ## GEM Structure -The maximal Gem structure looks like this: +The maximal GEM structure looks like this: ``` -+- GEM_NAME <- Name of Gem ++- GEM_NAME <- Name of GEM | +- mrblib/ <- Source for Ruby extension | @@ -16,36 +16,39 @@ The maximal Gem structure looks like this: | +- test/ <- Test code (Ruby) | - +- Makefile <- Makefile for Gem + +- Makefile <- Makefile for GEM | - +- README.md <- Readme for Gem + +- README.md <- Readme for GEM ``` The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files for testing purposes which will be used by mrbtest. The *Makefile* contains -rules to build all C files and integrates them into the normal mruby -build process. *README.md* is a short description of your Gem. +rules to build a *gem.a* file inside of the GEM directory. Which will be used +for integration into the normal mruby build process. *README.md* is a short +description of your GEM. -All Gems have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. +All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. ## C Extension -mruby can be extended with C. It is possible by using the C API to integrate C -libraries into mruby. You need to use the folder *src* for all C files. Pay -attention that your *Makefile* has to build the source and also add the object -files to libmruby.a +mruby can be extended with C. It is possible by using the C API to +integrate C libraries into mruby. + +The *Makefile* is used for building a C extension. You should +define *GEM* (GEM name), *GEM_C_FILES* (all C files) and +*GEM_OBJECTS* (all Object files). Pay also attention that your +*Makefile* has to build the object files. ### Pre-Conditions -mrbgems will automatically call the *gem-all* make target of your Gem. Make -sure that you build all files in this target and that you add your object -files to libmruby.a +mrbgems will automatically call the *gem-all* make target of your GEM. Make +sure that you build all files in this target. mrbgems expects that you have implemented a C method called *mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced -by the name of you Gem. The directory name of your Gem is considered also -as the name! If you call your Gem directory *c_extension_example*, your +by the name of you GEM. The directory name of your GEM is considered also +as the name! If you call your GEM directory *c_extension_example*, your initialisation method could look like this: ``` @@ -56,7 +59,7 @@ mrb_c_extension_example_gem_init(mrb_state* mrb) { } ``` -mrbgems will also use the *gem-clean* make target to clean up your Gem. Implement +mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement this target with the necessary rules! ### Example @@ -80,14 +83,17 @@ this target with the necessary rules! ## Ruby Extension mruby can be extended with pure Ruby. It is possible to override existing -classes or add new ones in this way. Put all Ruby files into the *mrblib* -folder. At the moment only one directory layer is supported. So don't -use a deeper structure for now! +or add new ones in this way. Put all Ruby files into the *mrblib* folder. + +The *Makefile* is used for building a Ruby extension. You should define +define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). + +### Pre-Conditions + +mrbgems will automatically call the *gem-all* make target of your GEM. -The *Makefile* is not used for building a Ruby extension. But you still -should maintain this file so that during the build process the progress -can be visualized. If you want to do additional things during the build -process of your Ruby extension you can use the *Makefile* too. +mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement +this target with the necessary rules! ### Example @@ -107,17 +113,55 @@ process of your Ruby extension you can use the *Makefile* too. +- README.md ``` -## Current Limitations +## C and Ruby Extension -The following limitations are currently existing: +mruby can be extended with C and Ruby at the same time. It is possible to +override existing classes or add new ones in this way. Put all Ruby files +into the *mrblib* folder and all C files into the *srclib* folder. -* Gem _MUST NOT_ have a *src* folder in case it doesn't have a - C extension -* Gem _MUST NOT_ have a *mrblib* folder in case it doesn't have a - Ruby extension -* Only Ruby files in the root directory of *mrblib* will be integrated -* C files in the directory of *src* are overriding object files with - the same name. +The *Makefile* is used for building a C and Ruby extension. You should +define *GEM* (GEM name), *GEM_C_FILES* (all C files), *GEM_OBJECTS* +(all Object files) and *GEM_RB_FILES* (all Ruby files). + +### Pre-Conditions + +mrbgems will automatically call the *gem-all* make target of your GEM. Make +sure that you build all files in this target. + +mrbgems expects that you have implemented a C method called +*mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced +by the name of you GEM. The directory name of your GEM is considered also +as the name! If you call your GEM directory *c_extension_example*, your +initialisation method could look like this: + +``` +void +mrb_c_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} +``` -If you have ideas how to fix these issues without implementing to much -complexity into the code please provide your code or idea. +mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement +this target with the necessary rules! + +### Example + +``` ++- c_and_ruby_extension_example/ + | + +- mrblib/ + | | + | +- example.rb <- Ruby extension source + | + +- src/ + | | + | +- example.c <- C extension source + | + +- test/ + | | + | +- example.rb <- Test code for C and Ruby extension + | + +- Makefile + | + +- README.md -- cgit v1.2.3 From 151521b325c375f84a0c4c19dbf73bae2dd4df7f Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 20:37:16 +0800 Subject: Fix some build documentation for mrbgems --- doc/mrbgems/README.md | 53 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index e799448f4..480e034a5 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -30,6 +30,19 @@ description of your GEM. All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. +## Build process + +mrbgems will call *make* to build and *make clean* to clean your GEM. You +have to create *gem.a* file during the build process. How you are going +to do this is you decision. + +To make your build process more easier and more standardized we suggest +to include *mrbgems/Makefile4gem* which defines some helper rules. In +case you include this Makefile you have to define specific pre-defined +rules like *gem-all* for the build process and *gem-clean* for the clean +process. There are additional helper rules for specific GEM examples +below. + ## C Extension mruby can be extended with C. It is possible by using the C API to @@ -38,13 +51,12 @@ integrate C libraries into mruby. The *Makefile* is used for building a C extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files) and *GEM_OBJECTS* (all Object files). Pay also attention that your -*Makefile* has to build the object files. +*Makefile* has to build the object files. You can use +*gem-c-files* to build a *gem.a* out of your Object code and use +*gem-clean-c-files* to clean the object files. ### Pre-Conditions -mrbgems will automatically call the *gem-all* make target of your GEM. Make -sure that you build all files in this target. - mrbgems expects that you have implemented a C method called *mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced by the name of you GEM. The directory name of your GEM is considered also @@ -83,10 +95,13 @@ this target with the necessary rules! ## Ruby Extension mruby can be extended with pure Ruby. It is possible to override existing -or add new ones in this way. Put all Ruby files into the *mrblib* folder. +classes or add new ones in this way. Put all Ruby files into the *mrblib* +folder. The *Makefile* is used for building a Ruby extension. You should define -define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). +define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use +*gem-rb-files* to build a *gem.a* out of your Ruby code and use +*gem-clean-rb-files* to clean the generated C files. ### Pre-Conditions @@ -117,33 +132,17 @@ this target with the necessary rules! mruby can be extended with C and Ruby at the same time. It is possible to override existing classes or add new ones in this way. Put all Ruby files -into the *mrblib* folder and all C files into the *srclib* folder. +into the *mrblib* folder and all C files into the *src* folder. The *Makefile* is used for building a C and Ruby extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files), *GEM_OBJECTS* -(all Object files) and *GEM_RB_FILES* (all Ruby files). +(all Object files) and *GEM_RB_FILES* (all Ruby files). You can use +*gem-c-and-rb-files* to build a *gem.a* out of your Object and Ruby code +and use *gem-clean-c-and-rb-files* to clean the generated C files. ### Pre-Conditions -mrbgems will automatically call the *gem-all* make target of your GEM. Make -sure that you build all files in this target. - -mrbgems expects that you have implemented a C method called -*mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced -by the name of you GEM. The directory name of your GEM is considered also -as the name! If you call your GEM directory *c_extension_example*, your -initialisation method could look like this: - -``` -void -mrb_c_extension_example_gem_init(mrb_state* mrb) { - _class_cextension = mrb_define_module(mrb, "CExtension"); - mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); -} -``` - -mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement -this target with the necessary rules! +See C and Ruby example. ### Example -- cgit v1.2.3 From a76647ead7d8af214de46a2eb4185b979964c88b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 20:44:34 +0800 Subject: Clean build documentation for mrbgems a bit more --- doc/mrbgems/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 480e034a5..e1de425f1 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -33,8 +33,8 @@ All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. ## Build process mrbgems will call *make* to build and *make clean* to clean your GEM. You -have to create *gem.a* file during the build process. How you are going -to do this is you decision. +have to build a *gem.a* file during this build process. How you are going +to do this is up to you. To make your build process more easier and more standardized we suggest to include *mrbgems/Makefile4gem* which defines some helper rules. In @@ -99,7 +99,7 @@ classes or add new ones in this way. Put all Ruby files into the *mrblib* folder. The *Makefile* is used for building a Ruby extension. You should define -define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use +*GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use *gem-rb-files* to build a *gem.a* out of your Ruby code and use *gem-clean-rb-files* to clean the generated C files. -- cgit v1.2.3 From 7e7b89a6fab07e92eb42d2a5768f7c714135ba5e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:55:18 +0800 Subject: Adapt c and ruby example to meaningful archive name --- doc/mrbgems/c_and_ruby_extension_example/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/c_and_ruby_extension_example/Makefile b/doc/mrbgems/c_and_ruby_extension_example/Makefile index 1744d73c3..0f562584e 100644 --- a/doc/mrbgems/c_and_ruby_extension_example/Makefile +++ b/doc/mrbgems/c_and_ruby_extension_example/Makefile @@ -1,7 +1,7 @@ -include ../../Makefile4gem - GEM := c_and_ruby_extension_example +include ../../Makefile4gem + GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) -- cgit v1.2.3 From 71bb91d72af3280e1d7f2c22f53d42486666a533 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:55:35 +0800 Subject: Adapt c example to meaningful archive name --- doc/mrbgems/c_extension_example/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile index 615557aca..4f78a0222 100644 --- a/doc/mrbgems/c_extension_example/Makefile +++ b/doc/mrbgems/c_extension_example/Makefile @@ -1,7 +1,7 @@ -include ../../Makefile4gem - GEM := c_extension_example +include ../../Makefile4gem + GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) -- cgit v1.2.3 From 8a5d40785c597dd7ba20b38313df5fbee20a0e86 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:55:52 +0800 Subject: Adapt Ruby example to meaningful archive name --- doc/mrbgems/ruby_extension_example/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile index 33eee97e9..50c99829e 100644 --- a/doc/mrbgems/ruby_extension_example/Makefile +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -1,7 +1,7 @@ -include ../../Makefile4gem - GEM := ruby_extension_example +include ../../Makefile4gem + GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb) gem-all : gem-rb-files -- cgit v1.2.3 From b7911ad18e437395c0ace808005e5b42ce329237 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 19:48:06 +0800 Subject: Improve documentation to latest changes --- doc/mrbgems/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index e1de425f1..da64446d7 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -33,8 +33,8 @@ All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. ## Build process mrbgems will call *make* to build and *make clean* to clean your GEM. You -have to build a *gem.a* file during this build process. How you are going -to do this is up to you. +have to build a *mrb-GEMNAME-gem.a* file during this build process. How you +are going to do this is up to you. To make your build process more easier and more standardized we suggest to include *mrbgems/Makefile4gem* which defines some helper rules. In @@ -52,8 +52,8 @@ The *Makefile* is used for building a C extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files) and *GEM_OBJECTS* (all Object files). Pay also attention that your *Makefile* has to build the object files. You can use -*gem-c-files* to build a *gem.a* out of your Object code and use -*gem-clean-c-files* to clean the object files. +*gem-c-files* to build a *mrb-GEMNAME-gem.a* out of your +Object code and use *gem-clean-c-files* to clean the object files. ### Pre-Conditions @@ -100,7 +100,7 @@ folder. The *Makefile* is used for building a Ruby extension. You should define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use -*gem-rb-files* to build a *gem.a* out of your Ruby code and use +*gem-rb-files* to build a *mrb-GEMNAME-gem.a* out of your Ruby code and use *gem-clean-rb-files* to clean the generated C files. ### Pre-Conditions @@ -137,8 +137,9 @@ into the *mrblib* folder and all C files into the *src* folder. The *Makefile* is used for building a C and Ruby extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files), *GEM_OBJECTS* (all Object files) and *GEM_RB_FILES* (all Ruby files). You can use -*gem-c-and-rb-files* to build a *gem.a* out of your Object and Ruby code -and use *gem-clean-c-and-rb-files* to clean the generated C files. +*gem-c-and-rb-files* to build a *mrb-GEMNAME-gem.a* out of your Object +and Ruby code. Use *gem-clean-c-and-rb-files* to clean the generated +C files. ### Pre-Conditions -- cgit v1.2.3 From 3d81ed3dc17e1112e9e47877946dea78a366a663 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 22:48:31 +0800 Subject: Improve examples with an absolute path to the mruby tree --- doc/mrbgems/c_and_ruby_extension_example/Makefile | 2 +- doc/mrbgems/c_extension_example/Makefile | 2 +- doc/mrbgems/ruby_extension_example/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/c_and_ruby_extension_example/Makefile b/doc/mrbgems/c_and_ruby_extension_example/Makefile index 0f562584e..57912a936 100644 --- a/doc/mrbgems/c_and_ruby_extension_example/Makefile +++ b/doc/mrbgems/c_and_ruby_extension_example/Makefile @@ -1,6 +1,6 @@ GEM := c_and_ruby_extension_example -include ../../Makefile4gem +include $(MAKEFILE_4_GEM) GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile index 4f78a0222..339669970 100644 --- a/doc/mrbgems/c_extension_example/Makefile +++ b/doc/mrbgems/c_extension_example/Makefile @@ -1,6 +1,6 @@ GEM := c_extension_example -include ../../Makefile4gem +include $(MAKEFILE_4_GEM) GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile index 50c99829e..9c5026744 100644 --- a/doc/mrbgems/ruby_extension_example/Makefile +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -1,6 +1,6 @@ GEM := ruby_extension_example -include ../../Makefile4gem +include $(MAKEFILE_4_GEM) GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb) -- cgit v1.2.3 From e9f87368825dc7061035bdc51e45f7d8f9ef66c9 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 24 Nov 2012 14:33:19 +0800 Subject: Add usage documentation for mrbgems --- doc/mrbgems/README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index da64446d7..c11e8a05f 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -3,6 +3,20 @@ mrbgems is a library manager to integrate C and Ruby extension in an easy and standardised way into mruby. +## Usage + +By default mrbgems is currently deactivated. As long as mrbgems is deactivated +there is no overhead inside of the mruby interpreter. + +To activate you have to make the following changes: +* set *ENABLE_GEMS* to *true* in *$(MRUBY_ROOT)/Makefile* +* define *ENABLE_GEMS* in *$(MRUBY_ROOT)/include/mrbconf.h* +* activate GEMs in *$(MRUBY_ROOT)/mrbgems/GEMS.active* + +Every activated GEM has to be listed with his absolute path in *GEMS.active*. It +is possible to point to an alternative activate file: +* set *ACTIVE_GEMS* to your customized GEM list in *$(MRUBY_ROOT)/Makefile* + ## GEM Structure The maximal GEM structure looks like this: @@ -28,8 +42,6 @@ rules to build a *gem.a* file inside of the GEM directory. Which will be used for integration into the normal mruby build process. *README.md* is a short description of your GEM. -All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. - ## Build process mrbgems will call *make* to build and *make clean* to clean your GEM. You -- cgit v1.2.3 From 5f00a837edd0f55ed56d4d532d06ee45d9850f3c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 28 Nov 2012 13:47:32 +0800 Subject: Small cosmetic change in the documentation for mrbgems --- doc/mrbgems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index c11e8a05f..98ff44720 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -37,7 +37,7 @@ The maximal GEM structure looks like this: The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files -for testing purposes which will be used by mrbtest. The *Makefile* contains +for testing purposes which will be used by *mrbtest*. The *Makefile* contains rules to build a *gem.a* file inside of the GEM directory. Which will be used for integration into the normal mruby build process. *README.md* is a short description of your GEM. -- cgit v1.2.3