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.crConstant Summary
-
WREN_METHODS =
[] of Wren::Method
Instance Method Summary
-
#bind(vm : Wren::VM)
Binds this instance to a specific VM
- #instance_handle : Pointer(LibWren::Handle) | Nil
- #instance_handle=(instance_handle : Pointer(LibWren::Handle) | Nil)
Macro Summary
-
foreign_def(name, &block)
Define a method in foreign Crystal code, callable from either Wren or Crystal.
-
native_def(name, *args, construct = false, &code)
Define a method in native Wren code, callable from either Wren or Crystal.
Instance Method Detail
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"
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"