r/lua
no os.setenv and I wanted a vim.env polyfill. Made one.
https://github.com/BirdeeHub/lua-osenv feel free to use it too if you want.
It is 1 C file <250 lines, with a nice interface, use the makefile, luarocks, nix, or write the c compiler command to build.
Please support him, he is depressed. The project is really cool. https://github.com/mcreatorLoginDanila/Lume/releases
I built a persistent semantic memory library for AI agents in pure Lua -- luamemo
Hey r/lua! I've been working on something I think a few people here might find useful, and I figured it was finally time to share it.
What is it?
luamemo is a library that gives AI agents persistent, searchable memory backed by PostgreSQL. The idea is simple: instead of an AI agent starting every conversation from scratch, it can write what it learned to a memory store, then retrieve the most relevant context next time it needs it. Think RAG, but designed specifically for agent workflows rather than document retrieval.
It works in any Lua 5.1+ runtime. Lapis/OpenResty is supported but not required -- you can use it from a plain Lua script, a CLI tool, or even just pipe JSON to it.
How does retrieval actually work?
It runs a hybrid search: vector similarity (cosine) combined with PostgreSQL full-text search, then merges the two result sets. There are three ANN backends depending on what you have available:
pgvector HNSW if the extension is installed (fastest, O(log N))
A pure-Lua LSH index that auto-activates when a scope grows past ~10k rows (no extensions needed, ~O(N^0.9))
Brute-force REAL[] scan as the always-available fallback
The LSH index is random-hyperplane cosine hashing (Charikar 2002) implemented entirely in Lua with no C dependencies. It reduces the candidate pool from ~1000 rows down to 100-300 before the final re-score, so search stays fast even on large corpora without pgvector.
Embedders
You can plug in Ollama, OpenAI, Voyage, Cohere, Anthropic, DeepSeek, a generic HTTP endpoint, or TEI (Hugging Face text-embeddings-inference). There's also a built-in hash embedder that requires literally zero external services -- useful for testing, air-gapped setups, or when you just want to see things working before configuring anything else.
Benchmark on LongMemEval (R@10, n=500): hash embedder hits 81.5%, nomic-embed-text gets 83%, bge-m3 via TEI on GPU gets 97.8%.
MCP server
The library ships with a bundled MCP (Model Context Protocol) server. This means you can connect it directly to Claude Desktop, VS Code Copilot Agent Mode, or Cursor without writing any glue code. Run memo calibrate and it will detect which IDEs you have installed and offer to write the MCP config for you.
The MCP tools cover the full lifecycle: write, search, recent memories, get/update/delete, promote (move memories between scopes), and knowledge graph queries.
Knowledge graph
There's a lightweight fact store alongside the main memory table (lm_kg_facts) for storing currently-valid facts with temporal validity -- things like "user is working on project X" that you want to be able to invalidate explicitly rather than just decay.
Secrets (no C crypto deps)
One thing I spent a lot of time on: the secrets module lets agents make authenticated HTTP requests without the secret value ever appearing in the LLM context. You store a key via the CLI (memo secret-store NAME), and the agent calls secret_execute with {secret} as a placeholder. The substitution happens server-side.
The crypto is AES-256-CBC + HMAC-SHA256 implemented in pure Lua (no lua-openssl, no C extensions). SSRF protection blocks private IP ranges. HMAC comparison is constant-time. Secrets live in a JSON file on disk, not a database table.
Getting started
luarocks install luamemoexport MEMO_DB_URL=postgresql://user:pass@localhost/mydbmemo calibrate
calibrate handles the schema, asks which embedder you want, and sets up MCP config if you have a supported IDE. After that you're writing memories from the CLI or calling the library directly.
Links
GitHub: https://github.com/kaio326/luamemo
LuaRocks: https://luarocks.org/modules/kaio326/luamemo
Happy to answer questions about design decisions, the LSH implementation, or anything else. This is my first time sharing it publicly so feedback is very welcome.
Tiny Lua Compiler: a complete educational Lua 5.1 compiler in a single Lua file
github.comSuper Strict is a Lua library that finds undeclared variables and other minor mistakes in your source code. Super Strict tests your Lua scripts during loading using static analysis. Super Strict is very secure because it can be used without downloading, installing or running any pre-compiled binaries.
SuperStrict can now detect invalid numeric precision in your Lua source code: https://2dengine.com/doc/sstrict.html
How to use Lua reference manual?
I'm brand new to programming, and entirely self taught atm. I'm trying to read the Lua reference Manual, and I find it extremely confusing. I feel like I need a tutorial on how to read it.
Does anyone have suggests on things I need to do or learn so I can actually understand the manual?
Even when I type the simplest Lua code into VS, I don't see any results. What can I do?
I made a simple lua IDE for Android with emmyLua LSP server, Git and Github integration, 245 themes, etc.
This is not some vibe coded app. It took me 2 years to finish this as a solo developer and student.
playstore link:
https://play.google.com/store/apps/details?id=com.roxum
source code:
How do I andle big ints that get cut off?
Hello, in a game im creating a mod. This mod meeds to get the user's steam ID. I've been trying for two days to fix this but at this point I ran out of ideas. I get an approx of it because it looks like lua can't handle big ints? I'm getting 1.23456789101112e16 insteaf of 123456789101112131415. this is a problem for me because im working on a project where i need the full steamid for autentication. Do you guys know how I could fix that? I tried to convert it into strings but I still get the last five-four digits cut and replaced with e16.
Most Lua tutorials send you to a blank text editor on day one. That's where beginners drop off.
I've been building LuaPath for the past few months. The core idea: write real Lua code directly in the browser, see it run instantly, no installs, no config, nothing to break before you even start.
The playground is paired with a structured lesson path - chapters that go from absolute zero to actual scripting logic. Each lesson has a code block you edit live. You see the output change as you type.
I also added visual progress tracking so you always know where you are in the curriculum. It sounds small but it matters a lot for beginners who otherwise have no idea if they're halfway done or just getting started.
Right now there are 5 people using it. The community is basically empty, which means early users get to shape what gets built next.
The use cases I'm targeting first: Roblox scripting, Nginx config, and Adobe Lightroom plugins - three very different worlds that all run on Lua.
Curious if anyone here has tried learning Lua and hit a wall early. What stopped you?
your*
Only know of these ways but kinda curious if there's more
Proceedural(?)
function make\_vector(x,y)
return {
x = x or 0,
y = y or x or 0
}
end
function print\_vector(vector)
print( "X: ".. vector.x .. " Y: " .. vector.y)
end
local pos1 = make\_vector(10,15)
print\_vector(pos1)
pos1.x = 0
print\_vector(pos1)
No metatables
local Vector = {}
function Vector.new(x,y)
local self = {}
self.x = x or 0
self.y = y or self.x
function self.print()
print("X: " .. self.x .. " Y: " .. self.y)
end
return self
end
local pos1 = Vector.new(10,15)
pos1.print()
pos1.x = 0
pos1.print()
metatables
local Vector = {}
Vector.__index = Vector
function Vector.new(x,y)
local self = setmetatable({},Vector)
self.x = x or 0
self.y = y or self.x
return self
end
function Vector:print()
print("X: " .. self.x .. " Y: " .. self.y)
end
local pos1 = Vector.new(10,15)
pos1:print()
pos1.x = 0
pos1:print()
I’ve been working on a new project: tear — a rewrite of Teal in Rust, aimed at making Lua tooling faster, more robust, and easier to extend.
The goal isn’t just performance — it’s also about better tooling ergonomics, cleaner architecture, and a foundation for future Lua ecosystem improvements (think package management, LSP, and beyond).
It’s still early, but I’d really appreciate feedback from the Lua community: what pain points should a next-gen Teal solve?
I made a thing called Sino
basically I got tired of not having classes in Lua and ended up making a small superset that transpiles to normal Lua (no runtime or anything)
I also threw in destructuring and some reference type stuff (it’s basically just table wrappers)
it’s pretty rough but I’ve been using it a bit and it’s not... that bad.
https://github.com/pero-sk/Sino/
no idea if this is actually useful or just a dumb idea, I'm curious what people think of this though.
My new website to learn "Lua". I created this so anyone can learn Lua step-by-step and try code right in the browser. You can read lessons and instantly run your own code to see results in real time. Perfect for complete beginners, Roblox scripters, game devs, or anyone who wants to learn Lua practically.https://master-lua-logic.base44.app
#Lua #LearnLua #LuaProgramming #Programming #Coding #RobloxDev #WebDevelopment #FreeResources #LearnToCode
I’d love your feedback! Tell me what you think, what’s missing, or any bugs you find. Happy to keep improving it.
aui
Hello everyone, I'm making a UI library in Lua using luajit + FFI module. The targeted platforms are OpenBSD and Windows. This is in a very early stage (aka not usable) but if you're interested in seeing my progress or give feedback here it is : https://codeberg.org/onuelito/aui
EDIT: The first version of this post had a clumsy title ("a girl just beat me in my own game") that didn't land well. That's on me. The point was always the leaderboard, not who was on it. I rewrote the post below. Thanks to the people who flagged it kindly, and to the ones who didn't, i hear you too.
TL;DR: I'm a solo dev who came up through Project Zomboid modding (around 130k combined Workshop subs, with Wheelbarrow alone past 140k). All in Lua. Recently used the same Lua experience to ship my first solo full game, a small browser arcade called SOLONE. Posting this hoping a few of you give it a shot and tell me what you actually think.
Hi, i'm Reifel.
Some of you might know me from Project Zomboid modding, where i built Wheelbarrow, Firetrail, and Dragon Radar over the last few years. A few of you might also remember the PZRank leaderboard project i shared a while back. All of those are written in Lua, which i learned the hard way by reading other people's mod source code and breaking things until they worked.
Defold (the engine i used for this new project) also runs on Lua. When i found that out, i figured i'd see if the same skills i used for modding could carry me through shipping a standalone game from scratch. The result is SOLONE, a 30 second arcade browser game with an online leaderboard, no install, opens right in your tab.
I'm putting a lot of myself into this. It's my first solo game, so i'm still learning what works and what doesn't, and feedback genuinely helps me improve it. The honest hook for posting today: my own friends are beating me on hard mode. One hit 329 kills in 276 seconds, another hit 211 in 188 seconds. I can't catch either of them. I wanted to see if anyone here could humble me further, or maybe let me reclaim my own game.
Play in your browser
- Latest build: https://mapafome.com.br/solone
- itch.io mirror: https://reifel.itch.io/solone
- Rate it on itch if you'd like to support: https://reifel.itch.io/solone/rate
A few things about the game
- No install, runs in any browser, no account needed
- Pause menu has a poll where you vote on which power ups ship in the next patch (your vote actually counts, i read every result)
- Solo dev, current version v1.8.97, constant updates
- Behind the scenes it's actively keeping your FPS stable while you play, even on cheaper devices. Stress tests pass cleanly. That part you'll never see, which is exactly the point.
- Short gameplay clip if you want a preview: TikTok
My PZ projects (in case you're curious)
- Wheelbarrow for carrying logs and heavy stuff while building
- Firetrail for pouring gasoline in a line and igniting it, great for corpse cleanup
- Dragon Radar for locating wanted items on the map
- PZRank leaderboard, a community survival ranking i built
- Workshop stats dashboard for tracking mod growth
If you're a designer or dev who'd like to collaborate on future versions, reach me on Discord: @reifel1 (server invite).
Honest feedback is welcome. So are kind words, since they fuel the next update. If you give it a shot, drop your high score below. Bonus respect if you beat me on hard mode.
Hi everyone!
I've been working on a library called fallo (failure in my native language) for quite a while now, and I realized I never actually shared it with the community until now. You know that classic "it's not ready yet" syndrome? Well, here we are!
If you've ever felt that Lua's pcall/error pattern gets messy in complex Neovim plugins, or you've written too many if err ~= nil then ... end chains, this might be exactly what you're looking for.
What's fallo?
Fallo is a modern, ergonomic error handling library for Lua, heavily inspired by Rust's Result type. Instead of throwing errors or returning nil, err pairs, you get explicit Ok and Err variants with immutability that you can chain, transform, and propagate cleanly. The whole idea is to make error handling in Lua less painful and way more readable (I hate Go's error handling pattern, if you haven't noticed it yet).
Why you might want to use it
- Error propagation: This is the big one. Tired of checking every single function call? With fallo, you can use
:unwrap()to bail out early, or:try()to propagate errors up the call stack without all the boilerplate. Makes deeply nested operations actually readable. - Seamless Lua interop: It doesn't force you to rewrite everything. You can wrap existing functions that throw errors and convert them to
Resulttypes. You can also go the other way around and convert Results back to Lua's error system. It plays nicely with the existing ecosystem. - Structured errors: No more strings all the way down. You can carry metadata, context, and even stack traces! And since fallo uses LuaCATS annotations, you get proper type inference in Neovim with LSP support, so you know exactly what you're dealing with at each step.
- Method chaining: Write fluent, readable code (example not specifically tailored to Neovim, since the library is meant to be used anywhere):
​
-- Old way:
local file = io.open("config.json")
if not file then return nil, "Could not open file" end
local content = file:read("*a")
local ok, parsed = pcall(json.decode, content)
if not ok then return nil, "Invalid JSON" end
-- ... now validate it, handle more errors ...
-- With fallo:
read_config()
:map(parse_json)
:and_then(validate)
:inspect(function(cfg) print("Config loaded:", cfg.name) end)
:unwrap_or_else(function(err) return default_config end)
- Zero dependencies: It's a self-contained single file. Drop it in your project,
git cloneit or install it through LuaRocks and you're good to go.
Why I'm sharing this now
The library is stable and battle-tested with a solid test suite right now, but I'm looking for early adopters to help with real-world dogfooding. I want to see how it actually performs in Neovim plugins, get feedback on the API, and understand what the plugin developer ecosystem needs for better error handling since I've been out of Neovim plugins development for quite a while now.
If this resonates with you, please try it out! There's a growing set of examples to get you started, and it's available on LuaRocks:
$ luarocks install fallo
Or just grab the single file from the repo if you prefer.
I'd genuinely love to hear your thoughts. What works, what doesn't, what's missing. That's how we make the ecosystem better for everyone!
Repository: https://github.com/NTBBloodbath/fallo
So i am by my Career a Certified Electrician in Germany and recently wanted to start learning how to Program Video Games :D
I have been doing some Blender Work afterall (Mostly for Resonite and VRC Furry Friends XD) and thought that it shouldnt be so Hard :P
Well basically it took me 4 Months to grasp the Concepts of creating a Breakout Clone sadly :(
and even more Embarassingly i still dont grasp them 100% :(
For Example i am trying to create a Super Mario Bros Game from Scratch but featuring Planets and Space Physics :(
First i did was create Super Mario Bros 1-1 and a Basic Platformer "Engine" as a Base >.>
But i now still struggle with Planetary Gravity and "Round" Planets still :(
Like my Player gets stuck in the Ground even tho he can move "along the Axis" and its just been so frustrating as to what im doing wrong :(
Does anyone know of a Library or by chance would be able to help me understand? ^^"
Im sadly still quite new to all of this so please bear with me >.<
Tthe header says it all. I'm developing a game engine in C, and I wanted to know if LuaJIT supports Windows XP, so people who're still using it—they probably exist—could use it.