1 /*
2 script/scripting_game.cpp
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 */
5 
6 /*
7 This file is part of Freeminer.
8 
9 Freeminer is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Freeminer  is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Freeminer.  If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "scripting_game.h"
24 #include "server.h"
25 #include "log.h"
26 #include "cpp_api/s_internal.h"
27 #include "lua_api/l_base.h"
28 #include "lua_api/l_craft.h"
29 #include "lua_api/l_env.h"
30 #include "lua_api/l_inventory.h"
31 #include "lua_api/l_item.h"
32 #include "lua_api/l_key_value_storage.h"
33 #include "lua_api/l_mapgen.h"
34 #include "lua_api/l_nodemeta.h"
35 #include "lua_api/l_nodetimer.h"
36 #include "lua_api/l_noise.h"
37 #include "lua_api/l_object.h"
38 #include "lua_api/l_particles.h"
39 #include "lua_api/l_rollback.h"
40 #include "lua_api/l_server.h"
41 #include "lua_api/l_util.h"
42 #include "lua_api/l_vmanip.h"
43 #include "lua_api/l_settings.h"
44 
45 extern "C" {
46 #include "lualib.h"
47 }
48 
GameScripting(Server * server)49 GameScripting::GameScripting(Server* server)
50 {
51 	setServer(server);
52 
53 	// setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
54 	// once the environment has been created
55 
56 	//TODO add security
57 
58 	SCRIPTAPI_PRECHECKHEADER
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 
InitializeModApi(lua_State * L,int top)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 	ModApiKeyValueStorage::Initialize(L, top);
88 	ModApiMapgen::Initialize(L, top);
89 	ModApiParticles::Initialize(L, top);
90 	ModApiRollback::Initialize(L, top);
91 	ModApiServer::Initialize(L, top);
92 	ModApiUtil::Initialize(L, top);
93 
94 	// Register reference classes (userdata)
95 	InvRef::Register(L);
96 	LuaItemStack::Register(L);
97 	LuaPerlinNoise::Register(L);
98 	LuaPerlinNoiseMap::Register(L);
99 	LuaPseudoRandom::Register(L);
100 	LuaVoxelManip::Register(L);
101 	NodeMetaRef::Register(L);
102 	NodeTimerRef::Register(L);
103 	ObjectRef::Register(L);
104 	LuaSettings::Register(L);
105 }
106 
log_deprecated(std::string message)107 void log_deprecated(std::string message)
108 {
109 	log_deprecated(NULL,message);
110 }
111