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
Are there any current plans for how to implement this? I've written up a very rough pr (no tests or anything) for this feature here but would like some feedback/opinions on it first.
First of all, syntax: this is what I settled on. The following is valid in the pr
local Vector = record
{number}
has +(Vector, Vector): Vector
has /(Vector, number): Vector
has ..(Vector, Vector): string
has -(Vector, Vector): Vector
-- technically unary ops arent in yet, but would be quite easy
has #(Vector): number
-- The framework is there to allow for binary and unary ops to have the same symbol
has -(Vector): Vector
-- etc
-- has is still a valid name
has: number
end
local a: Vector = {}
local b = a + a
local c = a / 4
Later on some assertions can be added that at least one of the arguments contains the type but I want to stress that this is a proof of concept
I'm haven't fully studied the parser yet but I was thinking a "has" fact and operator could be added and we could (as @hishamhm mentions in Standardized class model? #97) use the generated table to store the information and define some reserved keys in tables. For example
local Vector = record has+(Vector, Vector):Vector end
local a: Vector = {}
if a has + then
local b = a + a
end
(although I think lua reserves double underscore names)
and the compiler would error when someone tries to use has on a non record type
Speaking of #97, I think this is a decent way of adding operator overloading without stepping too far into committing to an OOP model.
notably this doesn't hook into metatables at all currently. My reasoning for this is that it's hard and I didn't want to get too far into anything without a second look at these ideas. Also metatable info is hard to track and can be (suprise suprise) super dynamic, not in practice usually, but it can be.
(Also I just realized I hadn't thought about generics at all ¯\_(ツ)_/¯)
The text was updated successfully, but these errors were encountered:
Are there any current plans for how to implement this? I've written up a very rough pr (no tests or anything) for this feature here but would like some feedback/opinions on it first.
Later on some assertions can be added that at least one of the arguments contains the type but I want to stress that this is a proof of concept
I'm haven't fully studied the parser yet but I was thinking a "has" fact and operator could be added and we could (as @hishamhm mentions in Standardized class model? #97) use the generated table to store the information and define some reserved keys in tables. For example
would generate
(although I think lua reserves double underscore names)
and the compiler would error when someone tries to use
has
on a non record typeSpeaking of #97, I think this is a decent way of adding operator overloading without stepping too far into committing to an OOP model.
notably this doesn't hook into metatables at all currently. My reasoning for this is that it's hard and I didn't want to get too far into anything without a second look at these ideas. Also metatable info is hard to track and can be (suprise suprise) super dynamic, not in practice usually, but it can be.
(Also I just realized I hadn't thought about generics at all ¯\_(ツ)_/¯)
The text was updated successfully, but these errors were encountered: