Context* GetContext(lua_State* L) { lua_getglobal(L, ".context"); if (lua_isnil(L, -1)) { lua_State* L1 = lua_getmainthread(L); return (L == L1) ? 0 : GetContext(L1); } tolua_Error error; // Ensure we are indeed getting a Context object before casting return tolua_isusertype(L, -1, "Context", 0, &error) ? static_cast<Context*>(tolua_tousertype(L, -1, 0)) : 0; }
Context* GetContext(lua_State* L) { HashMap<void*, Context*>::ConstIterator i = contextMapping.Find(L); if (i == contextMapping.End()) { lua_State* L1 = lua_getmainthread(L); return (L == L1) ? 0 : GetContext(L1); } return i->second_; }