r/lua • • May 24 '25
pipe operators in lua are weirdly satisfying
been playing with pluto, some superset of lua
local { http, json } = require "*"
local top_lua_repos = http.request("https://api.github.com/search/repositories?q=language:lua&sort=stars")
|> json.decode
|> |data| -> data.items
|> |items| -> items:filter(|r| -> r.stargazers_count > 1000)
for i = 1, math.min(5, #top_lua_repos) do
local repo = top_lua_repos[i]
print($"{repo.name} ({repo.stargazers_count} stars)")
endreads like "fetch → decode → filter → print" instead of a bunch of nested calls. also has string interpolation which is nice.
9
Upvotes
4
u/Interesting_Cut_6401 May 24 '25
So do Lua super sets compile to regular Lua?
6
u/Zerocchi May 24 '25
looks like elixir pipe operator and ruby blocks meshed together
2
u/[deleted] May 24 '25
Terse languages tend to be, moonscript is also a terse language btw.
1
u/EvilBadMadRetarded May 25 '25
For pipe operator, isn't it debug.setmetatable enough?
More complicated, shorter lambda may be possible via require with custom searcher/loader as transpiling from custom syntax within a module (for module library, may not apply for user code) .
1
u/negativedimension May 26 '25
I've got a rant about this in this repo (ignore the code): https://github.com/thenumbernine/leftargs-lua
TLDR is that we only put function arguments on the right because of 300 years of convention, but function arguments on the left is more readable.
0
u/[deleted] May 24 '25
[deleted] — view deleted comment