lua-mruby
lua-mruby copied to clipboard
Extend Lua using Ruby with MRuby
lua-mruby
Install
LuaRocks
NOTE: This is not implemented yet.
$ luarocks install mruby
Source
NOTE: If
rake
is not installed, you can use theminirake
executable inlib/mruby/minirake/
.
TheMakefile
simply callsrake
.
$ rake
Or:
$ make
This will compile a mruby.so
file in the pkg
directory which you can simply require
within Lua.
Usage
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.
mruby.run(" puts 'Hello, World!' ") -- prints "Hello, World!"
eval
The eval
function will evaluate MRuby code. The return value will converted into a Lua object.
print(
mruby.eval(" 'Hello,' ").." World!"
) -- prints "Hello, World!"
print(
mruby.eval(" 50 + 50 ") + 100
) -- prints 200
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.
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
matsumoto-r for mruby-on-Lua. This wouldn't exist, if not for him.
Copyright
Copyright © 2012-2013 Ryan Scott Lewis [email protected].
The MIT License (MIT) - See LICENSE for further details.