Add player:override_day_night_ratio() for arbitrarily controlling sunlight brightness
[oweals/minetest.git] / src / script / scripting_mainmenu.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #include "scripting_mainmenu.h"
21 #include "log.h"
22 #include "filesys.h"
23 #include "cpp_api/s_internal.h"
24 #include "lua_api/l_base.h"
25 #include "lua_api/l_mainmenu.h"
26 #include "lua_api/l_util.h"
27 #include "lua_api/l_settings.h"
28
29 extern "C" {
30 #include "lualib.h"
31         int luaopen_marshal(lua_State *L);
32 }
33 /******************************************************************************/
34 MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
35 {
36         setGuiEngine(guiengine);
37
38         //TODO add security
39
40         luaL_openlibs(getStack());
41         luaopen_marshal(getStack());
42
43         SCRIPTAPI_PRECHECKHEADER
44
45         lua_pushstring(L, DIR_DELIM);
46         lua_setglobal(L, "DIR_DELIM");
47
48         lua_newtable(L);
49         lua_setglobal(L, "gamedata");
50
51         lua_newtable(L);
52         lua_setglobal(L, "engine");
53
54         // Initialize our lua_api modules
55         lua_getglobal(L, "engine");
56         int top = lua_gettop(L);
57         InitializeModApi(L, top);
58         lua_pop(L, 1);
59
60         infostream << "SCRIPTAPI: initialized mainmenu modules" << std::endl;
61 }
62
63 /******************************************************************************/
64 void MainMenuScripting::InitializeModApi(lua_State *L, int top)
65 {
66         // Initialize mod api modules
67         ModApiMainMenu::Initialize(L, top);
68         ModApiUtil::Initialize(L, top);
69
70         // Register reference classes (userdata)
71         LuaSettings::Register(L);
72
73         // Register functions to async environment
74         ModApiMainMenu::InitializeAsync(m_AsyncEngine);
75         ModApiUtil::InitializeAsync(m_AsyncEngine);
76
77         // Initialize async environment
78         //TODO possibly make number of async threads configurable
79         m_AsyncEngine.Initialize(MAINMENU_NUMBER_OF_ASYNC_THREADS);
80 }
81
82 /******************************************************************************/
83 void MainMenuScripting::Step() {
84         m_AsyncEngine.Step(getStack());
85 }
86
87 /******************************************************************************/
88 unsigned int MainMenuScripting::DoAsync(std::string serialized_fct,
89                 std::string serialized_params) {
90         return m_AsyncEngine.doAsyncJob(serialized_fct,serialized_params);
91 }