XHandler Reference

XHandler

What

XHandler is an AppleScript library to execute a handler with specifying its name with a text. This libary allows to change a handler to execute at run-time.

Fhutermore, followings can be made possible.

XHandler can be used for chain of responder pattern and method forwarding.

XHandler can deal with handlers with positional parameters. But handlers which have labeld parameters are not supported.

Sample

use XHandler : script "XHandler"

script BScript
on say_msg(a_msg)
return "hey " & a_msg
end say_msg
end script

script AScript
on show_msg(a_msg)
return "hello " & a_msg
end show_msg

-- successor object to foward calling handlers which are not implemented.
on successor()
return BScript
end successor
end script

(*== Simply calling handler ==*)
set xhandler1 to XHandler's make_with("show_msg", 1)
log xhandler1's do(AScript, "good morning") -- hello good morning

(*== Test whether AScript can respont to the handler "show_msg" ==*)
log xhandler1's responded_by(AScript) -- true

(*== If target object can't resond to the handler, try to call handler in a successr object . ==*)
set xhandler2 to XHandler's make_with("say_msg", 1)
log xhandler2's call_to(AScript, "good evening") -- "hey good evening"
XHandler Reference