fix build errors with gcc
This commit is contained in:
+47
-36
@@ -26,26 +26,6 @@ namespace LuaHelpers
|
|||||||
bool FromStack( int &Object, int iOffset, lua_State *L );
|
bool FromStack( int &Object, int iOffset, lua_State *L );
|
||||||
bool FromStack( void *&Object, int iOffset, lua_State *L );
|
bool FromStack( void *&Object, int iOffset, lua_State *L );
|
||||||
bool FromStack( CString &Object, int iOffset, lua_State *L );
|
bool FromStack( CString &Object, int iOffset, lua_State *L );
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void ReadArrayFromTable( vector<T> aOut, lua_State *L )
|
|
||||||
{
|
|
||||||
if( L == NULL )
|
|
||||||
L = LUA->L;
|
|
||||||
|
|
||||||
luaL_checktype( L, -1, LUA_TTABLE );
|
|
||||||
|
|
||||||
unsigned iCount = luaL_getn( L, -1 );
|
|
||||||
|
|
||||||
for( unsigned i = 0; i < iCount; ++i )
|
|
||||||
{
|
|
||||||
lua_rawgeti( L, -1, i+1 );
|
|
||||||
T value = T();
|
|
||||||
LuaHelpers::FromStack( value, -1, L );
|
|
||||||
aOut.push_back( value );
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LuaManager
|
class LuaManager
|
||||||
@@ -93,23 +73,7 @@ public:
|
|||||||
|
|
||||||
void PushStackNil();
|
void PushStackNil();
|
||||||
void PushNopFunction();
|
void PushNopFunction();
|
||||||
template<class T>
|
|
||||||
static void PushStack( const T &val, lua_State *L = NULL )
|
|
||||||
{
|
|
||||||
if( L == NULL )
|
|
||||||
L = LUA->L;
|
|
||||||
LuaHelpers::Push( val, L );
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
static bool PopStack( T &val, lua_State *L = NULL )
|
|
||||||
{
|
|
||||||
if( L == NULL )
|
|
||||||
L = LUA->L;
|
|
||||||
bool bRet = LuaHelpers::FromStack( val, -1, L );
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
bool GetStack( int pos, int &out );
|
bool GetStack( int pos, int &out );
|
||||||
void SetGlobal( const CString &sName );
|
void SetGlobal( const CString &sName );
|
||||||
|
|
||||||
@@ -120,8 +84,55 @@ public:
|
|||||||
static void ReadArrayFromTableB( vector<bool> &aOut, lua_State *L = NULL );
|
static void ReadArrayFromTableB( vector<bool> &aOut, lua_State *L = NULL );
|
||||||
|
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
|
template<class T>
|
||||||
|
static void PushStack( const T &val, lua_State *L = NULL );
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
static bool PopStack( T &val, lua_State *L = NULL );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace LuaHelpers
|
||||||
|
{
|
||||||
|
template<class T>
|
||||||
|
void ReadArrayFromTable( vector<T> aOut, lua_State *L )
|
||||||
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
|
|
||||||
|
luaL_checktype( L, -1, LUA_TTABLE );
|
||||||
|
|
||||||
|
unsigned iCount = luaL_getn( L, -1 );
|
||||||
|
|
||||||
|
for( unsigned i = 0; i < iCount; ++i )
|
||||||
|
{
|
||||||
|
lua_rawgeti( L, -1, i+1 );
|
||||||
|
T value = T();
|
||||||
|
LuaHelpers::FromStack( value, -1, L );
|
||||||
|
aOut.push_back( value );
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void LuaManager::PushStack( const T &val, lua_State *L)
|
||||||
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
|
LuaHelpers::Push( val, L );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
bool LuaManager::PopStack( T &val, lua_State *L)
|
||||||
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
|
bool bRet = LuaHelpers::FromStack( val, -1, L );
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void CreateTableFromArray( const vector<T> &aIn, lua_State *L )
|
void CreateTableFromArray( const vector<T> &aIn, lua_State *L )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,6 +31,29 @@ enum Message
|
|||||||
};
|
};
|
||||||
const CString& MessageToString( Message m );
|
const CString& MessageToString( Message m );
|
||||||
|
|
||||||
|
class MessageManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MessageManager();
|
||||||
|
~MessageManager();
|
||||||
|
|
||||||
|
void Subscribe( IMessageSubscriber* pSubscriber, const CString& sMessage );
|
||||||
|
void Subscribe( IMessageSubscriber* pSubscriber, Message m );
|
||||||
|
void Unsubscribe( IMessageSubscriber* pSubscriber, const CString& sMessage );
|
||||||
|
void Unsubscribe( IMessageSubscriber* pSubscriber, Message m );
|
||||||
|
void Broadcast( const CString& sMessage ) const;
|
||||||
|
void Broadcast( Message m ) const;
|
||||||
|
|
||||||
|
// Lua
|
||||||
|
void PushSelf( lua_State *L );
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef set<IMessageSubscriber*> SubscribersSet;
|
||||||
|
map<CString,SubscribersSet> m_MessageToSubscribers;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern MessageManager* MESSAGEMAN; // global and accessable from anywhere in our program
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class BroadcastOnChange
|
class BroadcastOnChange
|
||||||
{
|
{
|
||||||
@@ -91,30 +114,6 @@ public:
|
|||||||
BroadcastOnChangePtr<T>& operator[]( unsigned i ) { return val[i]; }
|
BroadcastOnChangePtr<T>& operator[]( unsigned i ) { return val[i]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessageManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MessageManager();
|
|
||||||
~MessageManager();
|
|
||||||
|
|
||||||
void Subscribe( IMessageSubscriber* pSubscriber, const CString& sMessage );
|
|
||||||
void Subscribe( IMessageSubscriber* pSubscriber, Message m );
|
|
||||||
void Unsubscribe( IMessageSubscriber* pSubscriber, const CString& sMessage );
|
|
||||||
void Unsubscribe( IMessageSubscriber* pSubscriber, Message m );
|
|
||||||
void Broadcast( const CString& sMessage ) const;
|
|
||||||
void Broadcast( Message m ) const;
|
|
||||||
|
|
||||||
// Lua
|
|
||||||
void PushSelf( lua_State *L );
|
|
||||||
|
|
||||||
private:
|
|
||||||
typedef set<IMessageSubscriber*> SubscribersSet;
|
|
||||||
map<CString,SubscribersSet> m_MessageToSubscribers;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
extern MessageManager* MESSAGEMAN; // global and accessable from anywhere in our program
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user