= rua

Copyright (c) 2007 SUGAWARA Genki <[email protected]>

== Description

Rua is a library for using Lua under Ruby.

== Example

require 'rua'

class MyClass; end

error_handler = lambda do |e|
p e
end

rua = Rua.new(error_handler)
rua.openlibs(:all)
#rua.openlibs(:base, :package, :string)
#rua.secure = false

rua.str = 'xxx'
rua.num = 100
rua.proc = lambda do
puts 'proc called.'
end
rua.err = lambda do
raise 'err called.'
end
rua.Time = Time
rua.MyClass = MyClass

puts rua.eval(<<-EOS)
print('hello Rua!')
print(str)
print(num)
proc()
err()
print(Time.new().to_s())
my_obj = MyClass.new()

f = function()
print('f() called.')
end

return true
EOS

rua.f.call
p rua.my_obj
p rua.eval('return 1, 2, 3')

co = rua.eval(<<-EOS)
function foo (a)
print('foo', a)
return coroutine.yield(2 * a)
end

return coroutine.create(function (a, b)
print('co-body', a, b)
local r = foo(a + 1)
print('co-body', r)
local r, s = coroutine.yield(a + b, a - b)
print('co-body', r, s)
return b, 'end'
end)
EOS

p co.resume(1, 10)
p co.resume('r')
p co.resume('x', 'y')
p co.resume('x', 'y')