Skip to content

Commit fe07452

Browse files
committed
update README
1 parent 3d731d9 commit fe07452

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# mruby CLI
2-
A utility for setting up a CLI with [mruby](https://www.mruby.org) for compiling binaries for Linux, OS X, and Windows.
2+
A utility for setting up a CLI with [mruby](https://www.mruby.org) that compiles binaries to Linux, OS X, and Windows.
33

4-
## Docker Setup
5-
You'll need [Docker](https://docs.docker.com/installation/) and [Docker Compose](https://docs.docker.com/compose/install/) installed first.
4+
## Prequisites
5+
You'll need the following installed and in your `PATH`:
66

7-
## Building a CLI app
8-
This assumes you have a copy of the `mruby-cli` binary in your `PATH`.
7+
* [mruby-cli](https://github.com/hone/mruby-cli/releases)
8+
* [Docker](https://docs.docker.com/installation/)
9+
* [Docker Compose](https://docs.docker.com/compose/install/)
910

11+
## Building a CLI app
1012
To generate a new mruby CLI, there's a `--setup` option.
1113

1214
```sh
@@ -36,6 +38,35 @@ root@3da278e931fc:/home/mruby/code# mruby/build/host/bin/hello_world
3638
Hello World
3739
```
3840

41+
## Hello World
42+
43+
Building the canonical hello world example in mruby-cli is quite simple. The two files of note from the generate skeleton are `mrblib/hello_world.rb` and `mrbgem.rake`. The CLI hooks into the `__main__` method defined here and passes all the arguments as `argv`.
44+
45+
`mrblib/hello_world.rb`:
46+
```ruby
47+
def __main__(argv)
48+
puts "Hello World"
49+
end
50+
```
51+
52+
### Dependencies
53+
The rubygems equivalent is mrbgems. [mgem-list](https://github.com/mruby/mgem-list) contains a list of mgems you can pull from. By default mruby does not include everything in the kitchen sink like MRI. This means to even get `puts`, we need to include the `mruby-print`. The list of core gems can be found [here](https://github.com/mruby/mruby/tree/master/mrbgems). Adding dependencies is simple, you just need to add a line near the bottom of your `mrbgem.rake` with the two arguments: name and where it comes from.
54+
55+
`mrbgem.rake`:
56+
```ruby
57+
MRuby::Gem::Specification.new('hello_world') do |spec|
58+
spec.license = 'MIT'
59+
spec.author = 'Terence Lee'
60+
spec.summary = 'Hello World'
61+
spec.bins = ['hello_world']
62+
63+
spec.add_dependency 'mruby-print', :core => 'mruby-print'
64+
spec.add_dependency 'mruby-mtest', :mgem => 'mruby-test'
65+
end
66+
```
67+
### CLI Architecture
68+
The app is built from two parts a C wrapper in `tools/` and a mruby part in `mrblib/`. The C wrapper is fairly minimal and executes the `__main__` method in mruby and instantiates ARGV and passes it to the mruby code. The rest of the CLI is written in mruby. You can't have subfolders in `mrblib/` but you can have as many files in `mrblib/`. All these files are precompiled into mruby bytecode The build tool for mruby is written in CRuby (MRI).
69+
3970
### Testing
4071
By default, `mruby-cli` generates two kinds of tests: mtest and bintest.
4172

@@ -53,8 +84,9 @@ These are integration tests, are written in CRuby (MRI), and go in the `bintest/
5384
$ docker-compose run bintest
5485
```
5586

56-
### CLI Architecture
57-
The app is built from two parts a C wrapper in `tools/` and a mruby part in `mrblib/`. The C wrapper is fairly minimal and executes the `__main__` method in mruby and instantiates ARGV and passes it to the mruby code. The rest of the CLI is written in mruby. The build tool for mruby is written in CRuby (MRI).
87+
## Examples
88+
* `mruby-cli` itself is an app generated by `mruby-cli`, so you can explore this repo on how to build one.
89+
* [mruby-eso-research](https://github.com/hone/mruby-eso-research) - an app for managing crafting research in Elder Scrolls Online. It uses YAML as the data store.
5890

5991
## mruby-cli Development
6092
This app is built as a mruby-cli app, so you just need to run: `docker-compose run compile` and find the binaries in the appropriate directories.

0 commit comments

Comments
 (0)