]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/scripting_client.cpp
Unrestricted HTTP API for Client, Server and Main Menu
[dragonfireclient.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/client.h"
23 #include "client/game.h"
24 #include "cpp_api/s_internal.h"
25 #include "lua_api/l_client.h"
26 #include "lua_api/l_env.h"
27 #include "lua_api/l_item.h"
28 #include "lua_api/l_itemstackmeta.h"
29 #include "lua_api/l_minimap.h"
30 #include "lua_api/l_modchannels.h"
31 #include "lua_api/l_particles_local.h"
32 #include "lua_api/l_storage.h"
33 #include "lua_api/l_sound.h"
34 #include "lua_api/l_util.h"
35 #include "lua_api/l_item.h"
36 #include "lua_api/l_nodemeta.h"
37 #include "lua_api/l_localplayer.h"
38 #include "lua_api/l_camera.h"
39 #include "lua_api/l_settings.h"
40 #include "lua_api/l_http.h"
41
42 ClientScripting::ClientScripting(Client *client):
43         ScriptApiBase(ScriptingType::Client)
44 {
45         setGameDef(client);
46         setGame(g_game);
47
48         SCRIPTAPI_PRECHECKHEADER
49
50         // Security is mandatory client side
51         initializeSecurityClient();
52
53         lua_getglobal(L, "core");
54         int top = lua_gettop(L);
55
56         lua_newtable(L);
57         lua_setfield(L, -2, "ui");
58
59         InitializeModApi(L, top);
60         lua_pop(L, 1);
61
62         // Push builtin initialization type
63         lua_pushstring(L, "client");
64         lua_setglobal(L, "INIT");
65
66         infostream << "SCRIPTAPI: Initialized client game modules" << std::endl;
67 }
68
69 void ClientScripting::InitializeModApi(lua_State *L, int top)
70 {
71         LuaItemStack::Register(L);
72         ItemStackMetaRef::Register(L);
73         LuaRaycast::Register(L);
74         StorageRef::Register(L);
75         LuaMinimap::Register(L);
76         NodeMetaRef::RegisterClient(L);
77         LuaLocalPlayer::Register(L);
78         LuaCamera::Register(L);
79         ModChannelRef::Register(L);
80         LuaSettings::Register(L);
81
82         ModApiItemMod::Initialize(L, top);
83         ModApiUtil::InitializeClient(L, top);
84         ModApiHttp::Initialize(L, top);
85         ModApiClient::Initialize(L, top);
86         ModApiStorage::Initialize(L, top);
87         ModApiEnvMod::InitializeClient(L, top);
88         ModApiChannels::Initialize(L, top);
89         ModApiParticlesLocal::Initialize(L, top);
90 }
91
92 void ClientScripting::on_client_ready(LocalPlayer *localplayer)
93 {
94         LuaLocalPlayer::create(getStack(), localplayer);
95 }
96
97 void ClientScripting::on_camera_ready(Camera *camera)
98 {
99         LuaCamera::create(getStack(), camera);
100 }
101
102 void ClientScripting::on_minimap_ready(Minimap *minimap)
103 {
104         LuaMinimap::create(getStack(), minimap);
105 }