[C++-sig] void* cast to a specific type based on string name

Renato Araujo renatox at gmail.com
Mon Oct 6 15:42:30 CEST 2008


Hi,

for this case I would like  to know if is possible create a python
object based on string name like that:


void call_Pyfunction(int argc, char **types, void **args,
boost::python::object *callbak)
{
   boost::python::list pyArgs;
   for (int i=0; i <= count; i++)
   {
         //in types I have the typenames: {"int", "string", "MyObject", ....}
         boost::python::object o(types[i], args[i]);
        pyArgs.append(o);
    }
    callback(pyArgs);
}



On Sat, Oct 4, 2008 at 3:06 PM, Roman Yakovenko
<roman.yakovenko at gmail.com> wrote:
> On Sat, Oct 4, 2008 at 12:38 AM, Renato Araujo <renatox at gmail.com> wrote:
>> Hi thanks again, I found some e-mails about this, but my problem continue:
>>
>> now I reimplemented the function to some like that:
>>
>> void call_Pyfunction(int argc, char **types, void **args, PyObject *callbak)
>> {
>>    boost::python::list pyArgs;
>>    for (int i=0; i <= count; i++)
>>    {
>>        pyArgs.append(args[i]);
>>    }
>>    callback(pyArgs);
>> }
>>
>> but the error still happen:
>> If i put the correct cast before "args[i]" this works fine;
>>
>> ..........
>>    for (int i=0; i <= count; i++)
>>    {
>>        pyArgs.append(*(int *)args[i]);
>>    }
>
> I don't understand you. Why do you expect that boost::python::object
> will guess the actual type from void*?
>
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>



-- 
Renato Araujo Oliveira Filho



More information about the Cplusplus-sig mailing list