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 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(+) 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 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(+) 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(-) 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 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