push the watchlist vector as nested table on the lua stack
| 920 | |
| 921 | // push the watchlist vector as nested table on the lua stack |
| 922 | static int autobutcher_getWatchList(lua_State *L) { |
| 923 | color_ostream *out = Lua::GetOutput(L); |
| 924 | if (!out) |
| 925 | out = &Core::getInstance().getConsole(); |
| 926 | |
| 927 | lua_newtable(L); |
| 928 | int entry_index = 0; |
| 929 | for (auto wr : watched_races) { |
| 930 | lua_newtable(L); |
| 931 | int ctable = lua_gettop(L); |
| 932 | |
| 933 | WatchedRace * w = wr.second; |
| 934 | int id = w->raceId; |
| 935 | Lua::SetField(L, id, ctable, "id"); |
| 936 | Lua::SetField(L, w->isWatched, ctable, "watched"); |
| 937 | Lua::SetField(L, Units::getRaceNamePluralById(id), ctable, "name"); |
| 938 | Lua::SetField(L, w->fk, ctable, "fk"); |
| 939 | Lua::SetField(L, w->mk, ctable, "mk"); |
| 940 | Lua::SetField(L, w->fa, ctable, "fa"); |
| 941 | Lua::SetField(L, w->ma, ctable, "ma"); |
| 942 | |
| 943 | WatchedRace *tally = checkRaceStocksTotal(*out, id); |
| 944 | Lua::SetField(L, tally->fk_units.size(), ctable, "fk_total"); |
| 945 | Lua::SetField(L, tally->mk_units.size(), ctable, "mk_total"); |
| 946 | Lua::SetField(L, tally->fa_units.size(), ctable, "fa_total"); |
| 947 | Lua::SetField(L, tally->ma_units.size(), ctable, "ma_total"); |
| 948 | delete tally; |
| 949 | |
| 950 | tally = checkRaceStocksProtected(*out, id); |
| 951 | Lua::SetField(L, tally->fk_units.size(), ctable, "fk_protected"); |
| 952 | Lua::SetField(L, tally->mk_units.size(), ctable, "mk_protected"); |
| 953 | Lua::SetField(L, tally->fa_units.size(), ctable, "fa_protected"); |
| 954 | Lua::SetField(L, tally->ma_units.size(), ctable, "ma_protected"); |
| 955 | delete tally; |
| 956 | |
| 957 | tally = checkRaceStocksButcherable(*out, id); |
| 958 | Lua::SetField(L, tally->fk_units.size(), ctable, "fk_butcherable"); |
| 959 | Lua::SetField(L, tally->mk_units.size(), ctable, "mk_butcherable"); |
| 960 | Lua::SetField(L, tally->fa_units.size(), ctable, "fa_butcherable"); |
| 961 | Lua::SetField(L, tally->ma_units.size(), ctable, "ma_butcherable"); |
| 962 | delete tally; |
| 963 | |
| 964 | tally = checkRaceStocksButcherFlag(*out, id); |
| 965 | Lua::SetField(L, tally->fk_units.size(), ctable, "fk_butcherflag"); |
| 966 | Lua::SetField(L, tally->mk_units.size(), ctable, "mk_butcherflag"); |
| 967 | Lua::SetField(L, tally->fa_units.size(), ctable, "fa_butcherflag"); |
| 968 | Lua::SetField(L, tally->ma_units.size(), ctable, "ma_butcherflag"); |
| 969 | delete tally; |
| 970 | |
| 971 | lua_rawseti(L, -2, ++entry_index); |
| 972 | } |
| 973 | |
| 974 | return 1; |
| 975 | } |
| 976 | |
| 977 | DFHACK_PLUGIN_LUA_FUNCTIONS { |
| 978 | DFHACK_LUA_FUNCTION(autowatch_isEnabled), |
nothing calls this directly
no test coverage detected