Hi, I was looking for create a list (like python list or tuple) in juce, for example I should create a structure like this:
myList = ( 1, 2, [“my”, “yours”], false, “hello”, true, [3, [“value”, “other”, true] ] )
I was supposing to use var to store values, it’s the right choice? And how to create the function to parse them and store in var object?
for example I have them stored in a PythonObject (my class that own an object of type PyObject*, that is a c object that represent something of Python, in this case a list).
I suppose to create a func like this one to unpack this object and map it in a var object:
juce::var PythonObject::toVar() const
{
jassert(exist()); // this check if the PyObject* exist
juce::var var;
switch (getPythonType())
{ //I check if it's of type tuple or list because I think
//they shoud be represented both as a var structure
case Type::tuple:
var.append(iterateSequence(object));
return var;
case Type::list:
var.append(iterateSequence(object));
return var;
default:
var.append(PyBytes_AsString(object));
return var;
}
}
//======================================================
juce::var iterateSequence(PythonObject object)
{
juce::var var;
Py_ssize_t size = PySequence_Size(object);
for (Py_ssize_t i = 0; i < size; i++)
{
PythonObject item = PySequence_GetItem(object, i);
jassert(item.exist());
if (item.getPythonType() == PythonObject::Type::list || item.getPythonType() == PythonObject::Type::tuple)
{
var.append(iterateSequence(item));
} else
{
var.append(PyBytes_AsString(item));
}
}
return var;
}
Looking at the list I wrote above my idea should be to access to those value as in these example:
Suppose that my PythonObject that holds it is called myList
TO GET 2:
myList.toVar().getArray()->getReference(1);
TO GET “yours”:
myList.toVar().getArray()->getReference(2).getArray()->getReference(1);
TO GET “other”:
myList.toVar().getArray()->getReference(6).getArray()->getReference(1).getArray()->getReference(1);
…But my functions above don’t work…