]> git.lizzy.rs Git - minetest.git/blob - src/script/scripting_client.cpp
[CSM] Don't load the IO library. (#6087)
[minetest.git] / src / script / scripting_client.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include "scripting_client.h"
22 #include "client.h"
23 #include "cpp_api/s_internal.h"
24 #include "lua_api/l_client.h"
25 #include "lua_api/l_env.h"
26 #include "lua_api/l_minimap.h"
27 #include "lua_api/l_modchannels.h"
28 #include "lua_api/l_storage.h"
29 #include "lua_api/l_sound.h"
30 #include "lua_api/l_util.h"
31 #include "lua_api/l_item.h"
32 #include "lua_api/l_nodemeta.h"
33 #include "lua_api/l_localplayer.h"
34 #include "lua_api/l_camera.h"
35
36 ClientScripting::ClientScripting(Client *client):
37         ScriptApiBase(ScriptingType::Client)
38 {
39         setGameDef(client);
40
41         SCRIPTAPI_PRECHECKHEADER
42
43         // Security is mandatory client side
44         initializeSecurityClient();
45
46         lua_getglobal(L, "core");
47         int top = lua_gettop(L);
48
49         lua_newtable(L);
50         lua_setfield(L, -2, "ui");
51
52         InitializeModApi(L, top);
53         lua_pop(L, 1);
54
55         if (client->getMinimap())
56                 LuaMinimap::create(L, client->getMinimap());
57
58         // Push builtin initialization type
59         lua_pushstring(L, "client");
60         lua_setglobal(L, "INIT");
61
62         infostream << "SCRIPTAPI: Initialized client game modules" << std::endl;
63 }
64
65 void ClientScripting::InitializeModApi(lua_State *L, int top)
66 {
67         LuaItemStack::Register(L);
68         StorageRef::Register(L);
69         LuaMinimap::Register(L);
70         NodeMetaRef::RegisterClient(L);
71         LuaLocalPlayer::Register(L);
72         LuaCamera::Register(L);
73         ModChannelRef::Register(L);
74
75         ModApiUtil::InitializeClient(L, top);
76         ModApiClient::Initialize(L, top);
77         ModApiStorage::Initialize(L, top);
78         ModApiEnvMod::InitializeClient(L, top);
79         ModApiChannels::Initialize(L, top);
80 }
81
82 void ClientScripting::on_client_ready(LocalPlayer *localplayer)
83 {
84         lua_State *L = getStack();
85         LuaLocalPlayer::create(L, localplayer);
86 }
87
88 void ClientScripting::on_camera_ready(Camera *camera)
89 {
90         LuaCamera::create(getStack(), camera);
91 }