Skip to content
Browse files

Update README.md

  • Loading branch information...
1 parent b8d28fd commit 47ea62a1e536d14317b4b2dd14fec7ae789e9351 @RyanScottLewis committed Dec 24, 2012
Showing with 53 additions and 24 deletions.
  1. +53 −24 README.md
View
77 README.md
@@ -4,45 +4,74 @@ Use [mruby][mruby] from within [lua][lua].
## Install
-```shell
-$ rake
+### LuaRocks
+
+> NOTE: This is not implemented yet.
+
+```sh
+$ luarocks install mruby
```
-## Usage
+### Source
-### Simple
+> NOTE: If `rake` is not installed, you can use the `minirake` executable in `lib/mruby/minirake/`.
+> The `Makefile` simply calls `rake`.
-```lua
-require "mruby"
+```sh
+$ rake
+```
+
+Or:
-mruby.run(" puts 'Hello, world!' ")
+```sh
+$ make
```
-### Advanced
+This will compile a `mruby.so` file in the `pkg` directory which you can simply `require` within Lua.
-> NOTE: This has not been implemented yet.
+## Usage
-All MRuby C functions have been ported directly to Lua.
+### MRuby Table
+The `mruby` table contains a few helper functions just for evaluating and running MRuby code.
+
+#### `run`
+
+The `run` function simply runs MRuby code. It returns a `0` if it ran without any exceptions raised and `1`
+if an exception was raised.
```lua
-mrb = mrbOpen()
-mrbCode = " puts 'Hello, World!' "
-mrbParserState = mrbParseString(mrb, mrbCode, nil)
-mrbGeneratedCode = mrbGenerateCode(mrb, mrbParserState.tree)
-mrbResult = mrbRun( mrb, mrbProcNew(mrb, mrb.irep[mrbGeneratedCode]), mrbNilValue() )
-mrbClose(mrb)
+mruby.run(" puts 'Hello, World!' ") -- prints "Hello, World!"
```
-Or use the `mruby` helper table:
+#### `eval`
+
+The `eval` function will evaluate MRuby code. The return value will converted into a Lua object.
```lua
-mrb = mruby.new()
-mrb.assign("$myname", "RyanScottLewis")
-mrb.run("puts $myname")
+print(
+ mruby.eval(" 'Hello,' ").." World!"
+) -- prints "Hello, World!"
+
+print(
+ mruby.eval(" 50 + 50 ") + 100
+) -- prints 200
+```
-calculationResult = mrb.eval("10 + 10")
-print(calculationResult) -- 20
+### C Functions/Types
+
+> NOTE: This has not been implemented yet.
+
+All MRuby C functions/types have been ported directly to Lua.
+The name of the functions/types are identical to those of the C functions/types.
+
+```lua
+mrb_interpreter = mrb_open()
+mrb_code = " puts 'Hello, World!' "
+mrb_parser_state = mrb_parse_string(mrb_interpreter, mrb_code, nil)
+mrb_generated_code = mrb_generate_code(mrb_interpreter, mrb_parser_state.tree)
+mrb_result = mrb_run( mrb_interpreter, mrb_proc_new(mrb_interpreter, mrb_interpreter.irep[mrb_generated_code]), mrb_nil_value() )
+mrb_close(mrb_interpreter)
```
## Acknowlegements
@@ -51,11 +80,11 @@ print(calculationResult) -- 20
## Copyright
-Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>.
+Copyright © 2012-2013 Ryan Scott Lewis <ryan@rynet.us>.
The MIT License (MIT) - See LICENSE for further details.
[mruby]: https://github.com/mruby/mruby
[lua]: https://github.com/LuaDist/lua
[matsumoto-r]: https://github.com/matsumoto-r
-[mruby-on-Lua]: https://github.com/matsumoto-r/mruby-on-Lua
+[mruby-on-Lua]: https://github.com/matsumoto-r/mruby-on-Lua

0 comments on commit 47ea62a

Please sign in to comment.
Something went wrong with that request. Please try again.