diff --git a/stepmania/src/Actor.cpp b/stepmania/src/Actor.cpp index 786ba1b57c..b00007f85a 100644 --- a/stepmania/src/Actor.cpp +++ b/stepmania/src/Actor.cpp @@ -280,7 +280,7 @@ bool Actor::IsType( const CString &sType ) { Lua *L = LUA->Get(); this->PushSelf( L ); - bool bRet = CheckLuaObjectType( L, lua_gettop(L), sType, false ); + bool bRet = LuaBinding::CheckLuaObjectType( L, lua_gettop(L), sType, false ); lua_pop( L, 1 ); LUA->Release( L ); diff --git a/stepmania/src/LuaBinding.cpp b/stepmania/src/LuaBinding.cpp index 41b3c08731..babc0e84ce 100644 --- a/stepmania/src/LuaBinding.cpp +++ b/stepmania/src/LuaBinding.cpp @@ -8,7 +8,7 @@ // types (eg. "Actor.x(GAMESTATE, 10)"), which will crash or cause corruption. // #define FAST_LUA -void CreateMethodsTable( lua_State *L, const CString &sName ) +void LuaBinding::CreateMethodsTable( lua_State *L, const CString &sName ) { lua_pushlstring( L, sName.data(), sName.size() ); lua_rawget( L, LUA_GLOBALSINDEX ); @@ -26,7 +26,7 @@ void CreateMethodsTable( lua_State *L, const CString &sName ) * Get a userdata, and check that it's either szType or a type * derived from szType, by walking the __index chain. */ -bool CheckLuaObjectType( lua_State *L, int narg, const char *szType, bool bOptional ) +bool LuaBinding::CheckLuaObjectType( lua_State *L, int narg, const char *szType, bool bOptional ) { #if defined(FAST_LUA) if( bOptional ) @@ -77,7 +77,7 @@ bool CheckLuaObjectType( lua_State *L, int narg, const char *szType, bool bOptio } } -bool GetGlobalTable( Lua *L, bool bCreate ) +static bool GetGlobalTable( Lua *L, bool bCreate ) { lua_pushstring( L, "userdatas" ); lua_rawget( L, LUA_REGISTRYINDEX ); @@ -99,7 +99,7 @@ bool GetGlobalTable( Lua *L, bool bCreate ) /* The object is on the stack. It's either a table or a userdata. * If needed, associate the metatable; if a table, also add it to * the userdata table. */ -void ApplyDerivedType( Lua *L, const CString &sClassName, void *pSelf ) +void LuaBinding::ApplyDerivedType( Lua *L, const CString &sClassName, void *pSelf ) { int iTable = lua_gettop( L ); @@ -147,7 +147,7 @@ LuaClass::LuaClass() m_pSelf = NULL; } -void *GetUserdataFromGlobalTable( Lua *L, const char *szType, int iArg ) +void *LuaBinding::GetUserdataFromGlobalTable( Lua *L, const char *szType, int iArg ) { if( !GetGlobalTable(L, false) ) luaL_error( L, "stale %s referenced (object used but no longer exists)", szType ); @@ -256,7 +256,7 @@ void LuaClass::Register() { Lua *L = LUA->Get(); this->PushSelf(L); - ApplyDerivedType( L, m_sClassName, m_pSelf ); + LuaBinding::ApplyDerivedType( L, m_sClassName, m_pSelf ); LUA->Release( L ); /* To conserve memory, clear the class name. We only need it while restoring. */ diff --git a/stepmania/src/LuaBinding.h b/stepmania/src/LuaBinding.h index e3fc9c55cc..dd1eb9c332 100644 --- a/stepmania/src/LuaBinding.h +++ b/stepmania/src/LuaBinding.h @@ -6,10 +6,13 @@ #include "LuaManager.h" class LuaReference; -void CreateMethodsTable( lua_State *L, const CString &szName ); -bool CheckLuaObjectType( lua_State *L, int narg, const char *szType, bool bOptional=false ); -void *GetUserdataFromGlobalTable( Lua *L, const char *szType, int iArg ); -void ApplyDerivedType( Lua *L, const CString &sClassname, void *pSelf ); +namespace LuaBinding +{ + void CreateMethodsTable( lua_State *L, const CString &szName ); + bool CheckLuaObjectType( lua_State *L, int narg, const char *szType, bool bOptional=false ); + void *GetUserdataFromGlobalTable( Lua *L, const char *szType, int iArg ); + void ApplyDerivedType( Lua *L, const CString &sClassname, void *pSelf ); +}; template class Luna @@ -27,7 +30,7 @@ public: static void Register( Lua *L ) { /* Create the methods table, if it doesn't already exist. */ - CreateMethodsTable( L, m_sClassName ); + LuaBinding::CreateMethodsTable( L, m_sClassName ); int methods = lua_gettop( L ); @@ -79,7 +82,7 @@ public: // were called before the Register() of the base class; we'll fill // it in when we get to it. lua_pushliteral( L, "__index" ); - CreateMethodsTable( L, m_sBaseClassName ); + LuaBinding::CreateMethodsTable( L, m_sBaseClassName ); lua_settable( L, methods_metatable ); } @@ -96,7 +99,7 @@ public: // Get userdata from the Lua stack and return a pointer to T object. static T *check( lua_State *L, int narg, bool bIsSelf = false ) { - if( !CheckLuaObjectType(L, narg, m_sClassName, true) ) + if( !LuaBinding::CheckLuaObjectType(L, narg, m_sClassName, true) ) { if( bIsSelf ) luaL_typerror( L, narg, m_sClassName ); @@ -112,7 +115,7 @@ public: /* The stack has a userdata or a table. If it's a table, look up the associated userdata. */ if( lua_istable(L, narg) ) { - return (T *) GetUserdataFromGlobalTable( L, m_sClassName, narg ); + return (T *) LuaBinding::GetUserdataFromGlobalTable( L, m_sClassName, narg ); } else if( lua_isuserdata(L, narg) ) { @@ -169,8 +172,8 @@ private: return 1; } - if( !CheckLuaObjectType(L, 1, m_sClassName) || - !CheckLuaObjectType(L, 2, m_sClassName) ) + if( !LuaBinding::CheckLuaObjectType(L, 1, m_sClassName) || + !LuaBinding::CheckLuaObjectType(L, 2, m_sClassName) ) { lua_pushboolean( L, false ); } @@ -228,17 +231,17 @@ protected: #define LUA_REGISTER_INSTANCED_BASE_CLASS( T ) \ LUA_REGISTER_CLASS_BASIC( T, none ) \ template<> void Luna::PushObject( Lua *L, T* p ) { p->m_pLuaInstance->PushSelf( L ); } \ - void T::PushSelf( lua_State *L ) { Luna::PushObject( L, this ); ApplyDerivedType( L, #T, this ); } + void T::PushSelf( lua_State *L ) { Luna::PushObject( L, this ); LuaBinding::ApplyDerivedType( L, #T, this ); } #define LUA_REGISTER_CLASS( T ) \ LUA_REGISTER_CLASS_BASIC( T, none ) \ template<> void Luna::PushObject( Lua *L, T* p ) { void **pData = (void **) lua_newuserdata( L, sizeof(void *) ); *pData = p; } \ - void T::PushSelf( lua_State *L ) { Luna::PushObject( L, this ); ApplyDerivedType( L, #T, this ); } + void T::PushSelf( lua_State *L ) { Luna::PushObject( L, this ); LuaBinding::ApplyDerivedType( L, #T, this ); } #define LUA_REGISTER_DERIVED_CLASS( T, B ) \ LUA_REGISTER_CLASS_BASIC( T, B ) \ template<> void Luna::PushObject( Lua *L, T* p ) { Luna::PushObject( L, p ); } \ - void T::PushSelf( lua_State *L ) { Luna::PushObject( L, this ); ApplyDerivedType( L, #T, this ); } + void T::PushSelf( lua_State *L ) { Luna::PushObject( L, this ); LuaBinding::ApplyDerivedType( L, #T, this ); } #define LUA_REGISTER_CLASS_BASIC( T, B ) \ template<> const char *Luna::m_sClassName = #T; \