LÖVE port: love/ (generated by tools/love.sh), marked linguist-generated; submodule URLs -> GitHub

This commit is contained in:
4DBug committed 2026-10-17 13:15:46 -05:00
1 parent d471cb855c
commit 357fc01544
6 files changed
+3405 -1

No files matched your search

+1
View File
@@ -1,2 +1,3 @@
.gitattributes export-ignore .gitattributes export-ignore
tools/upstream/** linguist-vendored=true tools/upstream/** linguist-vendored=true
love/** linguist-generated=true
+1 -1
View File
@@ -1,3 +1,3 @@
[submodule "tools/core"] [submodule "tools/core"]
path = tools/core path = tools/core
url = https://git.bug.tools/bug/imgui-luau.git url = https://github.com/4DBug/imgui-luau.git
+2912
View File
File diff suppressed because it is too large. Load diff
+255
View File
@@ -0,0 +1,255 @@
-- GENERATED by tools/love.sh from the Luau source - do not edit
local function __iter(t, ...) if type(t) ~= 'table' or (getmetatable(t) and getmetatable(t).__call) then return t, ... end local n, i, k = #t, 0, nil return function() if i < n then i = i + 1 return i, t[i] end repeat k = next(t, k) until k == nil or type(k) ~= 'number' or k < 1 or k > n or k % 1 ~= 0 if k ~= nil then return k, t[k] end end end table.create = table.create or function(n, v) local t = {} if v ~= nil then for i = 1, n do t[i] = v end end return t end table.clone = table.clone or function(t) local c = {} for k, v in pairs(t) do c[k] = v end return setmetatable(c, getmetatable(t)) end math.clamp = math.clamp or function(x, a, b) return math.max(a, math.min(b, x)) end math.sign = math.sign or function(x) return x > 0 and 1 or (x < 0 and -1 or 0) end math.round = math.round or function(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end
-- Logic-gate simulator model (no UI). Usage: local LogicSim = require(RS.LogicSim)(G, ImNodes)
-- Pin ids: node.Id * 16 + slot; inputs use slots 0..7, outputs 8..15.
return function(G, ImNodes)
local LogicSim = {}
local MAX_PASSES = 16
local function b(x)
return x and 1 or 0
end
local function gate(f)
return { ins = { "A", "B" }, outs = { "Out" }, eval = function(i)
return { b(f(i[1] == 1, i[2] == 1)) }
end }
end
-- kind -> { ins = names, outs = names, eval = function(inputs, state) -> outputs }
LogicSim.Kinds = {
Switch = { ins = {}, outs = { "Out" }, eval = function(_, s) return { s.on and 1 or 0 } end },
Clock = { ins = {}, outs = { "Out" }, eval = function(_, s) return { s.on and 1 or 0 } end },
Const0 = { ins = {}, outs = { "Out" }, eval = function() return { 0 } end },
Const1 = { ins = {}, outs = { "Out" }, eval = function() return { 1 } end },
AND = gate(function(a, c) return a and c end),
OR = gate(function(a, c) return a or c end),
NAND = gate(function(a, c) return not (a and c) end),
NOR = gate(function(a, c) return not (a or c) end),
XOR = gate(function(a, c) return a ~= c end),
XNOR = gate(function(a, c) return a == c end),
NOT = { ins = { "In" }, outs = { "Out" }, eval = function(i) return { 1 - i[1] } end },
LED = { ins = { "In" }, outs = {}, eval = function(i, s) s.on = i[1] == 1; return {} end },
HexDisplay = { ins = { "1", "2", "4", "8" }, outs = {}, eval = function(i, s)
s.value = i[1] + 2 * i[2] + 4 * i[3] + 8 * i[4]
return {}
end },
DFlipFlop = { ins = { "D", "Clk" }, outs = { "Q", "notQ" }, eval = function(i, s)
if i[2] == 1 and s.prevClk ~= 1 then
s.q = i[1]
end
s.prevClk = i[2]
local q = s.q or 0
return { q, 1 - q }
end },
}
function LogicSim.InPin(nodeId, slot) return nodeId * 16 + slot - 1 end
function LogicSim.OutPin(nodeId, slot) return nodeId * 16 + 8 + slot - 1 end
function LogicSim.PinNode(pin) return math.floor(pin / 16), pin % 16 >= 8, pin % 8 + 1 end -- nodeId, isOutput, slot
function LogicSim.New()
return { nodes = {}, order = {}, links = {}, values = {}, nextNode = 1, nextLink = 1 }
end
function LogicSim.AddNode(g, kind, x, y, state, id)
assert(LogicSim.Kinds[kind], kind)
id = id or g.nextNode
g.nextNode = math.max(g.nextNode, id + 1)
local n = { Id = id, Kind = kind, Pos = { x or 0, y or 0 }, state = state or {} }
if kind == "Clock" then n.state.rate = n.state.rate or 1 end
g.nodes[id] = n
table.insert(g.order, id)
return n
end
function LogicSim.RemoveNode(g, id)
g.nodes[id] = nil
table.remove(g.order, table.find(g.order, id))
for lid, l in __iter(g.links) do
if math.floor(l.Start / 16 )== id or math.floor(l.End / 16 )== id then g.links[lid] = nil end
end
end
-- start = output pin, end = input pin (swapped if given reversed). An input takes one link; returns link id or nil.
function LogicSim.AddLink(g, a, c, id)
if select(2, LogicSim.PinNode(a)) == false then a, c = c, a end
if not select(2, LogicSim.PinNode(a)) or select(2, LogicSim.PinNode(c)) then return nil end
for lid, l in __iter(g.links) do
if l.End == c then g.links[lid] = nil end
end
id = id or g.nextLink
g.nextLink = math.max(g.nextLink, id + 1)
g.links[id] = { Id = id, Start = a, End = c }
return id
end
function LogicSim.RemoveLink(g, id) g.links[id] = nil end
function LogicSim.Connect(g, from, fromSlot, to, toSlot)
return LogicSim.AddLink(g, LogicSim.OutPin(from.Id, fromSlot or 1), LogicSim.InPin(to.Id, toSlot or 1))
end
function LogicSim.Value(g, pin) return g.values[pin] or 0 end
-- Advance clocks by dt, then propagate (Gauss-Seidel in node order, capped passes for feedback loops).
function LogicSim.Step(g, dt)
for _, id in __iter(g.order) do
local n = g.nodes[id]
if n.Kind == "Clock" then
local s = n.state
s.t = (s.t or 0) + (dt or 0)
local half = 0.5 / s.rate
while s.t >= half do s.t =s.t- half; s.on = not s.on end
end
end
local src = {}
for _, l in __iter(g.links) do src[l.End] = l.Start end
for _ = 1, MAX_PASSES do
local changed = false
for _, id in __iter(g.order) do
local n = g.nodes[id]
local k = LogicSim.Kinds[n.Kind]
local ins = {}
for i = 1, #k.ins do
local s = src[LogicSim.InPin(id, i)]
ins[i] = s and g.values[s] or 0
end
for i, v in __iter(k.eval(ins, n.state)) do
local p = LogicSim.OutPin(id, i)
if g.values[p] ~= v then g.values[p] = v; changed = true end
end
end
if not changed then break end
end
end
-- Text format: "N id kind x y key=val,...", "L id start end", "V pin value", then "INI" line followed by ImNodes ini (if a context exists).
function LogicSim.Save(g)
local out = {}
for _, id in __iter(g.order) do
local n = g.nodes[id]
local kv = {}
for k, v in __iter(n.state) do
if type(v) ~= "table" then table.insert(kv, string.format('%s=%s', tostring(k), tostring(v))) end
end
table.sort(kv)
table.insert(out, string.format('N %s %s %s %s %s', tostring(id), tostring(n.Kind), tostring(n.Pos[1]), tostring(n.Pos[2]), tostring(table.concat(kv, ","))))
end
local lids = {}
for lid in __iter(g.links) do table.insert(lids, lid) end
table.sort(lids)
for _, lid in __iter(lids) do
local l = g.links[lid]
table.insert(out, string.format('L %s %s %s', tostring(lid), tostring(l.Start), tostring(l.End)))
end
local pins = {} -- output values carry feedback memory (latches)
for pin, v in __iter(g.values) do
if v ~= 0 then table.insert(pins, pin) end
end
table.sort(pins)
for _, pin in __iter(pins) do table.insert(out, string.format('V %s %s', tostring(pin), tostring(g.values[pin]))) end
if ImNodes and ImNodes.GetCurrentContext() then
table.insert(out, "INI")
table.insert(out, ImNodes.SaveCurrentEditorStateToIniString())
end
return table.concat(out, "\n")
end
function LogicSim.Load(s)
local g = LogicSim.New()
local graphPart, ini = s, nil
local at = string.find(s, "\nINI\n", 1, true)
if at then graphPart, ini = string.sub(s, 1, at - 1), string.sub(s, at + 5) end
for line in __iter(string.gmatch(graphPart, "[^\n]+")) do
local id, kind, x, y, kv = string.match(line, "^N (%d+) (%w+) (%S+) (%S+) ?(.*)$")
if id then
local st = {}
for k, v in __iter(string.gmatch(kv, "(%w+)=([^,]+)")) do
st[k] = v == "true" and true or(v == "false" and{false }or{tonumber(v) or v
})[1] end
LogicSim.AddNode(g, kind, tonumber(x), tonumber(y), st, tonumber(id))
else
local lid, a, c = string.match(line, "^L (%d+) (%d+) (%d+)$")
if lid then LogicSim.AddLink(g, tonumber(a), tonumber(c), tonumber(lid)) end
local pin, v = string.match(line, "^V (%d+) (%d+)$")
if pin then g.values[tonumber(pin)] = tonumber(v) end
end
end
if ini and ImNodes and ImNodes.GetCurrentContext() then
ImNodes.LoadCurrentEditorStateFromIniString(ini)
end
return g
end
-- Example builders: each returns a fresh graph plus named nodes.
LogicSim.Examples = {}
local add, con = LogicSim.AddNode, LogicSim.Connect
function LogicSim.Examples.HalfAdder()
local g = LogicSim.New()
local a, c = add(g, "Switch", 0, 0), add(g, "Switch", 0, 100)
local x, n = add(g, "XOR", 200, 0), add(g, "AND", 200, 100)
local sum, carry = add(g, "LED", 400, 0), add(g, "LED", 400, 100)
con(g, a, 1, x, 1); con(g, c, 1, x, 2); con(g, a, 1, n, 1); con(g, c, 1, n, 2)
con(g, x, 1, sum); con(g, n, 1, carry)
return g, { A = a, B = c, Sum = sum, Carry = carry }
end
-- Adds a full adder's gates to g; returns xor2 (sum) and or (carry) nodes. Inputs: wire to x1(A,B) and cin via setter.
local function fullAdder(g, a, bb, cin, ox, oy)
local x1, x2 = add(g, "XOR", ox, oy), add(g, "XOR", ox + 150, oy)
local a1, a2, o = add(g, "AND", ox, oy + 80), add(g, "AND", ox + 150, oy + 80), add(g, "OR", ox + 300, oy + 80)
con(g, a, 1, x1, 1); con(g, bb, 1, x1, 2); con(g, a, 1, a1, 1); con(g, bb, 1, a1, 2)
con(g, x1, 1, x2, 1); con(g, cin, 1, x2, 2); con(g, x1, 1, a2, 1); con(g, cin, 1, a2, 2)
con(g, a1, 1, o, 1); con(g, a2, 1, o, 2)
return x2, o
end
function LogicSim.Examples.FullAdder()
local g = LogicSim.New()
local a, c, cin = add(g, "Switch", 0, 0), add(g, "Switch", 0, 100), add(g, "Switch", 0, 200)
local s, co = fullAdder(g, a, c, cin, 200, 0)
local sum, carry = add(g, "LED", 650, 0), add(g, "LED", 650, 100)
con(g, s, 1, sum); con(g, co, 1, carry)
return g, { A = a, B = c, Cin = cin, Sum = sum, Carry = carry }
end
function LogicSim.Examples.RippleAdder4()
local g = LogicSim.New()
local A, B = {}, {}
for i = 1, 4 do
A[i] = add(g, "Switch", 0, (i - 1) * 200)
B[i] = add(g, "Switch", 0, (i - 1) * 200 + 100)
end
local hex = add(g, "HexDisplay", 900, 0)
local carry = add(g, "Const0", 0, -100)
for i = 1, 4 do
local s
s, carry = fullAdder(g, A[i], B[i], carry, 200, (i - 1) * 200)
con(g, s, 1, hex, i)
end
local cout = add(g, "LED", 900, 200)
con(g, carry, 1, cout)
return g, { A = A, B = B, Hex = hex, Carry = cout }
end
function LogicSim.Examples.SRLatch()
local g = LogicSim.New()
local s, r = add(g, "Switch", 0, 0), add(g, "Switch", 0, 150)
local n1, n2 = add(g, "NOR", 200, 0), add(g, "NOR", 200, 150)
local q, nq = add(g, "LED", 400, 0), add(g, "LED", 400, 150)
con(g, r, 1, n1, 1); con(g, n2, 1, n1, 2) -- n1 = Q
con(g, s, 1, n2, 1); con(g, n1, 1, n2, 2) -- n2 = notQ
con(g, n1, 1, q); con(g, n2, 1, nq)
return g, { S = s, R = r, Q = q, NotQ = nq }
end
function LogicSim.Examples.Blinker()
local g = LogicSim.New()
local clk, led = add(g, "Clock", 0, 0, { rate = 2 }), add(g, "LED", 200, 0)
con(g, clk, 1, led)
return g, { Clock = clk, LED = led }
end
return LogicSim
end
+207
View File
@@ -0,0 +1,207 @@
-- GENERATED by tools/love.sh from the Luau source - do not edit
local function __iter(t, ...) if type(t) ~= 'table' or (getmetatable(t) and getmetatable(t).__call) then return t, ... end local n, i, k = #t, 0, nil return function() if i < n then i = i + 1 return i, t[i] end repeat k = next(t, k) until k == nil or type(k) ~= 'number' or k < 1 or k > n or k % 1 ~= 0 if k ~= nil then return k, t[k] end end end table.create = table.create or function(n, v) local t = {} if v ~= nil then for i = 1, n do t[i] = v end end return t end table.clone = table.clone or function(t) local c = {} for k, v in pairs(t) do c[k] = v end return setmetatable(c, getmetatable(t)) end math.clamp = math.clamp or function(x, a, b) return math.max(a, math.min(b, x)) end math.sign = math.sign or function(x) return x > 0 and 1 or (x < 0 and -1 or 0) end math.round = math.round or function(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end
-- "Logic Simulator" window over LogicSim. Usage: local UI = require(RS.LogicUI)(G, ImNodes, LogicSim); UI.Draw() each frame.
return function(G, ImNodes, LogicSim)
local ImGui, ImVec2, IM_COL32 = G.ImGui, G.ImVec2, G.IM_COL32
local Col = ImNodes.ImNodesCol
local LIT, DIM = IM_COL32(80, 220, 100, 255), IM_COL32(90, 90, 110, 255)
local Categories = {
{ "Inputs", { "Switch", "Clock", "Const0", "Const1" } },
{ "Gates", { "AND", "OR", "NAND", "NOR", "XOR", "XNOR", "NOT" } },
{ "Outputs", { "LED", "HexDisplay" } },
{ "Memory", { "DFlipFlop" } },
}
local ExampleList = {
{ "Half Adder", "HalfAdder" }, { "Full Adder", "FullAdder" }, { "4-bit Ripple Adder", "RippleAdder4" },
{ "SR Latch", "SRLatch" }, { "Blinker", "Blinker" },
}
local UI = { Graph = nil, Placed = {}, Saved = nil, SaveBuf = nil, ShowSave = false, AddAt = nil, Target = nil }
function UI.SetGraph(g)
UI.Graph, UI.Placed = g, {}
if ImNodes.GetCurrentContext() then
ImNodes.ClearNodeSelection()
ImNodes.ClearLinkSelection()
end
end
function UI.LoadExample(name)
local g = LogicSim.Examples[name]()
for _, n in __iter(g.nodes) do
n.Pos = { 40 + n.Pos[1] * 1.2, 40 + n.Pos[2] * 1.4 }
end
UI.SetGraph(g)
end
local function DeleteSelected()
local g = UI.Graph
for _, id in __iter(ImNodes.GetSelectedLinks()) do LogicSim.RemoveLink(g, id) end
for _, id in __iter(ImNodes.GetSelectedNodes()) do
if g.nodes[id] then LogicSim.RemoveNode(g, id) end
end
ImNodes.ClearNodeSelection()
ImNodes.ClearLinkSelection()
end
local function Pin(pin, isOut, label)
ImNodes.PushColorStyle(Col.Pin, LogicSim.Value(UI.Graph, pin) == 1 and LIT or DIM)
if isOut then
ImNodes.BeginOutputAttribute(pin)
ImGui.Indent(60)
ImGui.TextUnformatted(label)
ImNodes.EndOutputAttribute()
else
ImNodes.BeginInputAttribute(pin)
ImGui.TextUnformatted(label)
ImNodes.EndInputAttribute()
end
ImNodes.PopColorStyle()
end
local function DrawNode(n)
local k = LogicSim.Kinds[n.Kind]
ImNodes.BeginNode(n.Id)
if not UI.Placed[n.Id] then
UI.Placed[n.Id] = true
if n.ScreenPos then
ImNodes.SetNodeScreenSpacePos(n.Id, n.ScreenPos)
n.ScreenPos = nil
else
ImNodes.SetNodeGridSpacePos(n.Id, ImVec2(n.Pos[1], n.Pos[2]))
end
end
ImNodes.BeginNodeTitleBar()
ImGui.TextUnformatted(n.Kind)
ImNodes.EndNodeTitleBar()
ImGui.PushID(n.Id)
local s = n.state
if n.Kind == "Switch" then
if ImGui.Button(s.on and "1" or "0", ImVec2(40, 0)) then s.on = not s.on end
elseif n.Kind == "Clock" then
ImGui.PushItemWidth(70)
s.rate = math.max(ImGui.DragFloat("Hz", s.rate, 0.05, 0.1, 20, "%.2f"), 0.1)
ImGui.PopItemWidth()
elseif n.Kind == "LED" then
local p = ImGui.GetCursorScreenPos()
ImGui.GetWindowDrawList():AddCircleFilled(ImVec2(p.x + 12, p.y + 12), 10, s.on and LIT or IM_COL32(40, 40, 40, 255))
ImGui.Dummy(ImVec2(24, 24))
elseif n.Kind == "HexDisplay" then
ImGui.SetWindowFontScale(3)
ImGui.TextUnformatted(string.format("%X", s.value or 0))
ImGui.SetWindowFontScale(1)
end
ImGui.PopID()
for i, name in __iter(k.ins) do Pin(LogicSim.InPin(n.Id, i), false, name) end
for i, name in __iter(k.outs) do Pin(LogicSim.OutPin(n.Id, i), true, name) end
ImNodes.EndNode()
end
local function MenuBar()
if not ImGui.BeginMenuBar() then return end
if ImGui.BeginMenu("File") then
if ImGui.MenuItem("New") then UI.SetGraph(LogicSim.New()) end
if ImGui.MenuItem("Save") then
UI.Saved = LogicSim.Save(UI.Graph)
UI.SaveBuf = ImGui.NewTextBuffer(UI.Saved)
end
if ImGui.MenuItem("Load", nil, false, UI.Saved ~= nil) then UI.SetGraph(LogicSim.Load(UI.Saved)) end
if ImGui.MenuItem("Clear") then UI.Saved, UI.SaveBuf = nil, nil end
_, UI.ShowSave = ImGui.MenuItem("Show Save Text", nil, UI.ShowSave)
ImGui.EndMenu()
end
if ImGui.BeginMenu("Examples") then
for _, e in __iter(ExampleList) do
if ImGui.MenuItem(e[1]) then UI.LoadExample(e[2]) end
end
ImGui.EndMenu()
end
ImGui.EndMenuBar()
end
local function Popups()
local g = UI.Graph
ImGui.PushStyleVar(G.ImGuiStyleVar.WindowPadding, ImVec2(8, 8))
if ImGui.BeginPopup("Add Node") then
for _, c in __iter(Categories) do
if ImGui.BeginMenu(c[1]) then
for _, kind in __iter(c[2]) do
if ImGui.MenuItem(kind) then LogicSim.AddNode(g, kind, 0, 0).ScreenPos = UI.AddAt end
end
ImGui.EndMenu()
end
end
ImGui.EndPopup()
end
if ImGui.BeginPopup("Node Menu") then
local n = g.nodes[UI.Target]
if n and ImGui.MenuItem("Duplicate") then
LogicSim.AddNode(g, n.Kind, n.Pos[1] + 30, n.Pos[2] + 30, table.clone(n.state))
end
if n and ImGui.MenuItem("Delete") then LogicSim.RemoveNode(g, n.Id) end
ImGui.EndPopup()
end
if ImGui.BeginPopup("Link Menu") then
if ImGui.MenuItem("Delete") then LogicSim.RemoveLink(g, UI.Target) end
ImGui.EndPopup()
end
ImGui.PopStyleVar()
end
function UI.Draw(dt)
if not UI.Graph then UI.LoadExample("FullAdder") end
local g = UI.Graph
LogicSim.Step(g, dt or ImGui.GetIO().DeltaTime)
ImGui.SetNextWindowSize(ImVec2(900, 600), G.ImGuiCond.FirstUseEver)
ImGui.Begin("Logic Simulator", nil, G.ImGuiWindowFlags.MenuBar)
MenuBar()
if UI.ShowSave and UI.SaveBuf then
ImGui.InputTextMultiline("##save", UI.SaveBuf, #UI.Saved + 1, ImVec2(-1, 120), G.ImGuiInputTextFlags.ReadOnly)
end
local focused = ImGui.IsWindowFocused(G.ImGuiFocusedFlags.RootAndChildWindows)
ImNodes.BeginNodeEditor()
for _, id in __iter(g.order) do DrawNode(g.nodes[id]) end
for _, l in __iter(g.links) do
ImNodes.PushColorStyle(Col.Link, LogicSim.Value(g, l.Start) == 1 and LIT or DIM)
ImNodes.Link(l.Id, l.Start, l.End)
ImNodes.PopColorStyle()
end
ImNodes.MiniMap(0.2, ImNodes.ImNodesMiniMapLocation.BottomRight)
local editorHovered = ImNodes.IsEditorHovered()
ImNodes.EndNodeEditor()
for _, id in __iter(g.order) do
local p = ImNodes.GetNodeGridSpacePos(id)
g.nodes[id].Pos = { p.x, p.y }
end
local created, a, c = ImNodes.IsLinkCreated()
if created then LogicSim.AddLink(g, a, c) end
local destroyed, lid = ImNodes.IsLinkDestroyed()
if destroyed then LogicSim.RemoveLink(g, lid) end
if focused and editorHovered and ImGui.IsMouseClicked(1) then
local nodeHovered, nid = ImNodes.IsNodeHovered()
local linkHovered, hlid = ImNodes.IsLinkHovered()
if nodeHovered then
UI.Target = nid
ImGui.OpenPopup("Node Menu")
elseif linkHovered then
UI.Target = hlid
ImGui.OpenPopup("Link Menu")
else
UI.AddAt = ImGui.GetMousePos()
ImGui.OpenPopup("Add Node")
end
end
if focused and not ImGui.IsAnyItemActive()
and (ImGui.IsKeyPressed(G.ImGuiKey.Delete) or ImGui.IsKeyPressed(G.ImGuiKey.Backspace)) then
DeleteSelected()
end
Popups()
ImGui.End()
end
return UI
end
Executable
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env sh
# Regenerates love/: Lua 5.1 (LÖVE/LuaJIT) copies of the Luau sources. Needs darklua + python3.
set -e
cd "$(dirname "$0")/.."
mkdir -p love
CFG=$(mktemp)
echo '{ "generator": "retain_lines", "rules": ["remove_types", "remove_compound_assignment", "remove_if_expression", "remove_continue", "remove_interpolated_string", "remove_floor_division"] }' > "$CFG"
for f in ImNodes.lua examples/roblox/LogicSim.lua examples/roblox/LogicUI.lua; do
out="love/$(basename "$f")"
darklua process -c "$CFG" "$f" "$out"
python3 - "$out" <<'PY'
import re, sys
p = sys.argv[1]; src = open(p).read()
src = re.sub(r"^\s*@native\s*$", "", src, flags=re.M)
# Luau generalized iteration: for k, v in t do -> for k, v in __iter(t) do
src = re.sub(r"^([ \t]*for[ \t]+[\w][\w, \t]*[ \t]in[ \t]+)([^\n]*?)([ \t]+do\b)", r"\1__iter(\2)\3", src, flags=re.M)
head = ("-- GENERATED by tools/love.sh from the Luau source - do not edit\n"
"local function __iter(t, ...) if type(t) ~= 'table' or (getmetatable(t) and getmetatable(t).__call) then return t, ... end "
"local n, i, k = #t, 0, nil return function() if i < n then i = i + 1 return i, t[i] end "
"repeat k = next(t, k) until k == nil or type(k) ~= 'number' or k < 1 or k > n or k % 1 ~= 0 if k ~= nil then return k, t[k] end end end "
"table.create = table.create or function(n, v) local t = {} if v ~= nil then for i = 1, n do t[i] = v end end return t end "
"table.clone = table.clone or function(t) local c = {} for k, v in pairs(t) do c[k] = v end return setmetatable(c, getmetatable(t)) end "
"math.clamp = math.clamp or function(x, a, b) return math.max(a, math.min(b, x)) end "
"math.sign = math.sign or function(x) return x > 0 and 1 or (x < 0 and -1 or 0) end "
"math.round = math.round or function(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end\n")
open(p, "w").write(head + src)
PY
done
rm -f "$CFG"