bool CLuaRules::AllowCommand(const CUnit* unit, const Command& cmd, bool fromSynced) { if (!haveAllowCommand) return true; // the call is not defined LUA_CALL_IN_CHECK(L, true); lua_checkstack(L, 10); static const LuaHashString cmdStr("AllowCommand"); if (!cmdStr.GetGlobalFunc(L)) return true; // the call is not defined PushUnitAndCommand(L, unit, cmd); lua_pushboolean(L, fromSynced); // call the function if (!RunCallIn(cmdStr, 8, 1)) return true; // get the results if (!lua_isboolean(L, -1)) { LOG_L(L_WARNING, "%s() bad return value", cmdStr.GetString().c_str()); lua_pop(L, 1); return true; } const bool retval = !!lua_toboolean(L, -1); lua_pop(L, 1); return retval; }
bool CLuaRules::CommandFallback(const CUnit* unit, const Command& cmd) { if (!haveCommandFallback) return true; // the call is not defined LUA_CALL_IN_CHECK(L, true); lua_checkstack(L, 9); static const LuaHashString cmdStr("CommandFallback"); if (!cmdStr.GetGlobalFunc(L)) return true; // the call is not defined PushUnitAndCommand(L, unit, cmd); // call the function if (!RunCallIn(cmdStr, 7, 1)) return true; // get the results if (!lua_isboolean(L, -1)) { LOG_L(L_WARNING, "%s() bad return value", cmdStr.GetString().c_str()); lua_pop(L, 1); return true; } const bool retval = !!lua_toboolean(L, -1); lua_pop(L, 1); // return 'true' to remove the command return retval; }
bool CSyncedLuaHandle::CommandFallback(const CUnit* unit, const Command& cmd) { LUA_CALL_IN_CHECK(L, true); luaL_checkstack(L, 9, __FUNCTION__); static const LuaHashString cmdStr(__FUNCTION__); if (!cmdStr.GetGlobalFunc(L)) return true; // the call is not defined PushUnitAndCommand(L, unit, cmd); // call the function if (!RunCallIn(L, cmdStr, 7, 1)) return true; const bool retval = luaL_optboolean(L, -1, true); lua_pop(L, 1); return retval; // return 'true' to remove the command }
bool CSyncedLuaHandle::AllowCommand(const CUnit* unit, const Command& cmd, bool fromSynced) { LUA_CALL_IN_CHECK(L, true); luaL_checkstack(L, 10, __FUNCTION__); static const LuaHashString cmdStr(__FUNCTION__); if (!cmdStr.GetGlobalFunc(L)) return true; // the call is not defined PushUnitAndCommand(L, unit, cmd); lua_pushboolean(L, fromSynced); // call the function if (!RunCallIn(L, cmdStr, 8, 1)) return true; // get the results const bool retval = luaL_optboolean(L, -1, true); lua_pop(L, 1); return retval; }