[HN Gopher] React Lua
___________________________________________________________________
React Lua
Author : bundie
Score : 160 points
Date : 2024-06-20 14:31 UTC (4 days ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| pull_my_finger wrote:
| I'm reading the docs and it's very unclear if this project is for
| Lua or Luau (the Roblox derivative).
| nine_k wrote:
| Luau and Roblox..
|
| > _When possible, upstream flowtype and definitely-typed types
| have been translated into Luau type annotations._
|
| > _This repository is a fork of roblox /react-lua with the
| intention of being the Roblox and global Lua community go-to
| for React in Lua. Roblox's repository is a read-only mirror of
| their internal project, and as such cannot be contributed to by
| the community._
| pull_my_finger wrote:
| I read tfa. If we sit here and quote all lines that say "Lua"
| we'll be in for a long list as well.. including the project
| NAME no less.
| bilekas wrote:
| Looking at it's parity list its missing quite a lot, that's not
| the issue as this seems to be a for fun project (or masochism)
| but at what point is it considered react? It's unclear to me.
| imadj wrote:
| Some background for anyone interested: The project is a fork of
| `roblox/react-lua` to basically open it up for community
| engagement and it uses Luau
|
| Roblox's Luau: https://luau-lang.org/
|
| > Luau is a fast, small, safe, gradually typed embeddable
| scripting language derived from Lua.
|
| > Around 2006, Roblox started using Lua 5.1 as a scripting
| language for games. Over the years the runtime had to be tweaked
| to provide a safe, secure sandboxed environment; we gradually
| started accumulating small library changes and tweaks.
| k__ wrote:
| Interesting.
|
| I'd love to have type annotations in Lua.
|
| But this doesn't compile to Lua, right?
| gsck wrote:
| Unfortunately not, it is the whole Compiler and VM. I'm not
| super familiar with embedding Luau only having messed around
| with it for a bit, but I highly doubt it'd be too difficult
| to drop in Luau over top an existing Lua implementation
| k__ wrote:
| Thanks!
|
| I found Teal, which seems to Lua what TypeScript is to
| JavaScript
| hombre_fatal wrote:
| I use Teal for Pico8 game development. It's great.
| boredtofears wrote:
| There's also a Typescript to Lua transpiler
| https://typescripttolua.github.io/
|
| I've used it successfully with Love2d projects (albeit
| with some quirks)
| oblio wrote:
| Interesting, what do they do about missing type info? Is
| there some repo of types for popular libraries?
| MenhirMike wrote:
| No, Luau is a new programming language that's based on Lua.
| TheRealPomax wrote:
| So hang on. "We had to customize Lua, but didn't contribute all
| those changes back upstream"? Or "We tried to contribute those
| changes upstream but Lua didn't want to take them onboard"?
| samatman wrote:
| PUC Lua uses a closed development model. They have a small
| team, and that team both decides what goes into the language,
| and writes the implementation themselves.
|
| There are a great many implementations of Lua at this point,
| I'm aware of at least six. But Roblox upstreaming their
| semantic changes was never an option.
| CobrastanJorji wrote:
| PUC's Lua is, however, open source
| (https://www.lua.org/license.html), even if they don't
| solicit contributions, and they do accept happily accept
| financial support. It doesn't look like they release new
| versions very frequently at all (the last release was in
| over a year ago). Still, it appears they do accept
| financial contributions, so it seems like Roblox, whose
| market cap is $22 billion and whose offerings are at
| present entirely dependent on Lua, should probably consider
| offering at least token support
| (https://www.lua.org/thanks.html).
| imachine1980_ wrote:
| Why does the market cap allow you to decide about other
| people's projects? Lua is used in many places, and its
| users aren't all employees of Roblox. Lua is popular
| because it works in a way that sometimes breaks backward
| compatibility, making the language as easy and lean as it
| is. If there's a disagreement on how it should be used,
| just fork it like Roblox did.
| TheRealPomax wrote:
| Of course it was: there is nothing preventing a company
| from contacting the dev team and going "we've one quite a
| bit of work, are you interested in getting any of that
| upstreamed". Getting changes upstreamed is in no way the
| exclusive domain of fully open source projects, it just
| requires reaching out.
|
| Just because there's a closed development model doesn't
| automatically imply the devs team lives and breathes "not-
| invented-here"-ism and are no interested in discussing
| improvements that make a difference to actual people using
| Lua in (extremely) large real world products.
| samatman wrote:
| It was not a general statement, but rather, a specific
| one.
|
| > _Lua is not "open developed". The development is done
| exclusively by the Lua team, at PUC-Rio. So, we do not
| need a SVN repository. Currently, we keep Lua with the
| good old RCS._
|
| - Roberto Ierusalimschy
|
| http://lua-users.org/lists/lua-l/2007-09/msg00476.html
| TheRealPomax wrote:
| Yes, I know, that was my point too: it's closed
| development _and so you can talk to the dev team_ to get
| changes worked into Lua itself. You don 't get to just
| open a PR and start thigns that way, you have to talk to
| people. And going "well we didn't contact them" when
| you're the size of Roblox would be incredible.
| drekipus wrote:
| _> The development is done exclusively by the Lua team,
| at PUC-Rio. So, we do not need a SVN repository._
|
| If I had this as my message, and someone asked to ship
| changes, I would be more than mad.
|
| just take the L dude.
| jhatemyjob wrote:
| -
| jakedub4d2 wrote:
| Wouldn't this let you run a front end on the edge with
| Nginx??? Sounds fun!
| oDot wrote:
| I wrote Vleam[0], which is the equivalent to this, but for Vue
| and Gleam.
|
| The more options like this, the better. Especially for existing
| ecosystems.
|
| [0] https://github.com/vleam/vleam
| chadrs wrote:
| I think the equivalent would be if you ported Vue to the beam,
| but impressive work nonetheless!
| h1fra wrote:
| Another library/documentation that commits the sin of not showing
| any examples
| firtoz wrote:
| You could write react in Lua for a while, for example for Roblox.
| And, it's very cool. There's also another project that compiles
| typescript to Lua: https://roblox-ts.com
|
| And that one supports writing pretty much actual React tsx but
| with Roblox primitives.
|
| One of my clients asked me to make a Roblox plugin, it was my
| first time, and I was very pleasantly surprised with this
| workflow. There are also tools to enable really high iteration
| speed. It felt nicer than Unity at some moments. I didn't really
| need to write or know any Lua at all!
| snshn wrote:
| React has terrible performance
| TheRealPomax wrote:
| Poorly written React (which is a lot of it) has terrible
| performance. Properly written React (just like properly written
| _anything_ ) has great performance.
|
| The reason you experience it as terrible is because it's
| today's visual basic: it's so easy to start with that everyone
| does, without needing to understand programming or specifically
| how React works. You can just throw shit together _and it 'll
| work_. It's empowered an entire generation of web and app
| makers, with the cost being "and they're not good at that,
| through no fault of their own, but they _are_ just good enough
| to be dangerous ".
| tracker1 wrote:
| It isn't even that new, in terms of approach... a _LOT_ of
| game and simulation would work with state driven rendering...
| each frame is rendered against the current state. Similar
| workflows to React+Redux were in pretty broad use, the tools
| just brought it to web development... from there, React as a
| model for UI abstraction became more popular for other
| applications outside web use. It makes a lot of sense.
| TheRealPomax wrote:
| If you already understand the idea behind state driven
| updates, you're already writing better React than the
| majority of folks using it. React made it easy enough to
| write working UIs _without_ having a clue what 's actually
| happening, when, and why. (which is also why there's a
| never-ending stream of stackoverflow questions about why
| obvious state mutations don't immediately kick in)
| ajkjk wrote:
| It has adequate performance and the ease of development is
| worth it not being the most performant way to do things.
| classified wrote:
| Ancient quiche eater wisdom has it that you can write Fortran in
| any language. In that vein, React in Lua is not too much of a
| surprise.
| IggleSniggle wrote:
| I'm curious about what "quiche eater" means in this context. I
| have not run into that before.
| bee_rider wrote:
| It's a reference to:
|
| https://en.m.wikipedia.org/wiki/Real_Programmers_Don't_Use_P.
| ..
|
| Which is itself a reference to:
|
| https://en.m.wikipedia.org/wiki/Real_Men_Don%27t_Eat_Quiche
|
| It's all tongue-in-cheek references to stereotypes around
| what would now be called toxic masculinity/gatekeeping.
|
| Of the Fortran programmers (real, manly programmers in this
| story) it says:
|
| > Besides, the determined Real Programmer can write FORTRAN
| programs in any language.
|
| In this vein there's also the story of Mel the Programmer, a
| "Real Programmer" who would never stoop so low as to use so
| abstract a programming language as FORTRAN. Funny how
| perspectives change over time.
| romanhn wrote:
| Fascinating. Haven't heard of these despite coding for 30
| years. Probably because I started with Pascal.
| bee_rider wrote:
| When I started to learn to code, we were supposed to be
| dismissive of the Java wimps, but now I think it is
| Python that is too convenient to be cool. It's all very
| silly and anyone that takes it seriously should be
| regarded with suspicion I think.
| fire_lake wrote:
| Python is the new VBA
| sqeaky wrote:
| Primagen mentioned.
| xrd wrote:
| As others here have mentioned, why React?
|
| More specifically, I know that Roblox uses lua(u) but I assumed
| this was all for scripting. React is a tool for building UI.
|
| How do you use React inside Roblox? You can build UI? I'm trying
| to wrap my head around my clearly mistaken assumption that what
| was possible in Roblox was writing lua-ish scripts that handle
| events in Roblox and then alter the game flow. That's very
| different from a full UI element that manages state and
| presentation, which is why React was so exciting (ten years ago).
| debacle wrote:
| React is a tool for managing state. The UI component is
| somewhat secondary.
| throwadobe wrote:
| React is _one_ tool for managing state. Still doesn 't answer
| why
| shadowgovt wrote:
| It's a good tool for managing state, especially state that,
| well, reacts to messages about changes in shared state.
| recursive wrote:
| In react's model, all state is owned by a particular
| component instance. Most react devs opt for a 3rd party
| tool for shared state. I would not say that react is good
| at this.
| bluefirebrand wrote:
| This hasn't really been true for a while, most React
| projects that I encounter nowadays don't opt for things
| like Redux or MobX, they just use React Contexts. Which
| isn't a third party thing anymore
| recursive wrote:
| When context first came out, there was a buzz about it
| was going to obsolete Redux. Then it was actually "no
| it's not". I haven't followed it much since then. I
| haven't seen a code base that used a context for shared
| state that could be updated from descendant nodes. But I
| guess it pretty much _has_ to be an improvement over
| redux.
|
| Still though, the boilerplate required to do it doesn't
| make it seem like React is particularly _good_ at it,
| even though it 's technically capable.
| shadowgovt wrote:
| > I haven't seen a code base that used a context for
| shared state that could be updated from descendant nodes.
|
| I use this pattern commonly. You put a state-update
| callback into the context.
|
| It's my favorite go-to when I don't want to bother
| writing all that Redux boilerplate (state description
| plus accessors plus reducers feels... Half-baked).
| acemarke wrote:
| Note that Redux usage patterns have changed significantly
| since 2019. Modern Redux with our official Redux Toolkit
| package is drastically simpler and easier to use than the
| original legacy hand-written patterns:
|
| - https://redux.js.org/tutorials/essentials/part-2-app-
| structu...
|
| - https://redux.js.org/introduction/why-rtk-is-redux-
| today
| acemarke wrote:
| Hi, I'm a Redux maintainer.
|
| Context is not an "improvement" over Redux, because they
| are different tools with different purposes. (This is the
| primary misunderstanding people have when they try to
| compare Context and Redux.)
|
| Context is a Dependency Injection tool for a single
| value, used to avoid prop drilling.
|
| Redux is a tool for predictable global state management,
| with the state stored outside React.
|
| Note that Context itself isn't the "store", or "managing"
| anything - it's just a conduit for whatever state you are
| managing, or whatever other value you're passing through
| it (event emitter, etc).
|
| I wrote an extensive article specifically to answer this
| frequently asked question, including details about what
| the differences are between Context and Redux, and when
| to consider using either of them - I'd recommend reading
| through this:
|
| - https://blog.isquaredsoftware.com/2021/01/context-
| redux-diff...
| recursive wrote:
| Thanks for the info. I'd say you're speaking from some
| position of authority about what redux is and isn't. And
| to some degree, what react context is and isn't. I
| vaguely recall seeing this blog post before, maybe.
|
| So redux is for "managing and updating" shared state. And
| context is for "sharing values". All this seems to
| suggest that react actually isn't that good at shared
| state, at least when it can change.
| acemarke wrote:
| I'd both agree and disagree with that.
|
| React is based on the core concepts of encapsulated
| components, with the ability to manage state on a per-
| component-instance basis, and for parent components to
| pass _any_ values they want to their children as props,
| forming a "one-way data flow" approach.
|
| This is _good_, because it both enables predictable
| behavior and React's overall rendering model.
|
| It's _limiting_, because it means that React's own state
| management is inherently tree-shaped. If two widely
| separated components need to access the same data, you
| have to hoist the ownership of that state up to the
| nearest common ancestor, which could easily be the root
| `<App>` component. To put it another way, not all state
| is inherently tree-shaped, so there's often a mismatch.
|
| Context is essentially "props at a distance". Put a value
| in a `<MyContext.Provider>` component somewhere in your
| tree, then any deeply nested component can read it via
| `useContext(MyContext)` without having to explicitly pass
| the value as a prop through however many intervening
| levels of components.
|
| This simplifies making values accessible to that subtree,
| but doesn't solve the tree-vs-nontree-shaped state
| management question.
|
| You _can_ build an entire app out of nothing but React
| component state. Plenty of folks have done it, but it's
| limited in what tools you have available and how you can
| structure things.
|
| That's a large part of why there have been so many
| different state management libraries created for React,
| to provide alternative approaches that don't have the
| tree-shaped issue.
| ajkjk wrote:
| That's backwards. React is a tool for writing declarative UI
| (or declarative anything really) that can handle state
| updates. Probably they're using it because it's the best tool
| around for that job.
| afiori wrote:
| React manages the state of the UI, all the props and the
| virtual DOM counts as state.
|
| The declarative part is that the UI is recomputed from the
| state sorta-ex-novo at each update
| DonHopkins wrote:
| New Shimmer is a Floor Wax AND a Desert Topping!
|
| https://www.tiktok.com/@user2571420815968/video/72050111295
| 9...
|
| But both the JavaScript and Lua versions of React are full
| of high fructose corn syrup, anyway.
|
| https://www.youtube.com/watch?v=H_zsZMn5Efk
|
| I'd prefer a low-calorie high-performance port of Svelte to
| Lua.
|
| https://www.youtube.com/watch?v=T6EVgwMfzb0
| hipadev23 wrote:
| when htmx.lua
| Uehreka wrote:
| That parenthetical "or anything declarative really" is
| doing a lot of work, given that:
|
| React is a tool for writing 3D scenes that can handle state
| updates: https://github.com/pmndrs/react-three-fiber
|
| React is a tool for writing music that can handle state
| updates: https://github.com/FormidableLabs/react-music
|
| React is a tool for writing infrastructure-as-code
| templates that... um... could with some additional work
| handle state updates: https://www.linkedin.com/pulse/aws-
| terraform-generator-using...
| shepherdjerred wrote:
| How did you come to this conclusion?
| lovethevoid wrote:
| You can build UI in roblox, quite a fundamental piece of the
| puzzle, but you aren't forced into using react-lua, you can use
| whatever you want. The Roblox team uses react-lua for their
| roblox studio program, the desktop/mobile roblox app, and most
| plugins [1].
|
| [1]: https://devforum.roblox.com/t/how-to-react-roblox/2964543
| TimTheTinker wrote:
| So to answer OP's question - yes, this port of React APIs in
| Lua _is_ intended to be (and is being) used to render UI
| elements -- things like text boxes, windows, titles, buttons,
| etc.
| tanduv wrote:
| Seems to be the React/DOM conceptual model that has been
| "ported". Here is an example from the Robolox repo -
| https://github.com/Roblox/react-lua/blob/main/examples/chang...
| hipadev23 wrote:
| > what was possible in Roblox was writing lua-ish scripts that
| handle events in Roblox and then alter the game flow.
|
| Roblox is a game engine, like unity or unreal or godot, that
| produces games which run within their proprietary platform. But
| you still have to code the games from an empty starting point.
| reactworld wrote:
| React is eating the world
| throwadobe wrote:
| ...like lung cancer and we keep smoking
| probablyfiction wrote:
| I don't even like writing React in Javascript
| hk-hater420 wrote:
| This is unholy and cursed
| DonHopkins wrote:
| I bet they exploited child labor to develop it.
|
| https://www.youtube.com/watch?v=n6PYj93SGxc
___________________________________________________________________
(page generated 2024-06-24 23:01 UTC)