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_mainmenu.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"
33 #define MAINMENU_ASYNC_THREADS 4
36 MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
38 setGuiEngine(guiengine);
42 luaL_openlibs(getStack());
44 SCRIPTAPI_PRECHECKHEADER
47 lua_setglobal(L, "engine");
48 lua_getglobal(L, "engine");
49 int top = lua_gettop(L);
51 lua_pushstring(L, DIR_DELIM);
52 lua_setglobal(L, "DIR_DELIM");
55 lua_setglobal(L, "gamedata");
57 // Initialize our lua_api modules
58 InitializeModApi(L, top);
61 infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
64 /******************************************************************************/
65 void MainMenuScripting::InitializeModApi(lua_State *L, int top)
67 // Initialize mod API modules
68 ModApiMainMenu::Initialize(L, top);
69 ModApiUtil::Initialize(L, top);
71 // Register reference classes (userdata)
72 LuaSettings::Register(L);
74 // Register functions to async environment
75 ModApiMainMenu::InitializeAsync(m_AsyncEngine);
76 ModApiUtil::InitializeAsync(m_AsyncEngine);
78 // Initialize async environment
79 //TODO possibly make number of async threads configurable
80 m_AsyncEngine.Initialize(MAINMENU_ASYNC_THREADS);
83 /******************************************************************************/
84 void MainMenuScripting::Step() {
85 m_AsyncEngine.Step(getStack(), m_errorhandler);
88 /******************************************************************************/
89 unsigned int MainMenuScripting::DoAsync(std::string serialized_func,
90 std::string serialized_param) {
91 return m_AsyncEngine.doAsyncJob(serialized_func, serialized_param);