index_proxy forwarding problem

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

index_proxy forwarding problem

Marco Di Benedetto

I'm new to this list and apologize if this has been already discussed
(I didn't find any reference).

Basically, I'd like to be able to access in read/write to global
objects or object properties in a way like get(luaState, "MyGlobal") =
123. However, I incur in crashes or panic(). Digging into the luabind
code, I suspect there is some problem in transferring ownership
between adl::index_proxy instances, it's like the stack is not
correctly handled.
Or I am completely wrong :)
I set up the following code that explains the problem better than I could:

#include <iostream>
#include <luabind/luabind.hpp>

lua_State * L;

luabind::adl::index_proxy<luabind::object> get(const char * name)
        return luabind::globals(L)[name];

void main(void)
        L = luaL_newstate();

        std::cout << "begin" << std::endl;

        // case 1
                std::cout << "case 1" << std::endl;
                luabind::globals(L)["C1"] = 1; // ok

        // case 2
                std::cout << "case 2" << std::endl;
                luabind::object g = luabind::globals(L);
                g["C2"] = 1; // ok

        // case 3
                std::cout << "case 3" << std::endl;
                luabind::object g = luabind::globals(L);
                luabind::adl::index_proxy<luabind::object> p = g["C3"];
                p = 1; // ok

        // case 4
                std::cout << "case 4" << std::endl;
                luabind::adl::index_proxy<luabind::object> p = luabind::globals(L)["C4"];
                p = 1; // panic

        // case 5
                std::cout << "case 5" << std::endl;
                luabind::adl::index_proxy<luabind::object> p = get("C5");
                p = 1; // panic

        // case 6
                std::cout << "case 6" << std::endl;
                get("C6") = 1; // panic

        std::cout << "end" << std::endl;


As you can see from the comments, panic occurs in cases 4, 5, and 6.
In particular, what cause myself to raise the white flag is that case
3 works and case 4 does not.
What I was originally trying to accomplish is some wrapper class that
allows me to do something like:
LuaState lua; // takes care of creating the C lua state, init luabind etc.
lua["X"] = 1;
As you can imagine, overloading operator [] is the point in question,
so I wrote the above use cases to try to focus the problem. It seems
to me that the copy constructor of index_proxy is not correctly
managing the stack. Using references on returned l-values is not an
option because of the proxies are temporary. neither casting
index_proxy to object helps because of the lack of the assign operator
in the object class.

Any idea?

Thank you very much,

Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
luabind-user mailing list
[hidden email]