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)
This commit is contained in:
Glenn Maynard
2005-01-19 23:36:15 +00:00
parent dd3aa1c12e
commit 5ef0d4159d
+20
View File
@@ -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<Theme>::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 )