class Wren::VM
- Wren::VM
- Reference
- Object
Overview
High level interface to Wren
Defined in:
wren.crConstructors
Class Method Summary
Macro Summary
-
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()
Instance Method Summary
-
#_flatten(args : Array(Value))
Flatten arrays in the specific way _set_slots wants
-
#_get_slot(slot : Int32)
Get value from
slot
-
#_get_slots(start : Int32, count : Int32)
Get
count
slots starting withstart
- #_handle_interpret_result(result : API::WrenInterpretResult)
-
#_set_slot(n : Int32, val : Value)
Sets slot
n
to valueval
-
#_set_slots(slot : Int32, args : Array(Value))
Sets all
args
into slots starting withslot
-
#_to_float64(v : Value) : Float64
Helper to cast to Float64 a bit harder than Crystal does
-
#call(mod : String, obj : String, method : String, args : Array(Value) = [] of Value)
Call a method in a Wren object, passing values as needed
-
#finalize
Free resources allocated by Wren
-
#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.
- #register_function(mod : String, obj : String, name : String, cb : Tuple(CallbackFunction, Int32))
Constructor Detail
Class Method Detail
Macro Detail
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?
Instance Method Detail
Flatten arrays in the specific way _set_slots wants
Sets all args
into slots starting with slot
Helper to cast to Float64 a bit harder than Crystal does
Call a method in a Wren object, passing values as needed
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