class

Wren::VM

Inherits Reference < Object

High level interface to Wren

Constructors

new(id : String)
Source

Class methods

get_func(x)
Source
get_vm(vm)
Source

Instance methods

_flatten(args : Array(Value))

Flatten arrays in the specific way _set_slots wants

Source
_get_slot(slot : Int32)

Get value from slot

Source
_get_slots(start : Int32, count : Int32)

Get count slots starting with start

Source
_handle_interpret_result(result : API::WrenInterpretResult)
Source
_set_slot(n : Int32, val : Value)

Sets slot n to value val

Source
_set_slots(slot : Int32, args : Array(Value))

Sets all args into slots starting with slot

Source
_to_float64(v : Value) : Float64

Helper to cast to Float64 a bit harder than Crystal does

Source
call(mod : String, obj : String, method : String, args : Array(Value) = [] of Value)

Call a method in a Wren object, passing values as needed

Source
finalize

Free resources allocated by Wren

Source
interpret(mod : String, source : String)

Runs source, a string of Wren source code in a new fiber in the vm, in the context of resolved module mod. Raises exceptions in case of compile or runtime errors

Source
register_function(mod : String, obj : String, name : String, cb : Tuple(CallbackFunction, Int32))
Source

Macros

wrap(vm_id, proc)

Wraps any proc with any number of arguments into a CallbackFunction so it can be registered with the Wren interpreter using #register_function()

The first argument is the Wren::VM.@id for the VM where this function will be used. This is sort of ugly but I have found no workaround.

Arguments should have simple types like Float64 or String and they are casted using as() so if the actual argument passed from Wren is the wrong type it will raise an exception.

You can register multiple functions for the same name if their arity is different.

FIXME: since Crystal is polymorphic by type+arity and Wren is only polymorphic by arity, so maybe support multiple functions of the same arity wrapped together and dispatch to the one that matches signature of the received arguments?

Source

Nested types