Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpledisplay - empty handler doesn't work #338

Open
helikopterodaktyl opened this issue Oct 2, 2022 · 1 comment
Open

Simpledisplay - empty handler doesn't work #338

helikopterodaktyl opened this issue Oct 2, 2022 · 1 comment

Comments

@helikopterodaktyl
Copy link

What determines what is usable as a handler and what isn't? I am getting inconsistent behavior

import arsd.simpledisplay;
import std.stdio;

void main()
{
    SimpleWindow window = new SimpleWindow(Size(1024, 768), "Test");

    void foo()
    {
    }

    // works
    window.eventLoop(1,
        () { foo(); }
    );

    // doesn't work
    window.eventLoop(1,
        () { writeln("test"); }
    );

    // doesn't work
    window.eventLoop(1,
        () {}
    );

}
@adamdruppe
Copy link
Owner

They need to be delegates instead of function pointers. That's why the error message in that case suggests trying the delegate keyword - it specifies to the compiler that you need that specifically (though it is true the library could convert them internally too...).

The difference between them is a delegate accesses some local data and a function pointer doesn't. So { foo(); } works because foo is the local data it accesses. writeln doesn't because it is global, not local. And empty {} needs no extra data at all. So the compiler types them as function pointer.

If you use the delegate keyword though, the compiler just passes it a null pointer to local data, which since it doesn't use anyway, all works nicely.

Since you can just add the keyword on the outside when needed, I think that's good enough but it is tempting to make the library just go ahead and convert when necessary too, it wouldn't be that hard to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants