let each file register its own constants with Lua
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
struct lua_State;
|
||||
typedef void (*RegisterWithLuaFn)(lua_State*);
|
||||
|
||||
|
||||
class LuaManager
|
||||
{
|
||||
public:
|
||||
@@ -69,6 +70,10 @@ public:
|
||||
|
||||
extern LuaManager *LUA;
|
||||
|
||||
#define REGISTER_WITH_LUA_FUNCTION( Fn ) \
|
||||
class Register##Fn { public: Register##Fn() { LuaManager::Register( Fn ); } }; \
|
||||
static Register##Fn register##Fn;
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,8 +3,16 @@
|
||||
#include "ThemeManager.h"
|
||||
#include "GameState.h"
|
||||
#include "CommonMetrics.h"
|
||||
#include "LuaManager.h"
|
||||
|
||||
|
||||
void LuaPlayerNumber(lua_State* L)
|
||||
{
|
||||
FOREACH_PlayerNumber( pn )
|
||||
LUA->SetGlobal( ssprintf("PLAYER_%d",pn+1), pn );
|
||||
}
|
||||
REGISTER_WITH_LUA_FUNCTION( LuaPlayerNumber );
|
||||
|
||||
PlayerNumber GetNextHumanPlayer( PlayerNumber pn )
|
||||
{
|
||||
for( PlayerNumber p=(PlayerNumber)(pn+1); p<NUM_PLAYERS; ((int&)p)++ )
|
||||
|
||||
@@ -282,8 +282,6 @@ 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 );
|
||||
FOREACH_PlayerNumber( pn )
|
||||
LUA->SetGlobal( ssprintf("PLAYER_%d",pn+1), pn );
|
||||
|
||||
/* Run all script files in Lua for all themes. Start from the deepest fallback
|
||||
* theme and work outwards. */
|
||||
|
||||
Reference in New Issue
Block a user