ccdcb928d3ba9a2bc44b67b07ae53cf093ad69cb
[oweals/minetest.git] / src / script / clientscripting.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 "clientscripting.h"
22 #include "client.h"
23 #include "cpp_api/s_internal.h"
24 #include "lua_api/l_client.h"
25 #include "lua_api/l_storage.h"
26 #include "lua_api/l_sound.h"
27 #include "lua_api/l_util.h"
28 #include "lua_api/l_item.h"
29
30 ClientScripting::ClientScripting(Client *client):
31         ScriptApiBase()
32 {
33         setGameDef(client);
34
35         SCRIPTAPI_PRECHECKHEADER
36
37         // Security is mandatory client side
38         initializeSecurityClient();
39
40         lua_getglobal(L, "core");
41         int top = lua_gettop(L);
42
43         InitializeModApi(L, top);
44         lua_pop(L, 1);
45
46         // Push builtin initialization type
47         lua_pushstring(L, "client");
48         lua_setglobal(L, "INIT");
49
50         infostream << "SCRIPTAPI: Initialized client game modules" << std::endl;
51 }
52
53 void ClientScripting::InitializeModApi(lua_State *L, int top)
54 {
55         ModApiUtil::InitializeClient(L, top);
56         ModApiClient::Initialize(L, top);
57         ModApiSound::Initialize(L, top);
58         ModApiStorage::Initialize(L, top);
59
60         LuaItemStack::Register(L);
61         StorageRef::Register(L);
62 }