You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For clarification: If you have a class Point (like the example in the docs), and then want to create a new Point which is correctly done so: local p = Point(3,4)
But if you instead do: local p = Point:new(3,4) it just does nothing.
Maybe it's just me who ran into this, but the mistake was not very obvious. Raising an error as hint would be nice, or allowing it as kind of alternative syntax. Whichever is easier, I guess.
The text was updated successfully, but these errors were encountered:
Yeah, I just had to debug this for an hour when trying to setup the Bytepath Love2d tutorial. An error message, or at least a warning in the README would be useful.
I know this old, but in case anyone else has a similar experience:
I think this comes down to the fact that :new is really an initializer and :init would probably be a more fitting name. When you do Point:new(3,4) you're setting the static variables on the Point class itself to the given values.
As for hinting, it doesn't seem possible to throw a warning when calling :new since there isn't a way to distinguish whether it's being invoked directly or inside of classic's __call method. Allowing it as an alternative syntax would be up to rxi, but you can easily modify your copy of the project to behave the way you want. Still, the current behavior is useful for re-initializing object instances (in object pooling, for example). It's easy as:
localp=Point(3,4)
--- do stuffp:new(4, 5) -- re-init to new values
For clarification: If you have a class Point (like the example in the docs), and then want to create a new Point which is correctly done so:
local p = Point(3,4)
But if you instead do:
local p = Point:new(3,4)
it just does nothing.Maybe it's just me who ran into this, but the mistake was not very obvious. Raising an error as hint would be nice, or allowing it as kind of alternative syntax. Whichever is easier, I guess.
The text was updated successfully, but these errors were encountered: