2013-08-11 04:09:45 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scripting_mainmenu.h"
|
2018-04-17 15:54:50 +02:00
|
|
|
#include "content/mods.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "cpp_api/s_internal.h"
|
|
|
|
#include "lua_api/l_base.h"
|
2020-06-06 18:17:08 +02:00
|
|
|
#include "lua_api/l_http.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "lua_api/l_mainmenu.h"
|
2017-01-22 11:17:41 +01:00
|
|
|
#include "lua_api/l_sound.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "lua_api/l_util.h"
|
2013-09-09 22:50:25 +02:00
|
|
|
#include "lua_api/l_settings.h"
|
2017-08-18 19:25:07 +02:00
|
|
|
#include "log.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "lualib.h"
|
|
|
|
}
|
2014-04-15 19:41:07 +02:00
|
|
|
|
2014-04-15 21:10:30 +02:00
|
|
|
#define MAINMENU_NUM_ASYNC_THREADS 4
|
2014-04-15 19:41:07 +02:00
|
|
|
|
|
|
|
|
2018-01-04 08:21:12 +01:00
|
|
|
MainMenuScripting::MainMenuScripting(GUIEngine* guiengine):
|
|
|
|
ScriptApiBase(ScriptingType::MainMenu)
|
2013-08-11 04:09:45 +02:00
|
|
|
{
|
|
|
|
setGuiEngine(guiengine);
|
|
|
|
|
|
|
|
SCRIPTAPI_PRECHECKHEADER
|
|
|
|
|
2014-04-28 03:02:48 +02:00
|
|
|
lua_getglobal(L, "core");
|
2014-04-15 19:41:07 +02:00
|
|
|
int top = lua_gettop(L);
|
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
lua_setglobal(L, "gamedata");
|
|
|
|
|
|
|
|
// Initialize our lua_api modules
|
2014-04-15 21:10:30 +02:00
|
|
|
initializeModApi(L, top);
|
2013-08-11 04:09:45 +02:00
|
|
|
lua_pop(L, 1);
|
|
|
|
|
2014-04-27 23:55:49 +02:00
|
|
|
// Push builtin initialization type
|
|
|
|
lua_pushstring(L, "mainmenu");
|
|
|
|
lua_setglobal(L, "INIT");
|
|
|
|
|
2014-04-15 19:41:07 +02:00
|
|
|
infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
|
|
|
|
2013-11-26 18:15:31 +01:00
|
|
|
/******************************************************************************/
|
2014-04-15 21:10:30 +02:00
|
|
|
void MainMenuScripting::initializeModApi(lua_State *L, int top)
|
2013-08-11 04:09:45 +02:00
|
|
|
{
|
2014-12-12 20:49:19 +01:00
|
|
|
registerLuaClasses(L, top);
|
|
|
|
|
2014-04-15 19:41:07 +02:00
|
|
|
// Initialize mod API modules
|
2013-08-11 04:09:45 +02:00
|
|
|
ModApiMainMenu::Initialize(L, top);
|
|
|
|
ModApiUtil::Initialize(L, top);
|
2017-01-22 11:17:41 +01:00
|
|
|
ModApiSound::Initialize(L, top);
|
2020-06-06 18:17:08 +02:00
|
|
|
ModApiHttp::Initialize(L, top);
|
2013-09-09 22:50:25 +02:00
|
|
|
|
2014-12-12 20:49:19 +01:00
|
|
|
asyncEngine.registerStateInitializer(registerLuaClasses);
|
|
|
|
asyncEngine.registerStateInitializer(ModApiMainMenu::InitializeAsync);
|
|
|
|
asyncEngine.registerStateInitializer(ModApiUtil::InitializeAsync);
|
2013-11-26 18:15:31 +01:00
|
|
|
|
|
|
|
// Initialize async environment
|
|
|
|
//TODO possibly make number of async threads configurable
|
2014-04-15 21:10:30 +02:00
|
|
|
asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS);
|
2013-11-26 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
2014-12-12 20:49:19 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
void MainMenuScripting::registerLuaClasses(lua_State *L, int top)
|
|
|
|
{
|
|
|
|
LuaSettings::Register(L);
|
|
|
|
}
|
|
|
|
|
2013-11-26 18:15:31 +01:00
|
|
|
/******************************************************************************/
|
2017-04-20 00:12:52 +02:00
|
|
|
void MainMenuScripting::step()
|
|
|
|
{
|
2015-08-25 07:44:53 +02:00
|
|
|
asyncEngine.step(getStack());
|
2013-11-26 18:15:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2017-04-20 00:12:52 +02:00
|
|
|
unsigned int MainMenuScripting::queueAsync(const std::string &serialized_func,
|
|
|
|
const std::string &serialized_param)
|
|
|
|
{
|
2014-04-15 21:10:30 +02:00
|
|
|
return asyncEngine.queueAsyncJob(serialized_func, serialized_param);
|
2013-08-11 04:09:45 +02:00
|
|
|
}
|
2014-04-15 19:41:07 +02:00
|
|
|
|