Thread: [luabind] index_proxy forwarding problem
Brought to you by:
arvidn,
daniel_wallin
From: Marco Di B. <spa...@gm...> - 2012-10-12 11:34:25
|
Hi, 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(); luabind::open(L); 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; lua_close(L); } ------------------------ 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, m. |