add pushing to vectors with any type
This commit is contained in:
@@ -104,7 +104,7 @@ void LuaManager::PushStack( const CString &out, lua_State *L )
|
||||
lua_pushstring( L, out );
|
||||
}
|
||||
|
||||
void LuaManager::CreateTableFromArray( const vector<bool> &aIn, lua_State *L )
|
||||
void LuaManager::CreateTableFromArrayB( const vector<bool> &aIn, lua_State *L )
|
||||
{
|
||||
if( L == NULL )
|
||||
L = LUA->L;
|
||||
@@ -117,7 +117,7 @@ void LuaManager::CreateTableFromArray( const vector<bool> &aIn, lua_State *L )
|
||||
}
|
||||
}
|
||||
|
||||
void LuaManager::ReadArrayFromTable( vector<bool> &aOut, lua_State *L )
|
||||
void LuaManager::ReadArrayFromTableB( vector<bool> &aOut, lua_State *L )
|
||||
{
|
||||
if( L == NULL )
|
||||
L = LUA->L;
|
||||
|
||||
@@ -61,13 +61,27 @@ public:
|
||||
|
||||
/* Create a Lua array (a table with indices starting at 1) of the given vector,
|
||||
* and push it on the stack. */
|
||||
static void CreateTableFromArray( const vector<bool> &aIn, lua_State *L = NULL );
|
||||
static void CreateTableFromArrayB( const vector<bool> &aIn, lua_State *L = NULL );
|
||||
/* Read the table at the top of the stack back into a vector. */
|
||||
static void ReadArrayFromTable( vector<bool> &aOut, lua_State *L = NULL );
|
||||
static void ReadArrayFromTableB( vector<bool> &aOut, lua_State *L = NULL );
|
||||
|
||||
lua_State *L;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void CreateTableFromArray( const vector<T> &aIn, lua_State *L )
|
||||
{
|
||||
if( L == NULL )
|
||||
L = LUA->L;
|
||||
|
||||
lua_newtable( L );
|
||||
for( unsigned i = 0; i < aIn.size(); ++i )
|
||||
{
|
||||
aIn[i]->PushSelf( L );
|
||||
lua_rawseti( L, -2, i+1 );
|
||||
}
|
||||
}
|
||||
|
||||
extern LuaManager *LUA;
|
||||
|
||||
#define REGISTER_WITH_LUA_FUNCTION( Fn ) \
|
||||
|
||||
@@ -612,7 +612,7 @@ void ScreenOptionsMaster::ImportOption( const OptionRowDefinition &row, const Op
|
||||
vbSelectedOut[i] = false;
|
||||
|
||||
/* Create the vbSelectedOut table. */
|
||||
LUA->CreateTableFromArray( vbSelectedOut );
|
||||
LUA->CreateTableFromArrayB( vbSelectedOut );
|
||||
ASSERT( lua_gettop(LUA->L) == 1 ); /* vbSelectedOut table */
|
||||
|
||||
/* Get the function to call from m_LuaTable. */
|
||||
@@ -640,7 +640,7 @@ void ScreenOptionsMaster::ImportOption( const OptionRowDefinition &row, const Op
|
||||
|
||||
lua_pop( LUA->L, 1 ); /* pop option table */
|
||||
|
||||
LUA->ReadArrayFromTable( vbSelectedOut );
|
||||
LUA->ReadArrayFromTableB( vbSelectedOut );
|
||||
if( m_OptionsNavigation == NAV_TOGGLE_THREE_KEY )
|
||||
vbSelectedOut.insert( vbSelectedOut.begin(), false );
|
||||
|
||||
@@ -751,7 +751,7 @@ int ScreenOptionsMaster::ExportOption( const OptionRowDefinition &row, const Opt
|
||||
vbSelectedCopy.erase( vbSelectedCopy.begin() );
|
||||
|
||||
/* Create the vbSelectedOut table. */
|
||||
LUA->CreateTableFromArray( vbSelectedCopy );
|
||||
LUA->CreateTableFromArrayB( vbSelectedCopy );
|
||||
ASSERT( lua_gettop(LUA->L) == 1 ); /* vbSelectedOut table */
|
||||
|
||||
/* Get the function to call. */
|
||||
|
||||
Reference in New Issue
Block a user