LÖVE backend + build target (compat/luajit.lua shims, Roblox build unchanged), examples/example_love, examples/example_shared (same app on Roblox and LÖVE), LuaJIT checksum tests

This commit is contained in:
4DBug
2026-10-08 19:31:22 -05:00
parent 81c5ad9e43
commit 66fa061089
23 changed files with 56780 additions and 17 deletions
+53
View File
@@ -0,0 +1,53 @@
-- One UI that runs unchanged on Roblox and LÖVE: only the Dear ImGui API is used, and the code is plain Lua 5.1
-- (no Luau-only syntax), so both Luau and LuaJIT run it. The platform launchers are roblox.client.luau and main.lua.
-- local App = require(app)(G) -- G = the table returned by the ImGui bundle
-- every frame, between ImGui.NewFrame() and ImGui.Render(): App.Frame()
return function(G)
local ImGui, ImVec2, ImVec4 = G.ImGui, G.ImVec2, G.ImVec4
local App = {
Platform = "?", -- set by the launcher ("Roblox" / "LÖVE")
ClearColor = ImVec4(0.45, 0.55, 0.60, 1.00), -- launchers may use it as the background colour
}
local show_demo, show_table = false, true
local counter, speed = 0, 1.0
local name = ImGui.NewTextBuffer("Player", 64)
local samples, t = {}, 0.0
local items = { { "Sword", 1, 120 }, { "Potion", 5, 15 }, { "Arrow", 64, 1 }, { "Shield", 1, 80 } }
function App.Frame()
local io = ImGui.GetIO()
t = t + io.DeltaTime * speed
for i = 1, 90 do samples[i] = math.sin(i / 90 * math.pi * 4 + t * 3) end
ImGui.SetNextWindowPos(ImVec2(20, 20), G.ImGuiCond.FirstUseEver)
ImGui.SetNextWindowSize(ImVec2(420, 360), G.ImGuiCond.FirstUseEver)
ImGui.Begin("Shared Example")
ImGui.Text("Running on %s (%.1f FPS)", App.Platform, io.Framerate)
ImGui.Separator()
ImGui.InputText("name", name, 64)
if ImGui.Button("Click me") then counter = counter + 1 end
ImGui.SameLine(); ImGui.Text("%s clicked %d times", ImGui.TextBufferToString(name), counter)
speed = ImGui.SliderFloat("speed", speed, 0.0, 4.0)
ImGui.ColorEdit3("background", App.ClearColor)
ImGui.PlotLines("wave", samples, nil, #samples, 0, nil, -1.0, 1.0, ImVec2(0, 60))
local _
_, show_table = ImGui.Checkbox("Inventory table", show_table)
ImGui.SameLine(); _, show_demo = ImGui.Checkbox("Demo window", show_demo)
if show_table and ImGui.BeginTable("inv", 3, bit32.bor(G.ImGuiTableFlags.Borders, G.ImGuiTableFlags.RowBg, G.ImGuiTableFlags.Sortable)) then
ImGui.TableSetupColumn("Item"); ImGui.TableSetupColumn("Count"); ImGui.TableSetupColumn("Value")
ImGui.TableHeadersRow()
for _, it in ipairs(items) do
ImGui.TableNextRow()
ImGui.TableNextColumn(); ImGui.Text(it[1])
ImGui.TableNextColumn(); ImGui.Text("%d", it[2])
ImGui.TableNextColumn(); ImGui.Text("%d", it[3])
end
ImGui.EndTable()
end
ImGui.End()
if show_demo and ImGui.ShowDemoWindow then show_demo = ImGui.ShowDemoWindow(show_demo) end
end
return App
end
+5
View File
@@ -0,0 +1,5 @@
function love.conf(t)
t.window.title = "Dear ImGui - shared example (LÖVE)"
t.window.width, t.window.height = 1280, 800
t.window.resizable = true
end
@@ -0,0 +1,15 @@
{
"name": "imgui-shared-example",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"ImGui": { "$path": "../../build/ImGui.luau" },
"SharedApp": { "$path": "app.lua" }
},
"StarterPlayer": {
"StarterPlayerScripts": {
"SharedExample": { "$path": "roblox.client.luau" }
}
}
}
}
+43
View File
@@ -0,0 +1,43 @@
-- LÖVE launcher for app.lua: python3 tools/bundle.py --target love then love examples/example_shared
local ROOT = love.filesystem.getSource() .. "/../../" -- repo root (build/, fonts/)
local function load_bundle()
local f = assert(io.open(ROOT .. "build/imgui_love.lua", "rb"), "run: python3 tools/bundle.py --target love")
local src = f:read("*a"); f:close()
return assert(loadstring(src, "@imgui_love.lua"))()
end
local G, ImGui, App
function love.load()
G = load_bundle()
ImGui = G.ImGui
ImGui.CreateContext()
local io = ImGui.GetIO()
io.ConfigFlags = bit32.bor(io.ConfigFlags, G.ImGuiConfigFlags.NavEnableKeyboard, G.ImGuiConfigFlags.DockingEnable)
io.IniFilename = nil
G.ImGui_ImplLove.Init({ root = ROOT })
App = love.filesystem.load("app.lua")()(G)
App.Platform = "LÖVE"
end
function love.update(dt)
G.ImGui_ImplLove.NewFrame()
ImGui.NewFrame()
App.Frame()
ImGui.Render()
end
function love.draw()
local c = App.ClearColor
love.graphics.clear(c.x, c.y, c.z, 1)
G.ImGui_ImplLove.RenderDrawData(ImGui.GetDrawData())
end
function love.mousemoved(x, y) G.ImGui_ImplLove.MouseMoved(x, y) end
function love.mousepressed(x, y, b) G.ImGui_ImplLove.MousePressed(x, y, b) end
function love.mousereleased(x, y, b) G.ImGui_ImplLove.MouseReleased(x, y, b) end
function love.wheelmoved(x, y) G.ImGui_ImplLove.WheelMoved(x, y) end
function love.keypressed(k) G.ImGui_ImplLove.KeyPressed(k) end
function love.keyreleased(k) G.ImGui_ImplLove.KeyReleased(k) end
function love.textinput(t) G.ImGui_ImplLove.TextInput(t) end
function love.focus(f) G.ImGui_ImplLove.Focus(f) end
@@ -0,0 +1,21 @@
-- Roblox launcher for app.lua (sync with examples/example_shared/default.project.json).
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local G = require(ReplicatedStorage:WaitForChild("ImGui"))
local ImGui = G.ImGui
ImGui.CreateContext()
local io = ImGui.GetIO()
io.ConfigFlags = bit32.bor(io.ConfigFlags, G.ImGuiConfigFlags.NavEnableKeyboard, G.ImGuiConfigFlags.DockingEnable)
G.ImGui_ImplRoblox.Init()
local App = require(ReplicatedStorage:WaitForChild("SharedApp"))(G)
App.Platform = "Roblox"
RunService.Stepped:Connect(function()
G.ImGui_ImplRoblox.NewFrame()
ImGui.NewFrame()
App.Frame()
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
end)