class Wren::VM

Overview

High level interface to Wren

Defined in:

wren.cr

Constructors

Class Method Summary

Macro Summary

Instance Method Summary

Constructor Detail

def self.new(id : String) #

[View source]

Class Method Detail

def self.get_func(x) #

[View source]
def self.get_vm(vm) #

[View source]

Macro Detail

macro 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?


[View source]

Instance Method Detail

def _flatten(args : Array(Value)) #

Flatten arrays in the specific way _set_slots wants


[View source]
def _get_slot(slot : Int32) #

Get value from slot


[View source]
def _get_slots(start : Int32, count : Int32) #

Get count slots starting with start


[View source]
def _handle_interpret_result(result : API::WrenInterpretResult) #

[View source]
def _set_slot(n : Int32, val : Value) #

Sets slot n to value val


[View source]
def _set_slots(slot : Int32, args : Array(Value)) #

Sets all args into slots starting with slot


[View source]
def _to_float64(v : Value) : Float64 #

Helper to cast to Float64 a bit harder than Crystal does


[View source]
def call(mod : String, obj : String, method : String, args : Array(Value) = [] of Value) #

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


[View source]
def finalize #

Free resources allocated by Wren


[View source]
def 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


[View source]
def register_function(mod : String, obj : String, name : String, cb : Tuple(CallbackFunction, Int32)) #

[View source]