aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_internal.h
blob: bbedfe46edde7df7938010ac1bd36bb4a35ffca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/******************************************************************************/
/******************************************************************************/
/* WARNING!!!! do NOT add this header in any include file or any code file    */
/*             not being a modapi file!!!!!!!!                                */
/******************************************************************************/
/******************************************************************************/

#pragma once

#include "common/c_internal.h"

#define luamethod(class, name) {#name, class::l_##name}
#define luamethod_aliased(class, name, alias) {#name, class::l_##name}, {#alias, class::l_##name}
#define API_FCT(name) registerFunction(L, #name, l_##name, top)

#define MAP_LOCK_REQUIRED
#define NO_MAP_LOCK_REQUIRED

#define GET_ENV_PTR_NO_MAP_LOCK                              \
	ServerEnvironment *env = (ServerEnvironment *)getEnv(L); \
	if (env == NULL)                                         \
		return 0

#define GET_ENV_PTR         \
	MAP_LOCK_REQUIRED;      \
	GET_ENV_PTR_NO_MAP_LOCK
a">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 }) --Size of code input forms in X,Y notation. Must be at least 10x10 atlatc.CODE_FORM_SIZE = "15,12" --Position of Error Label in Code Form atlatc.CODE_FORM_ERRLABELPOS = "0,12" --assertt helper. error if a variable is not of a type function assertt(var, typ) if type(var)~=typ then error("Assertion failed, variable has to be of type "..typ) end end 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.."/mesecon_controller.lua") end dofile(mp.."/pcnaming.lua") dofile(mp.."/chatcmds.lua") local filename=minetest.get_worldpath().."/advtrains_luaautomation" function atlatc.load(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) atlatc.pcnaming.load(tbl.pcnaming) end -- run init code of all environments atlatc.run_initcode() end function atlatc.load_pre_v4() minetest.log("action", "[atlatc] Loading pre-v4 save file") local file, err = io.open(filename, "r") if not file then minetest.log("warning", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error")) minetest.log("warning", " (this is normal when first enabling advtrains on this world)") else atprint("luaautomation reading file:",filename) local tbl = minetest.deserialize(file:read("*a")) if type(tbl) == "table" then 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) atlatc.pcnaming.load(tbl.pcnaming) 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() end 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(), pcnaming = atlatc.pcnaming.save(), } return save_tbl end --[[ -- globalstep for step code local timer, step_int=0, 2 function atlatc.mainloop_stepcode(dtime) timer=timer+dtime if timer>step_int then timer=0 atlatc.run_stepcode() end end ]]