mruby/mruby — pull request #1676 by take-cheeze (2014-02-01 13:03:14+00:00)
Title: Support script only tool.

Currently mrbgem tools can only be written in C.
This pull request will make tools to support tool only written in mruby script.

Basically it defines default C *main* function for mruby script.

For example there is a mrbgem with following files:
* mrbgem.rake:
```Ruby
MRuby::Gem::Specification.new('testgem') do |spec|
spec.license = 'MIT'
spec.author = 'test'
spec.bins = ['test']
end
```
* testgem/tools/test/test.rb
```Ruby
p 'Test'
p $0
p ARGV
```
When it is built executable bin/test will be created and when you run it should output
```Shell
$ ./bin/test 0 1 2
"Test"
"./bin/test"
["0", "1", "2"]
```

Default main function will set *argv[0]* as *$0* and rest of argv as *ARGV* global variables.

Here is how script tool building works:
Whenever there is no object file to generate and there is \*.rb files in the same directory *libmruby_script_main.a*(which holds default main function) will be linked.
And if there is object files to generate and \*.rb files in the tool directory, the scripts will be compiled to C symbol *const uint8_t mrb_main_irep[]*. This symbol can be referenced by adding the following line to C code.
```C
extern const uint8_t mrb_main_irep[];
```