boost bind/lambda

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

boost bind/lambda

beo wulf
Goal: I want to luabind all of OpenGL.
Problem: glLightfv( int, int, GLfloat*)

Almost solution:  boost::bind

The following code almost works -- it can use boost::bind to convert
functions that take arg GLfloat* to take an arg of
boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
and luabind seem to not work with each other (in particular, the line

, def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile

Why?

Full code below:



#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>

#include <vector>
#include <iostream>

#include <luabind/luabind.hpp>
#include <luabind/operator.hpp>
#include <luabind/adopt_policy.hpp>
#include <luabind/copy_policy.hpp>
#include <luabind/class_info.hpp>

#include <GL/gl.h>



#define P boost::shared_ptr
#define V std::vector

float foo(int x, int y, float* f) {
  float ans = 0;
  ans = x + y + f[0] + f[1] + f[2];
  return ans;
}

float* get_raw(P<V<float> > p) {
  return &((*p)[0]);
}

void test() { // works fine
  P<V<float> > p(new V<float>());
  p->push_back(1);
  p->push_back(2);
  p->push_back(3);

  // I want this to output 9
  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
}


int main() {
  using namespace luabind;

  lua_State *L;

  module( L )
    [
    namespace_("gl") [
      def( "glLightfv", glLightfv)
      // Why do these two lines not compile?
//    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
//    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
    ]
    ]

    ;
}

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

beo wulf
Okay, this woks:
    , def( "glLightfv2", tag_function<void(int, int,
GLfloat*)>(bind(glLightfv, _1, _2, _3)))
    , def( "glLightfv3", tag_function<void(int, int, P<V<GLfloat>
>)>(bind(glLightfv, _1, _2, bind(get_raw, _3))))

However, is there a way I can do this without tag_function? I'd prefer
to not have to provide the type of every function that takes a
GLfloat*

Thanks!

On Tue, Jan 4, 2011 at 9:35 PM, beo wulf <[hidden email]> wrote:

> Goal: I want to luabind all of OpenGL.
> Problem: glLightfv( int, int, GLfloat*)
>
> Almost solution:  boost::bind
>
> The following code almost works -- it can use boost::bind to convert
> functions that take arg GLfloat* to take an arg of
> boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
> and luabind seem to not work with each other (in particular, the line
>
> , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
>
> Why?
>
> Full code below:
>
>
>
> #include <boost/shared_ptr.hpp>
> #include <boost/bind.hpp>
>
> #include <vector>
> #include <iostream>
>
> #include <luabind/luabind.hpp>
> #include <luabind/operator.hpp>
> #include <luabind/adopt_policy.hpp>
> #include <luabind/copy_policy.hpp>
> #include <luabind/class_info.hpp>
>
> #include <GL/gl.h>
>
>
>
> #define P boost::shared_ptr
> #define V std::vector
>
> float foo(int x, int y, float* f) {
>  float ans = 0;
>  ans = x + y + f[0] + f[1] + f[2];
>  return ans;
> }
>
> float* get_raw(P<V<float> > p) {
>  return &((*p)[0]);
> }
>
> void test() { // works fine
>  P<V<float> > p(new V<float>());
>  p->push_back(1);
>  p->push_back(2);
>  p->push_back(3);
>
>  // I want this to output 9
>  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
> }
>
>
> int main() {
>  using namespace luabind;
>
>  lua_State *L;
>
>  module( L )
>    [
>    namespace_("gl") [
>      def( "glLightfv", glLightfv)
>      // Why do these two lines not compile?
> //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
> //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
>    ]
>    ]
>
>    ;
> }
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Tony Kostanjsek
In reply to this post by beo wulf
"def" requires an address or function pointer, but bind returns a temporary
functor instance. Try to use a static instance or write a wrapper function
implementation and pass that.

Something like <type> func = bind(...)
.def("glLightfv", &func)
I'm not sure what <type> would look like though.

Alternatively, something like this might work:
void wrappedGlLightfv(GLenum light, GLenum pname, const
boost::shared_ptr<std::vector<GLfloat>> fv)
{
  glLightfv(light, pname, &fv->get()->front()); // not quite sure about front(),
but you get the idea
}

...
.def("glLightfv", wrappedGlLightfv)
...

----- Ursprüngliche Mail ----
Von: beo wulf <[hidden email]>
An: [hidden email]
Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
Betreff: [luabind] boost bind/lambda

Goal: I want to luabind all of OpenGL.
Problem: glLightfv( int, int, GLfloat*)

Almost solution:  boost::bind

The following code almost works -- it can use boost::bind to convert
functions that take arg GLfloat* to take an arg of
boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
and luabind seem to not work with each other (in particular, the line

, def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile

Why?

Full code below:



#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>

#include <vector>
#include <iostream>

#include <luabind/luabind.hpp>
#include <luabind/operator.hpp>
#include <luabind/adopt_policy.hpp>
#include <luabind/copy_policy.hpp>
#include <luabind/class_info.hpp>

#include <GL/gl.h>



#define P boost::shared_ptr
#define V std::vector

float foo(int x, int y, float* f) {
  float ans = 0;
  ans = x + y + f[0] + f[1] + f[2];
  return ans;
}

float* get_raw(P<V<float> > p) {
  return &((*p)[0]);
}

void test() { // works fine
  P<V<float> > p(new V<float>());
  p->push_back(1);
  p->push_back(2);
  p->push_back(3);

  // I want this to output 9
  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
}


int main() {
  using namespace luabind;

  lua_State *L;

  module( L )
    [
    namespace_("gl") [
      def( "glLightfv", glLightfv)
      // Why do these two lines not compile?
//    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
//    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
    ]
    ]

    ;
}

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

beo wulf
Why does wrapping it on a tag_function work then?

Writing wrappers is out of the question -- there are too many functions.

On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:

> "def" requires an address or function pointer, but bind returns a temporary
> functor instance. Try to use a static instance or write a wrapper function
> implementation and pass that.
>
> Something like <type> func = bind(...)
> .def("glLightfv", &func)
> I'm not sure what <type> would look like though.
>
> Alternatively, something like this might work:
> void wrappedGlLightfv(GLenum light, GLenum pname, const
> boost::shared_ptr<std::vector<GLfloat>> fv)
> {
>  glLightfv(light, pname, &fv->get()->front()); // not quite sure about front(),
> but you get the idea
> }
>
> ...
> .def("glLightfv", wrappedGlLightfv)
> ...
>
> ----- Ursprüngliche Mail ----
> Von: beo wulf <[hidden email]>
> An: [hidden email]
> Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
> Betreff: [luabind] boost bind/lambda
>
> Goal: I want to luabind all of OpenGL.
> Problem: glLightfv( int, int, GLfloat*)
>
> Almost solution:  boost::bind
>
> The following code almost works -- it can use boost::bind to convert
> functions that take arg GLfloat* to take an arg of
> boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
> and luabind seem to not work with each other (in particular, the line
>
> , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
>
> Why?
>
> Full code below:
>
>
>
> #include <boost/shared_ptr.hpp>
> #include <boost/bind.hpp>
>
> #include <vector>
> #include <iostream>
>
> #include <luabind/luabind.hpp>
> #include <luabind/operator.hpp>
> #include <luabind/adopt_policy.hpp>
> #include <luabind/copy_policy.hpp>
> #include <luabind/class_info.hpp>
>
> #include <GL/gl.h>
>
>
>
> #define P boost::shared_ptr
> #define V std::vector
>
> float foo(int x, int y, float* f) {
>  float ans = 0;
>  ans = x + y + f[0] + f[1] + f[2];
>  return ans;
> }
>
> float* get_raw(P<V<float> > p) {
>  return &((*p)[0]);
> }
>
> void test() { // works fine
>  P<V<float> > p(new V<float>());
>  p->push_back(1);
>  p->push_back(2);
>  p->push_back(3);
>
>  // I want this to output 9
>  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
> }
>
>
> int main() {
>  using namespace luabind;
>
>  lua_State *L;
>
>  module( L )
>    [
>    namespace_("gl") [
>      def( "glLightfv", glLightfv)
>      // Why do these two lines not compile?
> //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
> //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
>    ]
>    ]
>
>    ;
> }
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Tony Kostanjsek
I might've been mistaken on the function pointer issue, but I've only used it
that way.



----- Ursprüngliche Mail ----
Von: beo wulf <[hidden email]>
An: [hidden email]
Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
Betreff: Re: [luabind] boost bind/lambda

Why does wrapping it on a tag_function work then?

Writing wrappers is out of the question -- there are too many functions.

On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:

> "def" requires an address or function pointer, but bind returns a temporary
> functor instance. Try to use a static instance or write a wrapper function
> implementation and pass that.
>
> Something like <type> func = bind(...)
> .def("glLightfv", &func)
> I'm not sure what <type> would look like though.
>
> Alternatively, something like this might work:
> void wrappedGlLightfv(GLenum light, GLenum pname, const
> boost::shared_ptr<std::vector<GLfloat>> fv)
> {
>  glLightfv(light, pname, &fv->get()->front()); // not quite sure about
front(),

> but you get the idea
> }
>
> ...
> .def("glLightfv", wrappedGlLightfv)
> ...
>
> ----- Ursprüngliche Mail ----
> Von: beo wulf <[hidden email]>
> An: [hidden email]
> Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
> Betreff: [luabind] boost bind/lambda
>
> Goal: I want to luabind all of OpenGL.
> Problem: glLightfv( int, int, GLfloat*)
>
> Almost solution:  boost::bind
>
> The following code almost works -- it can use boost::bind to convert
> functions that take arg GLfloat* to take an arg of
> boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
> and luabind seem to not work with each other (in particular, the line
>
> , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
>
> Why?
>
> Full code below:
>
>
>
> #include <boost/shared_ptr.hpp>
> #include <boost/bind.hpp>
>
> #include <vector>
> #include <iostream>
>
> #include <luabind/luabind.hpp>
> #include <luabind/operator.hpp>
> #include <luabind/adopt_policy.hpp>
> #include <luabind/copy_policy.hpp>
> #include <luabind/class_info.hpp>
>
> #include <GL/gl.h>
>
>
>
> #define P boost::shared_ptr
> #define V std::vector
>
> float foo(int x, int y, float* f) {
>  float ans = 0;
>  ans = x + y + f[0] + f[1] + f[2];
>  return ans;
> }
>
> float* get_raw(P<V<float> > p) {
>  return &((*p)[0]);
> }
>
> void test() { // works fine
>  P<V<float> > p(new V<float>());
>  p->push_back(1);
>  p->push_back(2);
>  p->push_back(3);
>
>  // I want this to output 9
>  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
> }
>
>
> int main() {
>  using namespace luabind;
>
>  lua_State *L;
>
>  module( L )
>    [
>    namespace_("gl") [
>      def( "glLightfv", glLightfv)
>      // Why do these two lines not compile?
> //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
> //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
>    ]
>    ]
>
>    ;
> }
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Nigel Atkinson-2
You could bind GLfloat as a class.  I've done this in the past with
Ogre3d's "Real" witch is a typedef for float or double.  Depending on
how your using in your scripts, that's all you may need to do, i.e
without any defined methods. This makes GLfloat in scripts similar to an
opaque pointer, where it's allways come from C++ and only really used by
C++. You can also add operators and a constructor as well, to get more
scripting use out of it.

Using it this way as with pointers (arrays) make take a little tweaking,
I'll have to have a play around when I have time.

Nigel

On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:

> I might've been mistaken on the function pointer issue, but I've only used it
> that way.
>
>
>
> ----- Ursprüngliche Mail ----
> Von: beo wulf <[hidden email]>
> An: [hidden email]
> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
> Betreff: Re: [luabind] boost bind/lambda
>
> Why does wrapping it on a tag_function work then?
>
> Writing wrappers is out of the question -- there are too many functions.
>
> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:
> > "def" requires an address or function pointer, but bind returns a temporary
> > functor instance. Try to use a static instance or write a wrapper function
> > implementation and pass that.
> >
> > Something like <type> func = bind(...)
> > .def("glLightfv", &func)
> > I'm not sure what <type> would look like though.
> >
> > Alternatively, something like this might work:
> > void wrappedGlLightfv(GLenum light, GLenum pname, const
> > boost::shared_ptr<std::vector<GLfloat>> fv)
> > {
> >  glLightfv(light, pname, &fv->get()->front()); // not quite sure about
> front(),
> > but you get the idea
> > }
> >
> > ...
> > .def("glLightfv", wrappedGlLightfv)
> > ...
> >
> > ----- Ursprüngliche Mail ----
> > Von: beo wulf <[hidden email]>
> > An: [hidden email]
> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
> > Betreff: [luabind] boost bind/lambda
> >
> > Goal: I want to luabind all of OpenGL.
> > Problem: glLightfv( int, int, GLfloat*)
> >
> > Almost solution:  boost::bind
> >
> > The following code almost works -- it can use boost::bind to convert
> > functions that take arg GLfloat* to take an arg of
> > boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
> > and luabind seem to not work with each other (in particular, the line
> >
> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
> >
> > Why?
> >
> > Full code below:
> >
> >
> >
> > #include <boost/shared_ptr.hpp>
> > #include <boost/bind.hpp>
> >
> > #include <vector>
> > #include <iostream>
> >
> > #include <luabind/luabind.hpp>
> > #include <luabind/operator.hpp>
> > #include <luabind/adopt_policy.hpp>
> > #include <luabind/copy_policy.hpp>
> > #include <luabind/class_info.hpp>
> >
> > #include <GL/gl.h>
> >
> >
> >
> > #define P boost::shared_ptr
> > #define V std::vector
> >
> > float foo(int x, int y, float* f) {
> >  float ans = 0;
> >  ans = x + y + f[0] + f[1] + f[2];
> >  return ans;
> > }
> >
> > float* get_raw(P<V<float> > p) {
> >  return &((*p)[0]);
> > }
> >
> > void test() { // works fine
> >  P<V<float> > p(new V<float>());
> >  p->push_back(1);
> >  p->push_back(2);
> >  p->push_back(3);
> >
> >  // I want this to output 9
> >  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
> > }
> >
> >
> > int main() {
> >  using namespace luabind;
> >
> >  lua_State *L;
> >
> >  module( L )
> >    [
> >    namespace_("gl") [
> >      def( "glLightfv", glLightfv)
> >      // Why do these two lines not compile?
> > //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
> > //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
> >    ]
> >    ]
> >
> >    ;
> > }
> >
> > ------------------------------------------------------------------------------
> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> > to consolidate database storage, standardize their database environment, and,
> > should the need arise, upgrade to a full multi-node Oracle RAC database
> > without downtime or disruption
> > http://p.sf.net/sfu/oracle-sfdevnl
> > _______________________________________________
> > luabind-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
> >
> >
> >
> > ------------------------------------------------------------------------------
> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> > to consolidate database storage, standardize their database environment, and,
> > should the need arise, upgrade to a full multi-node Oracle RAC database
> > without downtime or disruption
> > http://p.sf.net/sfu/oracle-sfdevnl
> > _______________________________________________
> > luabind-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user



------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

beo wulf
I've tried

class_<GLfloat, boost::shared_ptr<GLfloat> > ....

but I'm not sure what to do with this. Can you explain? (Luabind's
template blackmagicery is a couple levels above my paygrade).

Thanks!

On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]> wrote:

> You could bind GLfloat as a class.  I've done this in the past with
> Ogre3d's "Real" witch is a typedef for float or double.  Depending on
> how your using in your scripts, that's all you may need to do, i.e
> without any defined methods. This makes GLfloat in scripts similar to an
> opaque pointer, where it's allways come from C++ and only really used by
> C++. You can also add operators and a constructor as well, to get more
> scripting use out of it.
>
> Using it this way as with pointers (arrays) make take a little tweaking,
> I'll have to have a play around when I have time.
>
> Nigel
>
> On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
>> I might've been mistaken on the function pointer issue, but I've only used it
>> that way.
>>
>>
>>
>> ----- Ursprüngliche Mail ----
>> Von: beo wulf <[hidden email]>
>> An: [hidden email]
>> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
>> Betreff: Re: [luabind] boost bind/lambda
>>
>> Why does wrapping it on a tag_function work then?
>>
>> Writing wrappers is out of the question -- there are too many functions.
>>
>> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:
>> > "def" requires an address or function pointer, but bind returns a temporary
>> > functor instance. Try to use a static instance or write a wrapper function
>> > implementation and pass that.
>> >
>> > Something like <type> func = bind(...)
>> > .def("glLightfv", &func)
>> > I'm not sure what <type> would look like though.
>> >
>> > Alternatively, something like this might work:
>> > void wrappedGlLightfv(GLenum light, GLenum pname, const
>> > boost::shared_ptr<std::vector<GLfloat>> fv)
>> > {
>> >  glLightfv(light, pname, &fv->get()->front()); // not quite sure about
>> front(),
>> > but you get the idea
>> > }
>> >
>> > ...
>> > .def("glLightfv", wrappedGlLightfv)
>> > ...
>> >
>> > ----- Ursprüngliche Mail ----
>> > Von: beo wulf <[hidden email]>
>> > An: [hidden email]
>> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
>> > Betreff: [luabind] boost bind/lambda
>> >
>> > Goal: I want to luabind all of OpenGL.
>> > Problem: glLightfv( int, int, GLfloat*)
>> >
>> > Almost solution:  boost::bind
>> >
>> > The following code almost works -- it can use boost::bind to convert
>> > functions that take arg GLfloat* to take an arg of
>> > boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
>> > and luabind seem to not work with each other (in particular, the line
>> >
>> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
>> >
>> > Why?
>> >
>> > Full code below:
>> >
>> >
>> >
>> > #include <boost/shared_ptr.hpp>
>> > #include <boost/bind.hpp>
>> >
>> > #include <vector>
>> > #include <iostream>
>> >
>> > #include <luabind/luabind.hpp>
>> > #include <luabind/operator.hpp>
>> > #include <luabind/adopt_policy.hpp>
>> > #include <luabind/copy_policy.hpp>
>> > #include <luabind/class_info.hpp>
>> >
>> > #include <GL/gl.h>
>> >
>> >
>> >
>> > #define P boost::shared_ptr
>> > #define V std::vector
>> >
>> > float foo(int x, int y, float* f) {
>> >  float ans = 0;
>> >  ans = x + y + f[0] + f[1] + f[2];
>> >  return ans;
>> > }
>> >
>> > float* get_raw(P<V<float> > p) {
>> >  return &((*p)[0]);
>> > }
>> >
>> > void test() { // works fine
>> >  P<V<float> > p(new V<float>());
>> >  p->push_back(1);
>> >  p->push_back(2);
>> >  p->push_back(3);
>> >
>> >  // I want this to output 9
>> >  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
>> > }
>> >
>> >
>> > int main() {
>> >  using namespace luabind;
>> >
>> >  lua_State *L;
>> >
>> >  module( L )
>> >    [
>> >    namespace_("gl") [
>> >      def( "glLightfv", glLightfv)
>> >      // Why do these two lines not compile?
>> > //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
>> > //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
>> >    ]
>> >    ]
>> >
>> >    ;
>> > }
>> >
>> > ------------------------------------------------------------------------------
>> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> > to consolidate database storage, standardize their database environment, and,
>> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> > without downtime or disruption
>> > http://p.sf.net/sfu/oracle-sfdevnl
>> > _______________________________________________
>> > luabind-user mailing list
>> > [hidden email]
>> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> > to consolidate database storage, standardize their database environment, and,
>> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> > without downtime or disruption
>> > http://p.sf.net/sfu/oracle-sfdevnl
>> > _______________________________________________
>> > luabind-user mailing list
>> > [hidden email]
>> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >
>>
>> ------------------------------------------------------------------------------
>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> to consolidate database storage, standardize their database environment, and,
>> should the need arise, upgrade to a full multi-node Oracle RAC database
>> without downtime or disruption
>> http://p.sf.net/sfu/oracle-sfdevnl
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> to consolidate database storage, standardize their database environment, and,
>> should the need arise, upgrade to a full multi-node Oracle RAC database
>> without downtime or disruption
>> http://p.sf.net/sfu/oracle-sfdevnl
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Nigel Atkinson-2
You're on the right track.  Perhaps an example will help (and let me
make sure it works as advertised!) Attached is a little program which
I've tested with gcc 4 and luabind 0.9.  I've added a couple of
comments.

It should work if GLfloat is a #define rather than a typedef, but I've
just checked on my machine (Linux), and it is a typedef.

On another note, if you are binding all of OpenGL, are you going to do
extensions?  That could be curly! Bound function pointers? That *might*
work perhaps. Hmmm.

Nigel

On Tue, 2011-01-04 at 23:44 -0800, beo wulf wrote:

> I've tried
>
> class_<GLfloat, boost::shared_ptr<GLfloat> > ....
>
> but I'm not sure what to do with this. Can you explain? (Luabind's
> template blackmagicery is a couple levels above my paygrade).
> Thanks!
>
> On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]> wrote:
> > You could bind GLfloat as a class.  I've done this in the past with
> > Ogre3d's "Real" witch is a typedef for float or double.  Depending on
> > how your using in your scripts, that's all you may need to do, i.e
> > without any defined methods. This makes GLfloat in scripts similar to an
> > opaque pointer, where it's allways come from C++ and only really used by
> > C++. You can also add operators and a constructor as well, to get more
> > scripting use out of it.
> >
> > Using it this way as with pointers (arrays) make take a little tweaking,
> > I'll have to have a play around when I have time.
> >
> > Nigel
> >
> > On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
> >> I might've been mistaken on the function pointer issue, but I've only used it
> >> that way.
> >>
> >>
> >>
> >> ----- Ursprüngliche Mail ----
> >> Von: beo wulf <[hidden email]>
> >> An: [hidden email]
> >> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
> >> Betreff: Re: [luabind] boost bind/lambda
> >>
> >> Why does wrapping it on a tag_function work then?
> >>
> >> Writing wrappers is out of the question -- there are too many functions.
> >>
> >> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:
> >> > "def" requires an address or function pointer, but bind returns a temporary
> >> > functor instance. Try to use a static instance or write a wrapper function
> >> > implementation and pass that.
> >> >
> >> > Something like <type> func = bind(...)
> >> > .def("glLightfv", &func)
> >> > I'm not sure what <type> would look like though.
> >> >
> >> > Alternatively, something like this might work:
> >> > void wrappedGlLightfv(GLenum light, GLenum pname, const
> >> > boost::shared_ptr<std::vector<GLfloat>> fv)
> >> > {
> >> >  glLightfv(light, pname, &fv->get()->front()); // not quite sure about
> >> front(),
> >> > but you get the idea
> >> > }
> >> >
> >> > ...
> >> > .def("glLightfv", wrappedGlLightfv)
> >> > ...
> >> >
> >> > ----- Ursprüngliche Mail ----
> >> > Von: beo wulf <[hidden email]>
> >> > An: [hidden email]
> >> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
> >> > Betreff: [luabind] boost bind/lambda
> >> >
> >> > Goal: I want to luabind all of OpenGL.
> >> > Problem: glLightfv( int, int, GLfloat*)
> >> >
> >> > Almost solution:  boost::bind
> >> >
> >> > The following code almost works -- it can use boost::bind to convert
> >> > functions that take arg GLfloat* to take an arg of
> >> > boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
> >> > and luabind seem to not work with each other (in particular, the line
> >> >
> >> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
> >> >
> >> > Why?
> >> >
> >> > Full code below:
> >> >
> >> >
> >> >
> >> > #include <boost/shared_ptr.hpp>
> >> > #include <boost/bind.hpp>
> >> >
> >> > #include <vector>
> >> > #include <iostream>
> >> >
> >> > #include <luabind/luabind.hpp>
> >> > #include <luabind/operator.hpp>
> >> > #include <luabind/adopt_policy.hpp>
> >> > #include <luabind/copy_policy.hpp>
> >> > #include <luabind/class_info.hpp>
> >> >
> >> > #include <GL/gl.h>
> >> >
> >> >
> >> >
> >> > #define P boost::shared_ptr
> >> > #define V std::vector
> >> >
> >> > float foo(int x, int y, float* f) {
> >> >  float ans = 0;
> >> >  ans = x + y + f[0] + f[1] + f[2];
> >> >  return ans;
> >> > }
> >> >
> >> > float* get_raw(P<V<float> > p) {
> >> >  return &((*p)[0]);
> >> > }
> >> >
> >> > void test() { // works fine
> >> >  P<V<float> > p(new V<float>());
> >> >  p->push_back(1);
> >> >  p->push_back(2);
> >> >  p->push_back(3);
> >> >
> >> >  // I want this to output 9
> >> >  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
> >> > }
> >> >
> >> >
> >> > int main() {
> >> >  using namespace luabind;
> >> >
> >> >  lua_State *L;
> >> >
> >> >  module( L )
> >> >    [
> >> >    namespace_("gl") [
> >> >      def( "glLightfv", glLightfv)
> >> >      // Why do these two lines not compile?
> >> > //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
> >> > //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
> >> >    ]
> >> >    ]
> >> >
> >> >    ;
> >> > }
> >> >
> >> > ------------------------------------------------------------------------------
> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> > to consolidate database storage, standardize their database environment, and,
> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
> >> > without downtime or disruption
> >> > http://p.sf.net/sfu/oracle-sfdevnl
> >> > _______________________________________________
> >> > luabind-user mailing list
> >> > [hidden email]
> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >> >
> >> >
> >> >
> >> >
> >> > ------------------------------------------------------------------------------
> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> > to consolidate database storage, standardize their database environment, and,
> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
> >> > without downtime or disruption
> >> > http://p.sf.net/sfu/oracle-sfdevnl
> >> > _______________________________________________
> >> > luabind-user mailing list
> >> > [hidden email]
> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >> >
> >>
> >> ------------------------------------------------------------------------------
> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> to consolidate database storage, standardize their database environment, and,
> >> should the need arise, upgrade to a full multi-node Oracle RAC database
> >> without downtime or disruption
> >> http://p.sf.net/sfu/oracle-sfdevnl
> >> _______________________________________________
> >> luabind-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
> >>
> >>
> >>
> >>
> >> ------------------------------------------------------------------------------
> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> to consolidate database storage, standardize their database environment, and,
> >> should the need arise, upgrade to a full multi-node Oracle RAC database
> >> without downtime or disruption
> >> http://p.sf.net/sfu/oracle-sfdevnl
> >> _______________________________________________
> >> luabind-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
> >
> >
> > ------------------------------------------------------------------------------
> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> > to consolidate database storage, standardize their database environment, and,
> > should the need arise, upgrade to a full multi-node Oracle RAC database
> > without downtime or disruption
> > http://p.sf.net/sfu/oracle-sfdevnl
> > _______________________________________________
> > luabind-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

luafloat.cpp (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Richard Watson (RARE)
You shouldn't use boost::shared_ptr to store things allocated with new[], shared_ptr  will call delete not delete[] on your array which isn't good, I don't know if lua bind supports it but boost::shared_array is what you should be using here

-----Original Message-----
From: Nigel Atkinson [mailto:[hidden email]]
Sent: 05 January 2011 10:55
To: [hidden email]
Subject: Re: [luabind] boost bind/lambda

You're on the right track.  Perhaps an example will help (and let me make sure it works as advertised!) Attached is a little program which I've tested with gcc 4 and luabind 0.9.  I've added a couple of comments.

It should work if GLfloat is a #define rather than a typedef, but I've just checked on my machine (Linux), and it is a typedef.

On another note, if you are binding all of OpenGL, are you going to do extensions?  That could be curly! Bound function pointers? That *might* work perhaps. Hmmm.

Nigel

On Tue, 2011-01-04 at 23:44 -0800, beo wulf wrote:

> I've tried
>
> class_<GLfloat, boost::shared_ptr<GLfloat> > ....
>
> but I'm not sure what to do with this. Can you explain? (Luabind's
> template blackmagicery is a couple levels above my paygrade).
> Thanks!
>
> On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]> wrote:
> > You could bind GLfloat as a class.  I've done this in the past with
> > Ogre3d's "Real" witch is a typedef for float or double.  Depending
> > on how your using in your scripts, that's all you may need to do,
> > i.e without any defined methods. This makes GLfloat in scripts
> > similar to an opaque pointer, where it's allways come from C++ and
> > only really used by
> > C++. You can also add operators and a constructor as well, to get
> > C++more
> > scripting use out of it.
> >
> > Using it this way as with pointers (arrays) make take a little
> > tweaking, I'll have to have a play around when I have time.
> >
> > Nigel
> >
> > On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
> >> I might've been mistaken on the function pointer issue, but I've
> >> only used it that way.
> >>
> >>
> >>
> >> ----- Ursprüngliche Mail ----
> >> Von: beo wulf <[hidden email]>
> >> An: [hidden email]
> >> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
> >> Betreff: Re: [luabind] boost bind/lambda
> >>
> >> Why does wrapping it on a tag_function work then?
> >>
> >> Writing wrappers is out of the question -- there are too many functions.
> >>
> >> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:
> >> > "def" requires an address or function pointer, but bind returns a
> >> > temporary functor instance. Try to use a static instance or write
> >> > a wrapper function implementation and pass that.
> >> >
> >> > Something like <type> func = bind(...) .def("glLightfv", &func)
> >> > I'm not sure what <type> would look like though.
> >> >
> >> > Alternatively, something like this might work:
> >> > void wrappedGlLightfv(GLenum light, GLenum pname, const
> >> > boost::shared_ptr<std::vector<GLfloat>> fv) {  glLightfv(light,
> >> > pname, &fv->get()->front()); // not quite sure about
> >> front(),
> >> > but you get the idea
> >> > }
> >> >
> >> > ...
> >> > .def("glLightfv", wrappedGlLightfv) ...
> >> >
> >> > ----- Ursprüngliche Mail ----
> >> > Von: beo wulf <[hidden email]>
> >> > An: [hidden email]
> >> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
> >> > Betreff: [luabind] boost bind/lambda
> >> >
> >> > Goal: I want to luabind all of OpenGL.
> >> > Problem: glLightfv( int, int, GLfloat*)
> >> >
> >> > Almost solution:  boost::bind
> >> >
> >> > The following code almost works -- it can use boost::bind to
> >> > convert functions that take arg GLfloat* to take an arg of
> >> > boost::shared_ptr<std::vector<GLfloat>> instead. However,
> >> > boost::bind and luabind seem to not work with each other (in
> >> > particular, the line
> >> >
> >> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does
> >> > not compile
> >> >
> >> > Why?
> >> >
> >> > Full code below:
> >> >
> >> >
> >> >
> >> > #include <boost/shared_ptr.hpp>
> >> > #include <boost/bind.hpp>
> >> >
> >> > #include <vector>
> >> > #include <iostream>
> >> >
> >> > #include <luabind/luabind.hpp>
> >> > #include <luabind/operator.hpp>
> >> > #include <luabind/adopt_policy.hpp> #include
> >> > <luabind/copy_policy.hpp> #include <luabind/class_info.hpp>
> >> >
> >> > #include <GL/gl.h>
> >> >
> >> >
> >> >
> >> > #define P boost::shared_ptr
> >> > #define V std::vector
> >> >
> >> > float foo(int x, int y, float* f) {  float ans = 0;  ans = x + y
> >> > + f[0] + f[1] + f[2];  return ans; }
> >> >
> >> > float* get_raw(P<V<float> > p) {
> >> >  return &((*p)[0]);
> >> > }
> >> >
> >> > void test() { // works fine
> >> >  P<V<float> > p(new V<float>());
> >> >  p->push_back(1);
> >> >  p->push_back(2);
> >> >  p->push_back(3);
> >> >
> >> >  // I want this to output 9
> >> >  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) <<
> >> > std::endl; }
> >> >
> >> >
> >> > int main() {
> >> >  using namespace luabind;
> >> >
> >> >  lua_State *L;
> >> >
> >> >  module( L )
> >> >    [
> >> >    namespace_("gl") [
> >> >      def( "glLightfv", glLightfv)
> >> >      // Why do these two lines not compile?
> >> > //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
> >> > //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
> >> >    ]
> >> >    ]
> >> >
> >> >    ;
> >> > }
> >> >
> >> > -----------------------------------------------------------------
> >> > ------------- Learn how Oracle Real Application Clusters (RAC)
> >> > One Node allows customers to consolidate database storage,
> >> > standardize their database environment, and, should the need
> >> > arise, upgrade to a full multi-node Oracle RAC database without
> >> > downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl
> >> > _______________________________________________
> >> > luabind-user mailing list
> >> > [hidden email]
> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >> >
> >> >
> >> >
> >> >
> >> > -----------------------------------------------------------------
> >> > ------------- Learn how Oracle Real Application Clusters (RAC)
> >> > One Node allows customers to consolidate database storage,
> >> > standardize their database environment, and, should the need
> >> > arise, upgrade to a full multi-node Oracle RAC database without
> >> > downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl
> >> > _______________________________________________
> >> > luabind-user mailing list
> >> > [hidden email]
> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >> >
> >>
> >> -------------------------------------------------------------------
> >> ----------- Learn how Oracle Real Application Clusters (RAC) One
> >> Node allows customers to consolidate database storage, standardize
> >> their database environment, and, should the need arise, upgrade to
> >> a full multi-node Oracle RAC database without downtime or
> >> disruption http://p.sf.net/sfu/oracle-sfdevnl
> >> _______________________________________________
> >> luabind-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
> >>
> >>
> >>
> >>
> >> -------------------------------------------------------------------
> >> ----------- Learn how Oracle Real Application Clusters (RAC) One
> >> Node allows customers to consolidate database storage, standardize
> >> their database environment, and, should the need arise, upgrade to
> >> a full multi-node Oracle RAC database without downtime or
> >> disruption http://p.sf.net/sfu/oracle-sfdevnl
> >> _______________________________________________
> >> luabind-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
> >
> >
> > --------------------------------------------------------------------
> > ---------- Learn how Oracle Real Application Clusters (RAC) One Node
> > allows customers to consolidate database storage, standardize their
> > database environment, and, should the need arise, upgrade to a full
> > multi-node Oracle RAC database without downtime or disruption
> > http://p.sf.net/sfu/oracle-sfdevnl
> > _______________________________________________
> > luabind-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>
> ----------------------------------------------------------------------
> -------- Learn how Oracle Real Application Clusters (RAC) One Node
> allows customers to consolidate database storage, standardize their
> database environment, and, should the need arise, upgrade to a full
> multi-node Oracle RAC database without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

beo wulf
In reply to this post by Nigel Atkinson-2
Admittedly, function pointers are currently not planned. I just wanted
to avoid hand wrapping all GLint* GLfloat* GL...* functions.

On Wed, Jan 5, 2011 at 2:55 AM, Nigel Atkinson <[hidden email]> wrote:

> You're on the right track.  Perhaps an example will help (and let me
> make sure it works as advertised!) Attached is a little program which
> I've tested with gcc 4 and luabind 0.9.  I've added a couple of
> comments.
>
> It should work if GLfloat is a #define rather than a typedef, but I've
> just checked on my machine (Linux), and it is a typedef.
>
> On another note, if you are binding all of OpenGL, are you going to do
> extensions?  That could be curly! Bound function pointers? That *might*
> work perhaps. Hmmm.
>
> Nigel
>
> On Tue, 2011-01-04 at 23:44 -0800, beo wulf wrote:
>> I've tried
>>
>> class_<GLfloat, boost::shared_ptr<GLfloat> > ....
>>
>> but I'm not sure what to do with this. Can you explain? (Luabind's
>> template blackmagicery is a couple levels above my paygrade).
>> Thanks!
>>
>> On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]> wrote:
>> > You could bind GLfloat as a class.  I've done this in the past with
>> > Ogre3d's "Real" witch is a typedef for float or double.  Depending on
>> > how your using in your scripts, that's all you may need to do, i.e
>> > without any defined methods. This makes GLfloat in scripts similar to an
>> > opaque pointer, where it's allways come from C++ and only really used by
>> > C++. You can also add operators and a constructor as well, to get more
>> > scripting use out of it.
>> >
>> > Using it this way as with pointers (arrays) make take a little tweaking,
>> > I'll have to have a play around when I have time.
>> >
>> > Nigel
>> >
>> > On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
>> >> I might've been mistaken on the function pointer issue, but I've only used it
>> >> that way.
>> >>
>> >>
>> >>
>> >> ----- Ursprüngliche Mail ----
>> >> Von: beo wulf <[hidden email]>
>> >> An: [hidden email]
>> >> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
>> >> Betreff: Re: [luabind] boost bind/lambda
>> >>
>> >> Why does wrapping it on a tag_function work then?
>> >>
>> >> Writing wrappers is out of the question -- there are too many functions.
>> >>
>> >> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:
>> >> > "def" requires an address or function pointer, but bind returns a temporary
>> >> > functor instance. Try to use a static instance or write a wrapper function
>> >> > implementation and pass that.
>> >> >
>> >> > Something like <type> func = bind(...)
>> >> > .def("glLightfv", &func)
>> >> > I'm not sure what <type> would look like though.
>> >> >
>> >> > Alternatively, something like this might work:
>> >> > void wrappedGlLightfv(GLenum light, GLenum pname, const
>> >> > boost::shared_ptr<std::vector<GLfloat>> fv)
>> >> > {
>> >> >  glLightfv(light, pname, &fv->get()->front()); // not quite sure about
>> >> front(),
>> >> > but you get the idea
>> >> > }
>> >> >
>> >> > ...
>> >> > .def("glLightfv", wrappedGlLightfv)
>> >> > ...
>> >> >
>> >> > ----- Ursprüngliche Mail ----
>> >> > Von: beo wulf <[hidden email]>
>> >> > An: [hidden email]
>> >> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
>> >> > Betreff: [luabind] boost bind/lambda
>> >> >
>> >> > Goal: I want to luabind all of OpenGL.
>> >> > Problem: glLightfv( int, int, GLfloat*)
>> >> >
>> >> > Almost solution:  boost::bind
>> >> >
>> >> > The following code almost works -- it can use boost::bind to convert
>> >> > functions that take arg GLfloat* to take an arg of
>> >> > boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
>> >> > and luabind seem to not work with each other (in particular, the line
>> >> >
>> >> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
>> >> >
>> >> > Why?
>> >> >
>> >> > Full code below:
>> >> >
>> >> >
>> >> >
>> >> > #include <boost/shared_ptr.hpp>
>> >> > #include <boost/bind.hpp>
>> >> >
>> >> > #include <vector>
>> >> > #include <iostream>
>> >> >
>> >> > #include <luabind/luabind.hpp>
>> >> > #include <luabind/operator.hpp>
>> >> > #include <luabind/adopt_policy.hpp>
>> >> > #include <luabind/copy_policy.hpp>
>> >> > #include <luabind/class_info.hpp>
>> >> >
>> >> > #include <GL/gl.h>
>> >> >
>> >> >
>> >> >
>> >> > #define P boost::shared_ptr
>> >> > #define V std::vector
>> >> >
>> >> > float foo(int x, int y, float* f) {
>> >> >  float ans = 0;
>> >> >  ans = x + y + f[0] + f[1] + f[2];
>> >> >  return ans;
>> >> > }
>> >> >
>> >> > float* get_raw(P<V<float> > p) {
>> >> >  return &((*p)[0]);
>> >> > }
>> >> >
>> >> > void test() { // works fine
>> >> >  P<V<float> > p(new V<float>());
>> >> >  p->push_back(1);
>> >> >  p->push_back(2);
>> >> >  p->push_back(3);
>> >> >
>> >> >  // I want this to output 9
>> >> >  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
>> >> > }
>> >> >
>> >> >
>> >> > int main() {
>> >> >  using namespace luabind;
>> >> >
>> >> >  lua_State *L;
>> >> >
>> >> >  module( L )
>> >> >    [
>> >> >    namespace_("gl") [
>> >> >      def( "glLightfv", glLightfv)
>> >> >      // Why do these two lines not compile?
>> >> > //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
>> >> > //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
>> >> >    ]
>> >> >    ]
>> >> >
>> >> >    ;
>> >> > }
>> >> >
>> >> > ------------------------------------------------------------------------------
>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> > to consolidate database storage, standardize their database environment, and,
>> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> > without downtime or disruption
>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>> >> > _______________________________________________
>> >> > luabind-user mailing list
>> >> > [hidden email]
>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > ------------------------------------------------------------------------------
>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> > to consolidate database storage, standardize their database environment, and,
>> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> > without downtime or disruption
>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>> >> > _______________________________________________
>> >> > luabind-user mailing list
>> >> > [hidden email]
>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >> >
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> to consolidate database storage, standardize their database environment, and,
>> >> should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> without downtime or disruption
>> >> http://p.sf.net/sfu/oracle-sfdevnl
>> >> _______________________________________________
>> >> luabind-user mailing list
>> >> [hidden email]
>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >>
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> to consolidate database storage, standardize their database environment, and,
>> >> should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> without downtime or disruption
>> >> http://p.sf.net/sfu/oracle-sfdevnl
>> >> _______________________________________________
>> >> luabind-user mailing list
>> >> [hidden email]
>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> > to consolidate database storage, standardize their database environment, and,
>> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> > without downtime or disruption
>> > http://p.sf.net/sfu/oracle-sfdevnl
>> > _______________________________________________
>> > luabind-user mailing list
>> > [hidden email]
>> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >
>>
>> ------------------------------------------------------------------------------
>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> to consolidate database storage, standardize their database environment, and,
>> should the need arise, upgrade to a full multi-node Oracle RAC database
>> without downtime or disruption
>> http://p.sf.net/sfu/oracle-sfdevnl
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

beo wulf
In reply to this post by Nigel Atkinson-2
This is _almost_ perfect, the only thing I can't figure out is:

#typedef P boost::shared_ptr
#typedef V std::vector

P<GLfloat> givemefloat(P<V<GLfloat> > p) {
  return P( & (*v) [0] );
}

is bad in my case since I don't want the data to be tried to be freed
when the pointer returned by givemefloat expires. Is there a way to
have a boost pointer that doesn't reference count? (or if it must
reference count, reference count on the P<V<GLfloat>> object ?

Thanks!

On Wed, Jan 5, 2011 at 2:55 AM, Nigel Atkinson <[hidden email]> wrote:

> You're on the right track.  Perhaps an example will help (and let me
> make sure it works as advertised!) Attached is a little program which
> I've tested with gcc 4 and luabind 0.9.  I've added a couple of
> comments.
>
> It should work if GLfloat is a #define rather than a typedef, but I've
> just checked on my machine (Linux), and it is a typedef.
>
> On another note, if you are binding all of OpenGL, are you going to do
> extensions?  That could be curly! Bound function pointers? That *might*
> work perhaps. Hmmm.
>
> Nigel
>
> On Tue, 2011-01-04 at 23:44 -0800, beo wulf wrote:
>> I've tried
>>
>> class_<GLfloat, boost::shared_ptr<GLfloat> > ....
>>
>> but I'm not sure what to do with this. Can you explain? (Luabind's
>> template blackmagicery is a couple levels above my paygrade).
>> Thanks!
>>
>> On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]> wrote:
>> > You could bind GLfloat as a class.  I've done this in the past with
>> > Ogre3d's "Real" witch is a typedef for float or double.  Depending on
>> > how your using in your scripts, that's all you may need to do, i.e
>> > without any defined methods. This makes GLfloat in scripts similar to an
>> > opaque pointer, where it's allways come from C++ and only really used by
>> > C++. You can also add operators and a constructor as well, to get more
>> > scripting use out of it.
>> >
>> > Using it this way as with pointers (arrays) make take a little tweaking,
>> > I'll have to have a play around when I have time.
>> >
>> > Nigel
>> >
>> > On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
>> >> I might've been mistaken on the function pointer issue, but I've only used it
>> >> that way.
>> >>
>> >>
>> >>
>> >> ----- Ursprüngliche Mail ----
>> >> Von: beo wulf <[hidden email]>
>> >> An: [hidden email]
>> >> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
>> >> Betreff: Re: [luabind] boost bind/lambda
>> >>
>> >> Why does wrapping it on a tag_function work then?
>> >>
>> >> Writing wrappers is out of the question -- there are too many functions.
>> >>
>> >> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:
>> >> > "def" requires an address or function pointer, but bind returns a temporary
>> >> > functor instance. Try to use a static instance or write a wrapper function
>> >> > implementation and pass that.
>> >> >
>> >> > Something like <type> func = bind(...)
>> >> > .def("glLightfv", &func)
>> >> > I'm not sure what <type> would look like though.
>> >> >
>> >> > Alternatively, something like this might work:
>> >> > void wrappedGlLightfv(GLenum light, GLenum pname, const
>> >> > boost::shared_ptr<std::vector<GLfloat>> fv)
>> >> > {
>> >> >  glLightfv(light, pname, &fv->get()->front()); // not quite sure about
>> >> front(),
>> >> > but you get the idea
>> >> > }
>> >> >
>> >> > ...
>> >> > .def("glLightfv", wrappedGlLightfv)
>> >> > ...
>> >> >
>> >> > ----- Ursprüngliche Mail ----
>> >> > Von: beo wulf <[hidden email]>
>> >> > An: [hidden email]
>> >> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
>> >> > Betreff: [luabind] boost bind/lambda
>> >> >
>> >> > Goal: I want to luabind all of OpenGL.
>> >> > Problem: glLightfv( int, int, GLfloat*)
>> >> >
>> >> > Almost solution:  boost::bind
>> >> >
>> >> > The following code almost works -- it can use boost::bind to convert
>> >> > functions that take arg GLfloat* to take an arg of
>> >> > boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
>> >> > and luabind seem to not work with each other (in particular, the line
>> >> >
>> >> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
>> >> >
>> >> > Why?
>> >> >
>> >> > Full code below:
>> >> >
>> >> >
>> >> >
>> >> > #include <boost/shared_ptr.hpp>
>> >> > #include <boost/bind.hpp>
>> >> >
>> >> > #include <vector>
>> >> > #include <iostream>
>> >> >
>> >> > #include <luabind/luabind.hpp>
>> >> > #include <luabind/operator.hpp>
>> >> > #include <luabind/adopt_policy.hpp>
>> >> > #include <luabind/copy_policy.hpp>
>> >> > #include <luabind/class_info.hpp>
>> >> >
>> >> > #include <GL/gl.h>
>> >> >
>> >> >
>> >> >
>> >> > #define P boost::shared_ptr
>> >> > #define V std::vector
>> >> >
>> >> > float foo(int x, int y, float* f) {
>> >> >  float ans = 0;
>> >> >  ans = x + y + f[0] + f[1] + f[2];
>> >> >  return ans;
>> >> > }
>> >> >
>> >> > float* get_raw(P<V<float> > p) {
>> >> >  return &((*p)[0]);
>> >> > }
>> >> >
>> >> > void test() { // works fine
>> >> >  P<V<float> > p(new V<float>());
>> >> >  p->push_back(1);
>> >> >  p->push_back(2);
>> >> >  p->push_back(3);
>> >> >
>> >> >  // I want this to output 9
>> >> >  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
>> >> > }
>> >> >
>> >> >
>> >> > int main() {
>> >> >  using namespace luabind;
>> >> >
>> >> >  lua_State *L;
>> >> >
>> >> >  module( L )
>> >> >    [
>> >> >    namespace_("gl") [
>> >> >      def( "glLightfv", glLightfv)
>> >> >      // Why do these two lines not compile?
>> >> > //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
>> >> > //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
>> >> >    ]
>> >> >    ]
>> >> >
>> >> >    ;
>> >> > }
>> >> >
>> >> > ------------------------------------------------------------------------------
>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> > to consolidate database storage, standardize their database environment, and,
>> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> > without downtime or disruption
>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>> >> > _______________________________________________
>> >> > luabind-user mailing list
>> >> > [hidden email]
>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > ------------------------------------------------------------------------------
>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> > to consolidate database storage, standardize their database environment, and,
>> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> > without downtime or disruption
>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>> >> > _______________________________________________
>> >> > luabind-user mailing list
>> >> > [hidden email]
>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >> >
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> to consolidate database storage, standardize their database environment, and,
>> >> should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> without downtime or disruption
>> >> http://p.sf.net/sfu/oracle-sfdevnl
>> >> _______________________________________________
>> >> luabind-user mailing list
>> >> [hidden email]
>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >>
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> >> to consolidate database storage, standardize their database environment, and,
>> >> should the need arise, upgrade to a full multi-node Oracle RAC database
>> >> without downtime or disruption
>> >> http://p.sf.net/sfu/oracle-sfdevnl
>> >> _______________________________________________
>> >> luabind-user mailing list
>> >> [hidden email]
>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >
>> >
>> >
>> > ------------------------------------------------------------------------------
>> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> > to consolidate database storage, standardize their database environment, and,
>> > should the need arise, upgrade to a full multi-node Oracle RAC database
>> > without downtime or disruption
>> > http://p.sf.net/sfu/oracle-sfdevnl
>> > _______________________________________________
>> > luabind-user mailing list
>> > [hidden email]
>> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>> >
>>
>> ------------------------------------------------------------------------------
>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> to consolidate database storage, standardize their database environment, and,
>> should the need arise, upgrade to a full multi-node Oracle RAC database
>> without downtime or disruption
>> http://p.sf.net/sfu/oracle-sfdevnl
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Ryan Pavlik-4
In reply to this post by Nigel Atkinson-2
Comment on the example code:

You can't use a boost::shared_ptr with a dynamically-allocated array: boost::shared_array is there for that purpose.

Ryan

On Wed, Jan 5, 2011 at 4:55 AM, Nigel Atkinson <[hidden email]> wrote:
You're on the right track.  Perhaps an example will help (and let me
make sure it works as advertised!) Attached is a little program which
I've tested with gcc 4 and luabind 0.9.  I've added a couple of
comments.

It should work if GLfloat is a #define rather than a typedef, but I've
just checked on my machine (Linux), and it is a typedef.

On another note, if you are binding all of OpenGL, are you going to do
extensions?  That could be curly! Bound function pointers? That *might*
work perhaps. Hmmm.

Nigel

On Tue, 2011-01-04 at 23:44 -0800, beo wulf wrote:
> I've tried
>
> class_<GLfloat, boost::shared_ptr<GLfloat> > ....
>
> but I'm not sure what to do with this. Can you explain? (Luabind's
> template blackmagicery is a couple levels above my paygrade).
> Thanks!
>
> On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]> wrote:
> > You could bind GLfloat as a class.  I've done this in the past with
> > Ogre3d's "Real" witch is a typedef for float or double.  Depending on
> > how your using in your scripts, that's all you may need to do, i.e
> > without any defined methods. This makes GLfloat in scripts similar to an
> > opaque pointer, where it's allways come from C++ and only really used by
> > C++. You can also add operators and a constructor as well, to get more
> > scripting use out of it.
> >
> > Using it this way as with pointers (arrays) make take a little tweaking,
> > I'll have to have a play around when I have time.
> >
> > Nigel
> >
> > On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
> >> I might've been mistaken on the function pointer issue, but I've only used it
> >> that way.
> >>
> >>
> >>
> >> ----- Ursprüngliche Mail ----
> >> Von: beo wulf <[hidden email]>
> >> An: [hidden email]
> >> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
> >> Betreff: Re: [luabind] boost bind/lambda
> >>
> >> Why does wrapping it on a tag_function work then?
> >>
> >> Writing wrappers is out of the question -- there are too many functions.
> >>
> >> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[hidden email]> wrote:
> >> > "def" requires an address or function pointer, but bind returns a temporary
> >> > functor instance. Try to use a static instance or write a wrapper function
> >> > implementation and pass that.
> >> >
> >> > Something like <type> func = bind(...)
> >> > .def("glLightfv", &func)
> >> > I'm not sure what <type> would look like though.
> >> >
> >> > Alternatively, something like this might work:
> >> > void wrappedGlLightfv(GLenum light, GLenum pname, const
> >> > boost::shared_ptr<std::vector<GLfloat>> fv)
> >> > {
> >> >  glLightfv(light, pname, &fv->get()->front()); // not quite sure about
> >> front(),
> >> > but you get the idea
> >> > }
> >> >
> >> > ...
> >> > .def("glLightfv", wrappedGlLightfv)
> >> > ...
> >> >
> >> > ----- Ursprüngliche Mail ----
> >> > Von: beo wulf <[hidden email]>
> >> > An: [hidden email]
> >> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
> >> > Betreff: [luabind] boost bind/lambda
> >> >
> >> > Goal: I want to luabind all of OpenGL.
> >> > Problem: glLightfv( int, int, GLfloat*)
> >> >
> >> > Almost solution:  boost::bind
> >> >
> >> > The following code almost works -- it can use boost::bind to convert
> >> > functions that take arg GLfloat* to take an arg of
> >> > boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind
> >> > and luabind seem to not work with each other (in particular, the line
> >> >
> >> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile
> >> >
> >> > Why?
> >> >
> >> > Full code below:
> >> >
> >> >
> >> >
> >> > #include <boost/shared_ptr.hpp>
> >> > #include <boost/bind.hpp>
> >> >
> >> > #include <vector>
> >> > #include <iostream>
> >> >
> >> > #include <luabind/luabind.hpp>
> >> > #include <luabind/operator.hpp>
> >> > #include <luabind/adopt_policy.hpp>
> >> > #include <luabind/copy_policy.hpp>
> >> > #include <luabind/class_info.hpp>
> >> >
> >> > #include <GL/gl.h>
> >> >
> >> >
> >> >
> >> > #define P boost::shared_ptr
> >> > #define V std::vector
> >> >
> >> > float foo(int x, int y, float* f) {
> >> >  float ans = 0;
> >> >  ans = x + y + f[0] + f[1] + f[2];
> >> >  return ans;
> >> > }
> >> >
> >> > float* get_raw(P<V<float> > p) {
> >> >  return &((*p)[0]);
> >> > }
> >> >
> >> > void test() { // works fine
> >> >  P<V<float> > p(new V<float>());
> >> >  p->push_back(1);
> >> >  p->push_back(2);
> >> >  p->push_back(3);
> >> >
> >> >  // I want this to output 9
> >> >  std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl;
> >> > }
> >> >
> >> >
> >> > int main() {
> >> >  using namespace luabind;
> >> >
> >> >  lua_State *L;
> >> >
> >> >  module( L )
> >> >    [
> >> >    namespace_("gl") [
> >> >      def( "glLightfv", glLightfv)
> >> >      // Why do these two lines not compile?
> >> > //    , def( "glLightfv2", bind(glLightfv, _1, _2, _3))
> >> > //    , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3)))
> >> >    ]
> >> >    ]
> >> >
> >> >    ;
> >> > }
> >> >
> >> > ------------------------------------------------------------------------------
> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> > to consolidate database storage, standardize their database environment, and,
> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
> >> > without downtime or disruption
> >> > http://p.sf.net/sfu/oracle-sfdevnl
> >> > _______________________________________________
> >> > luabind-user mailing list
> >> > [hidden email]
> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >> >
> >> >
> >> >
> >> >
> >> > ------------------------------------------------------------------------------
> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> > to consolidate database storage, standardize their database environment, and,
> >> > should the need arise, upgrade to a full multi-node Oracle RAC database
> >> > without downtime or disruption
> >> > http://p.sf.net/sfu/oracle-sfdevnl
> >> > _______________________________________________
> >> > luabind-user mailing list
> >> > [hidden email]
> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >> >
> >>
> >> ------------------------------------------------------------------------------
> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> to consolidate database storage, standardize their database environment, and,
> >> should the need arise, upgrade to a full multi-node Oracle RAC database
> >> without downtime or disruption
> >> http://p.sf.net/sfu/oracle-sfdevnl
> >> _______________________________________________
> >> luabind-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
> >>
> >>
> >>
> >>
> >> ------------------------------------------------------------------------------
> >> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> >> to consolidate database storage, standardize their database environment, and,
> >> should the need arise, upgrade to a full multi-node Oracle RAC database
> >> without downtime or disruption
> >> http://p.sf.net/sfu/oracle-sfdevnl
> >> _______________________________________________
> >> luabind-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
> >
> >
> > ------------------------------------------------------------------------------
> > Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> > to consolidate database storage, standardize their database environment, and,
> > should the need arise, upgrade to a full multi-node Oracle RAC database
> > without downtime or disruption
> > http://p.sf.net/sfu/oracle-sfdevnl
> > _______________________________________________
> > luabind-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




--
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

[hidden email]
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Nigel Atkinson-2
Ah, good point.  Other wise it would use the wrong style of 'delete'.

Nigel

On Thu, January 6, 2011 7:34 am, Ryan Pavlik wrote:
> Comment on the example code:
>
> You can't use a boost::shared_ptr with a dynamically-allocated array:
> boost::shared_array is there for that purpose.
>
> Ryan



------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

Nigel Atkinson-2
In reply to this post by beo wulf
If you want to manage the life time of the data manually (or elsewhere in
code), it's probably easiest to simply not use a shared pointer at all,
and a raw one instead:

GLfloat* givemefloat( .... etc

class_<GLfloat>("GLfloat")

If you really want to use a smart pointer for whatever reason, you can use
a 'null deleter'. See
http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/sp_techniques.html#static
which explains it.

As said previously by others it would be much better to use
boost::shared_array rather than shared_ptr, which you can use a null
deleter with.

Nigel


On Thu, January 6, 2011 6:27 am, beo wulf wrote:

> This is _almost_ perfect, the only thing I can't figure out is:
>
> #typedef P boost::shared_ptr
> #typedef V std::vector
>
> P<GLfloat> givemefloat(P<V<GLfloat> > p) {
>   return P( & (*v) [0] );
> }
>
> is bad in my case since I don't want the data to be tried to be freed
> when the pointer returned by givemefloat expires. Is there a way to
> have a boost pointer that doesn't reference count? (or if it must
> reference count, reference count on the P<V<GLfloat>> object ?
>
> Thanks!
>
> On Wed, Jan 5, 2011 at 2:55 AM, Nigel Atkinson <[hidden email]>
> wrote:
>> You're on the right track. �Perhaps an example will help (and let me
>> make sure it works as advertised!) Attached is a little program which
>> I've tested with gcc 4 and luabind 0.9. �I've added a couple of
>> comments.
>>
>> It should work if GLfloat is a #define rather than a typedef, but I've
>> just checked on my machine (Linux), and it is a typedef.
>>
>> On another note, if you are binding all of OpenGL, are you going to do
>> extensions? �That could be curly! Bound function pointers? That *might*
>> work perhaps. Hmmm.
>>
>> Nigel
>>
>> On Tue, 2011-01-04 at 23:44 -0800, beo wulf wrote:
>>> I've tried
>>>
>>> class_<GLfloat, boost::shared_ptr<GLfloat> > ....
>>>
>>> but I'm not sure what to do with this. Can you explain? (Luabind's
>>> template blackmagicery is a couple levels above my paygrade).
>>> Thanks!
>>>
>>> On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]>
>>> wrote:
>>> > You could bind GLfloat as a class. �I've done this in the past with
>>> > Ogre3d's "Real" witch is a typedef for float or double. �Depending on
>>> > how your using in your scripts, that's all you may need to do, i.e
>>> > without any defined methods. This makes GLfloat in scripts similar to
>>> an
>>> > opaque pointer, where it's allways come from C++ and only really used
>>> by
>>> > C++. You can also add operators and a constructor as well, to get
>>> more
>>> > scripting use out of it.
>>> >
>>> > Using it this way as with pointers (arrays) make take a little
>>> tweaking,
>>> > I'll have to have a play around when I have time.
>>> >
>>> > Nigel
>>> >
>>> > On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
>>> >> I might've been mistaken on the function pointer issue, but I've
>>> only used it
>>> >> that way.
>>> >>
>>> >>
>>> >>
>>> >> ----- Urspr�ngliche Mail ----
>>> >> Von: beo wulf <[hidden email]>
>>> >> An: [hidden email]
>>> >> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
>>> >> Betreff: Re: [luabind] boost bind/lambda
>>> >>
>>> >> Why does wrapping it on a tag_function work then?
>>> >>
>>> >> Writing wrappers is out of the question -- there are too many
>>> functions.
>>> >>
>>> >> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek
>>> <[hidden email]> wrote:
>>> >> > "def" requires an address or function pointer, but bind returns a
>>> temporary
>>> >> > functor instance. Try to use a static instance or write a wrapper
>>> function
>>> >> > implementation and pass that.
>>> >> >
>>> >> > Something like <type> func = bind(...)
>>> >> > .def("glLightfv", &func)
>>> >> > I'm not sure what <type> would look like though.
>>> >> >
>>> >> > Alternatively, something like this might work:
>>> >> > void wrappedGlLightfv(GLenum light, GLenum pname, const
>>> >> > boost::shared_ptr<std::vector<GLfloat>> fv)
>>> >> > {
>>> >> > �glLightfv(light, pname, &fv->get()->front()); // not quite sure
>>> about
>>> >> front(),
>>> >> > but you get the idea
>>> >> > }
>>> >> >
>>> >> > ...
>>> >> > .def("glLightfv", wrappedGlLightfv)
>>> >> > ...
>>> >> >
>>> >> > ----- Urspr�ngliche Mail ----
>>> >> > Von: beo wulf <[hidden email]>
>>> >> > An: [hidden email]
>>> >> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
>>> >> > Betreff: [luabind] boost bind/lambda
>>> >> >
>>> >> > Goal: I want to luabind all of OpenGL.
>>> >> > Problem: glLightfv( int, int, GLfloat*)
>>> >> >
>>> >> > Almost solution: �boost::bind
>>> >> >
>>> >> > The following code almost works -- it can use boost::bind to
>>> convert
>>> >> > functions that take arg GLfloat* to take an arg of
>>> >> > boost::shared_ptr<std::vector<GLfloat>> instead. However,
>>> boost::bind
>>> >> > and luabind seem to not work with each other (in particular, the
>>> line
>>> >> >
>>> >> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does
>>> not compile
>>> >> >
>>> >> > Why?
>>> >> >
>>> >> > Full code below:
>>> >> >
>>> >> >
>>> >> >
>>> >> > #include <boost/shared_ptr.hpp>
>>> >> > #include <boost/bind.hpp>
>>> >> >
>>> >> > #include <vector>
>>> >> > #include <iostream>
>>> >> >
>>> >> > #include <luabind/luabind.hpp>
>>> >> > #include <luabind/operator.hpp>
>>> >> > #include <luabind/adopt_policy.hpp>
>>> >> > #include <luabind/copy_policy.hpp>
>>> >> > #include <luabind/class_info.hpp>
>>> >> >
>>> >> > #include <GL/gl.h>
>>> >> >
>>> >> >
>>> >> >
>>> >> > #define P boost::shared_ptr
>>> >> > #define V std::vector
>>> >> >
>>> >> > float foo(int x, int y, float* f) {
>>> >> > �float ans = 0;
>>> >> > �ans = x + y + f[0] + f[1] + f[2];
>>> >> > �return ans;
>>> >> > }
>>> >> >
>>> >> > float* get_raw(P<V<float> > p) {
>>> >> > �return &((*p)[0]);
>>> >> > }
>>> >> >
>>> >> > void test() { // works fine
>>> >> > �P<V<float> > p(new V<float>());
>>> >> > �p->push_back(1);
>>> >> > �p->push_back(2);
>>> >> > �p->push_back(3);
>>> >> >
>>> >> > �// I want this to output 9
>>> >> > �std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) <<
>>> std::endl;
>>> >> > }
>>> >> >
>>> >> >
>>> >> > int main() {
>>> >> > �using namespace luabind;
>>> >> >
>>> >> > �lua_State *L;
>>> >> >
>>> >> > �module( L )
>>> >> > � �[
>>> >> > � �namespace_("gl") [
>>> >> > � � �def( "glLightfv", glLightfv)
>>> >> > � � �// Why do these two lines not compile?
>>> >> > // � �, def( "glLightfv2", bind(glLightfv, _1, _2, _3))
>>> >> > // � �, def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw,
>>> _3)))
>>> >> > � �]
>>> >> > � �]
>>> >> >
>>> >> > � �;
>>> >> > }
>>> >> >
>>> >> > ------------------------------------------------------------------------------
>>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows
>>> customers
>>> >> > to consolidate database storage, standardize their database
>>> environment, and,
>>> >> > should the need arise, upgrade to a full multi-node Oracle RAC
>>> database
>>> >> > without downtime or disruption
>>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>>> >> > _______________________________________________
>>> >> > luabind-user mailing list
>>> >> > [hidden email]
>>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > ------------------------------------------------------------------------------
>>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows
>>> customers
>>> >> > to consolidate database storage, standardize their database
>>> environment, and,
>>> >> > should the need arise, upgrade to a full multi-node Oracle RAC
>>> database
>>> >> > without downtime or disruption
>>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>>> >> > _______________________________________________
>>> >> > luabind-user mailing list
>>> >> > [hidden email]
>>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>>> >> >
>>> >>
>>> >> ------------------------------------------------------------------------------
>>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows
>>> customers
>>> >> to consolidate database storage, standardize their database
>>> environment, and,
>>> >> should the need arise, upgrade to a full multi-node Oracle RAC
>>> database
>>> >> without downtime or disruption
>>> >> http://p.sf.net/sfu/oracle-sfdevnl
>>> >> _______________________________________________
>>> >> luabind-user mailing list
>>> >> [hidden email]
>>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>> >>
>>> >>
>>> >>
>>> >>
>>> >> ------------------------------------------------------------------------------
>>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows
>>> customers
>>> >> to consolidate database storage, standardize their database
>>> environment, and,
>>> >> should the need arise, upgrade to a full multi-node Oracle RAC
>>> database
>>> >> without downtime or disruption
>>> >> http://p.sf.net/sfu/oracle-sfdevnl
>>> >> _______________________________________________
>>> >> luabind-user mailing list
>>> >> [hidden email]
>>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>> >
>>> >
>>> >
>>> > ------------------------------------------------------------------------------
>>> > Learn how Oracle Real Application Clusters (RAC) One Node allows
>>> customers
>>> > to consolidate database storage, standardize their database
>>> environment, and,
>>> > should the need arise, upgrade to a full multi-node Oracle RAC
>>> database
>>> > without downtime or disruption
>>> > http://p.sf.net/sfu/oracle-sfdevnl
>>> > _______________________________________________
>>> > luabind-user mailing list
>>> > [hidden email]
>>> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>>> >
>>>
>>> ------------------------------------------------------------------------------
>>> Learn how Oracle Real Application Clusters (RAC) One Node allows
>>> customers
>>> to consolidate database storage, standardize their database
>>> environment, and,
>>> should the need arise, upgrade to a full multi-node Oracle RAC database
>>> without downtime or disruption
>>> http://p.sf.net/sfu/oracle-sfdevnl
>>> _______________________________________________
>>> luabind-user mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>
>>
>> ------------------------------------------------------------------------------
>> Learn how Oracle Real Application Clusters (RAC) One Node allows
>> customers
>> to consolidate database storage, standardize their database environment,
>> and,
>> should the need arise, upgrade to a full multi-node Oracle RAC database
>> without downtime or disruption
>> http://p.sf.net/sfu/oracle-sfdevnl
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>
>>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment,
> and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>



------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: boost bind/lambda

beo wulf
I like to take this moment to thank everyone for their insights into
luabind, boost, and OpenGL issues. I've managed to luabind all the
constants/functions I need. Thanks again!

On Wed, Jan 5, 2011 at 4:25 PM, Nigel Atkinson <[hidden email]> wrote:

> If you want to manage the life time of the data manually (or elsewhere in
> code), it's probably easiest to simply not use a shared pointer at all,
> and a raw one instead:
>
> GLfloat* givemefloat( .... etc
>
> class_<GLfloat>("GLfloat")
>
> If you really want to use a smart pointer for whatever reason, you can use
> a 'null deleter'. See
> http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/sp_techniques.html#static
> which explains it.
>
> As said previously by others it would be much better to use
> boost::shared_array rather than shared_ptr, which you can use a null
> deleter with.
>
> Nigel
>
>
> On Thu, January 6, 2011 6:27 am, beo wulf wrote:
>> This is _almost_ perfect, the only thing I can't figure out is:
>>
>> #typedef P boost::shared_ptr
>> #typedef V std::vector
>>
>> P<GLfloat> givemefloat(P<V<GLfloat> > p) {
>>   return P( & (*v) [0] );
>> }
>>
>> is bad in my case since I don't want the data to be tried to be freed
>> when the pointer returned by givemefloat expires. Is there a way to
>> have a boost pointer that doesn't reference count? (or if it must
>> reference count, reference count on the P<V<GLfloat>> object ?
>>
>> Thanks!
>>
>> On Wed, Jan 5, 2011 at 2:55 AM, Nigel Atkinson <[hidden email]>
>> wrote:
>>> You're on the right track. �Perhaps an example will help (and let me
>>> make sure it works as advertised!) Attached is a little program which
>>> I've tested with gcc 4 and luabind 0.9. �I've added a couple of
>>> comments.
>>>
>>> It should work if GLfloat is a #define rather than a typedef, but I've
>>> just checked on my machine (Linux), and it is a typedef.
>>>
>>> On another note, if you are binding all of OpenGL, are you going to do
>>> extensions? �That could be curly! Bound function pointers? That *might*
>>> work perhaps. Hmmm.
>>>
>>> Nigel
>>>
>>> On Tue, 2011-01-04 at 23:44 -0800, beo wulf wrote:
>>>> I've tried
>>>>
>>>> class_<GLfloat, boost::shared_ptr<GLfloat> > ....
>>>>
>>>> but I'm not sure what to do with this. Can you explain? (Luabind's
>>>> template blackmagicery is a couple levels above my paygrade).
>>>> Thanks!
>>>>
>>>> On Tue, Jan 4, 2011 at 11:26 PM, Nigel Atkinson <[hidden email]>
>>>> wrote:
>>>> > You could bind GLfloat as a class. �I've done this in the past with
>>>> > Ogre3d's "Real" witch is a typedef for float or double. �Depending on
>>>> > how your using in your scripts, that's all you may need to do, i.e
>>>> > without any defined methods. This makes GLfloat in scripts similar to
>>>> an
>>>> > opaque pointer, where it's allways come from C++ and only really used
>>>> by
>>>> > C++. You can also add operators and a constructor as well, to get
>>>> more
>>>> > scripting use out of it.
>>>> >
>>>> > Using it this way as with pointers (arrays) make take a little
>>>> tweaking,
>>>> > I'll have to have a play around when I have time.
>>>> >
>>>> > Nigel
>>>> >
>>>> > On Wed, 2011-01-05 at 06:17 +0000, Tony Kostanjsek wrote:
>>>> >> I might've been mistaken on the function pointer issue, but I've
>>>> only used it
>>>> >> that way.
>>>> >>
>>>> >>
>>>> >>
>>>> >> ----- Urspr�ngliche Mail ----
>>>> >> Von: beo wulf <[hidden email]>
>>>> >> An: [hidden email]
>>>> >> Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr
>>>> >> Betreff: Re: [luabind] boost bind/lambda
>>>> >>
>>>> >> Why does wrapping it on a tag_function work then?
>>>> >>
>>>> >> Writing wrappers is out of the question -- there are too many
>>>> functions.
>>>> >>
>>>> >> On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek
>>>> <[hidden email]> wrote:
>>>> >> > "def" requires an address or function pointer, but bind returns a
>>>> temporary
>>>> >> > functor instance. Try to use a static instance or write a wrapper
>>>> function
>>>> >> > implementation and pass that.
>>>> >> >
>>>> >> > Something like <type> func = bind(...)
>>>> >> > .def("glLightfv", &func)
>>>> >> > I'm not sure what <type> would look like though.
>>>> >> >
>>>> >> > Alternatively, something like this might work:
>>>> >> > void wrappedGlLightfv(GLenum light, GLenum pname, const
>>>> >> > boost::shared_ptr<std::vector<GLfloat>> fv)
>>>> >> > {
>>>> >> > �glLightfv(light, pname, &fv->get()->front()); // not quite sure
>>>> about
>>>> >> front(),
>>>> >> > but you get the idea
>>>> >> > }
>>>> >> >
>>>> >> > ...
>>>> >> > .def("glLightfv", wrappedGlLightfv)
>>>> >> > ...
>>>> >> >
>>>> >> > ----- Urspr�ngliche Mail ----
>>>> >> > Von: beo wulf <[hidden email]>
>>>> >> > An: [hidden email]
>>>> >> > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr
>>>> >> > Betreff: [luabind] boost bind/lambda
>>>> >> >
>>>> >> > Goal: I want to luabind all of OpenGL.
>>>> >> > Problem: glLightfv( int, int, GLfloat*)
>>>> >> >
>>>> >> > Almost solution: �boost::bind
>>>> >> >
>>>> >> > The following code almost works -- it can use boost::bind to
>>>> convert
>>>> >> > functions that take arg GLfloat* to take an arg of
>>>> >> > boost::shared_ptr<std::vector<GLfloat>> instead. However,
>>>> boost::bind
>>>> >> > and luabind seem to not work with each other (in particular, the
>>>> line
>>>> >> >
>>>> >> > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does
>>>> not compile
>>>> >> >
>>>> >> > Why?
>>>> >> >
>>>> >> > Full code below:
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> > #include <boost/shared_ptr.hpp>
>>>> >> > #include <boost/bind.hpp>
>>>> >> >
>>>> >> > #include <vector>
>>>> >> > #include <iostream>
>>>> >> >
>>>> >> > #include <luabind/luabind.hpp>
>>>> >> > #include <luabind/operator.hpp>
>>>> >> > #include <luabind/adopt_policy.hpp>
>>>> >> > #include <luabind/copy_policy.hpp>
>>>> >> > #include <luabind/class_info.hpp>
>>>> >> >
>>>> >> > #include <GL/gl.h>
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> > #define P boost::shared_ptr
>>>> >> > #define V std::vector
>>>> >> >
>>>> >> > float foo(int x, int y, float* f) {
>>>> >> > �float ans = 0;
>>>> >> > �ans = x + y + f[0] + f[1] + f[2];
>>>> >> > �return ans;
>>>> >> > }
>>>> >> >
>>>> >> > float* get_raw(P<V<float> > p) {
>>>> >> > �return &((*p)[0]);
>>>> >> > }
>>>> >> >
>>>> >> > void test() { // works fine
>>>> >> > �P<V<float> > p(new V<float>());
>>>> >> > �p->push_back(1);
>>>> >> > �p->push_back(2);
>>>> >> > �p->push_back(3);
>>>> >> >
>>>> >> > �// I want this to output 9
>>>> >> > �std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) <<
>>>> std::endl;
>>>> >> > }
>>>> >> >
>>>> >> >
>>>> >> > int main() {
>>>> >> > �using namespace luabind;
>>>> >> >
>>>> >> > �lua_State *L;
>>>> >> >
>>>> >> > �module( L )
>>>> >> > � �[
>>>> >> > � �namespace_("gl") [
>>>> >> > � � �def( "glLightfv", glLightfv)
>>>> >> > � � �// Why do these two lines not compile?
>>>> >> > // � �, def( "glLightfv2", bind(glLightfv, _1, _2, _3))
>>>> >> > // � �, def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw,
>>>> _3)))
>>>> >> > � �]
>>>> >> > � �]
>>>> >> >
>>>> >> > � �;
>>>> >> > }
>>>> >> >
>>>> >> > ------------------------------------------------------------------------------
>>>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows
>>>> customers
>>>> >> > to consolidate database storage, standardize their database
>>>> environment, and,
>>>> >> > should the need arise, upgrade to a full multi-node Oracle RAC
>>>> database
>>>> >> > without downtime or disruption
>>>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>>>> >> > _______________________________________________
>>>> >> > luabind-user mailing list
>>>> >> > [hidden email]
>>>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> > ------------------------------------------------------------------------------
>>>> >> > Learn how Oracle Real Application Clusters (RAC) One Node allows
>>>> customers
>>>> >> > to consolidate database storage, standardize their database
>>>> environment, and,
>>>> >> > should the need arise, upgrade to a full multi-node Oracle RAC
>>>> database
>>>> >> > without downtime or disruption
>>>> >> > http://p.sf.net/sfu/oracle-sfdevnl
>>>> >> > _______________________________________________
>>>> >> > luabind-user mailing list
>>>> >> > [hidden email]
>>>> >> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>>>> >> >
>>>> >>
>>>> >> ------------------------------------------------------------------------------
>>>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows
>>>> customers
>>>> >> to consolidate database storage, standardize their database
>>>> environment, and,
>>>> >> should the need arise, upgrade to a full multi-node Oracle RAC
>>>> database
>>>> >> without downtime or disruption
>>>> >> http://p.sf.net/sfu/oracle-sfdevnl
>>>> >> _______________________________________________
>>>> >> luabind-user mailing list
>>>> >> [hidden email]
>>>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>>> >>
>>>> >>
>>>> >>
>>>> >>
>>>> >> ------------------------------------------------------------------------------
>>>> >> Learn how Oracle Real Application Clusters (RAC) One Node allows
>>>> customers
>>>> >> to consolidate database storage, standardize their database
>>>> environment, and,
>>>> >> should the need arise, upgrade to a full multi-node Oracle RAC
>>>> database
>>>> >> without downtime or disruption
>>>> >> http://p.sf.net/sfu/oracle-sfdevnl
>>>> >> _______________________________________________
>>>> >> luabind-user mailing list
>>>> >> [hidden email]
>>>> >> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>>> >
>>>> >
>>>> >
>>>> > ------------------------------------------------------------------------------
>>>> > Learn how Oracle Real Application Clusters (RAC) One Node allows
>>>> customers
>>>> > to consolidate database storage, standardize their database
>>>> environment, and,
>>>> > should the need arise, upgrade to a full multi-node Oracle RAC
>>>> database
>>>> > without downtime or disruption
>>>> > http://p.sf.net/sfu/oracle-sfdevnl
>>>> > _______________________________________________
>>>> > luabind-user mailing list
>>>> > [hidden email]
>>>> > https://lists.sourceforge.net/lists/listinfo/luabind-user
>>>> >
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Learn how Oracle Real Application Clusters (RAC) One Node allows
>>>> customers
>>>> to consolidate database storage, standardize their database
>>>> environment, and,
>>>> should the need arise, upgrade to a full multi-node Oracle RAC database
>>>> without downtime or disruption
>>>> http://p.sf.net/sfu/oracle-sfdevnl
>>>> _______________________________________________
>>>> luabind-user mailing list
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Learn how Oracle Real Application Clusters (RAC) One Node allows
>>> customers
>>> to consolidate database storage, standardize their database environment,
>>> and,
>>> should the need arise, upgrade to a full multi-node Oracle RAC database
>>> without downtime or disruption
>>> http://p.sf.net/sfu/oracle-sfdevnl
>>> _______________________________________________
>>> luabind-user mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>>
>>>
>>
>> ------------------------------------------------------------------------------
>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> to consolidate database storage, standardize their database environment,
>> and,
>> should the need arise, upgrade to a full multi-node Oracle RAC database
>> without downtime or disruption
>> http://p.sf.net/sfu/oracle-sfdevnl
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>
>
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user