3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #include "scripting_game.h"
22 #include "cpp_api/s_internal.h"
23 #include "lua_api/l_base.h"
24 #include "lua_api/l_craft.h"
25 #include "lua_api/l_env.h"
26 #include "lua_api/l_inventory.h"
27 #include "lua_api/l_item.h"
28 #include "lua_api/l_mapgen.h"
29 #include "lua_api/l_nodemeta.h"
30 #include "lua_api/l_nodetimer.h"
31 #include "lua_api/l_noise.h"
32 #include "lua_api/l_object.h"
33 #include "lua_api/l_particles.h"
34 #include "lua_api/l_rollback.h"
35 #include "lua_api/l_server.h"
36 #include "lua_api/l_util.h"
37 #include "lua_api/l_vmanip.h"
38 #include "lua_api/l_settings.h"
44 GameScripting::GameScripting(Server* server)
48 // setEnv(env) is called by ScriptApiEnv::initializeEnvironment()
49 // once the environment has been created
53 luaL_openlibs(getStack());
55 SCRIPTAPI_PRECHECKHEADER
57 // Create the main minetest table
61 lua_setfield(L, -2, "object_refs");
64 lua_setfield(L, -2, "luaentities");
66 lua_setglobal(L, "minetest");
68 // Initialize our lua_api modules
69 lua_getglobal(L, "minetest");
70 int top = lua_gettop(L);
71 InitializeModApi(L, top);
74 infostream << "SCRIPTAPI: initialized game modules" << std::endl;
77 void GameScripting::InitializeModApi(lua_State *L, int top)
79 // Initialize mod api modules
80 ModApiCraft::Initialize(L, top);
81 ModApiEnvMod::Initialize(L, top);
82 ModApiInventory::Initialize(L, top);
83 ModApiItemMod::Initialize(L, top);
84 ModApiMapgen::Initialize(L, top);
85 ModApiParticles::Initialize(L, top);
86 ModApiRollback::Initialize(L, top);
87 ModApiServer::Initialize(L, top);
88 ModApiUtil::Initialize(L, top);
90 // Register reference classes (userdata)
92 LuaItemStack::Register(L);
93 LuaPerlinNoise::Register(L);
94 LuaPerlinNoiseMap::Register(L);
95 LuaPseudoRandom::Register(L);
96 LuaVoxelManip::Register(L);
97 NodeMetaRef::Register(L);
98 NodeTimerRef::Register(L);
99 ObjectRef::Register(L);
100 LuaSettings::Register(L);