// ********************************************************************************************************* bool CDisplayerLua::init(const CLuaObject ¶meters) { //H_AUTO(R2_CDisplayerLua_init) // parameters should be a function that create the lua displayer CLuaStackChecker lsc(parameters.getLuaState()); _ToLua._LuaTable.release(); if (parameters.isString()) { getEditor().getEnv()[parameters.toString()].push(); // get method from the R2 env } else { parameters.push(); } CLuaState &ls = *parameters.getLuaState(); getEditor().getEnv().push(); // this is a method call if (CLuaIHM::executeFunctionOnStack(ls, 1, 1)) { _ToLua._LuaTable.pop(ls); } else { nlwarning("<CDisplayerLua::init> Error while calling displayer ctor (parameter should be a r2 method, or the *name* of a r2 method) : param is : "); parameters.dump(); return false; } return CDisplayerBase::init(parameters); }
bool LuaInterp::loadFile( const char* fileName ) { LuaStackCheck lsc(_luaState); int errCode = LUA_OK; errCode = luaL_loadfile( _luaState, fileName ); if( errCode != LUA_OK ) { printErr( "luaL_loadfile errCode %d \"%s\"\n", errCode, lua_tolstring( _luaState, -1, 0 ) ); lua_pop( _luaState, 1 ); return false; } int numArgs = 0; int numResults = 0; int ehi = 0; // error handler index lua_getglobal( _luaState, "debug" ); lua_getfield( _luaState, -1, "traceback" ); lua_remove( _luaState, -2 ); ehi = -2; lua_insert( _luaState, ehi ); errCode = lua_pcall( _luaState, numArgs, numResults, ehi ); if( errCode != LUA_OK ) { printErr( "lua_pcall %d \"%s\"\n", errCode, lua_tolstring( _luaState, -1, 0 ) ); lua_pop( _luaState, 2 ); return false; } lua_pop( _luaState, 1 ); return true; }
forceinline ExecStatus FixDim::nooverlap(Space& home, FixDim& d) { if (d.sec() > lsc()) { // Propagate that d must be after this GECODE_ES_CHECK(lec(home,d.lsc())); GECODE_ES_CHECK(d.ssc(home,sec())); } else { nooverlap(home, d.lsc(), d.sec()-1); } return ES_OK; }
void CDynamicMapClient::onNpcAnimationTargeted(uint32 mode) { //H_AUTO(R2_CDynamicMapClient_onNpcAnimationTargeted) nlinfo("R2Cl: DSS_TARGET"); CLuaState &lua = getEditor().getLua(); CLuaStackChecker lsc(&lua); int initialStackSize = lua.getTop(); if (mode & CAnimationProp::Spawnable) { lua.push("r2ed_anim_despawn"); } if (mode & CAnimationProp::Alive) { lua.push("r2ed_anim_kill"); if (mode & CAnimationProp::Grouped) { lua.push("r2ed_anim_grp_kill"); } lua.push("r2ed_anim_add_hp"); if (mode & CAnimationProp::Grouped) { lua.push("r2ed_anim_grp_heal"); } } if (mode & CAnimationProp::Controlable) { if (mode & CAnimationProp::Controled ) { lua.push("r2ed_anim_stop_control"); } else { lua.push("r2ed_anim_control"); } } if (mode & CAnimationProp::Speaking) { if(mode & CAnimationProp::SpeakedAs) { lua.push("r2ed_anim_stop_speak"); } else { lua.push("r2ed_anim_speak_as"); } } // getEditor().callEnvMethod("updateAnimBarActions", lua.getTop() - initialStackSize); }
bool CDynamicMapClient::loadAnimationFromBuffer(const std::string& content, const std::string& filename, std::string& errMsg, const CScenarioValidator::TValues& values) { //H_AUTO(R2_CDynamicMapClient_loadAnimationFromBuffer) CObject* data = _ComLua->loadFromBuffer(content, filename, values); if (!data) { errMsg = "Invalid Data"; R2::getEditor().setStartingAnimationFilename(""); R2::getEditor().getLua().push(errMsg); R2::getEditor().getLua().pcallByName("printWarning", 1, 0, -1 ); R2::getEditor().getLua().executeScriptNoThrow("UnitTest.testLoadAnimationScenarioUi()"); return false; } R2::getEditor().getLua().executeScriptNoThrow("r2.RingAccess.LoadAnimation = true"); _EditionModule->setMustStartScenario( true ); this->scenarioUpdated(data, false, 1); R2::getEditor().getLua().executeScriptNoThrow("r2.RingAccess.LoadAnimation = false"); if (ClientCfg.R2EDMustVerifyRingAccessWhileLoadingAnimation) { CLuaState &ls = R2::getEditor().getLua(); CLuaStackChecker lsc(&ls); R2::getEditor().callEnvFunc( "verifyScenario", 0, 2); if (!ls.isBoolean(-2)) { nlassert(0 && "verifyScenario return wrong type"); } if (!ls.isString(-1)) { nlassert(0 && "verifyScenario return wrong type"); } bool result = ls.toBoolean(-2); std::string msg = ls.toString(-1); ls.pop(2); if (!result) { _EditionModule->setMustStartScenario( false ); R2::getEditor().setStartingAnimationFilename(""); R2::getEditor().clearContent(); errMsg = msg; R2::getEditor().getLua().push(errMsg); R2::getEditor().getLua().pcallByName("printWarning", 1, 0, -1 ); R2::getEditor().getLua().executeScriptNoThrow("UnitTest.testLoadAnimationScenarioUi()"); return false; // Todo repop loading interface(); } } return true; }
bool LuaInterp::getString( const char* table, const char* key, std::string& value, bool nilOK ) { LuaStackCheck lsc(_luaState); bool isSuccess = false; int popCount = 0; assert( key != NULL ); if( table != NULL ) { lua_getglobal( _luaState, table ); popCount = 1; if( lua_istable( _luaState, -1 ) ) { lua_getfield( _luaState, -1, key ); popCount = 2; } } else { lua_getglobal( _luaState, key ); popCount = 1; } if( lua_isstring( _luaState, -1 ) ) { size_t len = 0; value = lua_tolstring( _luaState, -1, &len ); isSuccess = true; } else if( nilOK && lua_isnil( _luaState, -1 ) ) { isSuccess = true; } else if( table != NULL ) { printErr( "config \"%s.%s\" is not a string\n", table, key ); } else { printErr( "config \"%s\" is not a string\n", key ); } lua_pop( _luaState, popCount ); return isSuccess; }
// ************************************************************************ void CObjectTableClient::pushOnLuaStack(CLuaState &state, CLuaObject &metatable) const { //H_AUTO(R2_CObjectTableClient_pushOnLuaStack) // cache refptr here to avoid costly allocations CLuaStackChecker lsc(&state, 1); if (!_Ref.isValid()) { nlassert(metatable.isValid()); // return a new refptr on the sub table void *block = state.newUserData(sizeof(TRefPtrConst)); new (block) CObjectTable::TRefPtrConst(this); // create in place metatable.push(); state.setMetaTable(-2); _Ref.pop(state); } nlassert(_Ref.getLuaState() == &state); _Ref.push(); }
bool LuaInterp::getBoolean( const char* table, const char* key, bool& value, bool nilOK ) { LuaStackCheck lsc(_luaState); bool isSuccess = false; int popCount = 0; assert( key != NULL ); if( table != NULL ) { lua_getglobal( _luaState, table ); popCount = 1; if( lua_istable( _luaState, -1 ) ) { lua_getfield( _luaState, -1, key ); popCount = 2; } } else { lua_getglobal( _luaState, key ); popCount = 1; } if( lua_isboolean( _luaState, -1 ) ) { value = (lua_toboolean( _luaState, -1 ) != 0); isSuccess = true; } else if( nilOK && lua_isnil( _luaState, -1 ) ) { isSuccess = true; } else if( table != NULL ) { printErr( "config \"%s.%s\" is not a boolean\n", table, key ); } else { printErr( "config \"%s\" is not a boolean\n", key ); } lua_pop( _luaState, popCount ); return isSuccess; }