While I generally like Lua this code just looks .. not so Lua - like, it definitely is Lua, but it could look much better by utilizing language features like "Parenthesis-free calls":
I had a similar impression. It feels "not idiomatic". I disagree on the diagostic though - I think parenthesis-free calls are not what define what idiomatic lua is.
To me it is more about expressiveness and usage of basic language features. For example here's how a text field is set up currently.
ito.TextField(draft)
:label("Name")
:focused()
:on_submit(function(value)
if value:match("%S") then
phase.value = "review"
end
end)
:on_cancel(function()
phase.value = "choose"
end),
The field is created on the first line, and then altered further with subsequent method calls that alter it. This reads like someone very used to Rust (and its Builder pattern) and then translating it verbatim to Lua. A more native Lua interface for me would look like this:
ito.TextField(draft, {
label = "Name",
focused = true,
on_submit = function(value)
if value:match("%S") then
phase.value = "review"
end
end,
on_cancel = function()
phase.value = "choose"
end),
})
As in: just pass a table to the builder. And if they ned to modify it later, they can just do:
some_textfield.on_cancel = <some other function>
No need to "guard" the internal table with those extra methods.
Great job! The declarative API looks sick! I'll try it. Sometimes I love to think that if our universe is really infinite, then somewhere there's a universe where the browsers supports native luajit scripting instead of javascript(and in another universe all of this plus array indexes starting from 0 ;)
While I generally like Lua this code just looks .. not so Lua - like, it definitely is Lua, but it could look much better by utilizing language features like "Parenthesis-free calls":
or feels more Lua and slightly cleaner imoit does, but I am a fan of the composability that ratatui has, and I wanted to copy it over…
I had a similar impression. It feels "not idiomatic". I disagree on the diagostic though - I think parenthesis-free calls are not what define what idiomatic lua is.
To me it is more about expressiveness and usage of basic language features. For example here's how a text field is set up currently.
The field is created on the first line, and then altered further with subsequent method calls that alter it. This reads like someone very used to Rust (and its Builder pattern) and then translating it verbatim to Lua. A more native Lua interface for me would look like this: As in: just pass a table to the builder. And if they ned to modify it later, they can just do: No need to "guard" the internal table with those extra methods.that’s fair; I was suggesting something even more drastic than this https://github.com/uji-labs/ito/issues/4
maybe it’s a bad idea :X
Great job! The declarative API looks sick! I'll try it. Sometimes I love to think that if our universe is really infinite, then somewhere there's a universe where the browsers supports native luajit scripting instead of javascript(and in another universe all of this plus array indexes starting from 0 ;)
I trust you would make that happen! And I would be right there to use it in my next project
this is amazing, i'll try it out!
feel free to raise issues if anything feels off. The plan is to make it the rice harness :)
*oh! I meant the right harness for you