1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Create Lua frontend UI code

This commit is contained in:
v-rob 2024-01-23 22:54:45 -08:00
parent abfb319e9b
commit 9cc73f16f0
13 changed files with 1646 additions and 1 deletions

View file

@ -579,6 +579,15 @@ function table.insert_all(t, other)
end
function table.merge(...)
local new = {}
for _, t in ipairs{...} do
table.insert_all(new, t)
end
return new
end
function table.key_value_swap(t)
local ti = {}
for k,v in pairs(t) do
@ -872,3 +881,47 @@ function core.parse_coordinates(x, y, z, relative_to)
local rz = core.parse_relative_number(z, relative_to.z)
return rx and ry and rz and { x = rx, y = ry, z = rz }
end
local function class_try_return(obj, ...)
if select("#", ...) ~= 0 then
return ...
end
return obj
end
local function class_call(class, ...)
local obj = setmetatable({}, class)
if obj.new then
return class_try_return(obj, obj:new(...))
end
return obj
end
function core.class(super)
local class = setmetatable({}, {__call = class_call, __index = super})
class.__index = class
return class
end
function core.super(class)
local meta = getmetatable(class)
return meta and meta.__index
end
function core.is_subclass(class, super)
while class ~= nil do
if class == super then
return true
end
class = core.super(class)
end
return false
end
function core.is_instance(obj, class)
return type(obj) == "table" and core.is_subclass(getmetatable(obj), class)
end