]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/scripting_game.cpp
Improve Script CPP API diagnostics
[dragonfireclient.git] / src / script / scripting_game.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "scripting_game.h"
21 #include "server.h"
22 #include "log.h"
23 #include "settings.h"
24 #include "cpp_api/s_internal.h"
25 #include "lua_api/l_areastore.h"
26 #include "lua_api/l_base.h"
27 #include "lua_api/l_craft.h"
28 #include "lua_api/l_env.h"
29 #include "lua_api/l_inventory.h"
30 #include "lua_api/l_item.h"
31 #include "lua_api/l_mapgen.h"
32 #include "lua_api/l_nodemeta.h"
33 #include "lua_api/l_nodetimer.h"
34 #include "lua_api/l_noise.h"
35 #include "lua_api/l_object.h"
36 #include "lua_api/l_particles.h"
37 #include "lua_api/l_rollback.h"
38 #include "lua_api/l_server.h"
39 #include "lua_api/l_util.h"
40 #include "lua_api/l_vmanip.h"
41 #include "lua_api/l_settings.h"
42
43 extern "C" {
44 #include "lualib.h"
45 }
46
47 GameScripting::GameScripting(Server* server)
48 {
49         setServer(server);
50
51         // setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
52         // once the environment has been created
53
54         SCRIPTAPI_PRECHECKHEADER
55
56         if (g_settings->getBool("secure.enable_security")) {
57                 initializeSecurity();
58         }
59
60         lua_getglobal(L, "core");
61         int top = lua_gettop(L);
62
63         lua_newtable(L);
64         lua_setfield(L, -2, "object_refs");
65
66         lua_newtable(L);
67         lua_setfield(L, -2, "luaentities");
68
69         // Initialize our lua_api modules
70         InitializeModApi(L, top);
71         lua_pop(L, 1);
72
73         // Push builtin initialization type
74         lua_pushstring(L, "game");
75         lua_setglobal(L, "INIT");
76
77         infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
78 }
79
80 void GameScripting::InitializeModApi(lua_State *L, int top)
81 {
82         // Initialize mod api modules
83         ModApiCraft::Initialize(L, top);
84         ModApiEnvMod::Initialize(L, top);
85         ModApiInventory::Initialize(L, top);
86         ModApiItemMod::Initialize(L, top);
87         ModApiMapgen::Initialize(L, top);
88         ModApiParticles::Initialize(L, top);
89         ModApiRollback::Initialize(L, top);
90         ModApiServer::Initialize(L, top);
91         ModApiUtil::Initialize(L, top);
92
93         // Register reference classes (userdata)
94         InvRef::Register(L);
95         LuaAreaStore::Register(L);
96         LuaItemStack::Register(L);
97         LuaPerlinNoise::Register(L);
98         LuaPerlinNoiseMap::Register(L);
99         LuaPseudoRandom::Register(L);
100         LuaPcgRandom::Register(L);
101         LuaVoxelManip::Register(L);
102         NodeMetaRef::Register(L);
103         NodeTimerRef::Register(L);
104         ObjectRef::Register(L);
105         LuaSettings::Register(L);
106 }
107
108 void log_deprecated(const std::string &message)
109 {
110         log_deprecated(NULL, message);
111 }