-
I have a need to use a hash table (not a contiguous array) in Pallene. I know I could try to funnel this through a Lua function and do this on the Lua side, but the elements in my hash table are Pallene records and I have lots of little local helper functions in Pallene, so it would be more convenient to do this on the Pallene side. I'm trying to figure out what's okay to do on the Pallene side, and what must be done on the Lua side. So far my impression (through experimentation) is:
Are there any other considerations or warnings I should be aware of? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Proper hash tables might be the most glaring omission in the Pallene type system right now. The problem, however, is that we still haven't figured out the best way to add a hash table type to the type system. In particular, how to deal with "not found". For example, consider this bit of Lua: function greet(t, k)
local v = t[k]
if v then
return "hello"..v
else
return "default"
end
end To support this kind of idiom, we would need to tell the type system that if we test Alternatively we could go for a design with a simpler type system but which requires more type annotations. local va = t[k]
if va then
local v = va as string
return "hello"..v
else It's clunkier, but maybe it's a good solution to at least get some support for hash tables out of the gate? Anyway, I'm all ears! Would love to know if yall have any suggestions about the hash tables. |
Beta Was this translation helpful? Give feedback.
-
In the mean time, the (painful and slow) workaround is what you've been doing. Do the hash table manipulation in Lua and expose that to Pallene via functions. |
Beta Was this translation helpful? Give feedback.
In the mean time, the (painful and slow) workaround is what you've been doing. Do the hash table manipulation in Lua and expose that to Pallene via functions.