Provide pushLuaUDObject() to return an existing LuaUDObject from C

,

Is there any simple-ish way to push a LuaUDObject* onto the lua stack from C code? I have one acquired via pd->lua->getArgObject() but I can't use pd->lua->pushObject() because that would create a new LuaUDObject and therefore two retain counters for the same object in memory.

It looks like there isn't a way to do this so I'm moving this post to the features requests.

Basically we would need something like:

// -- Pushes the given LuaUDObject onto the stack,
void playdate->lua->pushLuaUDObject(LuaUDObject*);

On the Lua side of pushObject we have a weak table that maps C pointers to their Lua wrappers, so that we can return the existing LuaUDObject. You just have to make sure you retain it if you hold a reference to it on the C side.

Someone pointed this out but it doesn't seem to work for me when receiving any Lua SDK objects in my C code:

const char* class_name;
int item_type = pd->lua->getArgType(2, &class_name);
DM_LOG("Found object '%s'.", this->class_name);
LuaUDObject* l_object = NULL;
void* object = pd->lua->getArgObject(2, (char*)class_name, &l_object);
DM_LOG("%p %p", object, l_object);
			
void* new_l_object = pd->lua->pushObject(object, (char*)this->class_name, 0);
DM_LOG("   %p", new_l_object);

When passing a playdate.graphics.image, for example, new_l_object is not the same as l_object.

Is it possible that the SDK's objects are not added to this table?

Dang, sorry. I'd forgotten that's a 1.13 fix. I pushed that MR in September. :sob:

We'll get that out soon!

We'll get that out soon!

That's great news. I'll add that to my interop Lua/C Array class then.