mirror of
https://gitlab.com/luk3yx/minetest-formspec_ast.git
synced 2025-08-11 02:05:56 +02:00
Bugfix
This commit is contained in:
parent
7d1457279c
commit
09d076e1d2
26
init.lua
26
init.lua
@ -29,29 +29,47 @@
|
|||||||
|
|
||||||
formspec_ast = {}
|
formspec_ast = {}
|
||||||
|
|
||||||
local minetest = minetest
|
|
||||||
local modpath
|
local modpath
|
||||||
|
|
||||||
if minetest then
|
if minetest then
|
||||||
-- Running inside Minetest.
|
-- Running inside Minetest.
|
||||||
|
formspec_ast.minetest = minetest
|
||||||
modpath = minetest.get_modpath('formspec_ast')
|
modpath = minetest.get_modpath('formspec_ast')
|
||||||
is_yes = minetest.is_yes
|
|
||||||
assert(minetest.get_current_modname() == 'formspec_ast',
|
assert(minetest.get_current_modname() == 'formspec_ast',
|
||||||
'This mod must be called formspec_ast!')
|
'This mod must be called formspec_ast!')
|
||||||
else
|
else
|
||||||
-- Probably running outside Minetest.
|
-- Probably running outside Minetest.
|
||||||
modpath = '.'
|
modpath = '.'
|
||||||
minetest = core or {}
|
local minetest = {}
|
||||||
function minetest.is_yes(str)
|
function minetest.is_yes(str)
|
||||||
str = str:lower()
|
str = str:lower()
|
||||||
return str == 'true' or str == 'yes'
|
return str == 'true' or str == 'yes'
|
||||||
end
|
end
|
||||||
|
function minetest.formspec_escape(text)
|
||||||
|
if text then
|
||||||
|
for _, n in ipairs({'\\', ']', '[', ';', ','}) do
|
||||||
|
text = text:gsub('%' .. n, '\\' .. n)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
function string.trim(str)
|
function string.trim(str)
|
||||||
return str:gsub("^%s*(.-)%s*$", "%1")
|
return str:gsub("^%s*(.-)%s*$", "%1")
|
||||||
end
|
end
|
||||||
|
-- Mostly copied from https://stackoverflow.com/a/26367080
|
||||||
|
function table.copy(obj, s)
|
||||||
|
if type(obj) ~= 'table' then return obj end
|
||||||
|
if s and s[obj] ~= nil then return s[obj] end
|
||||||
|
s = s or {}
|
||||||
|
local res = {}
|
||||||
|
s[obj] = res
|
||||||
|
for k, v in pairs(obj) do res[table.copy(k, s)] = table.copy(v, s) end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
formspec_ast.minetest = minetest
|
||||||
end
|
end
|
||||||
|
|
||||||
formspec_ast.modpath, formspec_ast.minetest = modpath, minetest
|
formspec_ast.modpath = modpath
|
||||||
|
|
||||||
dofile(modpath .. '/core.lua')
|
dofile(modpath .. '/core.lua')
|
||||||
dofile(modpath .. '/helpers.lua')
|
dofile(modpath .. '/helpers.lua')
|
||||||
|
Loading…
Reference in New Issue
Block a user