Best way to pass data between Lua and C

Hello!

I have an object represented by several hundred coordinates, and its draw routine is unfortunately too slow in Lua, even after lots of optimization. I've moved the routine into C, where it's fast enough, but I'd still like to operate on the same points in Lua most of the time.

The API doesn't point me in a good direction for passing this kind of data between Lua and C. Has anyone found an efficient way of passing a Lua table of several hundred elements into C? My worst-case scenario is to dump it to file and read it back.

Reading from Lua could be slow, I think you should implement the array in C and expose a method to read a value (e.g. getCoordinatesAt).

Take a look at the array example in the SDK (C_API/Examples/Array).

2 Likes