allelua
is a Lua runtime with secure defaults and a great developer experience.
It's built on mlua
,
Rust and Tokio.
Here's what makes allelua
a unique alternative to language like Python and
runtimes like Deno / NodeJS:
- Fast and resources efficient: LuaJIT is extremely fast and lightweight.
- Simple:
- Lua is a lot simpler than other scripting language
- Stable, based on Lua 5.1 with a few 5.2 compatibility features, core language won't change or will remains 100% compatible
- Easy concurrency:
- No async/await
- Write concurrent code like single threaded code using structured concurrency
- Secure by default (planned)
- Batteries included:
- Linter
- Formatter
- LSP
- Package manager (planned)
- Task runner (planned)
- Test runner
- Benchmarking tool
- Documentation generator (wip)
- Type checker (wip)
- FFI support (planned)
Our goal is to transform Lua, originally designed as an embeddable scripting language, into a full-fledged, independent programming language capable of standalone use.
Here are a few examples:
allelua
supports structured concurrency built on top of Tokio. If you're
unfamiliar with structured concurrency and why unstructured concurrency isn't
supported read this article:
Notes on structured concurrency, or: Go statement considered harmful
coroutine.nursery(function(go)
go(f, x, y, z)
-- or
go(function()
f(x, y, z)
end)
end)
starts a new goroutine running
f(x, y, z)
A goroutine is a lightweight thread managed by the allelua
runtime. But unlike,
Go's goroutine, they can only be spawned in coroutine.nursery()
function. Also
when coroutine.nursery()
returns, all goroutines have finished to execute.
Here is an example proving that goroutines runs concurrently:
local time = require("time")
coroutine.nursery(function(go)
local now = time.Instant:now()
for i = 1, 3 do
go(function()
time.sleep(1 * time.second)
print("goroutine", i, "done in", now:elapsed())
end)
end
end)
prints
goroutine 1 done 1.001s
goroutine 2 done 1.001s
goroutine 3 done 1.001s
If goroutines were run one after another, they would print:
goroutine 1 done 1.001s
goroutine 2 done 2.001s
goroutine 3 done 3.001s
Allelua is legacy-free and breaks compatibility with standard Lua. We provide our
own standard library with handy modules such as sh
that provides a DSL for
shell scripting:
local os = require("os")
coroutine.nursery(function(go)
local sh = require("sh").new(go)
-- Pipe ls stdout into tr.
-- ls -l | tr [a-z] [A-Z]
local output = sh.ls("-l"):tr("[a-z]", "[A-Z]"):output()
-- Pass io.Reader as stdin.
-- You can also redirect stdout and stderr to io.Writer.
local f = os.File.open("/path/to/file", { read = true })
output = tr({ stdin = f }, "[a-z]", "[A-Z]"):output()
print(output)
end)
If you want to contribute to allelua
to add a feature or improve the code contact
me at [email protected], open an
issue or make a
pull request.
Please give a ⭐ if this project helped you!
MIT © Alexandre Negrel