// - LuaVariable::operator= ------------------------------------------------- const LuaValue& LuaVariable::operator= (const LuaValue& rhs) { pushLastTable(); PushLuaValue (state_, keys_.back()); PushLuaValue (state_, rhs); lua_settable (state_, -3); lua_pop (state_, 1); return rhs; }
// - LuaState::call --------------------------------------------------------- LuaValueList LuaState::call (LuaFunction& func, const LuaValueList& params, const std::string& chunkName) { func.setReaderFlag (false); PushLuaValue (state_, LuaValue (func)); return Impl::CallFunctionOnTop (state_, params); }
// - LuaVariable::pushTheReferencedValue ------------------------------------ void LuaVariable::pushTheReferencedValue() const { assert (keys_.size() > 0 && "There should be at least one key here."); lua_rawgeti (state_, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS); typedef std::vector<LuaValue>::const_iterator iter_t; for (iter_t p = keys_.begin(); p != keys_.end(); ++p) { PushLuaValue (state_, *p); lua_gettable (state_, -2); if (keys_.size() > 1 && p != keys_.end()-1 && !lua_istable(state_, -1)) throw TypeMismatchError ("table", p->typeName()); lua_remove (state_, -2); } }
// - LuaVariable::pushLastTable --------------------------------------------- void LuaVariable::pushLastTable() { // Push the globals table onto the stack lua_pushglobaltable (state_); // Reach the "final" table (and leave it at the stack top) typedef KeyList::const_iterator iter_t; assert (keys_.size() > 0 && "At least one key should be present here."); iter_t end = keys_.end(); --end; for (iter_t p = keys_.begin(); p != end; ++p) { PushLuaValue (state_, *p); lua_gettable (state_, -2); if (!lua_istable (state_, -1)) throw TypeMismatchError ("table", luaL_typename (state_, -1)); lua_remove (state_, -2); } }