Some reflection on Luabind types

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

Some reflection on Luabind types

Alexander Gladysh
Hi, all!

For my console rudimentary autocompletion feature I want to get list
of members of Luabind type from Lua (or C++). Is it possible?

Say, for

luabind::class_<Foo>("Foo")
  .def("Bar", &Foo::Bar)
  .def("Baz", &Foo::Baz)

local f = Foo();
local t = getmembers(f);

I want to get t = { "Bar", "Baz" }.

Thanks in advance,
Alexander.


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Some reflection on Luabind types

George Faraj
Hey, you could probably try something like:

function list_functions(from, table)
    local result = { };
   
    for name, value in pairs(from[table]) do
        if type(value) == "function" then
            table.insert(result, name);
        end
    end
   
    return result;
end

local Foo_functs =  list_functions(_G,  "Foo");

Regards,
YUY0x7


Hi, all!

For my console rudimentary autocompletion feature I want to get list
of members of Luabind type from Lua (or C++). Is it possible?

Say, for

luabind::class_<Foo>("Foo")
 .def("Bar", &Foo::Bar)
 .def("Baz", &Foo::Baz)

local f = Foo();
local t = getmembers(f);

I want to get t = { "Bar", "Baz" }.

Thanks in advance,
Alexander.
Reply | Threaded
Open this post in threaded view
|

Re: Some reflection on Luabind types

George Faraj
Sorry, change the "table" function parameter name to something else,
it would clash with the "table" table..

And that would help you find the functions if you know the type of the
instance you want the functions for. If you don't know the type, I
don't know how you could get that info, maybe someone else can help.


On 3/8/06, George Faraj <[hidden email]> wrote:

>
> Hey, you could probably try something like:
>
> function list_functions(from, table)
>     local result = { };
>
>     for name, value in pairs(from[table]) do
>         if type(value) == "function" then
>             table.insert(result, name);
>         end
>     end
>
>     return result;
> end
>
> local Foo_functs =  list_functions(_G,  "Foo");
>
> Regards,
> YUY0x7
>
>
> >
> > Hi, all!
> >
> > For my console rudimentary autocompletion feature I want to get list
> > of members of Luabind type from Lua (or C++). Is it possible?
> >
> > Say, for
> >
> > luabind::class_<Foo>("Foo")
> >  .def("Bar", &Foo::Bar)
> >  .def("Baz", &Foo::Baz)
> >
> > local f = Foo();
> > local t = getmembers(f);
> >
> > I want to get t = { "Bar", "Baz" }.
> >
> > Thanks in advance,
> > Alexander.
> >
>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Some reflection on Luabind types

Alexander Gladysh
In reply to this post by George Faraj
Hi!

Your solution would work for ordinary Lua classes.

But, unfortunately, luabind classes are not tables, they are userdata.
They have metatables attached to them, but AFAIR those metatables are
userdata too (?!). May be I've got the wrong impression.

:(

Thanks,
Alexander.

On 3/8/06, George Faraj <[hidden email]> wrote:

>
> Hey, you could probably try something like:
>
> function list_functions(from, table)
>     local result = { };
>
>     for name, value in pairs(from[table]) do
>         if type(value) == "function" then
>             table.insert(result, name);
>         end
>     end
>
>     return result;
> end
>
> local Foo_functs =  list_functions(_G,  "Foo");
>
> Regards,
> YUY0x7
>
>
> >
> > Hi, all!
> >
> > For my console rudimentary autocompletion feature I want to get list
> > of members of Luabind type from Lua (or C++). Is it possible?
> >
> > Say, for
> >
> > luabind::class_<Foo>("Foo")
> >  .def("Bar", &Foo::Bar)
> >  .def("Baz", &Foo::Baz)
> >
> > local f = Foo();
> > local t = getmembers(f);
> >
> > I want to get t = { "Bar", "Baz" }.
> >
> > Thanks in advance,
> > Alexander.
> >
>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
<a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Some reflection on Luabind types

Arvid Norberg

On Mar 9, 2006, at 12:41, Alexander Gladysh wrote:

> Hi!
>
> Your solution would work for ordinary Lua classes.
>
> But, unfortunately, luabind classes are not tables, they are userdata.
> They have metatables attached to them, but AFAIR those metatables are
> userdata too (?!). May be I've got the wrong impression.
>
> :(

We did add a function that could could do this, but it was/is  
experimental and undocumented.

You can find it in luabind/get_class_info.hpp

You pass a class to it, and and you retrieve the name of the class, a  
table of its member functions and properties.

The 'methods' member is a table with (name, c-closure)-pairs.
'attributes' is a table of strings with the names of the attributes.

While looking at the source, it looks like there's a bug in the  
get_class_info function as well. In the loop, the variable 'index'  
should be incremented. Please let me know if this works for you.

--
Arvid Norberg




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user