Hacker News new | ask | show | jobs
by umvi 745 days ago
I read his post less as Rust fanaticism and more someone who has learned their first programming language isn't perfect - strong types? iterators? These are all things that are present in many languages, it just sounds like Lua is lacking them and he is discovering some of the cool features of other languages.
1 comments

But lua isn't lacking them, <for in do> is for generators, and if you want iterators you can make those as well.
Do you know if Lua supports type annotations or gradual typing? I use those heavily when using dynamically typed languages.
It does not. The most viable solution is transpilation, teal is the most recent candidate.

You can have a hack of sorts using a schema and tables as in

local schema = { a = "number", b="string" } -- key = "type" local data, link = {a=4, b="default value"}, {} -- link -> data, link itself is always empty local tbl = setmetatable(link, { __index = data , __newindex = function (t,k,v) if schema[k] and type(v)==schema[k] then data[k] = v return true end error"type does not match schema" end })

tbl.b = 5 -- this will error because its the wrong type

There are certain solutions you can do with functions, lsp is also really good at telling you when you went wrong.

No, Lua does not, but check out Roblox's Luau which is a gradually typed extension of Lua.
I'd recommend teal because luau is not really lua.