add Lua hooks

This commit is contained in:
Glenn Maynard
2004-02-14 23:26:32 +00:00
parent 6b55d6840c
commit dcd308edb7
3 changed files with 165 additions and 0 deletions
+47
View File
@@ -946,3 +946,50 @@ void SongManager::FreeAllLoadedFromProfiles()
}
}
static bool CheckPointer( const Song *p )
{
const vector<Song*> &songs = SONGMAN->GetAllSongs();
for( unsigned i = 0; i < songs.size(); ++i )
if( songs[i] == p )
return true;
return false;
}
#include "LuaFunctions.h"
#define LuaFunction_Song( func, call ) \
int LuaFunc_##func( lua_State *L ) { \
REQ_ARGS( #func, 1 ); \
REQ_ARG( #func, 1, lightuserdata ); \
const Song *p = (const Song *) (lua_touserdata( L, -1 )); \
LUA_ASSERT( CheckPointer(p), ssprintf("%p is not a valid song", p) ); \
LUA_RETURN( call ); \
} \
LuaFunction( func ); /* register it */
LuaFunction_Str( Song, SONGMAN->FindSong( str ) );
LuaFunction_Song( SongFullDisplayTitle, p->GetFullDisplayTitle() );
static bool CheckPointer( const Steps *p )
{
const vector<Song*> &songs = SONGMAN->GetAllSongs();
for( unsigned i = 0; i < songs.size(); ++i )
{
for( unsigned j = 0; j < songs.size(); ++j )
if( songs[i]->m_apNotes[j] == p )
return true;
}
return false;
}
#define LuaFunction_Steps( func, call ) \
int LuaFunc_##func( lua_State *L ) { \
REQ_ARGS( #func, 1 ); \
REQ_ARG( #func, 1, lightuserdata ); \
const Steps *p = (const Steps *) (lua_touserdata( L, -1 )); \
LUA_ASSERT( CheckPointer(p), ssprintf("%p is not a valid steps", p) ); \
LUA_RETURN( call ); \
} \
LuaFunction( func ); /* register it */
LuaFunction_Steps( StepsMeter, p->GetMeter() );