Organize builtin into subdirectories
[oweals/minetest.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 "filesys.h"
23 #include "log.h"
24 #include "cpp_api/s_internal.h"
25 #include "lua_api/l_base.h"
26 #include "lua_api/l_craft.h"
27 #include "lua_api/l_env.h"
28 #include "lua_api/l_inventory.h"
29 #include "lua_api/l_item.h"
30 #include "lua_api/l_mapgen.h"
31 #include "lua_api/l_nodemeta.h"
32 #include "lua_api/l_nodetimer.h"
33 #include "lua_api/l_noise.h"
34 #include "lua_api/l_object.h"
35 #include "lua_api/l_particles.h"
36 #include "lua_api/l_rollback.h"
37 #include "lua_api/l_server.h"
38 #include "lua_api/l_util.h"
39 #include "lua_api/l_vmanip.h"
40 #include "lua_api/l_settings.h"
41
42 extern "C" {
43 #include "lualib.h"
44 }
45
46 GameScripting::GameScripting(Server* server)
47 {
48         setServer(server);
49
50         // setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
51         // once the environment has been created
52
53         //TODO add security
54
55         luaL_openlibs(getStack());
56
57         SCRIPTAPI_PRECHECKHEADER
58
59         lua_pushstring(L, DIR_DELIM);
60         lua_setglobal(L, "DIR_DELIM");
61
62         // Create the main minetest table
63         lua_newtable(L);
64         lua_setglobal(L, "minetest");
65         lua_getglobal(L, "minetest");
66         int top = lua_gettop(L);
67
68         lua_newtable(L);
69         lua_setfield(L, -2, "object_refs");
70
71         lua_newtable(L);
72         lua_setfield(L, -2, "luaentities");
73
74         // Initialize our lua_api modules
75         InitializeModApi(L, top);
76         lua_pop(L, 1);
77
78         // Push builtin initialization type
79         lua_pushstring(L, "game");
80         lua_setglobal(L, "INIT");
81
82         infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
83 }
84
85 void GameScripting::InitializeModApi(lua_State *L, int top)
86 {
87         // Initialize mod api modules
88         ModApiCraft::Initialize(L, top);
89         ModApiEnvMod::Initialize(L, top);
90         ModApiInventory::Initialize(L, top);
91         ModApiItemMod::Initialize(L, top);
92         ModApiMapgen::Initialize(L, top);
93         ModApiParticles::Initialize(L, top);
94         ModApiRollback::Initialize(L, top);
95         ModApiServer::Initialize(L, top);
96         ModApiUtil::Initialize(L, top);
97
98         // Register reference classes (userdata)
99         InvRef::Register(L);
100         LuaItemStack::Register(L);
101         LuaPerlinNoise::Register(L);
102         LuaPerlinNoiseMap::Register(L);
103         LuaPseudoRandom::Register(L);
104         LuaVoxelManip::Register(L);
105         NodeMetaRef::Register(L);
106         NodeTimerRef::Register(L);
107         ObjectRef::Register(L);
108         LuaSettings::Register(L);
109 }
110
111 void log_deprecated(std::string message)
112 {
113         log_deprecated(NULL,message);
114 }