Creating a map in C++ as a parameter of a Berry function #426
-
Hello, I am trying to pack data in my C++ code into a Berry map and then call a function that has this map as a parameter. be_newmap(vm);
[...]
be_pushstring(vm, 'key');
[...]
be_pushint(vm, 22);
[...]
be_data_insert(vm, -3);
be_pop(vm, 2); // Pop key and value
[...]
// Ultimately
be_pcall(vm, 1); This is the code that I repeat for more key-value pairs, calling the final function only once. However, after calling this in Berry: def update(data)
if (!initialized)
return
end
print(data['key'])
end I get this error: Any idea what's up? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There is a difference between the internal map structure, and the map instance which wraps the internal structure into a class instance of map. What I typically do is |
Beta Was this translation helpful? Give feedback.
There is a difference between the internal map structure, and the map instance which wraps the internal structure into a class instance of map.
What I typically do is
be_newobject(vm, "map");
to instanciate an empty map and then add elements with berry high level functions.See https://github.com/arendst/Tasmota/blob/89b4376e3160b304924802de76cd057827f15a64/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino#L172