From 7284d1d295c0eaaa2e36ce52e9dd65f8221ed8b2 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Sun, 31 May 2015 23:26:33 -0400 Subject: Update mruby.h.md Added documentation of more of the C API functions found inside mruby.h --- doc/api/mruby.h.md | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby.h.md b/doc/api/mruby.h.md index f537b6482..36712e5dc 100644 --- a/doc/api/mruby.h.md +++ b/doc/api/mruby.h.md @@ -67,3 +67,142 @@ char|mruby type|retrieve types|note `?`|optional given|`mrb_bool`|True if preceding argument is given. Used to check optional argument is given. The passing variadic arguments must be a pointer of retrieving type. + +### mrb_define_class +```C +MRB_API struct RClass *mrb_define_class(mrb_state *, const char*, struct RClass*); +``` +Creates a new class. If you're creating a gem it may look something like this: + +```C +void mrb_example_gem_init(mrb_state* mrb) { + struct RClass *example_class; + example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class); +} + +void mrb_example_gem_final(mrb_state* mrb) { + //free(TheAnimals); +} +``` +### mrb_define_method + +```C +MRB_API void mrb_define_method(mrb_state*, struct RClass*, const char*, mrb_func_t, mrb_aspec); +``` + +Creates a global function in ruby. If you're creating a gem it may look something like this: + +```C +mrb_value example_method(mrb_state* mrb, mrb_value self){ + puts("Executing example commad!"); + return self; +} + +void mrb_example_gem_init(mrb_state* mrb) { + mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE()); +} + +void mrb_example_gem_final(mrb_state* mrb) { + //free(TheAnimals); +} +``` + +Or maybe you want to create a class method for a class? It might look something like this: + +```C +mrb_value example_method(mrb_state* mrb, mrb_value self){ + puts("Examples are like pizza..."); + return self; +} + +void mrb_example_gem_init(mrb_state* mrb) { + struct RClass *example_class; + example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class); + mrb_define_method(mrb, example_class, "example_method", example_method, MRB_ARGS_NONE()); +} + +void mrb_example_gem_final(mrb_state* mrb) { + //free(TheAnimals); +} +``` +### mrb_define_module + +```C +MRB_API struct RClass *mrb_define_module(mrb_state *, const char*); +``` + +Creates a module in ruby. If you're creating a gem it may look something like this: + +```C +mrb_value example_method(mrb_state* mrb, mrb_value self){ + puts("Examples are like tacos..."); + return self; +} + +void mrb_example_gem_init(mrb_state* mrb) { + struct RClass *example_module; + example_module = mrb_define_module(mrb, "Example_Module"); +} + +void mrb_example_gem_final(mrb_state* mrb) { + //free(TheAnimals); +} +``` + +### mrb_define_module_function + +```C +MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, mrb_func_t, mrb_aspec); +``` + +Defines a module function. If you're creating a gem it may look something like this: + + +```C +mrb_value example_method(mrb_state* mrb, mrb_value self){ + puts("Examples are like hot wings..."); + return self; +} + +void mrb_example_gem_init(mrb_state* mrb) { + struct RClass *example_module; + example_module = mrb_define_module(mrb, "Example_Module"); + mrb_define_module_function(mrb, example_module, "example_method", example_method, MRB_ARGS_NONE()); +} + +void mrb_example_gem_final(mrb_state* mrb) { + //free(TheAnimals); +} +``` + +### mrb_define_const + +```C +MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value); +``` + +Defines a constant. If you're creating a gem it may look something like this: + +```C +mrb_value example_method(mrb_state* mrb, mrb_value self){ + puts("Examples are like hot wings..."); + return self; +} + +void mrb_example_gem_init(mrb_state* mrb) { + mrb_define_const(mrb, mrb->kernel_module, "EXAPMLE_CONSTANT", mrb_fixnum_value(0x00000001)); +} + +void mrb_example_gem_final(mrb_state* mrb) { + //free(TheAnimals); +} +``` + + + + + + + + + -- cgit v1.2.3 From 4959e4958abca0404c60fe54a4c700bfd1a25eb6 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Sun, 31 May 2015 23:27:12 -0400 Subject: Update mruby.h.md --- doc/api/mruby.h.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/api') diff --git a/doc/api/mruby.h.md b/doc/api/mruby.h.md index 36712e5dc..88fa2c7e5 100644 --- a/doc/api/mruby.h.md +++ b/doc/api/mruby.h.md @@ -94,7 +94,7 @@ Creates a global function in ruby. If you're creating a gem it may look somethin ```C mrb_value example_method(mrb_state* mrb, mrb_value self){ - puts("Executing example commad!"); + puts("Executing example command!"); return self; } -- cgit v1.2.3 From d90ccd7e6d06582ddb3d3c02e8337551a35b67d8 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Sun, 31 May 2015 23:33:36 -0400 Subject: Update mruby.h.md --- doc/api/mruby.h.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'doc/api') diff --git a/doc/api/mruby.h.md b/doc/api/mruby.h.md index 88fa2c7e5..5a71f5cd4 100644 --- a/doc/api/mruby.h.md +++ b/doc/api/mruby.h.md @@ -72,7 +72,7 @@ The passing variadic arguments must be a pointer of retrieving type. ```C MRB_API struct RClass *mrb_define_class(mrb_state *, const char*, struct RClass*); ``` -Creates a new class. If you're creating a gem it may look something like this: +Defines a new class. If you're creating a gem it may look something like this: ```C void mrb_example_gem_init(mrb_state* mrb) { @@ -90,7 +90,7 @@ void mrb_example_gem_final(mrb_state* mrb) { MRB_API void mrb_define_method(mrb_state*, struct RClass*, const char*, mrb_func_t, mrb_aspec); ``` -Creates a global function in ruby. If you're creating a gem it may look something like this: +Defines a global function in ruby. If you're creating a gem it may look something like this: ```C mrb_value example_method(mrb_state* mrb, mrb_value self){ @@ -131,7 +131,7 @@ void mrb_example_gem_final(mrb_state* mrb) { MRB_API struct RClass *mrb_define_module(mrb_state *, const char*); ``` -Creates a module in ruby. If you're creating a gem it may look something like this: +Defines a module. If you're creating a gem it may look something like this: ```C mrb_value example_method(mrb_state* mrb, mrb_value self){ @@ -198,11 +198,12 @@ void mrb_example_gem_final(mrb_state* mrb) { } ``` +### mrb_str_new_cstr +```C +MRB_API mrb_value mrb_str_new_cstr(mrb_state*, const char*); +``` - - - - +Turns a C string into a Ruby string value. -- cgit v1.2.3 From 1400c6e88ba20a07980770aa9217387a2cbd89bd Mon Sep 17 00:00:00 2001 From: Mav7 Date: Sun, 31 May 2015 23:50:56 -0400 Subject: Added a .md file for value.h --- doc/api/value.h.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/api/value.h.md (limited to 'doc/api') diff --git a/doc/api/value.h.md b/doc/api/value.h.md new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From 297b6fe6e6f97bc8e4ca95d47fa6b02f7eab6396 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Mon, 1 Jun 2015 00:42:23 -0400 Subject: Update value.h.md Wrote documentation for functions found in the value.h file. --- doc/api/value.h.md | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) (limited to 'doc/api') diff --git a/doc/api/value.h.md b/doc/api/value.h.md index e69de29bb..dd1c4b238 100644 --- a/doc/api/value.h.md +++ b/doc/api/value.h.md @@ -0,0 +1,233 @@ +### mrb_float_value +```C +static inline mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) +``` + +Returns a float in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_float f = 0.09. Alternatively +double i = 0.09 could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" +#include "mruby/string.h" + +int +main(void) +{ + mrb_float f = 0.09;// or double i = 0.09; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + +### mrb_fixnum_value + +```C +static inline mrb_value mrb_fixnum_value(mrb_int i) +``` + +Returns a fixnum in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_int i = 99. Alternativly int i = 99 +could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_int i = 99; // or int i = 99; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_nil_value + +```C +static inline mrb_value mrb_nil_value(void) +``` + +Returns nil in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get NillClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + +### mrb_false_value + +```C +static inline mrb_value mrb_false_value(void) +``` + +Returns false in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get FalseClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_true_value + +```C +static inline mrb_value mrb_true_value(void) +``` + +Returns true in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get TrueClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` -- cgit v1.2.3 From 1d90018cfa93e63366f4f1fe600bb356dabf8c3b Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Mon, 1 Jun 2015 00:44:34 -0400 Subject: Update mruby.h.md --- doc/api/mruby.h.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby.h.md b/doc/api/mruby.h.md index 5a71f5cd4..8862fee2c 100644 --- a/doc/api/mruby.h.md +++ b/doc/api/mruby.h.md @@ -207,3 +207,9 @@ MRB_API mrb_value mrb_str_new_cstr(mrb_state*, const char*); Turns a C string into a Ruby string value. +### mrb_value mrb_funcall + +```C +MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...); +``` +Call existing ruby functions. -- cgit v1.2.3 From f8b1de0ab47f3f0bae861bf11f73635aa8c02ba6 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Mon, 1 Jun 2015 00:54:30 -0400 Subject: Update README.md --- doc/api/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/api') diff --git a/doc/api/README.md b/doc/api/README.md index 131e50515..78dbc087d 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -25,6 +25,6 @@ Header name|Features [mruby/range.h](./mruby.range.h.md)|`Range` class. [mruby/re.h](./mruby.re.h.md)|`Regexp` class. [mruby/string.h](./mruby.string.h.md)|`String` class. -[mruby/value.h](./mruby.value.h.md)|`mrb_value` functions and macros. +[mruby/value.h](./value.h.md)|`mrb_value` functions and macros. [mruby/variable.h](./mruby.variable.h.md)|Functions to access to mruby variables. [mruby/version.h](./mruby.version.h.md)|Macros of mruby version. -- cgit v1.2.3 From cd38bcf074cbac24be458b4f14b111335f5a87db Mon Sep 17 00:00:00 2001 From: Mav7 Date: Thu, 4 Jun 2015 23:34:03 -0400 Subject: Adding an array readme markdown. --- doc/api/array.h.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/api/array.h.md (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From b735c0d9dfece2b1cc53947a4057c535bbcb773f Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Thu, 4 Jun 2015 23:37:41 -0400 Subject: Update README.md --- doc/api/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/api') diff --git a/doc/api/README.md b/doc/api/README.md index 78dbc087d..131e50515 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -25,6 +25,6 @@ Header name|Features [mruby/range.h](./mruby.range.h.md)|`Range` class. [mruby/re.h](./mruby.re.h.md)|`Regexp` class. [mruby/string.h](./mruby.string.h.md)|`String` class. -[mruby/value.h](./value.h.md)|`mrb_value` functions and macros. +[mruby/value.h](./mruby.value.h.md)|`mrb_value` functions and macros. [mruby/variable.h](./mruby.variable.h.md)|Functions to access to mruby variables. [mruby/version.h](./mruby.version.h.md)|Macros of mruby version. -- cgit v1.2.3 From 5d63350a3b7074694f0a7a361900814b513e01cf Mon Sep 17 00:00:00 2001 From: Mav7 Date: Thu, 4 Jun 2015 23:46:32 -0400 Subject: testing something. --- doc/api/array.h.md | 0 doc/api/mruby/array.h.md | 0 doc/api/mruby/value.h.md | 233 +++++++++++++++++++++++++++++++++++++++++++++++ doc/api/value.h.md | 233 ----------------------------------------------- 4 files changed, 233 insertions(+), 233 deletions(-) delete mode 100644 doc/api/array.h.md create mode 100644 doc/api/mruby/array.h.md create mode 100644 doc/api/mruby/value.h.md delete mode 100644 doc/api/value.h.md (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/doc/api/mruby/array.h.md b/doc/api/mruby/array.h.md new file mode 100644 index 000000000..e69de29bb diff --git a/doc/api/mruby/value.h.md b/doc/api/mruby/value.h.md new file mode 100644 index 000000000..dd1c4b238 --- /dev/null +++ b/doc/api/mruby/value.h.md @@ -0,0 +1,233 @@ +### mrb_float_value +```C +static inline mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) +``` + +Returns a float in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_float f = 0.09. Alternatively +double i = 0.09 could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" +#include "mruby/string.h" + +int +main(void) +{ + mrb_float f = 0.09;// or double i = 0.09; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + +### mrb_fixnum_value + +```C +static inline mrb_value mrb_fixnum_value(mrb_int i) +``` + +Returns a fixnum in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_int i = 99. Alternativly int i = 99 +could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_int i = 99; // or int i = 99; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_nil_value + +```C +static inline mrb_value mrb_nil_value(void) +``` + +Returns nil in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get NillClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + +### mrb_false_value + +```C +static inline mrb_value mrb_false_value(void) +``` + +Returns false in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get FalseClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_true_value + +```C +static inline mrb_value mrb_true_value(void) +``` + +Returns true in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get TrueClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` diff --git a/doc/api/value.h.md b/doc/api/value.h.md deleted file mode 100644 index dd1c4b238..000000000 --- a/doc/api/value.h.md +++ /dev/null @@ -1,233 +0,0 @@ -### mrb_float_value -```C -static inline mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) -``` - -Returns a float in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in mrb_float f = 0.09. Alternatively -double i = 0.09 could also be used. - - -example.c -```C -#include -#include -#include "mruby/compile.h" -#include "mruby/string.h" - -int -main(void) -{ - mrb_float f = 0.09;// or double i = 0.09; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - -### mrb_fixnum_value - -```C -static inline mrb_value mrb_fixnum_value(mrb_int i) -``` - -Returns a fixnum in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in mrb_int i = 99. Alternativly int i = 99 -could also be used. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_int i = 99; // or int i = 99; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - - -### mrb_nil_value - -```C -static inline mrb_value mrb_nil_value(void) -``` - -Returns nil in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get NillClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - -### mrb_false_value - -```C -static inline mrb_value mrb_false_value(void) -``` - -Returns false in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get FalseClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - - -### mrb_true_value - -```C -static inline mrb_value mrb_true_value(void) -``` - -Returns true in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get TrueClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` -- cgit v1.2.3 From d768dcc42c1e62d82ef639012b7e748af105676e Mon Sep 17 00:00:00 2001 From: Mav7 Date: Thu, 4 Jun 2015 23:49:43 -0400 Subject: Adding an array readme markdown. --- doc/api/array.h.md | 0 doc/api/mruby/array.h.md | 0 doc/api/mruby/value.h.md | 233 ----------------------------------------------- doc/api/value.h.md | 233 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+), 233 deletions(-) create mode 100644 doc/api/array.h.md delete mode 100644 doc/api/mruby/array.h.md delete mode 100644 doc/api/mruby/value.h.md create mode 100644 doc/api/value.h.md (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md new file mode 100644 index 000000000..e69de29bb diff --git a/doc/api/mruby/array.h.md b/doc/api/mruby/array.h.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/doc/api/mruby/value.h.md b/doc/api/mruby/value.h.md deleted file mode 100644 index dd1c4b238..000000000 --- a/doc/api/mruby/value.h.md +++ /dev/null @@ -1,233 +0,0 @@ -### mrb_float_value -```C -static inline mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) -``` - -Returns a float in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in mrb_float f = 0.09. Alternatively -double i = 0.09 could also be used. - - -example.c -```C -#include -#include -#include "mruby/compile.h" -#include "mruby/string.h" - -int -main(void) -{ - mrb_float f = 0.09;// or double i = 0.09; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - -### mrb_fixnum_value - -```C -static inline mrb_value mrb_fixnum_value(mrb_int i) -``` - -Returns a fixnum in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in mrb_int i = 99. Alternativly int i = 99 -could also be used. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_int i = 99; // or int i = 99; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - - -### mrb_nil_value - -```C -static inline mrb_value mrb_nil_value(void) -``` - -Returns nil in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get NillClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - -### mrb_false_value - -```C -static inline mrb_value mrb_false_value(void) -``` - -Returns false in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get FalseClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - - -### mrb_true_value - -```C -static inline mrb_value mrb_true_value(void) -``` - -Returns true in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get TrueClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); - fclose(fp); - mrb_close(mrb); -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` diff --git a/doc/api/value.h.md b/doc/api/value.h.md new file mode 100644 index 000000000..dd1c4b238 --- /dev/null +++ b/doc/api/value.h.md @@ -0,0 +1,233 @@ +### mrb_float_value +```C +static inline mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) +``` + +Returns a float in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_float f = 0.09. Alternatively +double i = 0.09 could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" +#include "mruby/string.h" + +int +main(void) +{ + mrb_float f = 0.09;// or double i = 0.09; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + +### mrb_fixnum_value + +```C +static inline mrb_value mrb_fixnum_value(mrb_int i) +``` + +Returns a fixnum in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_int i = 99. Alternativly int i = 99 +could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_int i = 99; // or int i = 99; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_nil_value + +```C +static inline mrb_value mrb_nil_value(void) +``` + +Returns nil in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get NillClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + +### mrb_false_value + +```C +static inline mrb_value mrb_false_value(void) +``` + +Returns false in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get FalseClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_true_value + +```C +static inline mrb_value mrb_true_value(void) +``` + +Returns true in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get TrueClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); + fclose(fp); + mrb_close(mrb); +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` -- cgit v1.2.3 From e63962c0a4df07897fe31966a8d768fc994f6da7 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Thu, 4 Jun 2015 23:53:15 -0400 Subject: Update array.h.md --- doc/api/array.h.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md index e69de29bb..d96d854b8 100644 --- a/doc/api/array.h.md +++ b/doc/api/array.h.md @@ -0,0 +1,2 @@ +### mrb_ary_new(mrb_state *mrb); +mrb_value mrb_ary_new(mrb_state *mrb); -- cgit v1.2.3 From 8a14073207dc43072003206be2b4f212d96051b2 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Thu, 4 Jun 2015 23:54:27 -0400 Subject: Update array.h.md --- doc/api/array.h.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md index d96d854b8..d3f5a12fa 100644 --- a/doc/api/array.h.md +++ b/doc/api/array.h.md @@ -1,2 +1 @@ -### mrb_ary_new(mrb_state *mrb); -mrb_value mrb_ary_new(mrb_state *mrb); + -- cgit v1.2.3 From b9716c59c7f32664ad6c27487766e81be8bdc2b2 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 5 Jun 2015 00:05:41 -0400 Subject: Update array.h.md --- doc/api/array.h.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md index d3f5a12fa..717522c62 100644 --- a/doc/api/array.h.md +++ b/doc/api/array.h.md @@ -1 +1,14 @@ +### mrb_ary_new +```C +mrb_value mrb_ary_new(mrb_state *mrb); +``` + +Initializes an array. + +#### Example + +example.c +```C + +``` -- cgit v1.2.3 From 88342b2709d9b795faeda5ba9d526bf600d351e8 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 5 Jun 2015 00:17:42 -0400 Subject: Update array.h.md --- doc/api/array.h.md | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md index 717522c62..d3f5a12fa 100644 --- a/doc/api/array.h.md +++ b/doc/api/array.h.md @@ -1,14 +1 @@ -### mrb_ary_new -```C -mrb_value mrb_ary_new(mrb_state *mrb); -``` - -Initializes an array. - -#### Example - -example.c -```C - -``` -- cgit v1.2.3 From 12b307396a9696d253232e7ac7c3c3a1cb53430c Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 5 Jun 2015 02:42:48 -0400 Subject: Added more function documentation for arrays. --- doc/api/array.h.md | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md index d3f5a12fa..714eacda0 100644 --- a/doc/api/array.h.md +++ b/doc/api/array.h.md @@ -1 +1,251 @@ +### mrb_ary_new() +```C +mrb_value mrb_ary_new(mrb_state *mrb); +``` +Initializes an array. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we are declaring a variable new_ary of data type mrb_value. Then we are initializing it with the mrb_ary_new function which only takes an mruby state as an argument. +```C +#include +#include +#include "mruby/array.h" // Need the array header. +#include "mruby/compile.h" + + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; // Declare variable. + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` + +### mrb_ary_push() +```C +void mrb_ary_push(mrb_state*, mrb_value, mrb_value); +``` +Pushes given value into an array. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case after initializing our array. We are declaring two variables with the mrb_int data type random_value1 & random_value2 and we initialize them 70 and 60 respectively. Then we use the mrb_ary_push function to push values those values into the array. +```C +#include +#include +#include "mruby/array.h" // Need the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +[70, 60] +Array +``` + +## mrb_ary_pop() +```C +mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary); +``` +Pops the last element from the array. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case after initializing our array. We are declaring two variables with the mrb_int data type random_value1 & random_value2 and we initialize them 70 and 60 respectively. Then we use the mrb_ary_push function to push values those values into the array. Now here in the Ruby files we add another method +called pop_ary that will return the array alone(just to be clean) and you should see the last element gone. +```C +#include +#include +#include "mruby/array.h" // Need the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + mrb_ary_pop(mrb, new_ary); // Pops the last element of the array. In this case 60. + mrb_funcall(mrb, obj, "pop_ary", 1, new_ary); // Calls the method again to show the results. + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end + def pop_ary(a) + puts a + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +[70, 60] +Array +[70] +``` +## mrb_ary_ref() +```C +mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n); +``` +Returns a reference to an element of the array. Specified by the value given to mrb_int n. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we're declaring a variable ary_ref with the data type of mrb_value. Then we assign mrb_ary_ref to it getting new_ary's value at index 1. +```C +#include +#include +#include "mruby/array.h" // Need the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value ary_ref; // Declare variable. + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + ary_ref = mrb_ary_ref(mrb, new_ary, 1); // Gets the value of new_ary's second element at index 1. + mrb_value obj = mrb_load_file(mrb,fp); + /* Passing the value from ary_ref to the method method_name.*/ + mrb_funcall(mrb, obj, "method_name", 1, ary_ref); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +60 +Fixnum +``` + +### mrb_ary_set +```C +void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val); +``` +Sets a value to an index. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we're declaring a variable ary_ref with the data type of mrb_value. Then we assign mrb_ary_ref to it getting new_ary's value at index 1. +```C +#include +#include +#include "mruby/array.h" // Need the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; + mrb_value ary_obj; + mrb_int random_value1 = 70; + mrb_int random_value2 = 60; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + /* Sets the fixnum value of 7 to the second index of the array.*/ + mrb_ary_set(mrb, new_ary, 2, mrb_fixnum_value(7)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "before_after", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end + def before_after(a) + puts a + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +[70, 60, 7] +``` -- cgit v1.2.3 From a3a18cd7a691b3382c41ae5e73ef85bcdbabca3d Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 5 Jun 2015 02:43:54 -0400 Subject: Update array.h.md --- doc/api/array.h.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md index 714eacda0..33466e149 100644 --- a/doc/api/array.h.md +++ b/doc/api/array.h.md @@ -1,4 +1,4 @@ -### mrb_ary_new() +### mrb_ary_new ```C mrb_value mrb_ary_new(mrb_state *mrb); @@ -38,7 +38,7 @@ end Example_Class.new ``` -### mrb_ary_push() +### mrb_ary_push ```C void mrb_ary_push(mrb_state*, mrb_value, mrb_value); ``` @@ -88,7 +88,7 @@ After compiling you should get these results. Array ``` -## mrb_ary_pop() +## mrb_ary_pop ```C mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary); ``` @@ -144,7 +144,7 @@ After compiling you should get these results. Array [70] ``` -## mrb_ary_ref() +## mrb_ary_ref ```C mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n); ``` -- cgit v1.2.3 From e1795cb72dad87c163a38a59915b86ac83c09563 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 5 Jun 2015 02:51:37 -0400 Subject: Update value.h.md --- doc/api/value.h.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'doc/api') diff --git a/doc/api/value.h.md b/doc/api/value.h.md index dd1c4b238..f3ae2d421 100644 --- a/doc/api/value.h.md +++ b/doc/api/value.h.md @@ -30,6 +30,7 @@ main(void) mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); fclose(fp); mrb_close(mrb); + return 0; } ``` @@ -77,6 +78,7 @@ main(void) mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); fclose(fp); mrb_close(mrb); + return 0; } ``` @@ -124,6 +126,7 @@ main(void) mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); fclose(fp); mrb_close(mrb); + return 0; } ``` @@ -170,6 +173,7 @@ main(void) mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); fclose(fp); mrb_close(mrb); + return 0; } ``` @@ -217,6 +221,7 @@ main(void) mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); fclose(fp); mrb_close(mrb); + return 0; } ``` -- cgit v1.2.3 From 0f93d9b7dbdc74f485617051b5db81db09c7b726 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 5 Jun 2015 02:54:11 -0400 Subject: Update array.h.md --- doc/api/array.h.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'doc/api') diff --git a/doc/api/array.h.md b/doc/api/array.h.md index 33466e149..e1fb0003d 100644 --- a/doc/api/array.h.md +++ b/doc/api/array.h.md @@ -9,7 +9,7 @@ In this example we read from a Ruby file inside C. The Ruby code will print what ```C #include #include -#include "mruby/array.h" // Need the array header. +#include "mruby/array.h" // Needs the array header. #include "mruby/compile.h" @@ -48,7 +48,7 @@ In this example we read from a Ruby file inside C. The Ruby code will print what ```C #include #include -#include "mruby/array.h" // Need the array header. +#include "mruby/array.h" // Needs the array header. #include "mruby/compile.h" int main(int argc, char *argv[]) @@ -99,7 +99,7 @@ called pop_ary that will return the array alone(just to be clean) and you should ```C #include #include -#include "mruby/array.h" // Need the array header. +#include "mruby/array.h" // Needs the array header. #include "mruby/compile.h" int main(int argc, char *argv[]) @@ -154,7 +154,7 @@ In this example we read from a Ruby file inside C. The Ruby code will print what ```C #include #include -#include "mruby/array.h" // Need the array header. +#include "mruby/array.h" // Needs the array header. #include "mruby/compile.h" int main(int argc, char *argv[]) @@ -207,7 +207,7 @@ In this example we read from a Ruby file inside C. The Ruby code will print what ```C #include #include -#include "mruby/array.h" // Need the array header. +#include "mruby/array.h" // Needs the array header. #include "mruby/compile.h" int main(int argc, char *argv[]) -- cgit v1.2.3 From 427cc64de0d3db4fa4c03d14c2785c37f91da12b Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Fri, 26 Jun 2015 14:37:57 +0200 Subject: Respect the directory structure of `include` As mentioned in the README, two files have been put under the `mruby` directory. --- doc/api/README.md | 40 ++++---- doc/api/array.h.md | 251 ----------------------------------------------- doc/api/mruby/array.h.md | 251 +++++++++++++++++++++++++++++++++++++++++++++++ doc/api/mruby/value.h.md | 238 ++++++++++++++++++++++++++++++++++++++++++++ doc/api/value.h.md | 238 -------------------------------------------- 5 files changed, 509 insertions(+), 509 deletions(-) delete mode 100644 doc/api/array.h.md create mode 100644 doc/api/mruby/array.h.md create mode 100644 doc/api/mruby/value.h.md delete mode 100644 doc/api/value.h.md (limited to 'doc/api') diff --git a/doc/api/README.md b/doc/api/README.md index 131e50515..a83330d82 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -8,23 +8,23 @@ Header name|Features -----------|-------- [mrbconf.h](../mrbconf/README.md)|Defines macros for mruby configurations. [mruby.h](./mruby.h.md)|Main header of mruby C API. Include this first. -[mruby/array.h](./mruby.array.h.md)|`Array` class. -[mruby/class.h](./mruby.class.h.md)|`Class` class. -[mruby/compile.h](./mruby.compile.h.md)|mruby compiler. -[mruby/data.h](./mruby.data.h.md)|User defined object. -[mruby/debug.h](./mruby.debug.h.md)|Debugging. -[mruby/dump.h](./mruby.dump.h.md)|Dumping compiled mruby script. -[mruby/error.h](./mruby.error.h.md)|Error handling. -[mruby/gc.h](./mruby.gc.h.md)|Uncommon memory management stuffs. -[mruby/hash.h](./mruby.hash.h.md)|`Hash` class. -[mruby/irep.h](./mruby.irep.h.md)|Compiled mruby script. -[mruby/khash.h](./mruby.khash.h.md)|Defines of khash which is used in hash table of mruby. -[mruby/numeric.h](./mruby.numeric.h.md)|`Numeric` class and sub-classes of it. -[mruby/opode.h](./mruby.opcode.h.md)|Operation codes used in mruby VM. -[mruby/proc.h](./mruby.proc.h.md)|`Proc` class. -[mruby/range.h](./mruby.range.h.md)|`Range` class. -[mruby/re.h](./mruby.re.h.md)|`Regexp` class. -[mruby/string.h](./mruby.string.h.md)|`String` class. -[mruby/value.h](./mruby.value.h.md)|`mrb_value` functions and macros. -[mruby/variable.h](./mruby.variable.h.md)|Functions to access to mruby variables. -[mruby/version.h](./mruby.version.h.md)|Macros of mruby version. +[mruby/array.h](./mruby/array.h.md)|`Array` class. +[mruby/class.h](./mruby/class.h.md)|`Class` class. +[mruby/compile.h](./mruby/compile.h.md)|mruby compiler. +[mruby/data.h](./mruby/data.h.md)|User defined object. +[mruby/debug.h](./mruby/debug.h.md)|Debugging. +[mruby/dump.h](./mruby/dump.h.md)|Dumping compiled mruby script. +[mruby/error.h](./mruby/error.h.md)|Error handling. +[mruby/gc.h](./mruby/gc.h.md)|Uncommon memory management stuffs. +[mruby/hash.h](./mruby/hash.h.md)|`Hash` class. +[mruby/irep.h](./mruby/irep.h.md)|Compiled mruby script. +[mruby/khash.h](./mruby/khash.h.md)|Defines of khash which is used in hash table of mruby. +[mruby/numeric.h](./mruby/numeric.h.md)|`Numeric` class and sub-classes of it. +[mruby/opode.h](./mruby/opcode.h.md)|Operation codes used in mruby VM. +[mruby/proc.h](./mruby/proc.h.md)|`Proc` class. +[mruby/range.h](./mruby/range.h.md)|`Range` class. +[mruby/re.h](./mruby/re.h.md)|`Regexp` class. +[mruby/string.h](./mruby/string.h.md)|`String` class. +[mruby/value.h](./mruby/value.h.md)|`mrb_value` functions and macros. +[mruby/variable.h](./mruby/variable.h.md)|Functions to access to mruby variables. +[mruby/version.h](./mruby/version.h.md)|Macros of mruby version. diff --git a/doc/api/array.h.md b/doc/api/array.h.md deleted file mode 100644 index e1fb0003d..000000000 --- a/doc/api/array.h.md +++ /dev/null @@ -1,251 +0,0 @@ -### mrb_ary_new - -```C -mrb_value mrb_ary_new(mrb_state *mrb); -``` -Initializes an array. -#### Example -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we are declaring a variable new_ary of data type mrb_value. Then we are initializing it with the mrb_ary_new function which only takes an mruby state as an argument. -```C -#include -#include -#include "mruby/array.h" // Needs the array header. -#include "mruby/compile.h" - - -int main(int argc, char *argv[]) -{ - mrb_value new_ary; // Declare variable. - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, new_ary); - fclose(fp); - mrb_close(mrb); - return 0; -} -``` -test.rb -```Ruby -class Example_Class - def method_name(a) - puts a - puts a.class - end -end -Example_Class.new -``` - -### mrb_ary_push -```C -void mrb_ary_push(mrb_state*, mrb_value, mrb_value); -``` -Pushes given value into an array. -#### Example -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case after initializing our array. We are declaring two variables with the mrb_int data type random_value1 & random_value2 and we initialize them 70 and 60 respectively. Then we use the mrb_ary_push function to push values those values into the array. -```C -#include -#include -#include "mruby/array.h" // Needs the array header. -#include "mruby/compile.h" - -int main(int argc, char *argv[]) -{ - mrb_value new_ary; // Declare variable. - mrb_int random_value1 = 70; // Initialize variable - mrb_int random_value2 = 60; // Initialize variable - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); // Initialize ruby array. - /* Pushes the fixnum value from random_value1 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - /* Pushes the fixnum value from random_value2 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, new_ary); - fclose(fp); - mrb_close(mrb); - return 0; -} -``` -test.rb -```Ruby -class Example_Class - def method_name(a) - puts a - puts a.class - end -end -Example_Class.new -``` -#### Result -After compiling you should get these results. -```Ruby -[70, 60] -Array -``` - -## mrb_ary_pop -```C -mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary); -``` -Pops the last element from the array. -#### Example -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case after initializing our array. We are declaring two variables with the mrb_int data type random_value1 & random_value2 and we initialize them 70 and 60 respectively. Then we use the mrb_ary_push function to push values those values into the array. Now here in the Ruby files we add another method -called pop_ary that will return the array alone(just to be clean) and you should see the last element gone. -```C -#include -#include -#include "mruby/array.h" // Needs the array header. -#include "mruby/compile.h" - -int main(int argc, char *argv[]) -{ - mrb_value new_ary; // Declare variable. - mrb_int random_value1 = 70; // Initialize variable - mrb_int random_value2 = 60; // Initialize variable - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); // Initialize ruby array. - /* Pushes the fixnum value from random_value1 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - /* Pushes the fixnum value from random_value2 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, new_ary); - mrb_ary_pop(mrb, new_ary); // Pops the last element of the array. In this case 60. - mrb_funcall(mrb, obj, "pop_ary", 1, new_ary); // Calls the method again to show the results. - fclose(fp); - mrb_close(mrb); - return 0; -} -``` -test.rb -```Ruby -class Example_Class - def method_name(a) - puts a - puts a.class - end - def pop_ary(a) - puts a - end -end -Example_Class.new -``` -#### Result -After compiling you should get these results. -```Ruby -[70, 60] -Array -[70] -``` -## mrb_ary_ref -```C -mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n); -``` -Returns a reference to an element of the array. Specified by the value given to mrb_int n. -#### Example -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we're declaring a variable ary_ref with the data type of mrb_value. Then we assign mrb_ary_ref to it getting new_ary's value at index 1. -```C -#include -#include -#include "mruby/array.h" // Needs the array header. -#include "mruby/compile.h" - -int main(int argc, char *argv[]) -{ - mrb_value ary_ref; // Declare variable. - mrb_value new_ary; // Declare variable. - mrb_int random_value1 = 70; // Initialize variable - mrb_int random_value2 = 60; // Initialize variable - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); // Initialize ruby array. - /* Pushes the fixnum value from random_value1 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - /* Pushes the fixnum value from random_value2 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - ary_ref = mrb_ary_ref(mrb, new_ary, 1); // Gets the value of new_ary's second element at index 1. - mrb_value obj = mrb_load_file(mrb,fp); - /* Passing the value from ary_ref to the method method_name.*/ - mrb_funcall(mrb, obj, "method_name", 1, ary_ref); - fclose(fp); - mrb_close(mrb); - return 0; -} -``` -test.rb -```Ruby -class Example_Class - def method_name(a) - puts a - puts a.class - end -end -Example_Class.new -``` -#### Result -After compiling you should get these results. -```Ruby -60 -Fixnum -``` - -### mrb_ary_set -```C -void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val); -``` -Sets a value to an index. -#### Example -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we're declaring a variable ary_ref with the data type of mrb_value. Then we assign mrb_ary_ref to it getting new_ary's value at index 1. -```C -#include -#include -#include "mruby/array.h" // Needs the array header. -#include "mruby/compile.h" - -int main(int argc, char *argv[]) -{ - mrb_value new_ary; - mrb_value ary_obj; - mrb_int random_value1 = 70; - mrb_int random_value2 = 60; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - /* Sets the fixnum value of 7 to the second index of the array.*/ - mrb_ary_set(mrb, new_ary, 2, mrb_fixnum_value(7)); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "before_after", 1, new_ary); - fclose(fp); - mrb_close(mrb); - return 0; -} -``` -test.rb -```Ruby -class Example_Class - def method_name(a) - puts a - puts a.class - end - def before_after(a) - puts a - end -end -Example_Class.new -``` -#### Result -After compiling you should get these results. -```Ruby -[70, 60, 7] -``` diff --git a/doc/api/mruby/array.h.md b/doc/api/mruby/array.h.md new file mode 100644 index 000000000..e1fb0003d --- /dev/null +++ b/doc/api/mruby/array.h.md @@ -0,0 +1,251 @@ +### mrb_ary_new + +```C +mrb_value mrb_ary_new(mrb_state *mrb); +``` +Initializes an array. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we are declaring a variable new_ary of data type mrb_value. Then we are initializing it with the mrb_ary_new function which only takes an mruby state as an argument. +```C +#include +#include +#include "mruby/array.h" // Needs the array header. +#include "mruby/compile.h" + + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; // Declare variable. + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` + +### mrb_ary_push +```C +void mrb_ary_push(mrb_state*, mrb_value, mrb_value); +``` +Pushes given value into an array. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case after initializing our array. We are declaring two variables with the mrb_int data type random_value1 & random_value2 and we initialize them 70 and 60 respectively. Then we use the mrb_ary_push function to push values those values into the array. +```C +#include +#include +#include "mruby/array.h" // Needs the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +[70, 60] +Array +``` + +## mrb_ary_pop +```C +mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary); +``` +Pops the last element from the array. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case after initializing our array. We are declaring two variables with the mrb_int data type random_value1 & random_value2 and we initialize them 70 and 60 respectively. Then we use the mrb_ary_push function to push values those values into the array. Now here in the Ruby files we add another method +called pop_ary that will return the array alone(just to be clean) and you should see the last element gone. +```C +#include +#include +#include "mruby/array.h" // Needs the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + mrb_ary_pop(mrb, new_ary); // Pops the last element of the array. In this case 60. + mrb_funcall(mrb, obj, "pop_ary", 1, new_ary); // Calls the method again to show the results. + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end + def pop_ary(a) + puts a + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +[70, 60] +Array +[70] +``` +## mrb_ary_ref +```C +mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n); +``` +Returns a reference to an element of the array. Specified by the value given to mrb_int n. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we're declaring a variable ary_ref with the data type of mrb_value. Then we assign mrb_ary_ref to it getting new_ary's value at index 1. +```C +#include +#include +#include "mruby/array.h" // Needs the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value ary_ref; // Declare variable. + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + ary_ref = mrb_ary_ref(mrb, new_ary, 1); // Gets the value of new_ary's second element at index 1. + mrb_value obj = mrb_load_file(mrb,fp); + /* Passing the value from ary_ref to the method method_name.*/ + mrb_funcall(mrb, obj, "method_name", 1, ary_ref); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +60 +Fixnum +``` + +### mrb_ary_set +```C +void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val); +``` +Sets a value to an index. +#### Example +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument and what class the passed in value is. In this case we're declaring a variable ary_ref with the data type of mrb_value. Then we assign mrb_ary_ref to it getting new_ary's value at index 1. +```C +#include +#include +#include "mruby/array.h" // Needs the array header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_value new_ary; + mrb_value ary_obj; + mrb_int random_value1 = 70; + mrb_int random_value2 = 60; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + /* Sets the fixnum value of 7 to the second index of the array.*/ + mrb_ary_set(mrb, new_ary, 2, mrb_fixnum_value(7)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "before_after", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` +test.rb +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end + def before_after(a) + puts a + end +end +Example_Class.new +``` +#### Result +After compiling you should get these results. +```Ruby +[70, 60, 7] +``` diff --git a/doc/api/mruby/value.h.md b/doc/api/mruby/value.h.md new file mode 100644 index 000000000..f3ae2d421 --- /dev/null +++ b/doc/api/mruby/value.h.md @@ -0,0 +1,238 @@ +### mrb_float_value +```C +static inline mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) +``` + +Returns a float in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_float f = 0.09. Alternatively +double i = 0.09 could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" +#include "mruby/string.h" + +int +main(void) +{ + mrb_float f = 0.09;// or double i = 0.09; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); + fclose(fp); + mrb_close(mrb); + return 0; +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + +### mrb_fixnum_value + +```C +static inline mrb_value mrb_fixnum_value(mrb_int i) +``` + +Returns a fixnum in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in mrb_int i = 99. Alternativly int i = 99 +could also be used. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_int i = 99; // or int i = 99; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); + fclose(fp); + mrb_close(mrb); + return 0; +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_nil_value + +```C +static inline mrb_value mrb_nil_value(void) +``` + +Returns nil in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get NillClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); + fclose(fp); + mrb_close(mrb); + return 0; +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + +### mrb_false_value + +```C +static inline mrb_value mrb_false_value(void) +``` + +Returns false in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get FalseClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); + fclose(fp); + mrb_close(mrb); + return 0; +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` + + + +### mrb_true_value + +```C +static inline mrb_value mrb_true_value(void) +``` + +Returns true in Ruby. + +##### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. In this case we are passing in nothing and we will get TrueClass. + + +example.c +```C +#include +#include +#include "mruby/compile.h" + +int +main(void) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); + fclose(fp); + mrb_close(mrb); + return 0; +} + +``` + +test.rb +```Ruby +class My_Class + def method_name(s) + puts s + puts s.class + end +end +a = My_Class.new +``` diff --git a/doc/api/value.h.md b/doc/api/value.h.md deleted file mode 100644 index f3ae2d421..000000000 --- a/doc/api/value.h.md +++ /dev/null @@ -1,238 +0,0 @@ -### mrb_float_value -```C -static inline mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) -``` - -Returns a float in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in mrb_float f = 0.09. Alternatively -double i = 0.09 could also be used. - - -example.c -```C -#include -#include -#include "mruby/compile.h" -#include "mruby/string.h" - -int -main(void) -{ - mrb_float f = 0.09;// or double i = 0.09; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_float_value(mrb, f)); - fclose(fp); - mrb_close(mrb); - return 0; -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - -### mrb_fixnum_value - -```C -static inline mrb_value mrb_fixnum_value(mrb_int i) -``` - -Returns a fixnum in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in mrb_int i = 99. Alternativly int i = 99 -could also be used. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_int i = 99; // or int i = 99; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i)); - fclose(fp); - mrb_close(mrb); - return 0; -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - - -### mrb_nil_value - -```C -static inline mrb_value mrb_nil_value(void) -``` - -Returns nil in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get NillClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_nil_value()); - fclose(fp); - mrb_close(mrb); - return 0; -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - -### mrb_false_value - -```C -static inline mrb_value mrb_false_value(void) -``` - -Returns false in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get FalseClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_false_value()); - fclose(fp); - mrb_close(mrb); - return 0; -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` - - - -### mrb_true_value - -```C -static inline mrb_value mrb_true_value(void) -``` - -Returns true in Ruby. - -##### Example - -In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. In this case we are passing in nothing and we will get TrueClass. - - -example.c -```C -#include -#include -#include "mruby/compile.h" - -int -main(void) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, mrb_true_value()); - fclose(fp); - mrb_close(mrb); - return 0; -} - -``` - -test.rb -```Ruby -class My_Class - def method_name(s) - puts s - puts s.class - end -end -a = My_Class.new -``` -- cgit v1.2.3 From 2523ed473af8d9e97c641f7263286d1af40a69a3 Mon Sep 17 00:00:00 2001 From: Mav7 Date: Wed, 8 Jul 2015 04:50:01 -0400 Subject: Added new markdowns. --- doc/api/mruby/hash.h.md | 0 doc/api/mruby/range.h.md | 0 doc/api/mruby/string.h.md | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/api/mruby/hash.h.md create mode 100644 doc/api/mruby/range.h.md create mode 100644 doc/api/mruby/string.h.md (limited to 'doc/api') diff --git a/doc/api/mruby/hash.h.md b/doc/api/mruby/hash.h.md new file mode 100644 index 000000000..e69de29bb diff --git a/doc/api/mruby/range.h.md b/doc/api/mruby/range.h.md new file mode 100644 index 000000000..e69de29bb diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From 82380780db07e9d776d3d7983a229a114f30ecb8 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Wed, 8 Jul 2015 05:35:37 -0400 Subject: Update hash.h.md --- doc/api/mruby/hash.h.md | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/hash.h.md b/doc/api/mruby/hash.h.md index e69de29bb..1d713d59e 100644 --- a/doc/api/mruby/hash.h.md +++ b/doc/api/mruby/hash.h.md @@ -0,0 +1,96 @@ +### mrb_hash_new + +```C +mrb_value mrb_hash_new(mrb_state *mrb); +``` + +Initializes a hash. +#### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. This example initializes a hash. In pure Ruby doing this is equivalent +to Hash.new. + +```C +#include +#include +#include "mruby/hash.h" // Needs the hash header. +#include "mruby/compile.h" + + +int main(int argc, char *argv[]) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` + +#### test_ext.rb + +``` Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` + +### mrb_hash_set + +```C +#include +#include +#include "mruby/hash.h" // Needs the hash header. +#include "mruby/compile.h" + + +int main(int argc, char *argv[]) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable. + mrb_sym hash_key = mrb_intern_cstr(mrb, "da_key"); // Declare a symbol. + mrb_int hash_value = 80; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key), mrb_fixnum_value(hash_value)); // Set values to hash. + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` + +#### test_ext.rb + +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` + +#### Result + +After compiling you should get these results. + +```Ruby +{:da_key=>80} +Hash +``` + + -- cgit v1.2.3 From 510e53d89f447b900a028f75c51ba18cb95d1670 Mon Sep 17 00:00:00 2001 From: jbreeden Date: Mon, 13 Jul 2015 23:21:19 -0700 Subject: Add ! documentation to mruby.h.md --- doc/api/mruby.h.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'doc/api') diff --git a/doc/api/mruby.h.md b/doc/api/mruby.h.md index 8862fee2c..8236b8244 100644 --- a/doc/api/mruby.h.md +++ b/doc/api/mruby.h.md @@ -43,20 +43,22 @@ Deletes `mrb_state`. int mrb_get_args(mrb_state *mrb, const char *format, ...); ``` Retrieve arguments from `mrb_state`. +When applicable, implicit conversions (such as `to_str`, +`to_ary`, `to_hash`) are be applied to received arguments. Use it inside a function pointed by `mrb_func_t`. -It returns number of function retrieved. -`format` is a list of following format specifier: +It returns the number of arguments retrieved. +`format` is a list of following format specifiers: char|mruby type|retrieve types|note :---:|----------|--------------|--- `o`|`Object`|`mrb_value`|Could be used to retrieve any type of argument `C`|`Class`/`Module`|`mrb_value`| -`S`|`String`|`mrb_value`| -`A`|`Array`|`mrb_value`| -`H`|`Hash`|`mrb_value`| -`s`|`String`|`char*`, `mrb_int`| -`z`|`String`|`char*`| -`a`|`Array`|`mrb_value*`, `mrb_int`| +`S`|`String`|`mrb_value`|when ! follows, the value may be nil +`A`|`Array`|`mrb_value`|when ! follows, the value may be nil +`H`|`Hash`|`mrb_value`|when ! follows, the value may be nil +`s`|`String`|`char*`, `mrb_int`|Receive two arguments; s! gives (NULL,0) for nil +`z`|`String`|`char*`|NUL terminated string; z! gives NULL for nil +`a`|`Array`|`mrb_value*`, `mrb_int`|Receive two arguments; a! gives (NULL,0) for nil `f`|`Float`|`mrb_float`| `i`|`Integer`|`mrb_int`| `b`|boolean|`mrb_bool`| @@ -118,7 +120,7 @@ mrb_value example_method(mrb_state* mrb, mrb_value self){ void mrb_example_gem_init(mrb_state* mrb) { struct RClass *example_class; example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class); - mrb_define_method(mrb, example_class, "example_method", example_method, MRB_ARGS_NONE()); + mrb_define_method(mrb, example_class, "example_method", example_method, MRB_ARGS_NONE()); } void mrb_example_gem_final(mrb_state* mrb) { -- cgit v1.2.3 From e92da7b76c75b0270fc4a9bfd8c8dd20985e1f00 Mon Sep 17 00:00:00 2001 From: jbreeden Date: Mon, 13 Jul 2015 23:26:29 -0700 Subject: Fix typo --- doc/api/mruby.h.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/api') diff --git a/doc/api/mruby.h.md b/doc/api/mruby.h.md index 8236b8244..06bab2d56 100644 --- a/doc/api/mruby.h.md +++ b/doc/api/mruby.h.md @@ -44,7 +44,7 @@ int mrb_get_args(mrb_state *mrb, const char *format, ...); ``` Retrieve arguments from `mrb_state`. When applicable, implicit conversions (such as `to_str`, -`to_ary`, `to_hash`) are be applied to received arguments. +`to_ary`, `to_hash`) are applied to received arguments. Use it inside a function pointed by `mrb_func_t`. It returns the number of arguments retrieved. `format` is a list of following format specifiers: -- cgit v1.2.3 From 78a40fce8881247419955291f34ca36eb0549126 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 17 Jul 2015 14:21:13 -0400 Subject: Update hash.h.md --- doc/api/mruby/hash.h.md | 272 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/hash.h.md b/doc/api/mruby/hash.h.md index 1d713d59e..bdc2a7f2b 100644 --- a/doc/api/mruby/hash.h.md +++ b/doc/api/mruby/hash.h.md @@ -47,6 +47,17 @@ Example_Class.new ### mrb_hash_set +```C +void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val); +``` + +Sets a keys and values to hashes. +#### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. This example sets a key and value pair to a hash. In pure Ruby doing this is equivalent to a = {:da_key => 80}. + + ```C #include #include @@ -93,4 +104,265 @@ After compiling you should get these results. Hash ``` +### mrb_hash_get + +```C +mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key); +``` + +Gets a value from a key. +#### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. This example gets a value from a key. In pure Ruby doing this is equivalent to a = {:da_key => 80} +a[:da_key]. + +```C +#include +#include +#include "mruby/hash.h" // Needs the hash header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash_value; // Declare variable for getting a value from a hash. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + get_hash_value = mrb_hash_get(mrb, new_hash, mrb_symbol_value(hash_key_b)); // Get value from hash. + mrb_funcall(mrb, obj, "method_name", 1, get_hash_value); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` + +#### test_ext.rb + +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` + +#### Result + +After compiling you should get these results. + +```Ruby +90 +Fixnum +``` + +### mrb_hash_delete_key + +```C +mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key); +``` + +Deletes hash key and value pair. +#### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. This example deletes hash key and value pair. In pure Ruby doing this is equivalent to a = {:da_key1 => 80,:da_key2 => 90} +a.delete(:da_key2) + + +```C +#include +#include +#include "mruby/hash.h" // Needs the hash header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash_value; // Declare variable for getting a value from a hash. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + mrb_hash_delete_key(mrb, new_hash, mrb_symbol_value(hash_key_b)); + mrb_funcall(mrb, obj, "another_method_name", 1, new_hash); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` + +#### test_ext.rb + +```Ruby +class Example_Class + def method_name(a) + puts "Hash pre deletion #{a}" + #puts a.class + end + # Show deleted key and value pair. + def another_method_name(a) + puts "Hash post deletion #{a}" + end +end +Example_Class.new +``` + +#### Result +After compiling you should get these results. + +```Ruby +Hash pre deletion {:da_key1 => 80, :da_key2 => 90} +Hash post deletion {:da_key1 => 80} +``` + +### mrb_hash_keys + +```C +mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash); +``` + +Gets an array of keys. +#### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. This example gets an array of keys from a hash. + +```C +#include +#include +#include "mruby/hash.h" // Needs the hash header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash_keys; // Declare variable for getting an array of keys. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + get_hash_keys = mrb_hash_keys(mrb, new_hash); // get an array of keys. + mrb_funcall(mrb, obj, "method_name", 1, get_hash_keys); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` + +#### test_ext.rb + +```Ruby +class Example_Class + def method_name(a) + puts a + puts a.class + end +end +Example_Class.new +``` + +#### Result + +After compiling you should get these results. + +```Ruby +[:da_key1, :da_key2] +Array +``` + +### mrb_hash_clear + +```C +mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash); +``` + +Clears the hash. +#### Example + +In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument +and what class the passed in value is. This example clears the hash. In pure Ruby doing this is equivalent to +a = {:da_key1 => 80,:da_key2 => 90} +a.clear + +```C +#include +#include +#include "mruby/hash.h" // Needs the hash header. +#include "mruby/compile.h" + +int main(int argc, char *argv[]) +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash; // Declare variable for getting a hash. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + get_hash = mrb_hash_clear(mrb, new_hash); + mrb_funcall(mrb, obj, "another_method_name", 1, get_hash); + fclose(fp); + mrb_close(mrb); + return 0; +} +``` + +#### test_ext.rb + +```Ruby +class Example_Class + def method_name(a) + puts "Hash pre clear #{a}" + #puts a.class + end + # Show clear hash. + def another_method_name(a) + puts "Hash post clear #{a}" + end +end +Example_Class.new +``` + +#### Result + +After compiling you should get these results. + +```Ruby +Hash pre clear {:da_key1 => 80, :da_key2 => 90} +Hash post clear {} +``` -- cgit v1.2.3 From f282d947933b81a4c93f2cccf0313c3431458b51 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Fri, 17 Jul 2015 14:25:15 -0400 Subject: Update hash.h.md --- doc/api/mruby/hash.h.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'doc/api') diff --git a/doc/api/mruby/hash.h.md b/doc/api/mruby/hash.h.md index bdc2a7f2b..b7962696c 100644 --- a/doc/api/mruby/hash.h.md +++ b/doc/api/mruby/hash.h.md @@ -55,8 +55,11 @@ Sets a keys and values to hashes. #### Example In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. This example sets a key and value pair to a hash. In pure Ruby doing this is equivalent to a = {:da_key => 80}. +and what class the passed in value is. This example sets a key and value pair to a hash. In pure Ruby doing this is equivalent to: +```Ruby +a = {:da_key => 80} +``` ```C #include @@ -114,8 +117,12 @@ Gets a value from a key. #### Example In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. This example gets a value from a key. In pure Ruby doing this is equivalent to a = {:da_key => 80} -a[:da_key]. +and what class the passed in value is. This example gets a value from a key. In pure Ruby doing this is equivalent to: + +```Ruby +a = {:da_key => 80} +a[:da_key] +``` ```C #include @@ -177,9 +184,12 @@ Deletes hash key and value pair. #### Example In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. This example deletes hash key and value pair. In pure Ruby doing this is equivalent to a = {:da_key1 => 80,:da_key2 => 90} -a.delete(:da_key2) +and what class the passed in value is. This example deletes hash key and value pair. In pure Ruby doing this is equivalent to: +```Ruby +a = {:da_key1 => 80,:da_key2 => 90} +a.delete(:da_key2) +``` ```C #include @@ -308,9 +318,12 @@ Clears the hash. #### Example In this example we read from a Ruby file inside C. The Ruby code will print what you pass as an argument -and what class the passed in value is. This example clears the hash. In pure Ruby doing this is equivalent to +and what class the passed in value is. This example clears the hash. In pure Ruby doing this is equivalent to: + +```Ruby a = {:da_key1 => 80,:da_key2 => 90} a.clear +``` ```C #include -- cgit v1.2.3 From 6619dc4d75126d98f77e0989d542a079982639b3 Mon Sep 17 00:00:00 2001 From: "Ralph Desir(Mav7)" Date: Fri, 17 Jul 2015 14:43:55 -0400 Subject: Deleted range and string markdowns for now. --- doc/api/mruby/range.h.md | 0 doc/api/mruby/string.h.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 doc/api/mruby/range.h.md delete mode 100644 doc/api/mruby/string.h.md (limited to 'doc/api') diff --git a/doc/api/mruby/range.h.md b/doc/api/mruby/range.h.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3 From 18a0900a8241575795838f6b803208dfb7bfa0b1 Mon Sep 17 00:00:00 2001 From: Jun Hiroe Date: Sun, 19 Jul 2015 22:34:48 +0900 Subject: Fix indents; Indent is two spaces; Delete tabs [skip ci] --- doc/api/mruby/array.h.md | 223 +++++++++++++++++++------------------- doc/api/mruby/hash.h.md | 273 +++++++++++++++++++++++------------------------ doc/api/mruby/value.h.md | 40 +++---- 3 files changed, 267 insertions(+), 269 deletions(-) (limited to 'doc/api') diff --git a/doc/api/mruby/array.h.md b/doc/api/mruby/array.h.md index e1fb0003d..36c253cec 100644 --- a/doc/api/mruby/array.h.md +++ b/doc/api/mruby/array.h.md @@ -12,28 +12,27 @@ In this example we read from a Ruby file inside C. The Ruby code will print what #include "mruby/array.h" // Needs the array header. #include "mruby/compile.h" - int main(int argc, char *argv[]) -{ - mrb_value new_ary; // Declare variable. - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, new_ary); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_value new_ary; // Declare variable. + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; } ``` test.rb ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end + def method_name(a) + puts a + puts a.class + end end Example_Class.new ``` @@ -52,32 +51,32 @@ In this example we read from a Ruby file inside C. The Ruby code will print what #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_value new_ary; // Declare variable. - mrb_int random_value1 = 70; // Initialize variable - mrb_int random_value2 = 60; // Initialize variable - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); // Initialize ruby array. - /* Pushes the fixnum value from random_value1 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - /* Pushes the fixnum value from random_value2 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, new_ary); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; } ``` test.rb ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end + def method_name(a) + puts a + puts a.class + end end Example_Class.new ``` @@ -103,37 +102,37 @@ called pop_ary that will return the array alone(just to be clean) and you should #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_value new_ary; // Declare variable. - mrb_int random_value1 = 70; // Initialize variable - mrb_int random_value2 = 60; // Initialize variable - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); // Initialize ruby array. - /* Pushes the fixnum value from random_value1 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - /* Pushes the fixnum value from random_value2 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, new_ary); - mrb_ary_pop(mrb, new_ary); // Pops the last element of the array. In this case 60. - mrb_funcall(mrb, obj, "pop_ary", 1, new_ary); // Calls the method again to show the results. - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_ary); + mrb_ary_pop(mrb, new_ary); // Pops the last element of the array. In this case 60. + mrb_funcall(mrb, obj, "pop_ary", 1, new_ary); // Calls the method again to show the results. + fclose(fp); + mrb_close(mrb); + return 0; } ``` test.rb ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end - def pop_ary(a) - puts a - end + def method_name(a) + puts a + puts a.class + end + def pop_ary(a) + puts a + end end Example_Class.new ``` @@ -158,35 +157,35 @@ In this example we read from a Ruby file inside C. The Ruby code will print what #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_value ary_ref; // Declare variable. - mrb_value new_ary; // Declare variable. - mrb_int random_value1 = 70; // Initialize variable - mrb_int random_value2 = 60; // Initialize variable - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); // Initialize ruby array. - /* Pushes the fixnum value from random_value1 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - /* Pushes the fixnum value from random_value2 to the new_ary instance. */ - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - ary_ref = mrb_ary_ref(mrb, new_ary, 1); // Gets the value of new_ary's second element at index 1. - mrb_value obj = mrb_load_file(mrb,fp); - /* Passing the value from ary_ref to the method method_name.*/ - mrb_funcall(mrb, obj, "method_name", 1, ary_ref); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_value ary_ref; // Declare variable. + mrb_value new_ary; // Declare variable. + mrb_int random_value1 = 70; // Initialize variable + mrb_int random_value2 = 60; // Initialize variable + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); // Initialize ruby array. + /* Pushes the fixnum value from random_value1 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + /* Pushes the fixnum value from random_value2 to the new_ary instance. */ + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + ary_ref = mrb_ary_ref(mrb, new_ary, 1); // Gets the value of new_ary's second element at index 1. + mrb_value obj = mrb_load_file(mrb,fp); + /* Passing the value from ary_ref to the method method_name.*/ + mrb_funcall(mrb, obj, "method_name", 1, ary_ref); + fclose(fp); + mrb_close(mrb); + return 0; } ``` test.rb ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end + def method_name(a) + puts a + puts a.class + end end Example_Class.new ``` @@ -211,36 +210,36 @@ In this example we read from a Ruby file inside C. The Ruby code will print what #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_value new_ary; - mrb_value ary_obj; - mrb_int random_value1 = 70; - mrb_int random_value2 = 60; - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - FILE *fp = fopen("test.rb","r"); - new_ary = mrb_ary_new(mrb); - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); - mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); - /* Sets the fixnum value of 7 to the second index of the array.*/ - mrb_ary_set(mrb, new_ary, 2, mrb_fixnum_value(7)); - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "before_after", 1, new_ary); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_value new_ary; + mrb_value ary_obj; + mrb_int random_value1 = 70; + mrb_int random_value2 = 60; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + new_ary = mrb_ary_new(mrb); + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value1)); + mrb_ary_push(mrb, new_ary, mrb_fixnum_value(random_value2)); + /* Sets the fixnum value of 7 to the second index of the array.*/ + mrb_ary_set(mrb, new_ary, 2, mrb_fixnum_value(7)); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "before_after", 1, new_ary); + fclose(fp); + mrb_close(mrb); + return 0; } ``` test.rb ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end - def before_after(a) - puts a - end + def method_name(a) + puts a + puts a.class + end + def before_after(a) + puts a + end end Example_Class.new ``` diff --git a/doc/api/mruby/hash.h.md b/doc/api/mruby/hash.h.md index b7962696c..fa12ea670 100644 --- a/doc/api/mruby/hash.h.md +++ b/doc/api/mruby/hash.h.md @@ -17,19 +17,18 @@ to Hash.new. #include "mruby/hash.h" // Needs the hash header. #include "mruby/compile.h" - int main(int argc, char *argv[]) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - mrb_value new_hash; // Declare variable. - FILE *fp = fopen("test_ext.rb","r"); - new_hash = mrb_hash_new(mrb); // Initialize hash. - mrb_value obj = mrb_load_file(mrb,fp); - mrb_funcall(mrb, obj, "method_name", 1, new_hash); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + fclose(fp); + mrb_close(mrb); + return 0; } ``` @@ -37,10 +36,10 @@ int main(int argc, char *argv[]) ``` Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end + def method_name(a) + puts a + puts a.class + end end Example_Class.new ``` @@ -67,22 +66,21 @@ a = {:da_key => 80} #include "mruby/hash.h" // Needs the hash header. #include "mruby/compile.h" - int main(int argc, char *argv[]) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - mrb_value new_hash; // Declare variable. - mrb_sym hash_key = mrb_intern_cstr(mrb, "da_key"); // Declare a symbol. - mrb_int hash_value = 80; // Declare a fixnum value. - FILE *fp = fopen("test_ext.rb","r"); - new_hash = mrb_hash_new(mrb); // Initialize hash. - mrb_value obj = mrb_load_file(mrb,fp); - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key), mrb_fixnum_value(hash_value)); // Set values to hash. - mrb_funcall(mrb, obj, "method_name", 1, new_hash); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable. + mrb_sym hash_key = mrb_intern_cstr(mrb, "da_key"); // Declare a symbol. + mrb_int hash_value = 80; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key), mrb_fixnum_value(hash_value)); // Set values to hash. + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + fclose(fp); + mrb_close(mrb); + return 0; } ``` @@ -90,10 +88,10 @@ int main(int argc, char *argv[]) ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end + def method_name(a) + puts a + puts a.class + end end Example_Class.new ``` @@ -131,25 +129,25 @@ a[:da_key] #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - mrb_value new_hash; // Declare variable for new hash object. - mrb_value get_hash_value; // Declare variable for getting a value from a hash. - mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. - mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. - mrb_int hash_value_a = 80; // Declare a fixnum value. - mrb_int hash_value_b = 90; // Declare a fixnum value. - FILE *fp = fopen("test_ext.rb","r"); - new_hash = mrb_hash_new(mrb); // Initialize hash. - mrb_value obj = mrb_load_file(mrb,fp); - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. - get_hash_value = mrb_hash_get(mrb, new_hash, mrb_symbol_value(hash_key_b)); // Get value from hash. - mrb_funcall(mrb, obj, "method_name", 1, get_hash_value); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash_value; // Declare variable for getting a value from a hash. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + get_hash_value = mrb_hash_get(mrb, new_hash, mrb_symbol_value(hash_key_b)); // Get value from hash. + mrb_funcall(mrb, obj, "method_name", 1, get_hash_value); + fclose(fp); + mrb_close(mrb); + return 0; } ``` @@ -157,10 +155,10 @@ int main(int argc, char *argv[]) ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end + def method_name(a) + puts a + puts a.class + end end Example_Class.new ``` @@ -198,26 +196,27 @@ a.delete(:da_key2) #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - mrb_value new_hash; // Declare variable for new hash object. - mrb_value get_hash_value; // Declare variable for getting a value from a hash. - mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. - mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. - mrb_int hash_value_a = 80; // Declare a fixnum value. - mrb_int hash_value_b = 90; // Declare a fixnum value. - FILE *fp = fopen("test_ext.rb","r"); - new_hash = mrb_hash_new(mrb); // Initialize hash. - mrb_value obj = mrb_load_file(mrb,fp); - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. - mrb_funcall(mrb, obj, "method_name", 1, new_hash); - mrb_hash_delete_key(mrb, new_hash, mrb_symbol_value(hash_key_b)); - mrb_funcall(mrb, obj, "another_method_name", 1, new_hash); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash_value; // Declare variable for getting a value from a hash. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + mrb_hash_delete_key(mrb, new_hash, mrb_symbol_value(hash_key_b)); + mrb_funcall(mrb, obj, "another_method_name", 1, new_hash); + fclose(fp); + mrb_close(mrb); + return 0; } ``` @@ -225,14 +224,14 @@ int main(int argc, char *argv[]) ```Ruby class Example_Class - def method_name(a) - puts "Hash pre deletion #{a}" - #puts a.class - end - # Show deleted key and value pair. - def another_method_name(a) - puts "Hash post deletion #{a}" - end + def method_name(a) + puts "Hash pre deletion #{a}" + #puts a.class + end + # Show deleted key and value pair. + def another_method_name(a) + puts "Hash post deletion #{a}" + end end Example_Class.new ``` @@ -265,25 +264,25 @@ and what class the passed in value is. This example gets an array of keys from a #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - mrb_value new_hash; // Declare variable for new hash object. - mrb_value get_hash_keys; // Declare variable for getting an array of keys. - mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. - mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. - mrb_int hash_value_a = 80; // Declare a fixnum value. - mrb_int hash_value_b = 90; // Declare a fixnum value. - FILE *fp = fopen("test_ext.rb","r"); - new_hash = mrb_hash_new(mrb); // Initialize hash. - mrb_value obj = mrb_load_file(mrb,fp); - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. - get_hash_keys = mrb_hash_keys(mrb, new_hash); // get an array of keys. - mrb_funcall(mrb, obj, "method_name", 1, get_hash_keys); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash_keys; // Declare variable for getting an array of keys. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + get_hash_keys = mrb_hash_keys(mrb, new_hash); // get an array of keys. + mrb_funcall(mrb, obj, "method_name", 1, get_hash_keys); + fclose(fp); + mrb_close(mrb); + return 0; } ``` @@ -291,10 +290,10 @@ int main(int argc, char *argv[]) ```Ruby class Example_Class - def method_name(a) - puts a - puts a.class - end + def method_name(a) + puts a + puts a.class + end end Example_Class.new ``` @@ -332,26 +331,26 @@ a.clear #include "mruby/compile.h" int main(int argc, char *argv[]) -{ - mrb_state *mrb = mrb_open(); - if (!mrb) { /* handle error */ } - mrb_value new_hash; // Declare variable for new hash object. - mrb_value get_hash; // Declare variable for getting a hash. - mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. - mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. - mrb_int hash_value_a = 80; // Declare a fixnum value. - mrb_int hash_value_b = 90; // Declare a fixnum value. - FILE *fp = fopen("test_ext.rb","r"); - new_hash = mrb_hash_new(mrb); // Initialize hash. - mrb_value obj = mrb_load_file(mrb,fp); - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. - mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. - mrb_funcall(mrb, obj, "method_name", 1, new_hash); - get_hash = mrb_hash_clear(mrb, new_hash); - mrb_funcall(mrb, obj, "another_method_name", 1, get_hash); - fclose(fp); - mrb_close(mrb); - return 0; +{ + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + mrb_value new_hash; // Declare variable for new hash object. + mrb_value get_hash; // Declare variable for getting a hash. + mrb_sym hash_key_a = mrb_intern_cstr(mrb, "da_key1"); // Declare a symbol. + mrb_sym hash_key_b = mrb_intern_cstr(mrb, "da_key2"); // Declare a symbol. + mrb_int hash_value_a = 80; // Declare a fixnum value. + mrb_int hash_value_b = 90; // Declare a fixnum value. + FILE *fp = fopen("test_ext.rb","r"); + new_hash = mrb_hash_new(mrb); // Initialize hash. + mrb_value obj = mrb_load_file(mrb,fp); + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_a), mrb_fixnum_value(hash_value_a)); // Set values to hash. + mrb_hash_set(mrb, new_hash, mrb_symbol_value(hash_key_b), mrb_fixnum_value(hash_value_b)); // Set values to hash. + mrb_funcall(mrb, obj, "method_name", 1, new_hash); + get_hash = mrb_hash_clear(mrb, new_hash); + mrb_funcall(mrb, obj, "another_method_name", 1, get_hash); + fclose(fp); + mrb_close(mrb); + return 0; } ``` @@ -359,14 +358,14 @@ int main(int argc, char *argv[]) ```Ruby class Example_Class - def method_name(a) - puts "Hash pre clear #{a}" - #puts a.class - end - # Show clear hash. - def another_method_name(a) - puts "Hash post clear #{a}" - end + def method_name(a) + puts "Hash pre clear #{a}" + #puts a.class + end + # Show clear hash. + def another_method_name(a) + puts "Hash post clear #{a}" + end end Example_Class.new ``` diff --git a/doc/api/mruby/value.h.md b/doc/api/mruby/value.h.md index f3ae2d421..fbf2dadf1 100644 --- a/doc/api/mruby/value.h.md +++ b/doc/api/mruby/value.h.md @@ -38,10 +38,10 @@ main(void) test.rb ```Ruby class My_Class - def method_name(s) - puts s - puts s.class - end + def method_name(s) + puts s + puts s.class + end end a = My_Class.new ``` @@ -86,10 +86,10 @@ main(void) test.rb ```Ruby class My_Class - def method_name(s) - puts s - puts s.class - end + def method_name(s) + puts s + puts s.class + end end a = My_Class.new ``` @@ -134,10 +134,10 @@ main(void) test.rb ```Ruby class My_Class - def method_name(s) - puts s - puts s.class - end + def method_name(s) + puts s + puts s.class + end end a = My_Class.new ``` @@ -181,10 +181,10 @@ main(void) test.rb ```Ruby class My_Class - def method_name(s) - puts s - puts s.class - end + def method_name(s) + puts s + puts s.class + end end a = My_Class.new ``` @@ -229,10 +229,10 @@ main(void) test.rb ```Ruby class My_Class - def method_name(s) - puts s - puts s.class - end + def method_name(s) + puts s + puts s.class + end end a = My_Class.new ``` -- cgit v1.2.3 From 0f2b3643ba47a0778eb8571b029e93f16e142b23 Mon Sep 17 00:00:00 2001 From: "Ralph Desir(Mav7)" Date: Sun, 30 Aug 2015 20:20:45 -0400 Subject: Added string markdown. --- doc/api/mruby/string.h.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/api/mruby/string.h.md (limited to 'doc/api') diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From a2f6152be8a2d1775830f32ca955864237fd1081 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Sun, 30 Aug 2015 23:55:55 -0400 Subject: Update string.h.md --- doc/api/mruby/string.h.md | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md index e69de29bb..b031c564c 100644 --- a/doc/api/mruby/string.h.md +++ b/doc/api/mruby/string.h.md @@ -0,0 +1,10 @@ +### mrb_str_plus +```C + mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value); +``` +Adds to strings together. +### mrb_ptr_to_str +```C + mrb_value mrb_ptr_to_str(mrb_state *, void*); +``` +Converts pointer into a Ruby string. -- cgit v1.2.3 From 00dd2dfa3939d15e437d1779a7de23b1018a7cd7 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Mon, 31 Aug 2015 14:11:17 -0400 Subject: Update string.h.md --- doc/api/mruby/string.h.md | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md index b031c564c..e2a10c2cf 100644 --- a/doc/api/mruby/string.h.md +++ b/doc/api/mruby/string.h.md @@ -8,3 +8,8 @@ Adds to strings together. mrb_value mrb_ptr_to_str(mrb_state *, void*); ``` Converts pointer into a Ruby string. +### mrb_obj_as_string +```C + mrb_obj_as_string(mrb_state *mrb, mrb_value obj); +``` +Returns an object as a Ruby string. -- cgit v1.2.3 From d78d0017342ef42cc0d5db517446c805e23ae344 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Mon, 31 Aug 2015 23:16:45 -0400 Subject: Update string.h.md --- doc/api/mruby/string.h.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'doc/api') diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md index e2a10c2cf..428a3ca40 100644 --- a/doc/api/mruby/string.h.md +++ b/doc/api/mruby/string.h.md @@ -10,6 +10,36 @@ Adds to strings together. Converts pointer into a Ruby string. ### mrb_obj_as_string ```C - mrb_obj_as_string(mrb_state *mrb, mrb_value obj); + mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); ``` Returns an object as a Ruby string. +### mrb_str_resize +```C + mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); +``` +Resizes the string's length. +### mrb_str_substr +```C + mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); +``` +Returns a sub string. +### mrb_string_type +```C + mrb_value mrb_string_type(mrb_state *mrb, mrb_value str); +``` +Returns a Ruby string type. +### mrb_str_new_cstr +```C + const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr); +``` +Returns a Ruby string as a C string. +### mrb_str_dup +```C + mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); +``` +Duplicates a string object. +### mrb_str_intern +```C + mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); +``` +Returns a symbol from a passed in string. -- cgit v1.2.3 From 8ad8c547dda2850e67113f6d5a8c4b4d186fe27f Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Tue, 1 Sep 2015 13:50:27 -0400 Subject: Update string.h.md --- doc/api/mruby/string.h.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md index 428a3ca40..1268792e0 100644 --- a/doc/api/mruby/string.h.md +++ b/doc/api/mruby/string.h.md @@ -1,3 +1,7 @@ +## Macros +### mrb_str_ptr(s) +Returns a pointer from a Ruby string. +## Functions ### mrb_str_plus ```C mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value); @@ -43,3 +47,45 @@ Duplicates a string object. mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); ``` Returns a symbol from a passed in string. +### mrb_str_to_str +```C + mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str); +``` +Returns a converted string type. +### mrb_str_equal +```C + mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); +``` +Returns true if the strings match and false if the strings don't match. +### mrb_str_cat +```C + mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len); +``` +Returns a concated string comprised of a Ruby string and a C string. +### mrb_str_cat_cstr +```C + mrb_value mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2); +``` +Returns a concated string comprised of a Ruby string and a C string(A shorter alternative to mrb_str_cat). +### mrb_str_append +```C + mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2); +``` +Adds str2 to the end of str1. +### mrb_str_cmp +```C + int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); +``` +Returns 0 if both Ruby strings are equal. +Returns a value < 0 if Ruby str1 is less than Ruby str2. +Returns a value > 0 if Ruby str2 is greater than Ruby str1. +### mrb_str_to_cstr +```C + char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str); +``` +Returns a C string from a Ruby string. +### mrb_str_inspect +```C + mrb_str_inspect(mrb_state *mrb, mrb_value str); +``` +Returns a printable version of str, surrounded by quote marks, with special characters escaped. -- cgit v1.2.3 From 14f0e4a4e4657fe0dc6512cf735c9c75201bd406 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 2 Sep 2015 15:09:50 +0900 Subject: update string.h.md; ref #2931 --- doc/api/mruby/string.h.md | 2 +- src/string.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'doc/api') diff --git a/doc/api/mruby/string.h.md b/doc/api/mruby/string.h.md index 1268792e0..7bf94df5b 100644 --- a/doc/api/mruby/string.h.md +++ b/doc/api/mruby/string.h.md @@ -69,7 +69,7 @@ Returns a concated string comprised of a Ruby string and a C string. Returns a concated string comprised of a Ruby string and a C string(A shorter alternative to mrb_str_cat). ### mrb_str_append ```C - mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2); + mrb_value mrb_str_append(mrb_state *mrb, mrb_value str1, mrb_value str2); ``` Adds str2 to the end of str1. ### mrb_str_cmp diff --git a/src/string.c b/src/string.c index e5f446bde..73ef341bb 100644 --- a/src/string.c +++ b/src/string.c @@ -2385,10 +2385,10 @@ mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2) } MRB_API mrb_value -mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2) +mrb_str_append(mrb_state *mrb, mrb_value str1, mrb_value str2) { str2 = mrb_str_to_str(mrb, str2); - return mrb_str_cat_str(mrb, str, str2); + return mrb_str_cat_str(mrb, str1, str2); } #define CHAR_ESC_LEN 13 /* sizeof(\x{ hex of 32bit unsigned int } \0) */ -- cgit v1.2.3 From da0dc6937da11dec6c47f93f24bfac3ca02d1464 Mon Sep 17 00:00:00 2001 From: "Ralph Desir(Mav7)" Date: Wed, 2 Sep 2015 18:19:53 -0400 Subject: doc/api/mruby/version.h.md --- doc/api/mruby/version.h.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/api/mruby/version.h.md (limited to 'doc/api') diff --git a/doc/api/mruby/version.h.md b/doc/api/mruby/version.h.md new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From 6beae5ec71718f36efbb60037f929f1b5e279208 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Wed, 2 Sep 2015 18:45:03 -0400 Subject: Created version.h markdown. --- doc/api/mruby/version.h.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/version.h.md b/doc/api/mruby/version.h.md index e69de29bb..daf87077d 100644 --- a/doc/api/mruby/version.h.md +++ b/doc/api/mruby/version.h.md @@ -0,0 +1,33 @@ +#### Macros +### MRUBY_RUBY_VERSION +The version of Ruby used by mruby. +### MRUBY_RUBY_ENGINE +Ruby engine. +### MRUBY_VERSION +The mruby version. +### MRUBY_RELEASE_MAJOR +Major release version. +### MRUBY_RELEASE_MINOR +Minor release version. +### MRUBY_RELEASE_NO +Release number. +### MRUBY_RELEASE_DATE +Release date as a string. +### MRUBY_RELEASE_YEAR +Release year. +### MRUBY_RELEASE_MONTH +Release month. +### MRUBY_RELEASE_DAY +Release day. +### MRUBY_BIRTH_YEAR +The year mruby was first created. +### MRUBY_AUTHOR +Mruby's authors. +### MRB_STRINGIZE0(expr) +A passed in expression. +### MRB_STRINGIZE(expr) +Passes in an expression to MRB_STRINGIZE0. +### MRUBY_DESCRIPTION +mruby's version, and release date. +### MRUBY_COPYRIGHT +mruby's copyright information. -- cgit v1.2.3 From 1bd5c4859615f3b6012093ace07b032c86336c69 Mon Sep 17 00:00:00 2001 From: "Ralph Desir(Mav7)" Date: Wed, 2 Sep 2015 18:52:16 -0400 Subject: Added regular expression header markdown. --- doc/api/mruby/re.h.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/api/mruby/re.h.md (limited to 'doc/api') diff --git a/doc/api/mruby/re.h.md b/doc/api/mruby/re.h.md new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From 79aa0866cea908d9ce03da4a3828816e1abed7cb Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Wed, 2 Sep 2015 18:57:00 -0400 Subject: Added reg.h markdown. --- doc/api/mruby/re.h.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/re.h.md b/doc/api/mruby/re.h.md index e69de29bb..01e18c6a5 100644 --- a/doc/api/mruby/re.h.md +++ b/doc/api/mruby/re.h.md @@ -0,0 +1,3 @@ +#### Macros +### REGEXP_CLASS +A string with the name of the REGEXP class. -- cgit v1.2.3 From 93aaa0673678ec53cf977ac908e962225db962cf Mon Sep 17 00:00:00 2001 From: "Ralph Desir(Mav7)" Date: Thu, 3 Sep 2015 14:16:57 -0400 Subject: Added range markdown. --- doc/api/mruby/range.h.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/api/mruby/range.h.md (limited to 'doc/api') diff --git a/doc/api/mruby/range.h.md b/doc/api/mruby/range.h.md new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From e1beb502ab133d4bfae5fa3df856aa2b851e2655 Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Thu, 3 Sep 2015 14:19:02 -0400 Subject: Cleaned up the re.h markdown. --- doc/api/mruby/re.h.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc/api') diff --git a/doc/api/mruby/re.h.md b/doc/api/mruby/re.h.md index 01e18c6a5..f5cd2a71e 100644 --- a/doc/api/mruby/re.h.md +++ b/doc/api/mruby/re.h.md @@ -1,3 +1,3 @@ -#### Macros -### REGEXP_CLASS +### Macros +#### REGEXP_CLASS A string with the name of the REGEXP class. -- cgit v1.2.3 From 8a09515c6c7b1e8315c6b1accb92cb93d8e8138c Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Thu, 3 Sep 2015 14:20:16 -0400 Subject: Cleaned up the version.h markdown. --- doc/api/mruby/version.h.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'doc/api') diff --git a/doc/api/mruby/version.h.md b/doc/api/mruby/version.h.md index daf87077d..f627b1da1 100644 --- a/doc/api/mruby/version.h.md +++ b/doc/api/mruby/version.h.md @@ -1,33 +1,33 @@ -#### Macros -### MRUBY_RUBY_VERSION +### Macros +#### MRUBY_RUBY_VERSION The version of Ruby used by mruby. -### MRUBY_RUBY_ENGINE +#### MRUBY_RUBY_ENGINE Ruby engine. -### MRUBY_VERSION +#### MRUBY_VERSION The mruby version. -### MRUBY_RELEASE_MAJOR +#### MRUBY_RELEASE_MAJOR Major release version. -### MRUBY_RELEASE_MINOR +#### MRUBY_RELEASE_MINOR Minor release version. -### MRUBY_RELEASE_NO +#### MRUBY_RELEASE_NO Release number. -### MRUBY_RELEASE_DATE +#### MRUBY_RELEASE_DATE Release date as a string. -### MRUBY_RELEASE_YEAR +#### MRUBY_RELEASE_YEAR Release year. -### MRUBY_RELEASE_MONTH +#### MRUBY_RELEASE_MONTH Release month. -### MRUBY_RELEASE_DAY +#### MRUBY_RELEASE_DAY Release day. -### MRUBY_BIRTH_YEAR +#### MRUBY_BIRTH_YEAR The year mruby was first created. -### MRUBY_AUTHOR +#### MRUBY_AUTHOR Mruby's authors. -### MRB_STRINGIZE0(expr) +#### MRB_STRINGIZE0(expr) A passed in expression. -### MRB_STRINGIZE(expr) +#### MRB_STRINGIZE(expr) Passes in an expression to MRB_STRINGIZE0. -### MRUBY_DESCRIPTION +#### MRUBY_DESCRIPTION mruby's version, and release date. -### MRUBY_COPYRIGHT +#### MRUBY_COPYRIGHT mruby's copyright information. -- cgit v1.2.3 From 743432d4ecc2052f6808d1e1012eb356e85ccb1e Mon Sep 17 00:00:00 2001 From: Ralph Desir Date: Thu, 3 Sep 2015 14:52:21 -0400 Subject: Update range.h.md --- doc/api/mruby/range.h.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'doc/api') diff --git a/doc/api/mruby/range.h.md b/doc/api/mruby/range.h.md index e69de29bb..188e6ede6 100644 --- a/doc/api/mruby/range.h.md +++ b/doc/api/mruby/range.h.md @@ -0,0 +1,47 @@ +#### mrb_range_new +```C + mrb_value mrb_range_new(mrb_state*, mrb_value, mrb_value, mrb_bool); +``` +Initializes a Range. The first mrb_value being the beginning value and second being the ending value. +The third parameter is an mrb_bool value that represents the inclusion or exclusion of the last value. +If the third parameter is 0 then it includes the last value in the range. If the third parameter is 1 +then it excludes the last value in the range. +C code +```C + #include + #include + #include "mruby/range.h" // Needs the range header. + #include "mruby/compile.h" + + int main(int argc, char *argv[]) + { + mrb_int beg = 0; + mrb_int end = 2; + mrb_bool exclude = 1; + mrb_value range_obj; + mrb_state *mrb = mrb_open(); + if (!mrb) { /* handle error */ } + FILE *fp = fopen("test.rb","r"); + range_obj = mrb_range_new(mrb, mrb_fixnum_value(beg), mrb_fixnum_value(end), exclude); + mrb_value obj = mrb_load_file(mrb,fp); + mrb_funcall(mrb, obj, "method_name", 1, range_obj); + fclose(fp); + mrb_close(mrb); + return 0; + } +``` +Ruby code +```Ruby + class Example_Class + def method_name(a) + puts a + puts a.class + end + end + Example_Class.new +``` +This returns the following: +```Ruby + 0...2 + Range +``` -- cgit v1.2.3