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"
24 #include "cpp_api/s_internal.h"
25 #include "lua_api/l_base.h"
26 #include "lua_api/l_mainmenu.h"
27 #include "lua_api/l_util.h"
28 #include "lua_api/l_settings.h"
34 #define MAINMENU_NUM_ASYNC_THREADS 4
37 MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
39 setGuiEngine(guiengine);
43 SCRIPTAPI_PRECHECKHEADER
45 lua_getglobal(L, "core");
46 int top = lua_gettop(L);
49 lua_setglobal(L, "gamedata");
51 // Initialize our lua_api modules
52 initializeModApi(L, top);
55 // Push builtin initialization type
56 lua_pushstring(L, "mainmenu");
57 lua_setglobal(L, "INIT");
59 infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
62 /******************************************************************************/
63 void MainMenuScripting::initializeModApi(lua_State *L, int top)
65 // Initialize mod API modules
66 ModApiMainMenu::Initialize(L, top);
67 ModApiUtil::Initialize(L, top);
69 // Register reference classes (userdata)
70 LuaSettings::Register(L);
72 // Register functions to async environment
73 ModApiMainMenu::InitializeAsync(asyncEngine);
74 ModApiUtil::InitializeAsync(asyncEngine);
76 // Initialize async environment
77 //TODO possibly make number of async threads configurable
78 asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS);
81 /******************************************************************************/
82 void MainMenuScripting::step() {
83 asyncEngine.step(getStack(), m_errorhandler);
86 /******************************************************************************/
87 unsigned int MainMenuScripting::queueAsync(std::string serialized_func,
88 std::string serialized_param) {
89 return asyncEngine.queueAsyncJob(serialized_func, serialized_param);