module Wren::Class

Overview

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

Defined in:

wren/class.cr

Constant Summary

WREN_METHODS = [] of Wren::Method

Instance Method Summary

Macro Summary

Instance Method Detail

def bind(vm : Wren::VM) #

Binds this instance to a specific VM


[View source]
def instance_handle : Pointer(LibWren::Handle) | Nil #

[View source]
def instance_handle=(instance_handle : Pointer(LibWren::Handle) | Nil) #

[View source]

Macro Detail

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

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

[View source]