Debugging variables of a lua class

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

Debugging variables of a lua class

Stefan Schwarzbach
Hello there,

when I fetch the current local variables using lua_getlocal, I can get
variables of primitive types as well as local variables representing a
lua class or a cpp class.

At the moment, I use this code to get the class name of such a variable:
            luabind::detail::object_rep* obj =
static_cast<luabind::detail::object_rep*>(lua_touserdata(GetLuaState(),
-1));
            luabind::detail::class_rep* rep = obj->crep();
            if (rep != NULL) className = crep()->name();

Is it anyhow possible to also fetch the member variables and their
values of a local variable instantiating a lua class or cpp class?

Thanks in advance
Stefan Schwarzbach


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Debugging variables of a lua class

Dmitriy Iassenev
SS> when I fetch the current local variables using lua_getlocal, I can get
SS> variables of primitive types as well as local variables representing a
SS> lua class or a cpp class.

SS> At the moment, I use this code to get the class name of such a variable:
SS>             luabind::detail::object_rep* obj =
SS> static_cast<luabind::detail::object_rep*>(lua_touserdata(GetLuaState(),
SS> -1));
SS>             luabind::detail::class_rep* rep = obj->crep();
SS>             if (rep != NULL) className = crep()->name();

SS> Is it anyhow possible to also fetch the member variables and their
SS> values of a local variable instantiating a lua class or cpp class?

you can use

luabind::detail::lua_reference const    &tbl = obj->get_lua_table();
verify                                  (tbl.is_valid());
tbl.get                                 (state);

here on top of the you have Lua table, which represents the
object (since in Lua class instance may have different number of
members than the class itself). Iterating on it you get all the
members of the object, defined in Lua. To get C++ part of the object
or information about inherited classes, you should analyze
luabind::detail::class_rep structure.

--
Best regards,
 Dmitriy                            mailto:[hidden email]


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Debugging variables of a lua class

Stefan Schwarzbach
Thank you for the info!
I have now the problem to iterate through that table representing the  
lua class.

I thought of something like that:

luabind::detail::lua_reference const &tbl = obj->get_lua_table();
if (tbl.is_valid())
{
        lua_State *state = GetLuaState();
        tbl.get(state);

        int tableEntry = 1;
        while (true)
        {
                lua_rawgeti(state, -1, tableEntry);
                if (lua_isnil(state, -1)) break;

                // Fetch value here...

                lua_pop(state, 1);  /* remove variable value */

                tableEntry ++;
        }
}

But I get lua_isnil always returns true for the first element I try to  
get via lua_rawgeti, but the table should have entries. Did I do  
something wrong?

Another think question:
How can get the variable name in addition to the value? I think the  
variable name is the key of the table entry, right? How do I get that?

Thanks in Advance
Stefan Schwarzbach



Quoting Dmitriy Iassenev <[hidden email]>:

> SS> when I fetch the current local variables using lua_getlocal, I can get
> SS> variables of primitive types as well as local variables representing a
> SS> lua class or a cpp class.
>
> SS> At the moment, I use this code to get the class name of such a variable:
> SS>             luabind::detail::object_rep* obj =
> SS> static_cast<luabind::detail::object_rep*>(lua_touserdata(GetLuaState(),
> SS> -1));
> SS>             luabind::detail::class_rep* rep = obj->crep();
> SS>             if (rep != NULL) className = crep()->name();
>
> SS> Is it anyhow possible to also fetch the member variables and their
> SS> values of a local variable instantiating a lua class or cpp class?
>
> you can use
>
> luabind::detail::lua_reference const    &tbl = obj->get_lua_table();
> verify                                  (tbl.is_valid());
> tbl.get                                 (state);
>
> here on top of the you have Lua table, which represents the
> object (since in Lua class instance may have different number of
> members than the class itself). Iterating on it you get all the
> members of the object, defined in Lua. To get C++ part of the object
> or information about inherited classes, you should analyze
> luabind::detail::class_rep structure.
>
> --
> Best regards,
>  Dmitriy                            mailto:[hidden email]
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Debugging variables of a lua class

Stefan Schwarzbach
I found an interesting post on the lua forum mentioning lua_next.
With this function, it seems to work.

Thanks
Stefan


Quoting Stefan Schwarzbach <[hidden email]>:

> Thank you for the info!
> I have now the problem to iterate through that table representing the
> lua class.
>
> I thought of something like that:
>
> luabind::detail::lua_reference const &tbl = obj->get_lua_table();
> if (tbl.is_valid())
> {
> lua_State *state = GetLuaState();
> tbl.get(state);
>
> int tableEntry = 1;
> while (true)
> {
> lua_rawgeti(state, -1, tableEntry);
> if (lua_isnil(state, -1)) break;
>
> // Fetch value here...
>
> lua_pop(state, 1);  /* remove variable value */
>
> tableEntry ++;
> }
> }
>
> But I get lua_isnil always returns true for the first element I try to
> get via lua_rawgeti, but the table should have entries. Did I do
> something wrong?
>
> Another think question:
> How can get the variable name in addition to the value? I think the
> variable name is the key of the table entry, right? How do I get that?
>
> Thanks in Advance
> Stefan Schwarzbach
>
>
>
> Quoting Dmitriy Iassenev <[hidden email]>:
>
>> SS> when I fetch the current local variables using lua_getlocal, I can get
>> SS> variables of primitive types as well as local variables representing a
>> SS> lua class or a cpp class.
>>
>> SS> At the moment, I use this code to get the class name of such a variable:
>> SS>             luabind::detail::object_rep* obj =
>> SS> static_cast<luabind::detail::object_rep*>(lua_touserdata(GetLuaState(),
>> SS> -1));
>> SS>             luabind::detail::class_rep* rep = obj->crep();
>> SS>             if (rep != NULL) className = crep()->name();
>>
>> SS> Is it anyhow possible to also fetch the member variables and their
>> SS> values of a local variable instantiating a lua class or cpp class?
>>
>> you can use
>>
>> luabind::detail::lua_reference const    &tbl = obj->get_lua_table();
>> verify                                  (tbl.is_valid());
>> tbl.get                                 (state);
>>
>> here on top of the you have Lua table, which represents the
>> object (since in Lua class instance may have different number of
>> members than the class itself). Iterating on it you get all the
>> members of the object, defined in Lua. To get C++ part of the object
>> or information about inherited classes, you should analyze
>> luabind::detail::class_rep structure.
>>
>> --
>> Best regards,
>>  Dmitriy                            mailto:[hidden email]
>>
>>
>> Using Tomcat but need to do more? Need to support web services, security?
>> Get stuff done quickly with pre-integrated technology to make your  
>> job easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>> _______________________________________________
>> luabind-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>
>>
>>
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>



.....................................................
Stefan Schwarzbach
Geschäftsführer & Lead Programmer
Silent Dreams

Talhofstr. 6
82205 Gilching
+49 Germany

Tel.   +49 8105 7749776
Mobil  +49 179 5162222
Email  [hidden email]
Web    www.SilentDreams.de

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Debugging variables of a lua class

Arvid Norberg-2

On Jun 23, 2006, at 13:50, Stefan Schwarzbach wrote:

> I found an interesting post on the lua forum mentioning lua_next.
> With this function, it seems to work.

You could also use luabind::iterator. Like this:

for (iterator i(my_ref), end; i != end; ++i)
{
    // *i behaves as a luabind::object
}


--
Arvid Norberg



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Debugging variables of a lua class

Stefan Schwarzbach
Thanks for the info!

I still have one problem getting the attributes of a C++ Class  
registered to lua.

I get an object_rep and so also a class_rep:
luabind::detail::object_rep* obj =  
static_cast<luabind::detail::object_rep*>(lua_touserdata(GetLuaState(),  
-1));
luabind::detail::class_rep* rep = obj->crep();

But how can I now iterate throw the registered Class attributes  
defined by def_readwrite and def_readonly? When I fetch the crep table  
via rep->get_table(state), I seems that the table only contains the  
functions, not the attributes.

luabind::iterator seems not to work, if I pass a object_rep instance  
or class_rep instance in the constructor.

Can you give me help?

Thank You
Stefan



Quoting Arvid Norberg <[hidden email]>:

>
> On Jun 23, 2006, at 13:50, Stefan Schwarzbach wrote:
>
>> I found an interesting post on the lua forum mentioning lua_next.
>> With this function, it seems to work.
>
> You could also use luabind::iterator. Like this:
>
> for (iterator i(my_ref), end; i != end; ++i)
> {
>     // *i behaves as a luabind::object
> }
>
>
> --
> Arvid Norberg
>
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
>



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Debugging variables of a lua class

Arvid Norberg-2

On Jun 23, 2006, at 17:24, Stefan Schwarzbach wrote:

> Thanks for the info!
>
> I still have one problem getting the attributes of a C++ Class
> registered to lua.
>
> I get an object_rep and so also a class_rep:
> luabind::detail::object_rep* obj =
> static_cast<luabind::detail::object_rep*>(lua_touserdata(GetLuaState
> (),
> -1));
> luabind::detail::class_rep* rep = obj->crep();
>
> But how can I now iterate throw the registered Class attributes
> defined by def_readwrite and def_readonly? When I fetch the crep table
> via rep->get_table(state), I seems that the table only contains the
> functions, not the attributes.

I believe most of the things you want to do is in luabind/
class_info.hpp and src/class_info.cpp. You could have a look at these.

What you get back from get_class_info() is:

struct class_info
{
    std::string name;
    object methods;
    object attributes;
};

name: name of the class
methods: a lua table of the member functions on the class
attributes: a lua table of the data members on the class

Hope this is to some help. This hasn't been documented in the manual.

> luabind::iterator seems not to work, if I pass a object_rep instance
> or class_rep instance in the constructor.
>
> Can you give me help?

iterator assumes the type you give it is a luabind::object or an  
object proxy (returned by the index operator or when dereferencing  
another iterator).

--
Arvid Norberg



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user