Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
e2798541
Commit
e2798541
authored
Dec 12, 2015
by
Ralph Desir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
One space indentation.
parent
4e267d74
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
7 deletions
+64
-7
include/mruby.h
include/mruby.h
+64
-7
No files found.
include/mruby.h
View file @
e2798541
...
@@ -182,6 +182,7 @@ typedef mrb_value (*mrb_func_t)(mrb_state *mrb, mrb_value);
...
@@ -182,6 +182,7 @@ typedef mrb_value (*mrb_func_t)(mrb_state *mrb, mrb_value);
* !!!c
* !!!c
* void mrb_example_gem_init(mrb_state* mrb) {
* void mrb_example_gem_init(mrb_state* mrb) {
* struct RClass *example_class;
* struct RClass *example_class;
*
* example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class);
* example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class);
* }
* }
*
*
...
@@ -199,6 +200,7 @@ MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct
...
@@ -199,6 +200,7 @@ MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct
/**
/**
* Defines a new module.
* Defines a new module.
*
* @param [mrb_state *] mrb_state* The current mruby state.
* @param [mrb_state *] mrb_state* The current mruby state.
* @param [const char *] char* The name of the module.
* @param [const char *] char* The name of the module.
* @return [struct RClass *] Reference to the newly defined module.
* @return [struct RClass *] Reference to the newly defined module.
...
@@ -243,6 +245,7 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*);
...
@@ -243,6 +245,7 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*);
* mrb_value example_method(mrb_state* mrb, mrb_value self)
* mrb_value example_method(mrb_state* mrb, mrb_value self)
* {
* {
* puts("Executing example command!");
* puts("Executing example command!");
*
* return self;
* return self;
* }
* }
*
*
...
@@ -267,16 +270,20 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n
...
@@ -267,16 +270,20 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n
* # Ruby style
* # Ruby style
* class Foo
* class Foo
* def Foo.bar
* def Foo.bar
*
* end
* end
* end
* end
*
*
* // C style
* // C style
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
*
* return mrb_nil_value();
* return mrb_nil_value();
* }
* }
* void mrb_example_gem_init(mrb_state* mrb){
* void mrb_example_gem_init(mrb_state* mrb){
* struct RClass *foo;
* struct RClass *foo;
*
* foo = mrb_define_class(mrb, "Foo", mrb->object_class);
* foo = mrb_define_class(mrb, "Foo", mrb->object_class);
*
* mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
* mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
* }
* }
* @param [mrb_state *] mrb_state* The MRuby state reference.
* @param [mrb_state *] mrb_state* The MRuby state reference.
...
@@ -296,15 +303,19 @@ MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char
...
@@ -296,15 +303,19 @@ MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char
* # Ruby style
* # Ruby style
* module Foo
* module Foo
* def Foo.bar
* def Foo.bar
*
* end
* end
* end
* end
* // C style
* // C style
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
*
* return mrb_nil_value();
* return mrb_nil_value();
* }
* }
* void mrb_example_gem_init(mrb_state* mrb){
* void mrb_example_gem_init(mrb_state* mrb){
* struct RClass *foo;
* struct RClass *foo;
*
* foo = mrb_define_module(mrb, "Foo");
* foo = mrb_define_module(mrb, "Foo");
*
* mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
* mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
* }
* }
* @param [mrb_state *] mrb_state* The MRuby state reference.
* @param [mrb_state *] mrb_state* The MRuby state reference.
...
@@ -329,13 +340,16 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*,
...
@@ -329,13 +340,16 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*,
* // C style
* // C style
* #include <stdio.h>
* #include <stdio.h>
* #include <mruby.h>
* #include <mruby.h>
*
* void
* void
* mrb_example_gem_init(mrb_state* mrb){
* mrb_example_gem_init(mrb_state* mrb){
*
* mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
* mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
* }
* }
*
*
* mrb_value
* mrb_value
* mrb_example_gem_final(mrb_state* mrb){
* mrb_example_gem_final(mrb_state* mrb){
*
* }
* }
* @param [mrb_state *] mrb_state* The MRuby state reference.
* @param [mrb_state *] mrb_state* The MRuby state reference.
* @param [struct RClass *] RClass* A class or module the constant is defined in.
* @param [struct RClass *] RClass* A class or module the constant is defined in.
...
@@ -353,6 +367,7 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
...
@@ -353,6 +367,7 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
*
*
* class ExampleClassA
* class ExampleClassA
* def example_method
* def example_method
*
* "example"
* "example"
* end
* end
* end
* end
...
@@ -360,6 +375,7 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
...
@@ -360,6 +375,7 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
*
*
* class ExampleClassB < ExampleClassA
* class ExampleClassB < ExampleClassA
* undef_method :example_method
* undef_method :example_method
*
* end
* end
*
*
* ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
* ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
...
@@ -370,6 +386,7 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
...
@@ -370,6 +386,7 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
*
*
* mrb_value
* mrb_value
* mrb_example_method(mrb_state *mrb){
* mrb_example_method(mrb_state *mrb){
*
* return mrb_str_new_cstr(mrb, "example");
* return mrb_str_new_cstr(mrb, "example");
* }
* }
*
*
...
@@ -378,13 +395,20 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
...
@@ -378,13 +395,20 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
* struct RClass *example_class_a;
* struct RClass *example_class_a;
* struct RClass *example_class_b;
* struct RClass *example_class_b;
* struct RClass *example_class_c;
* struct RClass *example_class_c;
*
* example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
* example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
*
* mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
* mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
*
* example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
* example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
*
* example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
* example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
*
* mrb_undef_method(mrb, example_class_c, "example_method");
* mrb_undef_method(mrb, example_class_c, "example_method");
* }
* }
*
* mrb_example_gem_final(mrb_state* mrb){
* mrb_example_gem_final(mrb_state* mrb){
*
* }
* }
* @param [mrb_state*] mrb_state* The mruby state reference.
* @param [mrb_state*] mrb_state* The mruby state reference.
* @param [struct RClass*] RClass* A class the method will be undefined from.
* @param [struct RClass*] RClass* A class the method will be undefined from.
...
@@ -399,6 +423,7 @@ MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
...
@@ -399,6 +423,7 @@ MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
* # Ruby style
* # Ruby style
* class ExampleClass
* class ExampleClass
* def self.example_method
* def self.example_method
*
* "example"
* "example"
* end
* end
* end
* end
...
@@ -411,17 +436,24 @@ MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
...
@@ -411,17 +436,24 @@ MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
*
*
* mrb_value
* mrb_value
* mrb_example_method(mrb_state *mrb){
* mrb_example_method(mrb_state *mrb){
*
* return mrb_str_new_cstr(mrb, "example");
* return mrb_str_new_cstr(mrb, "example");
* }
* }
*
* void
* void
* mrb_example_gem_init(mrb_state* mrb){
* mrb_example_gem_init(mrb_state* mrb){
* struct RClass *example_class;
* struct RClass *example_class;
*
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
*
* mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
* mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
*
* mrb_undef_class_method(mrb, example_class, "example_method");
* mrb_undef_class_method(mrb, example_class, "example_method");
* }
* }
*
* void
* void
* mrb_example_gem_final(mrb_state* mrb){
* mrb_example_gem_final(mrb_state* mrb){
*
* }
* }
* @param [mrb_state*] mrb_state* The mruby state reference.
* @param [mrb_state*] mrb_state* The mruby state reference.
* @param [RClass*] RClass* A class the class method will be undefined from.
* @param [RClass*] RClass* A class the class method will be undefined from.
...
@@ -436,6 +468,7 @@ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
...
@@ -436,6 +468,7 @@ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
*
*
* # Ruby style
* # Ruby style
* class ExampleClass
* class ExampleClass
*
* end
* end
*
*
* p ExampleClass # => #<ExampleClass:0x9958588>
* p ExampleClass # => #<ExampleClass:0x9958588>
...
@@ -449,7 +482,9 @@ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
...
@@ -449,7 +482,9 @@ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
* mrb_value obj;
* mrb_value obj;
*
*
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end
*
* obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
* obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
*
* mrb_p(mrb, obj); // => Kernel#p
* mrb_p(mrb, obj); // => Kernel#p
* }
* }
* @param [mrb_state*] mrb The current mruby state.
* @param [mrb_state*] mrb The current mruby state.
...
@@ -479,7 +514,9 @@ MRB_API mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
...
@@ -479,7 +514,9 @@ MRB_API mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
* mrb_value obj;
* mrb_value obj;
*
*
* example_class = mrb_class_new(mrb, mrb->object_class);
* example_class = mrb_class_new(mrb, mrb->object_class);
*
* obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>
* obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>
*
* mrb_p(mrb, obj); // => Kernel#p
* mrb_p(mrb, obj); // => Kernel#p
* }
* }
*
*
...
@@ -588,6 +625,7 @@ MRB_API mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char
...
@@ -588,6 +625,7 @@ MRB_API mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char
* # Ruby style
* # Ruby style
* class ExampleClass
* class ExampleClass
* def example_method
* def example_method
*
* end
* end
* end
* end
*
*
...
@@ -601,8 +639,11 @@ MRB_API mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char
...
@@ -601,8 +639,11 @@ MRB_API mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char
* mrb_bool obj_resp;
* mrb_bool obj_resp;
*
*
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
*
* mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE());
* mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE());
*
* mid = mrb_intern_str(mrb, mrb_str_new_cstr(mrb, "example_method" ));
* mid = mrb_intern_str(mrb, mrb_str_new_cstr(mrb, "example_method" ));
*
* obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world)
* obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world)
*
*
* // If mrb_obj_respond_to returns 1 then puts "True"
* // If mrb_obj_respond_to returns 1 then puts "True"
...
@@ -755,16 +796,24 @@ mrb_get_argc(mrb_state *mrb) /* get argc */
...
@@ -755,16 +796,24 @@ mrb_get_argc(mrb_state *mrb) /* get argc */
* #include <stdio.h>
* #include <stdio.h>
* #include <mruby.h>
* #include <mruby.h>
* #include "mruby/compile.h"
* #include "mruby/compile.h"
*
* int
* int
* main()
* main()
* {
* {
* mrb_int i = 99;
* mrb_int i = 99;
*
* mrb_state *mrb = mrb_open();
* mrb_state *mrb = mrb_open();
*
* if (!mrb) { }
* if (!mrb) { }
*
* FILE *fp = fopen("test.rb","r");
* FILE *fp = fopen("test.rb","r");
*
* mrb_value obj = mrb_load_file(mrb,fp);
* mrb_value obj = mrb_load_file(mrb,fp);
*
* mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
* mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
*
* fclose(fp);
* fclose(fp);
*
* mrb_close(mrb);
* mrb_close(mrb);
* }
* }
* @param [mrb_state*] mrb_state* The current mruby state.
* @param [mrb_state*] mrb_state* The current mruby state.
...
@@ -785,13 +834,21 @@ MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...);
...
@@ -785,13 +834,21 @@ MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...);
* main()
* main()
* {
* {
* mrb_int i = 99;
* mrb_int i = 99;
*
* mrb_state *mrb = mrb_open();
* mrb_state *mrb = mrb_open();
*
* if (!mrb) { }
* if (!mrb) { }
*
* mrb_sym m_sym = mrb_intern_cstr(mrb, "method_name"); // Symbol for method.
* mrb_sym m_sym = mrb_intern_cstr(mrb, "method_name"); // Symbol for method.
*
* FILE *fp = fopen("test.rb","r");
* FILE *fp = fopen("test.rb","r");
*
* mrb_value obj = mrb_load_file(mrb,fp);
* mrb_value obj = mrb_load_file(mrb,fp);
*
* mrb_funcall_argv(mrb, obj, m_sym, 1, &obj); // Calling ruby function from test.rb.
* mrb_funcall_argv(mrb, obj, m_sym, 1, &obj); // Calling ruby function from test.rb.
*
* fclose(fp);
* fclose(fp);
*
* mrb_close(mrb);
* mrb_close(mrb);
* }
* }
* @param [mrb_state*] mrb_state* The current mruby state.
* @param [mrb_state*] mrb_state* The current mruby state.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment