private func Activity() { var pBait; // Ein Köder in der Nähe? if (pBait=FindObject(0,-1000,-1250,2000,1500, OCF_InLiquid(), "Bait" ) ) // Schwarze Fische sind nicht wählerisch SetCommand(this(),"Follow",pBait); // Schwimmverhalten if (!GBackLiquid (0, -8)) return (SetComDir (COMD_Down ())); if (Random(2)) return(1); if (SEqual(GetAction(),"Walk")) WalkDir(); if (Not( SEqual(GetAction(),"Swim") )) return(1); if (Random(2)) return(TurnRight(),SetComDir(COMD_Right())); return(TurnLeft(),SetComDir(COMD_Left())); }
static int lua_walkDir(lua_State* L) { struct LuaTask { int Run(const char* pszPath, WIN32_FIND_DATAA& FindData) { int res = true; int top = lua_gettop(L); lua_pushvalue(L, funStkId); lua_pushstring(L, pszPath); lua_pushvalue(L, tabStkId); lua_pushstring(L, "bDir"); lua_pushboolean(L, (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); lua_settable(L, -3); lua_pushstring(L, "FileName"); lua_pushstring(L, FindData.cFileName); lua_settable(L, -3); lua_pushstring(L, "dwCreateTimeLow"); lua_pushnumber(L, FindData.ftCreationTime.dwLowDateTime); lua_settable(L, -3); lua_pushstring(L, "dwCreateTimeHigh"); lua_pushnumber(L, FindData.ftCreationTime.dwHighDateTime); lua_settable(L, -3); lua_pushstring(L, "dwLastAccessTimeLow"); lua_pushnumber(L, FindData.ftLastAccessTime.dwLowDateTime); lua_settable(L, -3); lua_pushstring(L, "dwLastAccessTimeHigh"); lua_pushnumber(L, FindData.ftLastAccessTime.dwHighDateTime); lua_settable(L, -3); lua_pushstring(L, "dwLastWriteTimeLow"); lua_pushnumber(L, FindData.ftLastWriteTime.dwLowDateTime); lua_settable(L, -3); lua_pushstring(L, "dwLastWriteTimeHigh"); lua_pushnumber(L, FindData.ftLastWriteTime.dwHighDateTime); lua_settable(L, -3); int ret = lua_pcall(L, 2, 1, 0); if (ret != 0) printf("lua call failed [%s]\n%s\n", lua_tostring(L, 1), lua_tostring(L, -1)); res = (int)lua_toboolean(L, -1); lua_settop(L, top); return res; } int funStkId; int tabStkId; lua_State* L; } task; int ret = false; int top = 0; const char* path = NULL; const char* fliter = NULL; top = lua_gettop(L); jn2Exit0(top == 2 || top == 3); path = lua_tostring(L, 1); jn2Exit0(path); ret = lua_isfunction(L, 2); jn2Exit0(ret); if (top == 3) { fliter = lua_tostring(L, 3); jn2Exit0(fliter); } task.L = L; task.funStkId = 2; lua_newtable(L); task.tabStkId = lua_gettop(L); WalkDir(path, &task, fliter); Exit0: lua_settop(L, top); return 0; }