LuaX: A Lua Dialect with JSX
bvisness.me
bvisness.me
But I'm never quite sure why people insist that you cannot do web dev the old school ways of HTML files with a little PHP or other scripting. All of that still works just fine. So when people say they wrote an entirely new system because they miss being able to stay simple like in ye olde days... I'm not sure I understand the connection.
Frameworks exist for Software at Scale (TM). Big Corp has a revolving door of developers and they need cookie cutter tools that isolate the damage a "bad" developer can cause. If you're a solo developer or a small company, then this digital bureaucracy is unnecessary.
Developers leave about every two years. Engineering management want to use technologies that allow for resource flexibility, and those libraries are designed to attract both parties. You, and management, for different reasons.
JSX works well for a component approach because you’re expressing the component in a fully functional programming language. Doing a lot of that work tends to make the developer quite capable in Javascript.
Ah, the sweet sweet nostalgia of XSS
> When I started out, you could just copy HTML files up to your server and you had a website. It was magical! And PHP made it even better; you could just throw in a little snippet of server-side code and you had a dynamic page.
Well, you can still very much do this. Sure, it's not bleeding edge, but large chunks of the web (even newer sites) still do it this way and rely on PHP or sinilar server side languages.
Could build Figma or Google Sheets "with HTML files with a little PHP or other scripting?" I don't see how either app could be developed without significant amounts of "scripting" (i.e. code running in the browser and on the server).
I don't know how JSX is made in LuaX but in my QuickJS fork [1] JSX allows to generate as tree literals as procedure calls (JSX(tag,props,kids)) that can be used for various purposes - DOM population, VDOM generation, HTML/XML string composition, etc.
And being embedded into a compiler JSX a) prevents common mistakes like non-closed tags and b) effective internalization ( translation happens at compile time once ).
[1] JSX implementation for QuickJS : https://gitlab.com/c-smile/quickjspp/-/blob/master/quickjs-j...
Wrt $subj, Lua has even better thing - Lua table, which can hold both kv-pairs and indexed items. With function environments that could allow something like:
function comp:render()
return div {
class = "foo",
input {
type = "text",
disabled = true,
value = self.value,
}
}
end
That’s what Lua was made for. Idk why I would “<choose><jsx></jsx></choose>” over “choose { lua }”.React was made for web developers. Most web developers know HTML already. Many of them probably know Lua too, but not as widespread as HTML-knowledge.
JSX is basically HTML in JavaScript, so it's easy because it's familiar. The reason for JSX is to make DOM creation in JS more like DOM creation in HTML.
I'm just explaining to someone why people chose JSX in favor of X, when they come from a HTML/CSS/JS background.
That said, historically lisps are the most featureful runtime-wise. It’s a real shame we hide behind our complexity but collectively chicken out before really powerful concepts lisps introduced.
So, in `div`, `class` is a property, but `input` that immediately follows is a child of the component
It's a similar issue as CSS nesting, by the way :) I'm not saying it's inherently bad, it's just it could be confusing. But could probably solved by a linter: put attributes at the top, nested children at the bottom
To me JSX and hyperscript are both about the same thing. JSX gets compiled to a bunch of createElement calls that looks just like hyperscript. I prefer the look of JSX over hyperscript.
div {…}
Comp {…}
Ns.Comp {…}https://engineering.fb.com/2015/07/09/open-source/announcing...
Lua can be trivially sandboxed. Throw in a parser for acquiring metadata (dependencies) and you have a full blown config language in a few hundred LoC
https://github.com/civboot/civlua/tree/main/luck
I love Lua
I also hate (well, dislike) static website builders... so I built my own based on markdown, with an embedded Scheme-like template language. But this is much nicer as you turned things around and made the website basically a Lua program that happens to output HTML.
Do you have support for stuff like syntax highlighting for code samples, table-of-contents "widgets" and so on?
At some point maybe I’ll make syntax highlighting for my editor, but it’s not a super high priority for me.
https://github.com/civboot/civlua/tree/main/cxt
I'm planning on supporting syntax highlighting. I could imagine creating a cxx that does what LuaX is doing, except it would support rendering to the command line as well as html.
Want to team up?
When I read the article, I was thinking that Go templates were used wrong. I was thinking there must be a way to define the template so you inject the content and don't need to define the start and the end of the html, but instead yield a block of other html as some kind of argument. I was trying to look it up, but couldn't find documentation on this. Maybe the author is right and I'm wrong.
And I was wondering why the author isn't using something like Templ [0], which is kind of JSX with Go as hosting language. Probably because it needs the preprocessor / compile step?
I hope he decides to open source it.
I share the frustration of template systems being separate from the rest of your code, let alone your language.
IME, JSX and Hiccup are the best approaches to 'HTML in your functions'.
Having this for Lua would be great; its a wonderful scripting language.
It's similar with languages will permit fluent SQL-like syntax mixed with general purpose programming.
Bridging these realms into a single integrated programming environment should be celebrated. There's no reason our ecosystem is so fragmented.
Lua shares many aspects with JS, but also does async programming in a much better way than JS, because it was adapted for games, where many things happen concurrently and not in a blocking way. The syntax is also clear and more minimal, like Python is.
I'm working on a hobby language (who isn't!) which combines many aspects from Erlang, JS, JSX, LISP, SmallTalk etc. and while Erlang is my model fo runtime concurrency, Lua is my model for syntax concurrency (that is no red/blue separation: every function is implicitly sync or async depending on how you call it). I think projects like these are a good thing for our industry.
Enough divergence, it's time for convergence!
Other than t-sql and plpgsql, can you give an example of languages with native SQL syntax? I've been thinking about building a toy language like that and haven't found anything not native to a database engine.
Forking Pallene (https://github.com/pallene-lang/pallene) would introduce: - Types - LuaX -> Lua - LuaX -> C
It makes sense in the browser because it was made to mimic the dom api. But the interface between the browser and server is text.
When using jsx in the server you're extremely limited. You cannot just use any html tag unless the framework has a specific solution for it.
Also I can totally use any tag I want. LuaX powers the RSS feed of my site too, with all its `atom:link` and `pubDate` and `guid` tags. It doesn't care about the names of tags, only the structure.
Usually this is where JSX implementations fail.
Doesn't look like that's the case in OP's solution, where HTML tags are transformed into Lua tables. I guess then there's some code that turns the lua tables into the html text to be sent to the client
Lisp works great for this sort of thing.
Us developers as a group seem to hold the belief that updating the copyright dates manually is bad or wrong.
But AIUI, the copyright should be more than a simple "today.getYear()" call. If you first published the page in 2020, then the copyright should reflect that.
If instead, when we delete the 2020 and auto update it to _currentYear_ dynamically, we have removed the claim to have published it earlier. So if there is a copyright issue where another site copied some content but left the copyright year as say 2021, now from a first glance it would have the more senior copyright claim.
What you would want is something that generates a copyright notice like "Copyright 2020-2023". See here for more examples: https://www.websitepolicies.com/blog/copyright-notice
I keep mine up to date on my sites just because it's basically a staple of modern web design. Not having it would be weird, and having it out of date would probably confuse people.
So what? What matters is authorship, not the date at which it was published on this or that website. Even if a website copies your text, no matter the date, that is still your text and still copyright infringement no matter what if you didn't license this text to them.