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

JS values passed improperly to Lua callbacks #41

Closed
s-ol opened this issue May 2, 2018 · 3 comments
Closed

JS values passed improperly to Lua callbacks #41

s-ol opened this issue May 2, 2018 · 3 comments

Comments

@s-ol
Copy link

s-ol commented May 2, 2018

This works fine:

local canvas = document:createElement('canvas')
canvas.width = 400
canvas.height = 400
function canvas:onclick(event)
  print(event.offsetX, event.offsetY)
end

document.body:appendChild(canvas)

but this prints nil for the values in event:

local canvas = document:createElement('canvas')
canvas.width = 400
canvas.height = 400
canvas:addEventListener('click', function (event)
  print(event.offsetX, event.offsetY)
end)

document.body:appendChild(canvas)

the event is passed correctly, as it's printed as [object HTMLCanvasEvent].

The same restriction prevents me from accessing for example the timestamp passed into a requestAnimationFrame callback.

Given that I know the type of the JS object there, isn't there a way I can at least extract the properties?

@daurnimator
Copy link
Member

The first argument to your callback is this. The second argument is the event object.

@s-ol
Copy link
Author

s-ol commented May 2, 2018

welp, you're right 😄
I could swear I was printing the number but couldn't use it in the second case but seems like this is on me...

Going to close this, but while I'm here: is there a way I can extend an ES6 class defined in JS with Lua?

@daurnimator
Copy link
Member

You can do it manually, but a helper might be nice. That's tracked in #29

@s-ol s-ol closed this as completed May 2, 2018
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