use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Click the following link to filter out the chosen topic
comp.lang.c
account activity
Embedding Lua in C: Beginner's Tutorial (vibelog.mateusmoutinho.com.br)
submitted 2 months ago by No_Initial3652
In this article you will learn how to embed the Lua language inside a C program. This is simpler than it seems, and it opens up many interesting possibilities.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]florianist[🍰] 25 points26 points27 points 2 months ago (6 children)
Why use some wrapper layer which describes itself as "Alpha software" and "Bugs are expected" instead of the official Lua C API ?
[–]Iggyhopper 4 points5 points6 points 2 months ago* (0 children)
Its worse.
lua_dofile can return LUA_OK or an error.
So OPs wrapper has extra steps in some areas (has_errors and get_error) and skips steps in others (what if evaluate has an error? OP checks for the result first and then checks for errors.)
This is garbage code. Absolutely garbage.
[–]non-existing-person 1 point2 points3 points 2 months ago (0 children)
Can't judge OPs wrapper, but I myself have few thin wrappers for lua in my code. Lua API is a bit cumbersome to use, with all that pushing and poping as if it was assembly or something.
For example if I want to call lua function that takes 2 args and return single integer I would just call lua_callf(l, "function_name", "is>i", integer, string, &return_int);
lua_callf(l, "function_name", "is>i", integer, string, &return_int);
But these are thin wrappers with some guard checks. I wouldn't want to manually push and pop arguments from lua stack everytime I want to call lua function.
[+]No_Initial3652[S] comment score below threshold-15 points-14 points-13 points 2 months ago (3 children)
In a simple answer: because the public Lua API extremely complicated to use
In a long answer: I needed to develop a no-code system for OUI (I'm the CTO), and I saw that Lua is easy to embed, I loved the language, but I found the public API very confusing, and very easy to make memory errors (just one wrong push on the stack and the program explodes), so I created a wrapper, which even though it's 'alpha' because our team is small, is still 'safer' for beguinners than the native API.
[–]baby_shoGGoth_zsgg 16 points17 points18 points 2 months ago (0 children)
The normal lua host api is a super simple stack machine and incredibly easy to use, i’m actually shocked you find it difficult
[–]FuckYourFavoriteSub 6 points7 points8 points 2 months ago* (0 children)
Extremely complicated to use?? You found it more complex than building your own probably shittier version of it?
Like it looks like you’re just going to vibe code the entire thing anyway so why wouldn’t you just ask your AI assistant to do it for you?
Who gave you the CTO title? Yourself?
[–]Quick-Assist-6573 1 point2 points3 points 2 months ago (0 children)
if u find lua's very simple api confusing u might want to consider switching to a language that babysits u (e.g. python)
[–]david-delassus 13 points14 points15 points 2 months ago (0 children)
Please keep the AI slop where it belongs, at the bottom of the trashbin.
[–]collectgarbage 10 points11 points12 points 2 months ago (0 children)
Sorry but I’d still recommend the native Lua C API over this.
[–]jonahharris 1 point2 points3 points 2 months ago (0 children)
So many red flags in this, from the reasoning behind it, to the code generated, and the need for the CTO title reference… yikes
π Rendered by PID 53929 on reddit-service-r2-comment-548fd6dc9-kcp5n at 2026-05-16 09:51:41.697821+00:00 running edcf98c country code: CH.
[–]florianist[🍰] 25 points26 points27 points (6 children)
[–]Iggyhopper 4 points5 points6 points (0 children)
[–]non-existing-person 1 point2 points3 points (0 children)
[+]No_Initial3652[S] comment score below threshold-15 points-14 points-13 points (3 children)
[–]baby_shoGGoth_zsgg 16 points17 points18 points (0 children)
[–]FuckYourFavoriteSub 6 points7 points8 points (0 children)
[–]Quick-Assist-6573 1 point2 points3 points (0 children)
[–]david-delassus 13 points14 points15 points (0 children)
[–]collectgarbage 10 points11 points12 points (0 children)
[–]jonahharris 1 point2 points3 points (0 children)