Is it possible to read/write tilemaps from C++ extension?

I know that it is possible to read/write tilemaps using Lua code (https://defold.com/ref/tilemap/), but I can’t find how to do it in C++ extension, maybe I’m missing something. Basically I’d like the users of my native extension to be able to write something like myextension.do_stuff("#tilemap", "layer1") in Lua and the extension would read the content of the tilemap and modify it. Is it somehow possible? Does such native extension apis exists?

As far as I know it is not possible to direct access(read/write) Defold tilemap from c/c++.(there might be a hack)
But you can combine your native extension with lua and c++. This way you can iterate through the users tilemap by using lua and pass the array to c/c++

Should I just store and pass it as a two dimensional table? Or is there a more efficient way to work with it (like vmath.matrix4 maybe)?

I prefer passing it as a lua table and storing values on c++ side as a one dimensional array. But this is just me…

Not sure, but there is a build in dmArray. I thing array is the more efficient way of handling simple tables on c++ side.

Okey, I see.

I stumbled on another problem. How can I resize the tilemap from Lua code? If I want to proceduraly generate a tilemap in Lua code the only option for me is to create tilemap in the interface by putting some tile at the corners and then replacing them with the generated ones, is that so?

Unfortunately you can’t right now. And yes this is the only way. You have to put some dummies to end points.
This one is a long awaited feature request(and not easy one). You can vote for this issue on github.

2 Likes