Deferred registering

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Deferred registering

Laurent Auneau
Hi list,

I want to register a class in two separate functions, called at two
different times. Ie, I want to do something like

struct MyClass {
        void f () {} ;
        void g () {} ;
} ;

void function1 () {
        module(L) [
                class_<MyClass, "MyClass">
                        .def("f", f)
        ] ;
}

void function2 () {
        module(L) [
                class_<MyClass, "MyClass">
                        .def("g", g)
        ] ;
}

How could I perform this?

I tried to construct a global luabind::scope, but it doesn't support .def.
I was trying to do
luabind::scope s (class_<MyClass, "MyClass">) ;
and then
void function1 () {
        s = s.def("f", f) ;
}
void function2 () {
        s = s.def("g", g) ;
}

Thanks for the help,

        SeskaPeel.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Deferred registering

Alexander Gladysh
(Untested) Looks like you should do something like this:

void reg_first(luabind::class_<MyClass, "MyClass"> & c)
{
  c.def("f", f);
}

void reg_second(luabind::class_<MyClass, "MyClass"> & c)
{
  c.def("g", g)
}

luabind::class_<MyClass, "MyClass"> c;
reg_first(c);
reg_second(c);

luabind::module(L)[ c ];

HTH,
Alexander.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Deferred registering

Laurent Auneau
Hi Alexander.

Yes I overlooked I could simply define the global with the concrete type.
But, I think I overlooked too that the .def was a modifier on the instance
of the class. I thought it was only a syntactic sugar and that the aim was
only to RETURN the .defed class_ variable.
I read somewhere that class_ was non copyable, so I was trying to elaborate
super complex strategies to achieve my goal.

At least, now it compiles, and if the variable is not correctly modified by
the successive calls to .def, I'll come back by here.

Cheers,

        SeskaPeel.



-------------------------------------------------------------------------
De la part de Alexander Gladysh
Envoyé : lundi 24 juillet 2006 19:43
Objet : Re: [luabind] Deferred registering

(Untested) Looks like you should do something like this:

void reg_first(luabind::class_<MyClass, "MyClass"> & c)
{
  c.def("f", f);
}

void reg_second(luabind::class_<MyClass, "MyClass"> & c)
{
  c.def("g", g)
}

luabind::class_<MyClass, "MyClass"> c;
reg_first(c);
reg_second(c);

luabind::module(L)[ c ];

HTH,
Alexander.



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user