News for hackers. Stuff that matters.
Re:Gravity: An embeddable programming language without any e... by astatine on Tuesday June 09, 2020 @11:34AM (#23467525)
I imagine this would be an alternative where embedded Lua gets used. A comparison with Lua would have been great to see. The 200K runtime, for example, indicates that this might weigh in somewhat heavier than Lua.
Re:Gravity: An embeddable programming language without any e... by Rochus on Tuesday June 09, 2020 @02:30PM (#23469274)
Lua is indeed difficult to beat in this respect. If you need performance you can even embedd LuaJIT with a footprint still far under one megabyte. And if you don't like the Lua syntax, there are already good alternatives,e.g. the statically/strongly typed https://github.com/rochus-keller/Oberon which directly generates LuaJIT bytecode (based on https://github.com/rochus-keller/LjTools). Here is a fairly complete list of languages compiling to Lua: https://github.com/hengestone/lua-languages. Gravity could be one of these if need be.
Re:Gravity: An embeddable programming language without any e... by zeotroph on Tuesday June 09, 2020 @07:39PM (#23472208)
LuaJIT development has effectively halted, and only supports Lua 5.1 (5.3 is current, 5.4 imminent).

I get the feeling that Lua is slowly on its way out because the academic nature of it never meant it had to be more than "good enough" outside it's core strengths.

I think they should have kept a super-light "classic" Lua where ~= still means !=, there are only tables, and all the other quirks (but also speed). Then add official, optional support for classes, lists, dicts, sets. This probably can all be built on top of setmetatable, so be pure lua, but at least it comes as one consistent standard library and not in the form of a fractured ecosystem.

All the mentioned compiles-to-lua Projects tried something similar, but never gained significant traction, probably because of the lack of an official blessing.

Re:Gravity: An embeddable programming language without any e... by Rochus on Tuesday June 09, 2020 @08:04PM (#23472415)
> LuaJIT development has effectively halted ... never meant it had to be more than "good enough" outside it's core strengths

That's a wrong impression. Even the original author of LuaJIT still commits regularly and there are dozens of companies maintaining and using it in industrial scale applications, and there are a couple of forks which focus on specific use cases and are independently developed. Not to forget the hundreds of games using Lua as a scripting language.

> only supports Lua 5.1 (5.3 is current, 5.4 imminent).

Which is obviously enough for most people using it including me. I don't see any unique selling point which would force me to update to Lua 5.3 or higher.

> and all the other quirks (but also speed).

Well, do your research. LuaJIT is among the fastest JITs available (e.g. a factor ~1.5 faster in geometric mean than JS V8), but with a much smaller footprint.

Re:Gravity: An embeddable programming language without any e... by zeotroph on Wednesday June 10, 2020 @08:00AM (#23476110)
> 5.1 / 5.3 -- "don't see any unique selling point" -- "there are a couple of forks"

Doesn't that show that the actual users of Lua and the authors have drifted apart, and the former are not willing to commit to a hard fork or taking over development? Or both sides could come together to form a much-beloved committee. The curse of "good enough".

> quirks / fastest

I think you misunderstood: Yes, it is fast even without LuaJIT, and super easy to embed and integrate - which is why this slow fading away into the embedded only realm would be quite a shame.

But it is also "quirky", and adding some (optional, possibly slower) syntax sugar over it could make it more appealing. Sure, Lua-fans will argue that tables are better than anything, but for those who just want to transfer existing language knowledge are hard to convince, and setmetatable makes everything even weirder.

Re:Gravity: An embeddable programming language without any e... by Rochus on Wednesday June 10, 2020 @11:05AM (#23477829)
> the actual users of Lua and the authors have drifted apart

So what? It has an MIT license, and there are obviously different communities with different requirements.

> it is fast even without LuaJIT

Not really. The PUC Lua VM is even slower than Python (in geometric mean) according to https://benchmarksgame-team.pages.debian.net/benchmarksgame/.... LuaJIT in interpreted (not JIT) mode is still four times faster than PUC Lua (see http://luajit.org/performance.html).

> this slow fading away into the embedded only realm would be quite a shame.

I assume you mean "embedded use in applications" (i.e. not embedded systems). That's exactly what Lua was designed and built for by its original authors. An that's how it is mostly used.

> adding some (optional, possibly slower) syntax sugar over it could make it more appealing

Lua can do surprisingly much for this lean and simple syntax. If instead you prefer a baroque, pretentious syntax like Python or TypeScript, and are obviously satisfied with Python's performance, you already have a well established solution. And as I've demonstrated e.g. with https://github.com/rochus-keller/Oberon you can replace Lua by a more complex language and still profit from the performance and leanness of LuaJIT.

Re:Gravity: An embeddable programming language without any e... by simcop2387 on Tuesday June 09, 2020 @11:37PM (#23473645)
For me the biggest things with newer luas would be things like the bitwise operators, 32bit numbers and utf8 support. I haven't played with 5.4 yet but the garbage collection changes look rather nice too for some of the embedded work i've done with lua
Re:Gravity: An embeddable programming language without any e... by Rochus on Wednesday June 10, 2020 @04:35AM (#23475106)
> biggest things with newer luas would be things like the bitwise operators, 32bit numbers

LuaJIT has that already.

> utf8 support

This is rudimentary. Easy to add an even better library to previous Lua versions.

Re:Gravity: An embeddable programming language without any e... by vorpalhex on Tuesday June 09, 2020 @11:58AM (#23467759)
As someone who just worked on a project where I embedded lua, that's exactly what I was looking for. Why would I want to choose this over lua and what's the pro/con matrix?
Re:Gravity: An embeddable programming language without any e... by kevin_thibedeau on Tuesday June 09, 2020 @08:59PM (#23472729)
0-based array indexing and local scoping by default.
Re:Gravity: An embeddable programming language without any e... by rumanator on Wednesday June 10, 2020 @01:47AM (#23474341)
If that's the best you can come up with then I'm afraid there isn't much of a case to use this over lua.
Re:Gravity: An embeddable programming language without any e... by VWWHFSfQ on Tuesday June 09, 2020 @10:24PM (#23473250)
would have to do better than that
Re:Gravity: An embeddable programming language without any e... by cygx on Tuesday June 09, 2020 @01:23PM (#23468642)
If such a comparison gets added, Wren[1] might also be of interest.

[1] https://wren.io/

Re:Gravity: An embeddable programming language without any e... by mythz on Tuesday June 09, 2020 @01:33PM (#23468765)
Wren and Bob Nystrom are called out as major inspirations:

https://github.com/marcobambini/gravity#special-thanks

Re:Gravity: An embeddable programming language without any e... by ctas on Tuesday June 09, 2020 @01:28PM (#23468703)
The similarity to Gravity is astonishing.
Re:Gravity: An embeddable programming language without any e... by fallat on Tuesday June 09, 2020 @08:17PM (#23472512)
wren is so far my favorite small, simple language.
Re:Gravity: An embeddable programming language without any e... by theptip on Tuesday June 09, 2020 @12:45PM (#23468206)
Agreed, Lua seems to be the de-facto standard here, as it's so lightweight to embed. But the language has some pretty janky rough edges (e.g. only having Tables and no other data structures) so a modern alternative would be nice.
Re:Gravity: An embeddable programming language without any e... by tastyminerals on Tuesday June 09, 2020 @01:36PM (#23468804)
Once you get to know Lua tables and then metatables, you will question the existence of different data structures :)
Re:Gravity: An embeddable programming language without any e... by jmiskovic on Tuesday June 09, 2020 @02:18PM (#23469173)
Yes, Lua tables are incredibly versatile tool. I'm not a fan of global-scope-by-default and of verbosity, but other than that it's a fantastic language.
Re:Gravity: An embeddable programming language without any e... by craftinator on Tuesday June 09, 2020 @03:58PM (#23470232)
I think global by default is one of the reason Lua shines in the embedded world. Not many other arenas where that is good practice.
Re:Gravity: An embeddable programming language without any e... by centimeter on Tuesday June 09, 2020 @04:42PM (#23470674)
Global scope by default isn't good practice in embedded. Global scope isn't synonymous with static allocation, but unfortunately that goes over the head of many people. Best practice in embedded is to have locally scoped statically allocated data passed around by reference.
Re:Gravity: An embeddable programming language without any e... by craftinator on Wednesday June 10, 2020 @04:51PM (#23481956)
It really depends on the application. For smaller, more targetted embedded applications, global scope is fine. If every function needs to have access to a common set of variables, there's really no need to be passing references around.
Re:Gravity: An embeddable programming language without any e... by centimeter on Wednesday June 10, 2020 @05:33PM (#23482403)
Even if the application is tiny, that's no excuse. It makes it even easier to chuck everything into a single struct type. It's not like there's any performance gain to having globally scoped stuff on a modern compiler compared to passing references.

One reason using global variables is bad practice is it makes testing harder. An unfortunately high percentage of embedded software doesn't have any sort of harness-based testing because it's written with globals spammed everywhere, which prevents you from using any kind of principled testing strategy where you mock out all the hardware dependencies. It's especially bad if there's globally defined MMIO stuff like "#DEFINE CCR1A (uint64_t)0x74FEA10". Good luck testing that!

Re:Gravity: An embeddable programming language without any e... by jmiskovic on Thursday June 11, 2020 @09:21AM (#23488549)
Smaller embedded targets don't have modern C++ compilers. Also many engineers want to solve domain problems instead of dealing with C++ related problems.

In domain of C, passing by reference means passing pointer. If you chuck everything into single struct and pass by pointer, it has same problems as global scope.

Not that I'm advocating for global variables. Even tiny projects tend to grow with time, and localizing scope across the code base is not fun at all. In context of Lua, I've just trained myself to prefix variables with 'local' and I don't give it much thought.

Re:Gravity: An embeddable programming language without any e... by centimeter on Thursday June 11, 2020 @02:00PM (#23491552)
> If you chuck everything into single struct and pass by pointer, it has same problems as global scope.

Not true. In fact, this refactor is one of the best things you can do to improve an old shitty embedded C codebase. Among other benefits, it allows you to have multiple instances (an arbitrary and easily-adjusted number, in fact) of a system sharing the same memory, reduces the complexity of linker-related BS, and simplifies testing. It's vastly better than relying on horrendous C cross-module scoping rules for sharing.

Re:Gravity: An embeddable programming language without any e... by jmiskovic on Friday June 12, 2020 @08:21AM (#23498481)
To me the main problem of global is that any module can mutate and affect any other part. All encapsulation and modularisation is then leaky and you are always on your toes about implementation details in some other part of code. Your approach does not attempt to solve this downside of globals.

I agree that passing in structs is vastly better than communicating over globals. On the other hand, taking existing code base and implementing this state-passing is quite large undertaking that affects all function declarations/implementations. It might be beneficial, but there are often better investments of your time.

Re:Gravity: An embeddable programming language without any e... by zem on Tuesday June 09, 2020 @04:28PM (#23470537)
editor scripting, perhaps
Re:Gravity: An embeddable programming language without any e... by novemberisms on Tuesday June 09, 2020 @06:47PM (#23471809)
A lot of people who don't like Lua list "only having tables" as some sort of negative, but honestly I don't see how that is bad in any way.

1. Having only 1 data structure makes for a simpler, more elegant language. Once you understand tables, you understand everything you need to know about lua.

2. You could implement any other data structure with a table.

* A table is basically a dictionary / map already

* A table can be an array if you use numbers as keys. They don't even have to start at 1.

* A table can easily be made into a set if you use the elements of the set as keys and 'true' as the values.

* A table can be made into a proper OOP class with metatables

* A table can use prototypical inheritance too

* A table can act as a basic data record object

Those using the language don't really miss having the more specific data structures.

Re:Gravity: An embeddable programming language without any e... by theptip on Wednesday June 10, 2020 @02:38PM (#23480540)
In my experience, it took a bit of conceptual work to get used to the "Lua way", and that impedance mismatch would have been reduced if it shared more similarities with the other languages we were working with.

Context is important IMO; if you're going to using a language as your primary development tool, then you'll get over that hump fairly quickly, and my objection is less relevant. But for our use-case (embedding Lua in a C application to have user-provided scripts drive our C library's callback hooks), the developers were primarily working in C and Python, and so most of us didn't use Lua often enough to really click with it.

For our use-case, something a bit closer to Python or Java would have been much easier to grok, and therefore would have made our development easier and more productive. "Easy and more productive" is all I'm really looking for in a language, always within the context of the specific usecase of course.

I'd be fine with dropping most of the sugar in Python or Java, but I'd be surprised if there were no "zero-cost abstractions" that could be added to Lua without making it too heavyweight for embedding.

Re:Gravity: An embeddable programming language without any e... by Rochus on Tuesday June 09, 2020 @02:52PM (#23469520)
There are a lot of alternatives. See https://github.com/hengestone/lua-languages. These languages use the Lua or LuaJIT VM as a backend, either as a Lua transpiler or a bytecode compiler.
Re:Gravity: An embeddable programming language without any e... by runawaybottle on Tuesday June 09, 2020 @01:02PM (#23468390)
Isn’t that what makes it lightweight?

It literally doesn’t have the extra weight.

Re:Gravity: An embeddable programming language without any e... by tastyminerals on Tuesday June 09, 2020 @01:40PM (#23468841)
And don't forget that "modern alternative" should boast as good as Lua C ffi which is a tough thing to beat. Should I mention luajit?
Re:Gravity: An embeddable programming language without any e... by astrobe_ on Tuesday June 09, 2020 @02:42PM (#23469408)
Oh yes, we need a modern powerful web-scalable professionally infrastructured alternative.

Sorry for the sarcasm, but if you are thinking with theses words, you are thinking wrong.

Re:Gravity: An embeddable programming language without any e... by pinopinopino on Tuesday June 09, 2020 @04:19PM (#23470434)
I feel your sentiment. Modern doesn't mean good perse.