Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update README.md

  • Loading branch information...
commit 47ea62a1e536d14317b4b2dd14fec7ae789e9351 1 parent b8d28fd
Ryan Scott Lewis authored

Showing 1 changed file with 53 additions and 24 deletions. Show diff stats Hide diff stats

  1. +53 24 README.md
77 README.md
Source Rendered
@@ -4,45 +4,74 @@ Use [mruby][mruby] from within [lua][lua].
4 4
5 5 ## Install
6 6
7   -```shell
8   -$ rake
  7 +### LuaRocks
  8 +
  9 +> NOTE: This is not implemented yet.
  10 +
  11 +```sh
  12 +$ luarocks install mruby
9 13 ```
10 14
11   -## Usage
  15 +### Source
12 16
13   -### Simple
  17 +> NOTE: If `rake` is not installed, you can use the `minirake` executable in `lib/mruby/minirake/`.
  18 +> The `Makefile` simply calls `rake`.
14 19
15   -```lua
16   -require "mruby"
  20 +```sh
  21 +$ rake
  22 +```
  23 +
  24 +Or:
17 25
18   -mruby.run(" puts 'Hello, world!' ")
  26 +```sh
  27 +$ make
19 28 ```
20 29
21   -### Advanced
  30 +This will compile a `mruby.so` file in the `pkg` directory which you can simply `require` within Lua.
22 31
23   -> NOTE: This has not been implemented yet.
  32 +## Usage
24 33
25   -All MRuby C functions have been ported directly to Lua.
  34 +### MRuby Table
26 35
  36 +The `mruby` table contains a few helper functions just for evaluating and running MRuby code.
  37 +
  38 +#### `run`
  39 +
  40 +The `run` function simply runs MRuby code. It returns a `0` if it ran without any exceptions raised and `1`
  41 +if an exception was raised.
27 42
28 43 ```lua
29   -mrb = mrbOpen()
30   -mrbCode = " puts 'Hello, World!' "
31   -mrbParserState = mrbParseString(mrb, mrbCode, nil)
32   -mrbGeneratedCode = mrbGenerateCode(mrb, mrbParserState.tree)
33   -mrbResult = mrbRun( mrb, mrbProcNew(mrb, mrb.irep[mrbGeneratedCode]), mrbNilValue() )
34   -mrbClose(mrb)
  44 +mruby.run(" puts 'Hello, World!' ") -- prints "Hello, World!"
35 45 ```
36 46
37   -Or use the `mruby` helper table:
  47 +#### `eval`
  48 +
  49 +The `eval` function will evaluate MRuby code. The return value will converted into a Lua object.
38 50
39 51 ```lua
40   -mrb = mruby.new()
41   -mrb.assign("$myname", "RyanScottLewis")
42   -mrb.run("puts $myname")
  52 +print(
  53 + mruby.eval(" 'Hello,' ").." World!"
  54 +) -- prints "Hello, World!"
  55 +
  56 +print(
  57 + mruby.eval(" 50 + 50 ") + 100
  58 +) -- prints 200
  59 +```
43 60
44   -calculationResult = mrb.eval("10 + 10")
45   -print(calculationResult) -- 20
  61 +### C Functions/Types
  62 +
  63 +> NOTE: This has not been implemented yet.
  64 +
  65 +All MRuby C functions/types have been ported directly to Lua.
  66 +The name of the functions/types are identical to those of the C functions/types.
  67 +
  68 +```lua
  69 +mrb_interpreter = mrb_open()
  70 +mrb_code = " puts 'Hello, World!' "
  71 +mrb_parser_state = mrb_parse_string(mrb_interpreter, mrb_code, nil)
  72 +mrb_generated_code = mrb_generate_code(mrb_interpreter, mrb_parser_state.tree)
  73 +mrb_result = mrb_run( mrb_interpreter, mrb_proc_new(mrb_interpreter, mrb_interpreter.irep[mrb_generated_code]), mrb_nil_value() )
  74 +mrb_close(mrb_interpreter)
46 75 ```
47 76
48 77 ## Acknowlegements
@@ -51,11 +80,11 @@ print(calculationResult) -- 20
51 80
52 81 ## Copyright
53 82
54   -Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>.
  83 +Copyright © 2012-2013 Ryan Scott Lewis <ryan@rynet.us>.
55 84
56 85 The MIT License (MIT) - See LICENSE for further details.
57 86
58 87 [mruby]: https://github.com/mruby/mruby
59 88 [lua]: https://github.com/LuaDist/lua
60 89 [matsumoto-r]: https://github.com/matsumoto-r
61   -[mruby-on-Lua]: https://github.com/matsumoto-r/mruby-on-Lua
  90 +[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.