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

Calling functions through Dynamic doesn't do anything #575

Closed
nadako opened this issue Mar 4, 2017 · 2 comments
Closed

Calling functions through Dynamic doesn't do anything #575

nadako opened this issue Mar 4, 2017 · 2 comments

Comments

@nadako
Copy link
Member

nadako commented Mar 4, 2017

This doesn't work, because when wrapped in Dynamic, the Function is stored in PointerData, which doesn't override the default __Run method, so it effectively does nothing.

class Main {
    static function test() {
        return 1;
    }

    static function getFnDynamic():Dynamic {
        return cpp.Function.fromStaticFunction(test);
    }

    static function main() {
        var fn = getFnDynamic();
        if (fn() != 1)
            throw "oh no";
    }
}

This might be an issue @larsiusprime is currently fighting with.

@nadako
Copy link
Member Author

nadako commented Mar 4, 2017

Wrapping in Dynamic lime/openfl in the first place is caused by HaxeFoundation/haxe#6074.

@hughsando
Copy link
Member

Pointers wrapped in Dynamic are not designed to be callable Dynamically.
They must be unwrapped explicitly before calling, like:

    static function main() {
        var fn:cpp.Callable<Void->Int> = getFnDynamic();
        if (fn() != 1)
            throw "oh no";
    }

The problem with the referring issue is that the Dynamic was created in the first place, not that it is not callable once it is created.

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