From 5ef0d4159d388baddcdab9043c0c8d7545d200e7 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 19 Jan 2005 23:36:15 +0000 Subject: [PATCH] Load global Lua scripts. This is appropriate for global scripts which are loaded only once, and used multiple times: the scripts can safely affect global state (eg. override functions), and stay in memory. There's no way to unload them short of resetting the Lua state. It's not appropriate for one-shot scripts, such as those that might be associated with BGAnimations. (needs more work) --- stepmania/src/ThemeManager.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 2be1030f6e..64c8ebc750 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -276,6 +276,8 @@ void ThemeManager::SwitchThemeAndLanguage( const CString &sThemeName, const CStr void ThemeManager::UpdateLuaGlobals() { + LUA->Init(); + /* Important: explicitly refresh cached metrics that we use. */ THEME_SCREEN_WIDTH.Read(); THEME_SCREEN_HEIGHT.Read(); @@ -288,6 +290,24 @@ void ThemeManager::UpdateLuaGlobals() LUA->SetGlobal( "SCREEN_BOTTOM", (int) SCREEN_BOTTOM ); LUA->SetGlobal( "SCREEN_CENTER_X", (int) SCREEN_CENTER_X ); LUA->SetGlobal( "SCREEN_CENTER_Y", (int) SCREEN_CENTER_Y ); + + /* Run all script files in Lua for all themes. Start from the deepest fallback + * theme and work outwards. */ + deque::const_iterator iter = g_vThemes.end(); + --iter; + do + { + const CString &sThemeDir = GetThemeDirFromName( iter->sThemeName ); + CStringArray asElementPaths; + GetDirListing( sThemeDir + "Lua/*.lua", asElementPaths, false, true ); + for( unsigned i = 0; i < asElementPaths.size(); ++i ) + { + const CString &sPath = asElementPaths[i]; + LOG->Trace( "Loading \"%s\" ...", sPath.c_str() ); + LUA->RunScriptFile( sPath ); + } + } + while( iter != g_vThemes.begin() ); } CString ThemeManager::GetThemeDirFromName( const CString &sThemeName )