A first glance at LuaGravity
As a pragmatic programmer, I’ll try to mix the academic bla,bla,bla with practice, so…
LuaGravity is the name of my toy language that implements the synchronous approach for concurrency (I’ll dig into it sometime).
(Actually, it’s a *serious* toy language as a I’m very concerned to it and keep adding features and tweaking it all the time.)
When running it without a filename, you’ll see a prompt just like in the Lua Language .
As you type the statements and expressions you’ll attest that it’s just normal Lua…
Except, it’s reactive!
The video above shows that the variables a and b reacts to the current time, a – b to a and to b, and so on.
The INT function integrates its argument over dt (remember it from Calculus?).
It’s used here only to create a time reference for the application.
The L function states to its arguments that they should behave reactively (the name comes from “function Lifting”).
The result of the expression a – b shows the perfect synchronism between its arguments: no need for locks, no milliseconds difference, no text blinking, just zero as it is expected.
LuaGravity is roughly based on Esterel  and FrTime , two synchronous languages, the former having an imperative style, the latter being functional.
The example above shows only some functional features.
Here are some LuaGravity Implementation Facts:
- It’s implemented over the Lua language runtime (there’s no need to parse source code).
- The engine running the system is “just” an event handler.
- The elapsed time during an event handling determines the dt value used by INT and varies over the time.
- The prompt you see is a collection of graphical objects (no, it’s not a magical raw terminal).
- It’s single threaded, of course.
- The engine’s whole source has about 300 lines of Lua code.
In the next examples we’ll escape from the dry command line and see a lot of graphics, where LuaGravity really rocks.