aboutsummaryrefslogtreecommitdiff
path: root/builtin/init.lua
diff options
context:
space:
mode:
authorLars Müller <34514239+appgurueu@users.noreply.github.com>2022-06-06 18:32:28 +0200
committerGitHub <noreply@github.com>2022-06-06 18:32:28 +0200
commitedc7df54801ab3bf30f96ac5aad6ce11a102f6b9 (patch)
tree269a904645d70ae3d284535930e6588b6e4f4076 /builtin/init.lua
parent951604e29ff9d4b796003264574e06031c014a3f (diff)
downloadminetest-edc7df54801ab3bf30f96ac5aad6ce11a102f6b9.tar.gz
minetest-edc7df54801ab3bf30f96ac5aad6ce11a102f6b9.tar.bz2
minetest-edc7df54801ab3bf30f96ac5aad6ce11a102f6b9.zip
core.formspec_escape: Restore backwards compat
Support numbers as arguments by using `string.gsub(text, ...)` instead of `text:gsub(...)` which will coerce `text` to a string
Diffstat (limited to 'builtin/init.lua')
0 files changed, 0 insertions, 0 deletions
ef='#n96'>96 97 98 99 100 101 102 103 104 105
-- advtrains_luaautomation/init.lua
-- Lua automation features for advtrains
-- Uses global table 'atlatc' (AdvTrains_LuaATC)

-- Boilerplate to support localized strings if intllib mod is installed.
if minetest.get_modpath("intllib") then
    atltrans = intllib.Getter()
else
    atltrans = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
end

--Privilege
--Only trusted players should be enabled to build stuff which can break the server.

atlatc = { envs = {}}

minetest.register_privilege("atlatc", { description = "Player can place and modify LUA ATC components. Grant with care! Allows to execute bad LUA code.", give_to_singleplayer = false, default= false })

local mp=minetest.get_modpath("advtrains_luaautomation")
if not mp then
	error("Mod name error: Mod folder is not named 'advtrains_luaautomation'!")
end
dofile(mp.."/environment.lua")
dofile(mp.."/interrupt.lua")
dofile(mp.."/active_common.lua")
dofile(mp.."/atc_rail.lua")
dofile(mp.."/operation_panel.lua")
if mesecon then
	dofile(mp.."/p_mesecon_iface.lua")
end
dofile(mp.."/chatcmds.lua")


local filename=minetest.get_worldpath().."/advtrains_luaautomation"
local file, err = io.open(filename, "r")
if not file then
	minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error"))
else
	atprint("luaautomation reading file:",filename)
	local tbl = minetest.deserialize(file:read("*a"))
	if type(tbl) == "table" then
		atprint(tbl)
		if tbl.version==1 then
			for envname, data in pairs(tbl.envs) do
				atlatc.envs[envname]=atlatc.env_load(envname, data)
			end
			atlatc.active.load(tbl.active)
			atlatc.interrupt.load(tbl.interrupt)
		end
	else
		minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": Not a table!")
	end
	file:close()
end

-- run init code of all environments
atlatc.run_initcode()

atlatc.save = function()
	--versions:
	-- 1 - Initial save format.
	
	local envdata={}
	for envname, env in pairs(atlatc.envs) do
		envdata[envname]=env:save()
	end
	local save_tbl={
		version = 1,
		envs=envdata,
		active = atlatc.active.save(),
		interrupt = atlatc.interrupt.save(),
	}
	
	local datastr = minetest.serialize(save_tbl)
	if not datastr then
		minetest.log("error", " Failed to save advtrains_luaautomation save data to file "..filename..": Can't serialize!")
		return
	end
	local file, err = io.open(filename, "w")
	if err then
		minetest.log("error", " Failed to save advtrains_luaautomation save data to file "..filename..": "..(err or "Unknown Error"))
		return
	end
	file:write(datastr)
	file:close()
end

minetest.register_on_shutdown(atlatc.save)

-- globalstep for step code
local timer, step_int=0, 2