module

Wren::Class

Mixin that when included in a class, adds macros for defining foreign and native Wren methods attached to the class

class MyClass
  include Wren::Class

  foreign_def self.method1 do
    "response1"
  end

  native_def self.method2 do
    <<-WREN
      "response2"
    WREN
  end
end

Constants

WREN_METHODS = [] of Wren::Method

Instance methods

bind(vm : Wren::VM)

Binds this instance to a specific VM

Source
instance_handle
Source
instance_handle=(instance_handle : Pointer(LibWren::Handle) | Nil)
Source

Macros

foreign_def(name, &block)

Define a method in foreign Crystal code, callable from either Wren or Crystal. Does not support foreign constructs

class MyClass
  include Wren::Class

  foreign_def self.my_method do |arg1|
    case arg1
    when String
      "foo " + arg1
    end
  end
end

MyClass.my_method("bar") # => "foo bar"
Source
native_def(name, *args, construct = false, &code)

Define a method in native Wren code, callable from either Wren or Crystal. Cannot be modified at runtime.

class MyClass
  include Wren::Class

  native_def self.my_method, arg1, <<-WREN
    return "foo " + arg1
  WREN
end

MyClass.my_method("bar") # => "foo bar"
Source