2010-05-17, 20:05
Py_BuildValue can return a tuple (array) when the format string is eg "(ss)" and a known number of values, the problem i am having is i do not know the total number of values that will be returned.
so i loop thru and create the format string and also fill a CStdStringArray.
this works, although there may be a simpler way.
what doesn't work is the return.
so:
question 1: how would i build the return statement.
question 2. can this be done with less code by just using self->pAddon->GetDeps()
any help would be appreciated.
here is the part of the function:
this is for a module for python and the new addons. the function is getAddonInfo(), where it returns all the usable values of an addon. eg name, version, id, "dependencies"...
so i loop thru and create the format string and also fill a CStdStringArray.
this works, although there may be a simpler way.
what doesn't work is the return.
PHP Code:
return Py_BuildValue((char*)fmtstring.c_str(), values);
so:
question 1: how would i build the return statement.
question 2. can this be done with less code by just using self->pAddon->GetDeps()
any help would be appreciated.
here is the part of the function:
PHP Code:
else if (strcmpi(id, "dependencies") == 0)
{
PyXBMCGUILock();
CStdString fmtstring;
CStdStringArray values;
for (ADDON::ADDONDEPS::iterator itr = self->pAddon->GetDeps().begin(); itr != self->pAddon->GetDeps().end(); ++itr)
{
fmtstring.append("(sss)");
CStdString id = (*itr).first;
values.push_back(id);
CLog::Log(LOGNOTICE, "DEPEND: %s",id.c_str());
CStdString min = (*itr).second.first.str;
values.push_back(min);
CLog::Log(LOGNOTICE, "MIN: %s", min.c_str());
CStdString max = (*itr).second.second.str;
values.push_back(max);
CLog::Log(LOGNOTICE, "MAX: %s", max.c_str());
}
fmtstring.Format("(%s)", fmtstring.c_str());
PyXBMCGUIUnlock();
CLog::Log(LOGNOTICE, "FORMAT STRING: %s", fmtstring.c_str());
for (CStdStringArray::iterator itr = values.begin(); itr != values.end(); ++itr)
{
CStdString value = *itr;
CLog::Log(LOGNOTICE, "VALUE: %s", value.c_str());
}
return Py_BuildValue((char*)fmtstring.c_str(), values);
}
this is for a module for python and the new addons. the function is getAddonInfo(), where it returns all the usable values of an addon. eg name, version, id, "dependencies"...