wren.cr
Crystal bindings to the Wren interpreter.
Includes additional libraries / utilities out of the box:
Installation
-
Add the dependency to your
shard.yml
:dependencies: wren: github: nobodywasishere/wren.cr
-
Run
shards install
-
Run
./src/ext/generate.sh
Usage
require "wren"
vm = Wren::VM.new
# Supports low-level interfacing with the VM
vm.bind_method("MyKlass", true, "method(_,_)") do |vm|
a = LibWren.get_slot_double(vm, 1)
b = LibWren.get_slot_double(vm, 2)
LibWren.set_slot_double(vm, 0, a + b)
end
vm.interpret <<-WREN
class MyKlass {
foreign static method(a, b)
}
WREN
puts vm.call("MyKlass", "method(_,_)", [1, 2]) # => 3.0
vm.interpret <<-WREN
System.print(MyKlass.method(1, 2)) // => "3"
WREN
# Equivalent to above, also supports automatically creating bindings
class MyOtherKlass
include Wren::Class
foreign_def self.method do |a, b|
case {a, b}
when {Float64, Float64}
a + b
end
end
end
vm.bind(MyOtherKlass)
puts MyOtherKlass.method(1, 2) # => 3.0
vm.interpret <<-WREN
System.print(MyOtherKlass.method(1, 2)) // => "3"
WREN
Contributing
- Fork it (https://github.com/nobodywasishere/wren.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Margret Riegert - creator and maintainer