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