News for hackers. Stuff that matters.
Re:Cosmopolitan v3.5.0 by auggierose on Monday June 24, 2024 @04:21AM (#40773620)
Is there a UI library that goes with that?
Re:Cosmopolitan v3.5.0 by DrNosferatu on Monday June 24, 2024 @05:18AM (#40773925)
A Web Interface for Cosmopolitan Apps would be a great bridge for an UI.
Re:Cosmopolitan v3.5.0 by auggierose on Monday June 24, 2024 @05:20AM (#40773941)
I am looking for an Electron replacement for writing my apps. Could cosmopolitan be the basis of something like that, or is that not really its purpose?
Re:Cosmopolitan v3.5.0 by brabel on Monday June 24, 2024 @06:21AM (#40774255)
Lua is perfect for Redbean because it's tiny and made for embedding, which is this exactly use case. Something like TypeScript would require a transpiler to JS and a JS runtime, which as far as I know, even the smallest one would be much bigger than Lua. And Lua has well defined semantics to call C and be called by C, which may be hard to do with JS/TS.
Re:Cosmopolitan v3.5.0 by DrNosferatu on Monday June 24, 2024 @06:30AM (#40774313)
Any examples and good tutorials on how to best go about it?
Re:Cosmopolitan v3.5.0 by brabel on Monday June 24, 2024 @11:50AM (#40777529)
Best go about using Redbean? The project is well documented: https://redbean.dev/

Just go through it, it answers all questions you may come up with IMO.

Or you mean about embedding Lua? The official docs are great too: https://www.lua.org/pil/24.html

If you prefer a tutorial, there's plenty as Lua has been around for a long time. Search on Youtube for example and there's lots of videos.

The top hit on DDG for me was https://lucasklassmann.com/blog/2019-02-02-embedding-lua-in-... which seems pretty straightforward to follow.

Re:Cosmopolitan v3.5.0 by stutonk on Monday June 24, 2024 @11:55AM (#40777608)
quickjs [1] has native support for Cosmopolitan, is meant to be easily embeddable, and is included as part of the standard Cosmopolitan distribution. It looks like qjs also has patches for recent-ish versions of the Typescript compiler as well. Someone has made a nodejs-style project called txiki.js [2] using vanilla qjs. Maybe it would build with Cosmopolitan with some tweaking. But if you're thinking of packaging a whole browser engine like Electron that might be a Sisyphian effort.

[1] https://bellard.org/quickjs/ [2] https://github.com/saghul/txiki.js/

Re:Cosmopolitan v3.5.0 by airstrike on Monday June 24, 2024 @12:29PM (#40778027)
I would suggest iced if you're ok with Rust https://github.com/iced-rs/iced

It's amazing, but I should warn documentation right now is not quite thorough

Re:Cosmopolitan v3.5.0 by lxgr on Monday June 24, 2024 @10:31AM (#40776523)
Llamafile does that (i.e. it hosts a local web server that presents a GUI).
Re:Cosmopolitan v3.5.0 by BiteCode_dev on Monday June 24, 2024 @05:28AM (#40773981)
I would use redbean, from the same author, and use HTML.
Re:Cosmopolitan v3.5.0 by auggierose on Monday June 24, 2024 @05:40AM (#40774047)
Impressive stuff. Unfortunately, Lua. From a user point of view (well, at least this user), TypeScript would be a better fit.
Re:Cosmopolitan v3.5.0 by ukuina on Monday June 24, 2024 @07:52AM (#40774918)
What are your misgivings about Lua?
Re:Cosmopolitan v3.5.0 by NateEag on Monday June 24, 2024 @08:47AM (#40775368)
Not OP, but having written some Lua, I can make some guesses:

- Relatively obscure language, so potential contributor base is limited from the start

- Lua shares PHP's "One datatype to rule them all" design, which works but feels ugly. In PHP it's "arrays", in Lua it's "tables", but either way you have all the attendant problems and weird edge cases to learn

- Expanding on above point, Lua's APIs for working with tables are, uh, idiosyncratic. Slicing a "list", last I looked, was an unintuitive monstrosity like `new_table = { table.unpack(old_table, start_index, length) }`

I could keep going, but I have other things to do during my brief time in this universe.

To any Lua aficionados out there, my apologies if I've misrepresented it. Corrections to my misunderstandings will be appreciated.

Re:Cosmopolitan v3.5.0 by samatman on Monday June 24, 2024 @03:40PM (#40779819)
> Relatively obscure language

Lua is among the most used languages in existence.

It's probably the most used language by under-21-year-olds, and almost certainly so for under 16. Roblox is absolutely enormous.

It's the usual choice of embedded scripting language, so a great number of programmers who don't use it as a daily driver, nonetheless learn it to modify this or that program. Being a very simple, minimalist language, this is easy to do.

It's true that it's missing some affordances which you'll find in larger (and frequently less efficient) languages. You'll end up doing more iteration and setting of metatables. That bothers some people more than others. These are the tradeoffs one must accept, to get a 70KiB binary which fits in an L1 cache while being multiples faster than e.g. Python or Ruby.

Re:Cosmopolitan v3.5.0 by giraffe_lady on Monday June 24, 2024 @10:40AM (#40776624)
Lua is too bare bones. It's a carefully considered tradeoff for the project goals of being a very small & easily embeddable language for C projects, but it means you need to implement too much load-bearing functionality yourself. Each lua project ends up being an ad hoc framework composed of C bindings and standard lib extensions, but it doesn't have an ecosystem that makes this straightforward or consistent.

A lot of people like lua from using it on very small projects, or like, spiritual reasons related to its implementation simplicity. But having used it quite a lot professionally, in practice it ends up being a slog to work with.

All that said, lua is closely tied to C, and embedded in a C project is both its intended use and the place where it fits best. So while I don't really like lua and would almost never choose it myself, this is one of the rare exceptions where I think it's a good choice.

A lot of people want redbean to use TS or python instead, and imo either would make it much bigger, more complex, for relatively little benefit. It would definitely benefit from a more full-featured language, but I think a weirder one that is still intended for embedding in C would be best. Something out there like janet or fuck it, tcl. But lua has a lot of allure for a lot of programmers and I think gives the project a feeling of "old school cool" while still being pretty accessible. So is probably the best choice in the end.

Re:Cosmopolitan v3.5.0 by auggierose on Monday June 24, 2024 @11:18AM (#40777058)
None in particular, except that all the code I am currently writing is in TypeScript. Especially if it comes together with HTML files.
Re:Cosmopolitan v3.5.0 by phkahler on Monday June 24, 2024 @09:58AM (#40776148)
>> I would use redbean, from the same author, and use HTML.

Wait... Could we build Solvespace web version and bundle it into that and have a completely portable CAD program that runs locally but in the browser?