It's not possible to pass a lua table to a C function

Hi

There is no function to get values from a lua table using the C_API, right now.
Is it planned in a future version of the SDK?
I try to do it myself by using <lua.h> but It produce identifier conflicts.

3 Likes

I'll +1 this one. It seems like you can get the type of argument as kTypeTable:

	enum LuaType (*getArgType)(int pos, const char** outClass);

but then you need to get a LuaUDObject:

	void* (*getArgObject)(int pos, char* type, LuaUDObject** outud);

and then???

yeah, ran into this as well

you can kind of work around it by pushing the values as stack arguments, but I measured the FFI cost to be pretty high in that case, so the computation on the C side would need to be quite significant to become a win.

I'm assuming the SDK is doing it for things like:

playdate.graphics.tilemap:setTiles()

so maybe there is a way to expose that in a future release?

In case someone finds this useful, I added an Array type to version 2.3.0 of my pdbase toybox. If you're using toybox.py you can add it like so:

toybox add pdbase
toybox update

or you can check out the repo here.

Basically this is an interop class that can be created in C or LUA and passed back and forth between both. If you pre-allocated the number of items stored when creating the array, it's actually faster than LUA's tables in most cases.

You can add ints, floats, strings, booleans or LUA objects but unfortunately you cannot, at this point, retrieve a LUA object from LUA because of a missing SDK method.