Re: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall)

2010-01-10 Thread Ravi
On Tuesday 05 January 2010 12:26:27 Nicolas Lelong wrote:
> Is this mailing list the best route to submit this patch, what more work
>  should be done to get it accepted into trunk ?

Please file a trac ticket at svn.boost.org so that this does not get lost.

Ravi

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Exposing C++ data with Boost.Python

2010-01-10 Thread devin kelly
Well what I really to do is turn an STL vector into and python list.  I want
to do this in a separate script, so I don't think eval is right for me.  I
just started with an int because that's easier.  I've gotten that part too,
my code looks like this:

int main(){
int
five_squared=0;

int a =3;
try {
Py_Initialize();
object main_module = import("__main__");
object main_namespace = main_module.attr("__dict__");
main_namespace["var"]=a;
object ignored = exec("result = 5 ** var", main_namespace);
five_squared = extract(main_namespace["result"]);
} catch( error_already_set ) {
PyErr_Print();
}
std::cout << five_squared << std::endl;
return 0;
}

This code works just like you expect it to, it prints 5^3 or 125.

However I try to change my code to this

int main(){
int
five_squared=0;

std::vector v(2);
v[0]=2;
v[1]=3;
try {
Py_Initialize();
object main_module = import("__main__");
object main_namespace = main_module.attr("__dict__");
main_namespace["var"]=v;
object ignored = exec("result = 5 ** var[1]",
main_namespace);
five_squared = extract(main_namespace["result"]);
} catch( error_already_set ) {
PyErr_Print();
}
std::cout << five_squared << std::endl;
return 0;
}

I want this to print 5^2 or 25.  But instead I get this error:

TypeError: No to_python (by-value) converter found for C++ type:
std::vector >

Which makes sense, python doesn't know how to handle stdd::vector.  So I
have to make something to do this conversion.  This is where I'm stuck now,
I think I have to do something like this

BOOST_PYTHON_MODULE(vector_indexing_suite_ext){
boost::python::class_ >("PyVec")
.def(boost::python::vector_indexing_suite >());
}

Is this all I need?  Do I need to define __getitem__ ?  If this is all I
need how do I use it in main()?

Also does anyone know of any good resources for embedding in boost.python?

Thanks!

On Sat, Jan 9, 2010 at 2:55 PM, Stefan Seefeld  wrote:

> On 01/09/2010 01:52 PM, devin kelly wrote:
>
>> Hello,
>>
>> I'm trying to expose some data that I develop in C++ to python.
>>  Basically, the reverse of this sample code:
>>
>> #include 
>> #include 
>> #include 
>> #include 
>>
>> int main(){
>>
>>Py_Initialize();
>>object main_module = import("__main__");
>>object main_namespace = main_module.attr("__dict__");
>>ignored = exec("result = 5 ** 2", main_namespace);
>>int five_squared = extract(main_namespace["result"]);
>>std::cout << five_squared << std::endl;
>>
>>return 0;
>> }
>>
>>
>> So this code starts the python interpreter, squares 5 (in python) and then
>> extracts the result to an int called five_squared.  This works fine for me,
>> it's basically an example straight out of the boost.python webpage.
>>
>> What I'd really like to do though is have an int that I initialize in C++
>> and then square in python.  So this would require me to pass (or expose)
>> that data to python.  I've been trying this for a while and have had no luck
>> whatsoever.  The best I can think of is code like this:
>>
>> int main(){
>>Py_Initialize();
>>object main_module = import("__main__");
>>object main_namespace = main_module.attr("__dict__");
>>main_namespace["num2square"] = 6;
>>ignored = exec("result = num2square ** 2", main_namespace);
>>int five_squared = extract(main_namespace["result"]);
>>std::cout << five_squared << std::endl;
>>return 0;
>> }
>>
>> This doesn't work.  Python throws an error.  What am I doing wrong??
>>
>
> It might help indicating what error Python actually throws.
>
> Also, if all you want is to evaluate an expression, I'd suggest you use
> "eval()", not "exec()".
>
>Stefan
>
> --
>
>  ...ich hab' noch einen Koffer in Berlin...
>
>
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



-- 
http://users.wpi.edu/~dkelly/
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Exposing C++ data with Boost.Python

2010-01-10 Thread Stefan Seefeld

On 01/10/2010 12:36 PM, devin kelly wrote:
 So I have to make something to do this conversion.  This is where I'm 
stuck now, I think I have to do something like this


BOOST_PYTHON_MODULE(vector_indexing_suite_ext){
boost::python::class_ >("PyVec")
.def(boost::python::vector_indexing_suite 
>());

}

Is this all I need?  Do I need to define __getitem__ ?  If this is all 
I need how do I use it in main()?


You presumably use it just like any other conversion you have defined. 
Have you looked at
http://www.boost.org/doc/libs/1_41_0/libs/python/doc/v2/indexing.html, 
and tried it out ? Reading the docs is typically the best way to get 
started...




Also does anyone know of any good resources for embedding in boost.python?


This list is a good place to ask questions, for anything not covered by 
the (online) docs. (We may even improve the docs if it turns out 
something important isn't covered.)


Stefan

--

  ...ich hab' noch einen Koffer in Berlin...

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


[C++-sig] [boost.python] How can I wrap operator==?

2010-01-10 Thread blp330

Hi,

I want to wrap operator== for my object, Py++ generates that:

Document_exposer.def( bp::self != bp::self);
Document_exposer.def( bp::self == bp::self );

But I want to do something more, so I try to wrap it with:

Document_exposer.def( 
bp::self != bp::self
, &Document__NotEqualWrap );
Document_exposer.def( 
bp::self == bp::self
, &Document__EqualWrap );

It can't be compiled...

How can I do?

Thanks.
-- 
View this message in context: 
http://old.nabble.com/-boost.python--How-can-I-wrap-operator%3D%3D--tp27105703p27105703.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig