-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support for arrayrecords #61
Comments
teal doesn't have array records yet. Once it does, I want numeric field names to map to them. The only problem is that Rust is 0 based and Lua is 1 based when it comes to indexing. Something that the FromTloLua macro would need to account for. |
Hmm are you sure? I added the "{T}" bit to my "LuaVec" which allowed me to index the vector with integers |
oh, we are talking about different things then. I was talking about teal-language/tl#497 if I remember correctly, a A |
This appears in the teal-lang docs, and is what I am talking about: -- an arrayrecord: a record which doubles as a record and an array
local record TreeNode<T>
{TreeNode<T>} -- tealr does not allow adding this bit
item: T
end Being able to generate this highlighted bit would allow support for all the other record types I believe. Otherwise I am forced to do things like these: local cells = life_state.cells as {boolean} |
ah, I see.... hmm... I need to think about how to best do this |
stupid question but, what happens if you overwrite the index metamethod yourself so it takes an integer? That should show up in the record that tealr generates. And I think that that would allow teal to use ipairs() to loop over it (if it doesn't then I think that is a bug on teals side or I am missing something in how ipairs works) |
The record is this right now: record LuaVec<T>
userdata
-- Mutating methods
push: function(LuaVec<T>,any):()
pop: function(LuaVec<T>):(any)
clear: function(LuaVec<T>):()
insert: function(LuaVec<T>,(integer),(any)):()
remove: function(LuaVec<T>,integer):(any)
-- Meta methods
metamethod __tostring: function(LuaVec<T>):(string)
metamethod __index: function(LuaVec<T>,integer):(ReflectedValue)
metamethod __pairs: function(LuaVec<T>):(function():((any),(any)))
metamethod __len: function(LuaVec<T>):(integer)
-- Mutating MetaMethods
metamethod __newindex: function(LuaVec<T>,(integer),(any)):()
end I don't think these indexing metamethods get taken into account, and I tried with setmetamethod as well. Ipairs does not work either |
going by the error messages, I am going to say that it is a bug in teal. As |
Yeah it does feel like it, although I don't think teal ever had support for these in the first place, I tried looking for these in commits but no mention of __index, I'll pop em an issue: |
I don't think there's currently a way to support teal arrayrecords
The text was updated successfully, but these errors were encountered: