Pack Table in Coppeliasim and Unpack in Python Remote API

Typically: "How do I... ", "How can I... " questions
Post Reply
zhy149
Posts: 132
Joined: 14 Apr 2021, 20:18

Pack Table in Coppeliasim and Unpack in Python Remote API

Post by zhy149 »

Hello Coppelia,

I see that there are multiple different ways to pack table in Lua scripts: such as packInt, packFloat, packDouble, packTable, etc. But there are only unpackInt and unpackFloat for the remote API, what if I want to pack table of table such as {{1,2,3
},{3,4,5}} and unpack them in python to get [[1,2,3],[3,4,5]]? What should I do?

Thank you!

fferri
Posts: 1217
Joined: 09 Sep 2013, 19:28

Re: Pack Table in Coppeliasim and Unpack in Python Remote API

Post by fferri »

For complex data, one option is to use a codec such as JSON or CBOR.

E.g. in Lua:

Code: Select all

--lua
cbor=require'cbor'
buf=cbor.encode{{1,2,3},{3,4,5}}
-- send buf...
in Python:

Code: Select all

#python
# receive buf...
import cbor
print(cbor.loads(buf))
# prints [[1, 2, 3], [3, 4, 5]]

Post Reply