Lua_newtable and lua_settable

I'm on my second project now where I'm writing most of the game in Lua and some functions in C. Both times, given my prior experience writing Lua bindings, I've been annoyed at the lack of lua_newtable and lua_settable.

I can see what you're going for, trying to make Lua appear more object-oriented. For many use cases it's probably way better and easier to understand! However, sometimes I just want to return a short list of values from a function, and with the current state of the C API I'd need to make an entire class with an __index method.

(Related thread, both of these would be fixed by just pulling in all of lua.h)

For a short list, you should be able to just push the values to the stack without running over the reserved space--the API function doesn't call lua_checkstack(), but it probably should. There's also an Array example in the C_API/Examples folder now which should give you a head start on making a collection class. Or you could just copy the Lua 5.4.3 source into your project.. (201.0 KB)

It's kinda sketchy but it seems to work? Two changes I had to make in the SDK: added an #ifndef lua_h check around typedef void* lua_State in pd_api_lua.h so it doesn't redefine that if you've already included lua.h, and I changed the LDFLAGS = in to LDFLAGS += so I could put LDFLAGS = -specs=nosys.specs in the project's Makefile.

But yeah, after doing this I'm much more inclined towards adding more of lua.h to the Lua C API

Ha, I guess that works! I'll give that sample code a look.

(Sorry to spam you with multiple different demands re: lua.h, I just keep running into it apparently!)