Here are some quick comments on just looking over the code.
1) You can remove pop_a_t() as the function luaL_checkudata() already does
the error checking for you. Yes, it's in the manual, it's the [-0,+0,v] bit
past the function prototype in section 4.8 (there's a similar notation for
each function in that section). The 'v' means it will throw an error.
2) There's no need to call lua_checkstack() as Lua will have at least 20
stack slots available (section 4.2) unless Lua has been compiled with a
3) I'm personally not a fan of getters and setters, and I would create a
function for __index that would allow me to avoid having to call a function
to set/get a value from the userdata. You can see an example in my own
network interface  for both sockets and network addresses. But that's
4) I think there's a bug with your use of LUA_REGISTRYINDEX, but it's not
easy to follow the code. The only place you set the registry is in
push_a_t() and that just uses the pointer to an a_t. You later attempt get
info out of the registry in getter_a_pp(), but at no point do you save the
address to a c_t in the registry. Did you try running the code you wrote in
Having written code for Lua 5.1 through 5.3, an old tutorial should still
be mostly fine (a few API calls have changed). Also, what use case do you
have? You don't spell that out in the tutorial and it seems overly complex
for what it actually done in the code.
(And what version of Python? 2.7? 3.0? It makes a difference)
The shebang on luatablegen.py reads "#!/usr/bin/python3", so it is some version of Python 3.x. The use of print as a function confirms this. I see nothing in the code at a glance (I didn't look to hard as it was painful to read) limiting it to specific Python 3.x versions, other than the argparse dependency which was introduced to the stdlib in 3.2 (although there is a backport on PyPI for 3.1 and 2.x).
Thank you for taking the time and looking through the tutorial.
I did run the code. It works. I guess the confusion reinforces your
point on the tutorial being too complex for what it talks about. This
is pretty much my first time writing a tutorial
The script is in Python 3.0. The script is in Python because I'm a
little bit better in Python than in Lua. Though to be honest, I
realized the ridiculousness of plugging a Python script on the Lua
mailing list in a Lua tutorial after you asked why it is in Python and
not Lua. Sorry about that.
I'm working on a tool that embeds Lua as its scripting language(the
tool is a cli). Right now another code-generator pushes out code that
reads a binary file format(like WASM, ELF,...) and the script I
mentioned will wrap the resulting C structs for Lua.
Regarding the API changes being minimal from 5.1 to 5.3, you know
that, true, but someone new to Lua doesn't. To top it off, you get the
"different Lua versions are really different" line on lua.org, so not
knowing much, I had to assume things were very different. I had to
spend a lot of time to realize all of the things in the tutorial. The
point of the tutorial is to save beginners like myself the time(also
the self-plug tbh) that I had to spend going through old tutorials,
Stackoverflow and the Lua mailist to learn all of that. Besides, for
my particular use-case(structures having pointers to other structures)
I couldn't find any tutorials.