mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Organize builtin into subdirectories
This commit is contained in:
parent
fef2729fd0
commit
1cd512913e
44 changed files with 206 additions and 203 deletions
|
@ -269,9 +269,9 @@ void set_default_settings(Settings *settings)
|
|||
settings->setDefault("enable_ipv6", "true");
|
||||
settings->setDefault("ipv6_server", "false");
|
||||
|
||||
settings->setDefault("main_menu_script","");
|
||||
settings->setDefault("main_menu_mod_mgr","1");
|
||||
settings->setDefault("main_menu_game_mgr","0");
|
||||
settings->setDefault("main_menu_path", "");
|
||||
settings->setDefault("main_menu_mod_mgr", "1");
|
||||
settings->setDefault("main_menu_game_mgr", "0");
|
||||
settings->setDefault("modstore_download_url", "https://forum.minetest.net/media/");
|
||||
settings->setDefault("modstore_listmods_url", "https://forum.minetest.net/mmdb/mods/");
|
||||
settings->setDefault("modstore_details_url", "https://forum.minetest.net/mmdb/mod/*/");
|
||||
|
|
|
@ -169,17 +169,16 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
|
|||
m_formspecgui = new FormspecFormSource("");
|
||||
|
||||
/* Create menu */
|
||||
m_menu =
|
||||
new GUIFormSpecMenu( m_device,
|
||||
m_parent,
|
||||
-1,
|
||||
m_menumanager,
|
||||
0 /* &client */,
|
||||
0 /* gamedef */,
|
||||
m_texture_source,
|
||||
m_formspecgui,
|
||||
m_buttonhandler,
|
||||
NULL);
|
||||
m_menu = new GUIFormSpecMenu(m_device,
|
||||
m_parent,
|
||||
-1,
|
||||
m_menumanager,
|
||||
NULL /* &client */,
|
||||
NULL /* gamedef */,
|
||||
m_texture_source,
|
||||
m_formspecgui,
|
||||
m_buttonhandler,
|
||||
NULL);
|
||||
|
||||
m_menu->allowClose(false);
|
||||
m_menu->lockSize(true,v2u32(800,600));
|
||||
|
@ -216,43 +215,21 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
|
|||
/******************************************************************************/
|
||||
bool GUIEngine::loadMainMenuScript()
|
||||
{
|
||||
// Try custom menu script (main_menu_script)
|
||||
// Try custom menu script (main_menu_path)
|
||||
|
||||
std::string menuscript = g_settings->get("main_menu_script");
|
||||
if(menuscript != "") {
|
||||
m_scriptdir = fs::RemoveLastPathComponent(menuscript);
|
||||
|
||||
if(m_script->loadMod(menuscript, "__custommenu")) {
|
||||
// custom menu script loaded
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
infostream
|
||||
<< "GUIEngine: execution of custom menu: \""
|
||||
<< menuscript << "\" failed!"
|
||||
<< std::endl
|
||||
<< "\tfalling back to builtin menu"
|
||||
<< std::endl;
|
||||
}
|
||||
m_scriptdir = g_settings->get("main_menu_path");
|
||||
if (m_scriptdir.empty()) {
|
||||
m_scriptdir = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "mainmenu";
|
||||
}
|
||||
|
||||
// Try builtin menu script (main_menu_script)
|
||||
|
||||
std::string builtin_menuscript =
|
||||
porting::path_share + DIR_DELIM + "builtin"
|
||||
+ DIR_DELIM + "mainmenu.lua";
|
||||
|
||||
m_scriptdir = fs::RemoveRelativePathComponents(
|
||||
fs::RemoveLastPathComponent(builtin_menuscript));
|
||||
|
||||
if(m_script->loadMod(builtin_menuscript, "__builtinmenu")) {
|
||||
// builtin menu script loaded
|
||||
std::string script = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "init.lua";
|
||||
if (m_script->loadScript(script)) {
|
||||
// Menu script loaded
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
errorstream
|
||||
<< "GUIEngine: unable to load builtin menu"
|
||||
<< std::endl;
|
||||
} else {
|
||||
infostream
|
||||
<< "GUIEngine: execution of menu script in: \""
|
||||
<< m_scriptdir << "\" failed!" << std::endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
|||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "server.h"
|
||||
#include "s_async.h"
|
||||
#include "log.h"
|
||||
#include "filesys.h"
|
||||
|
@ -233,9 +234,9 @@ AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher,
|
|||
lua_pushstring(L, DIR_DELIM);
|
||||
lua_setglobal(L, "DIR_DELIM");
|
||||
|
||||
lua_pushstring(L,
|
||||
(porting::path_share + DIR_DELIM + "builtin").c_str());
|
||||
lua_setglobal(L, "SCRIPTDIR");
|
||||
// Push builtin initialization type
|
||||
lua_pushstring(L, "async");
|
||||
lua_setglobal(L, "INIT");
|
||||
|
||||
jobDispatcher->prepareEnvironment(L, top);
|
||||
}
|
||||
|
@ -258,17 +259,16 @@ void* AsyncWorkerThread::Thread()
|
|||
|
||||
porting::setThreadName((std::string("AsyncWorkTh_") + number).c_str());
|
||||
|
||||
std::string asyncscript = porting::path_share + DIR_DELIM + "builtin"
|
||||
+ DIR_DELIM + "async_env.lua";
|
||||
lua_State *L = getStack();
|
||||
|
||||
if (!loadScript(asyncscript)) {
|
||||
std::string script = getServer()->getBuiltinLuaPath() + DIR_DELIM + "init.lua";
|
||||
if (!loadScript(script)) {
|
||||
errorstream
|
||||
<< "AsyncWorkderThread execution of async base environment failed!"
|
||||
<< std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
lua_State *L = getStack();
|
||||
// Main loop
|
||||
while (!StopRequested()) {
|
||||
// Wait for job
|
||||
|
|
|
@ -88,9 +88,9 @@ ScriptApiBase::ScriptApiBase()
|
|||
lua_pop(m_luastack, 1);
|
||||
#endif
|
||||
|
||||
m_server = 0;
|
||||
m_environment = 0;
|
||||
m_guiengine = 0;
|
||||
m_server = NULL;
|
||||
m_environment = NULL;
|
||||
m_guiengine = NULL;
|
||||
}
|
||||
|
||||
ScriptApiBase::~ScriptApiBase()
|
||||
|
@ -103,24 +103,14 @@ bool ScriptApiBase::loadMod(const std::string &scriptpath,
|
|||
{
|
||||
ModNameStorer modnamestorer(getStack(), modname);
|
||||
|
||||
if(!string_allowed(modname, MODNAME_ALLOWED_CHARS)){
|
||||
if (!string_allowed(modname, MODNAME_ALLOWED_CHARS)) {
|
||||
errorstream<<"Error loading mod \""<<modname
|
||||
<<"\": modname does not follow naming conventions: "
|
||||
<<"Only chararacters [a-z0-9_] are allowed."<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
|
||||
try{
|
||||
success = loadScript(scriptpath);
|
||||
}
|
||||
catch(LuaError &e){
|
||||
errorstream<<"Error loading mod \""<<modname
|
||||
<<"\": "<<e.what()<<std::endl;
|
||||
}
|
||||
|
||||
return success;
|
||||
return loadScript(scriptpath);
|
||||
}
|
||||
|
||||
bool ScriptApiBase::loadScript(const std::string &scriptpath)
|
||||
|
|
|
@ -885,7 +885,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
|
|||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_get_scriptdir(lua_State *L)
|
||||
int ModApiMainMenu::l_get_mainmenu_path(lua_State *L)
|
||||
{
|
||||
GUIEngine* engine = getGuiEngine(L);
|
||||
assert(engine != 0);
|
||||
|
@ -1077,7 +1077,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
|
|||
API_FCT(delete_dir);
|
||||
API_FCT(copy_dir);
|
||||
API_FCT(extract_zip);
|
||||
API_FCT(get_scriptdir);
|
||||
API_FCT(get_mainmenu_path);
|
||||
API_FCT(show_file_open_dialog);
|
||||
API_FCT(get_version);
|
||||
API_FCT(download_file);
|
||||
|
|
|
@ -107,7 +107,7 @@ private:
|
|||
|
||||
//filesystem
|
||||
|
||||
static int l_get_scriptdir(lua_State *L);
|
||||
static int l_get_mainmenu_path(lua_State *L);
|
||||
|
||||
static int l_get_modpath(lua_State *L);
|
||||
|
||||
|
|
|
@ -350,14 +350,8 @@ int ModApiServer::l_get_modpath(lua_State *L)
|
|||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
std::string modname = luaL_checkstring(L, 1);
|
||||
// Do it
|
||||
if(modname == "__builtin"){
|
||||
std::string path = getServer(L)->getBuiltinLuaPath();
|
||||
lua_pushstring(L, path.c_str());
|
||||
return 1;
|
||||
}
|
||||
const ModSpec *mod = getServer(L)->getModSpec(modname);
|
||||
if(!mod){
|
||||
if (!mod) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "common/c_content.h"
|
||||
#include "cpp_api/s_async.h"
|
||||
#include "debug.h"
|
||||
#include "porting.h"
|
||||
#include "log.h"
|
||||
#include "tool.h"
|
||||
#include "settings.h"
|
||||
|
@ -274,6 +275,14 @@ int ModApiUtil::l_is_yes(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int ModApiUtil::l_get_builtin_path(lua_State *L)
|
||||
{
|
||||
std::string path = porting::path_share + DIR_DELIM + "builtin";
|
||||
lua_pushstring(L, path.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void ModApiUtil::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(debug);
|
||||
|
@ -294,6 +303,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
|
|||
API_FCT(get_password_hash);
|
||||
|
||||
API_FCT(is_yes);
|
||||
|
||||
API_FCT(get_builtin_path);
|
||||
}
|
||||
|
||||
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
|
||||
|
@ -311,4 +322,7 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
|
|||
ASYNC_API_FCT(write_json);
|
||||
|
||||
ASYNC_API_FCT(is_yes);
|
||||
|
||||
ASYNC_API_FCT(get_builtin_path);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,9 @@ private:
|
|||
// is_yes(arg)
|
||||
static int l_is_yes(lua_State *L);
|
||||
|
||||
// get_scriptdir()
|
||||
static int l_get_builtin_path(lua_State *L);
|
||||
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include "scripting_game.h"
|
||||
#include "server.h"
|
||||
#include "filesys.h"
|
||||
#include "log.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
#include "lua_api/l_base.h"
|
||||
|
@ -54,6 +56,9 @@ GameScripting::GameScripting(Server* server)
|
|||
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_pushstring(L, DIR_DELIM);
|
||||
lua_setglobal(L, "DIR_DELIM");
|
||||
|
||||
// Create the main minetest table
|
||||
lua_newtable(L);
|
||||
lua_setglobal(L, "minetest");
|
||||
|
@ -70,6 +75,10 @@ GameScripting::GameScripting(Server* server)
|
|||
InitializeModApi(L, top);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Push builtin initialization type
|
||||
lua_pushstring(L, "game");
|
||||
lua_setglobal(L, "INIT");
|
||||
|
||||
infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include "scripting_mainmenu.h"
|
||||
#include "mods.h"
|
||||
#include "porting.h"
|
||||
#include "log.h"
|
||||
#include "filesys.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
|
@ -58,6 +60,10 @@ MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
|
|||
initializeModApi(L, top);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Push builtin initialization type
|
||||
lua_pushstring(L, "mainmenu");
|
||||
lua_setglobal(L, "INIT");
|
||||
|
||||
infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -294,9 +294,6 @@ Server::Server(
|
|||
errorstream << std::endl;
|
||||
}
|
||||
|
||||
// Path to builtin.lua
|
||||
std::string builtinpath = getBuiltinLuaPath() + DIR_DELIM + "builtin.lua";
|
||||
|
||||
// Lock environment
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
|
||||
|
@ -305,16 +302,13 @@ Server::Server(
|
|||
|
||||
m_script = new GameScripting(this);
|
||||
|
||||
std::string scriptpath = getBuiltinLuaPath() + DIR_DELIM "init.lua";
|
||||
|
||||
// Load and run builtin.lua
|
||||
infostream<<"Server: Loading builtin.lua [\""
|
||||
<<builtinpath<<"\"]"<<std::endl;
|
||||
bool success = m_script->loadMod(builtinpath, "__builtin");
|
||||
if(!success){
|
||||
errorstream<<"Server: Failed to load and run "
|
||||
<<builtinpath<<std::endl;
|
||||
throw ModError("Failed to load and run "+builtinpath);
|
||||
if (!m_script->loadScript(scriptpath)) {
|
||||
throw ModError("Failed to load and run " + scriptpath);
|
||||
}
|
||||
|
||||
|
||||
// Print 'em
|
||||
infostream<<"Server: Loading mods: ";
|
||||
for(std::vector<ModSpec>::iterator i = m_mods.begin();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue