Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import arsd.script;
- import arsd.jsvar;
- alias ClickHandler = void delegate(int x, int y);
- class Window
- {
- void addOnClick(ClickHandler ch)
- {
- clickHandlers ~= ch;
- }
- void click(int x, int y)
- {
- foreach(ch ; clickHandlers)
- {
- ch(x, y);
- }
- }
- private ClickHandler[] clickHandlers;
- }
- void print(const string s)
- {
- writeln(s);
- }
- void main(string [] args)
- {
- var globals = var.emptyObject;
- globals.print = &print;
- globals["Window"] = subclassable!Window;
- interpret(q{
- var window = new Window();
- window.addOnClicked(function(x,y){
- print("Clicked! " ~ x ~ " " ~ y);
- });
- window.click(25, 30);
- }, globals);
- }
- unittest
- {
- Window window = new Window;
- window.addOnClick((x,y){writeln(x," ",y);});
- window.addOnClick((x,y){writeln("Second click!");});
- window.click(42, 69);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement