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

Can't use constructors with JS interop #123

Open
qgcarver opened this issue Sep 27, 2024 · 0 comments
Open

Can't use constructors with JS interop #123

qgcarver opened this issue Sep 27, 2024 · 0 comments

Comments

@qgcarver
Copy link

qgcarver commented Sep 27, 2024

If I try to pass in a function that takes in a constructor as a parameter, the closure I send in doesn't treat it that way.

lua.global.set("DOM",{
    new: (T=>{
        let Constructor = T;
        return (...a) => {
            let constructed = new Constructor(...a);
            return constructed;
        };
    }),
    window: window
    log: console.log
    exampleElement: document.getElementById("mycanvas")
}),

lua.doString(`
function f()
  local ImageConstructor = DOM.new(DOM.window.Image)
  DOM.log(ImageConstructor())
end
DOM.exampleElement.onclick = f
`)

I get an error saying n is not a constructor
I tried currying and saving a local as seen above to try to work around this, but it seems like there's some kind of wrapping going on that's preventing that from working.
It seems like a way to support constructors in the interop system itself would be good, (if it doesn't already exist and I just missed it.)

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

1 participant