core/functional.lua
srift c1bfbaf36a scriptcore: reconstructed from preserved seed files
Reconstructed Lua scripting infrastructure consumed by every per-game
flash script. Two source files preserved at D:\B\Srift\games\Flash\:

  - functional.lua (109 lines): table.from/max/min/find/filter/map
  - internal.lua  (172 lines): Markers, Rule.All/Any sugar, Hex/Addr,
                                print override, gadget enumerators

Surface inventory at D:\B\Srift\games\Flash\SURFACE.md confirms
these two files cover scriptcore's lua-level responsibilities for
CODMW, CODMW2, IW9, DayZ, Template. RB6 may need a Rule.Refs stub.

Server contract (Builder.ts:286-380): pushing this repo to Gitea as
srift/core triggers the standard webhook pipeline and produces
S.Build doc { kind:'script', product:'scriptcore' }.
2026-06-29 21:03:19 +02:00

110 lines
1.5 KiB
Lua

table.from = function(f)
local tbl = {}
local i = 1
for v in f do
tbl[i] = v
i = i + 1
end
return tbl
end
table.max = function(t)
local maxk, maxv
if type(t) == "table" then
for k,v in pairs(t) do
if not maxk or maxv < v then
maxk = k
maxv = v
end
end
else
for k,v in t do
if not maxk or maxv < v then
maxk = k
maxv = v
end
end
end
return maxk, maxv
end
table.min = function(t)
local mink, minv
if type(t) == "table" then
for k,v in pairs(t) do
if not mink or minv > v then
mink = k
minv = v
end
end
else
for k,v in t do
if not mink or minv > v then
mink = k
minv = v
end
end
end
return mink, minv
end
table.find = function(t, f)
if type(t) == "table" then
for k,v in pairs(t) do
if f(k,v) then
return k,v
end
end
else
for k,v in t do
if f(k,v) then
return k,v
end
end
end
end
table.filter = function(t, f)
if type(t) == "table" then
local it = nil
return function()
while true do
it = next(t, it)
if not it then
break
elseif f(it,t[it]) then
return it,t[it]
end
end
end
else
return function()
while true do
local k,v = t()
if not k then
break
elseif f(k,v) then
return k,v
end
end
end
end
end
table.map = function(t, f)
if type(t) == "table" then
local it = nil
return function()
it = next(t, it)
if it then
return f(it, t[it])
end
end
else
return function()
local k,v = t()
if k then
return f(k,v)
end
end
end
end