Reorganize like upstream: library at root (docking/dragdrop/debug tools merged into imgui.lua, tabs into imgui_widgets.lua), single imgui_demo.lua, backends/, fonts/, examples/, docs/; --no-demo build
This commit is contained in:
+11
-8
@@ -1,26 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
# Bundles imgui/*.lua + backend into ONE ModuleScript: build/ImGui.luau
|
||||
# Bundles the root *.lua (library + imgui_demo.lua), backends/ and fonts/ into ONE ModuleScript: build/ImGui.luau
|
||||
# --no-demo: library only (imgui_demo.lua left out, like not compiling imgui_demo.cpp)
|
||||
# Why: ModuleScripts don't share globals, and the setfenv() alternative turns off Luau's fast paths / native codegen.
|
||||
# Each source file becomes a function in __FILES; IM_INCLUDE(name) runs it once and caches the result.
|
||||
# The module returns a table with every global the library defines (ImGui, ImVec2, ImGuiConfigFlags, ImGui_ImplRoblox, ...).
|
||||
import os, re
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SRC = os.path.join(ROOT, "imgui")
|
||||
import sys
|
||||
NO_DEMO = "--no-demo" in sys.argv
|
||||
sys.argv = [a for a in sys.argv if a != "--no-demo"]
|
||||
FILES = {}
|
||||
for dp, _, fn in os.walk(SRC):
|
||||
for f in sorted(fn):
|
||||
if f.endswith(".lua"):
|
||||
FILES[f] = open(os.path.join(dp, f)).read()
|
||||
for d in (ROOT, os.path.join(ROOT, "backends"), os.path.join(ROOT, "fonts")):
|
||||
for f in sorted(os.listdir(d)):
|
||||
if f.endswith(".lua") and not (NO_DEMO and f == "imgui_demo.lua"):
|
||||
FILES[f] = open(os.path.join(d, f)).read()
|
||||
|
||||
ENTRY = ["imgui.lua", "imgui_impl_roblox.lua"] + sorted(f for f in FILES if f.startswith("imgui_demo")) # run order
|
||||
ENTRY = ["imgui.lua", "imgui_impl_roblox.lua"] + ([] if NO_DEMO else ["imgui_demo.lua"]) # run order
|
||||
|
||||
names = set()
|
||||
for src in FILES.values():
|
||||
names.update(re.findall(r"^function ([A-Za-z_]\w*)\s*\(", src, re.M))
|
||||
names.update(re.findall(r"^([A-Za-z_]\w*)\s*=[^=]", src, re.M))
|
||||
|
||||
out = ["--!optimize 2", "-- GENERATED by tools/bundle.py from imgui/*.lua - do not edit", "",
|
||||
out = ["--!optimize 2", "-- GENERATED by tools/bundle.py from *.lua, backends/, fonts/ - do not edit", "",
|
||||
"local __FILES, __LOADED = {}, {}",
|
||||
"function IM_INCLUDE(name)",
|
||||
" local r = __LOADED[name]",
|
||||
|
||||
Reference in New Issue
Block a user