Webview::Callback
Marks a method as a callback which can be called from Javascript.
An extra value can be passed through to be received by the called method
when the javascript function is called. This value is not accessible from
Javascript. Internally, this value is stored as a Pointer(Void), so the
type of the extra data must be specified, either as the extra_type, or
by adding a type restriction to the extra argument of the annotated
method.
Examples:
@[Callback(extra: "some data", extra_type : String)]
def foo(extra data)
puts data # => "some data"
end
@[Callback(extra: "some data")]
def foo(extra : String)
puts extra # => "some data"
end
Arguments
There are 3 options for how arguments are received from Javascript. By
default, the arguments are parsed from the received string and cast to
the types they are restricted to. This means that, unless you use the
RawArguments or ArgumentType annotations alongside this one, you
must specifiy the types of all arguments.
Examples:
@[Callback]
def foo(some : String, data : Int32) # OK - types annotated
# foo("data", 1234) called from Javascript
puts some # => "data"
puts data # => 1234
end
@[Callback]
def foo(some, data) # Not ok -- compile-time error
end