summaryrefslogtreecommitdiffhomepage
path: root/doc/api
diff options
context:
space:
mode:
Diffstat (limited to 'doc/api')
-rw-r--r--doc/api/mruby.h.md20
-rw-r--r--doc/api/mruby/array.h.md223
-rw-r--r--doc/api/mruby/hash.h.md273
-rw-r--r--doc/api/mruby/string.h.md2
-rw-r--r--doc/api/mruby/value.h.md40
5 files changed, 279 insertions, 279 deletions
diff --git a/doc/api/mruby.h.md b/doc/api/mruby.h.md
index 8862fee2c..06bab2d56 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 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) {
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/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/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
```