https://github.com/nobodywasishere/wren.cr
https://github.com/nobodywasishere/wren.cr
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nobodywasishere/wren.cr
- Owner: nobodywasishere
- License: mit
- Created: 2023-12-29T00:09:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-31T18:28:48.000Z (over 1 year ago)
- Last Synced: 2025-03-23T23:36:01.368Z (3 months ago)
- Language: Crystal
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wren.cr
Crystal bindings to the [Wren](https://wren.io) interpreter.
Includes additional libraries / utilities out of the box:
- [wren-json](https://github.com/brandly/wren-json)## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
wren:
github: nobodywasishere/wren.cr
```2. Run `shards install`
3. Run `./src/ext/generate.sh`## Usage
```crystal
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)
endvm.interpret <<-WREN
class MyKlass {
foreign static method(a, b)
}
WRENputs 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::Classforeign_def self.method do |a, b|
case {a, b}
when {Float64, Float64}
a + b
end
end
endvm.bind(MyOtherKlass)
puts MyOtherKlass.method(1, 2) # => 3.0
vm.interpret <<-WREN
System.print(MyOtherKlass.method(1, 2)) // => "3"
WREN
```## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Margret Riegert](https://github.com/nobodywasishere) - creator and maintainer