From 1cd512913e4d4ad1fb43d4b6e3d7971bb6c67528 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 27 Apr 2014 17:55:49 -0400 Subject: Organize builtin into subdirectories --- src/script/cpp_api/s_async.cpp | 14 +++++++------- src/script/cpp_api/s_base.cpp | 20 +++++--------------- src/script/lua_api/l_mainmenu.cpp | 4 ++-- src/script/lua_api/l_mainmenu.h | 2 +- src/script/lua_api/l_server.cpp | 8 +------- src/script/lua_api/l_util.cpp | 14 ++++++++++++++ src/script/lua_api/l_util.h | 3 +++ src/script/scripting_game.cpp | 9 +++++++++ src/script/scripting_mainmenu.cpp | 6 ++++++ 9 files changed, 48 insertions(+), 32 deletions(-) (limited to 'src/script') diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 4feed3e56..64260fb3a 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -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 diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 774b3f51d..1a172fd31 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -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 \""<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; } diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index f26a88a93..b30bab292 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -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); } + diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h index 13357587a..d72978dc6 100644 --- a/src/script/lua_api/l_util.h +++ b/src/script/lua_api/l_util.h @@ -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); diff --git a/src/script/scripting_game.cpp b/src/script/scripting_game.cpp index b2c2150c6..fccd10722 100644 --- a/src/script/scripting_game.cpp +++ b/src/script/scripting_game.cpp @@ -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; } diff --git a/src/script/scripting_mainmenu.cpp b/src/script/scripting_mainmenu.cpp index dbf1fc45e..9afddd156 100644 --- a/src/script/scripting_mainmenu.cpp +++ b/src/script/scripting_mainmenu.cpp @@ -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; } -- cgit v1.2.3