Allow passing a lua_State to PushStack; make them static.
Add SetGlobal(bool), UnsetGlobal, PushStackNil. Pass lua_State* to LUA_RETURN.
This commit is contained in:
@@ -1897,7 +1897,7 @@ int LuaFunc_UsingModifier( lua_State *L )
|
|||||||
|
|
||||||
const PlayerNumber pn = (PlayerNumber) (int(lua_tonumber( L, 1 ))-1);
|
const PlayerNumber pn = (PlayerNumber) (int(lua_tonumber( L, 1 ))-1);
|
||||||
const CString modifier = lua_tostring( L, 2 );
|
const CString modifier = lua_tostring( L, 2 );
|
||||||
LUA_RETURN( PlayerIsUsingModifier( pn, modifier ) );
|
LUA_RETURN( PlayerIsUsingModifier( pn, modifier ), L );
|
||||||
}
|
}
|
||||||
LuaFunction( UsingModifier );
|
LuaFunction( UsingModifier );
|
||||||
|
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ extern "C"
|
|||||||
const int val = (int) lua_tonumber( L, n ); \
|
const int val = (int) lua_tonumber( L, n ); \
|
||||||
LUA_ASSERT( val >= minimum && val <= maximum, ssprintf("Argument %i to " func " must be an integer between %i and %i (got %i)", n, minimum, maximum, val) ); \
|
LUA_ASSERT( val >= minimum && val <= maximum, ssprintf("Argument %i to " func " must be an integer between %i and %i (got %i)", n, minimum, maximum, val) ); \
|
||||||
}
|
}
|
||||||
#define LUA_RETURN( expr ) { LUA->PushStack( expr ); return 1; }
|
#define LUA_RETURN( expr, L ) { LUA->PushStack( expr, L ); return 1; }
|
||||||
|
|
||||||
/* Helpers to create common functions: */
|
/* Helpers to create common functions: */
|
||||||
/* Functions that take no arguments: */
|
/* Functions that take no arguments: */
|
||||||
#define LuaFunction_NoArgs( func, call ) \
|
#define LuaFunction_NoArgs( func, call ) \
|
||||||
int LuaFunc_##func( lua_State *L ) { \
|
int LuaFunc_##func( lua_State *L ) { \
|
||||||
REQ_ARGS( #func, 0 ); \
|
REQ_ARGS( #func, 0 ); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
|||||||
REQ_ARGS( #func, 1 ); \
|
REQ_ARGS( #func, 1 ); \
|
||||||
REQ_ARG( #func, 1, number ); \
|
REQ_ARG( #func, 1, number ); \
|
||||||
const int a1 = int(lua_tonumber( L, 1 )); \
|
const int a1 = int(lua_tonumber( L, 1 )); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
|||||||
REQ_ARG( #func, 2, number ); \
|
REQ_ARG( #func, 2, number ); \
|
||||||
const int a1 = int(lua_tonumber( L, 1 )); \
|
const int a1 = int(lua_tonumber( L, 1 )); \
|
||||||
const int a2 = int(lua_tonumber( L, 2 )); \
|
const int a2 = int(lua_tonumber( L, 2 )); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
|||||||
REQ_ARG( #func, 1, string ); \
|
REQ_ARG( #func, 1, string ); \
|
||||||
CString str; \
|
CString str; \
|
||||||
LUA->PopStack( str ); \
|
LUA->PopStack( str ); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
|||||||
CString str2; \
|
CString str2; \
|
||||||
LUA->PopStack( str2 ); \
|
LUA->PopStack( str2 ); \
|
||||||
LUA->PopStack( str1 ); \
|
LUA->PopStack( str1 ); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
|||||||
REQ_ARGS( #func, 1 ); \
|
REQ_ARGS( #func, 1 ); \
|
||||||
REQ_ARG_NUMBER_RANGE( #func, 1, 1, NUM_PLAYERS ); \
|
REQ_ARG_NUMBER_RANGE( #func, 1, 1, NUM_PLAYERS ); \
|
||||||
const PlayerNumber pn = (PlayerNumber) (int(lua_tonumber( L, -1 ))-1); \
|
const PlayerNumber pn = (PlayerNumber) (int(lua_tonumber( L, -1 ))-1); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
|
|
||||||
|
|||||||
@@ -53,29 +53,53 @@ const char *ChunkReaderString( lua_State *L, void *ptr, size_t *size )
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaManager::PushStack( int out )
|
void LuaManager::PushStackNil()
|
||||||
{
|
{
|
||||||
|
lua_pushnil( L );
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaManager::PushStack( int out, lua_State *L )
|
||||||
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
|
|
||||||
/* XXX: stack bounds */
|
/* XXX: stack bounds */
|
||||||
lua_pushnumber( L, out );
|
lua_pushnumber( L, out );
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaManager::PushStack( bool out )
|
void LuaManager::PushStack( bool out, lua_State *L )
|
||||||
{
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
|
|
||||||
/* XXX: stack bounds */
|
/* XXX: stack bounds */
|
||||||
lua_pushboolean( L, out );
|
lua_pushboolean( L, out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaManager::PushStack( float val, lua_State *L )
|
||||||
void LuaManager::PushStack( void *out )
|
|
||||||
{
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
|
|
||||||
|
/* XXX: stack bounds */
|
||||||
|
lua_pushnumber( L, val );
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaManager::PushStack( void *out, lua_State *L )
|
||||||
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
|
|
||||||
if( out )
|
if( out )
|
||||||
lua_pushlightuserdata( L, out );
|
lua_pushlightuserdata( L, out );
|
||||||
else
|
else
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaManager::PushStack( const CString &out )
|
void LuaManager::PushStack( const CString &out, lua_State *L )
|
||||||
{
|
{
|
||||||
|
if( L == NULL )
|
||||||
|
L = LUA->L;
|
||||||
lua_pushstring( L, out );
|
lua_pushstring( L, out );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,15 +35,20 @@ public:
|
|||||||
void Fail( const CString &err );
|
void Fail( const CString &err );
|
||||||
|
|
||||||
void SetGlobal( const CString &sName, int val ) { PushStack(val); SetGlobal( sName ); }
|
void SetGlobal( const CString &sName, int val ) { PushStack(val); SetGlobal( sName ); }
|
||||||
|
void SetGlobal( const CString &sName, bool val ) { PushStack(val); SetGlobal( sName ); }
|
||||||
|
void UnsetGlobal( const CString &sName ) { PushStackNil(); SetGlobal( sName ); }
|
||||||
|
|
||||||
void PushStack( bool val );
|
void PushStackNil();
|
||||||
void PushStack( int val );
|
static void PushStack( bool val, lua_State *L = NULL );
|
||||||
void PushStack( void *val );
|
static void PushStack( float val, lua_State *L = NULL );
|
||||||
void PushStack( const CString &val );
|
static void PushStack( int val, lua_State *L = NULL );
|
||||||
|
static void PushStack( void *val, lua_State *L = NULL );
|
||||||
|
static void PushStack( const CString &val, lua_State *L = NULL );
|
||||||
void PopStack( CString &out );
|
void PopStack( CString &out );
|
||||||
bool GetStack( int pos, int &out );
|
bool GetStack( int pos, int &out );
|
||||||
void SetGlobal( const CString &sName );
|
void SetGlobal( const CString &sName );
|
||||||
|
|
||||||
|
|
||||||
/* Run an expression. The result is left on the Lua stack. */
|
/* Run an expression. The result is left on the Lua stack. */
|
||||||
bool RunExpression( const CString &str );
|
bool RunExpression( const CString &str );
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
|
|||||||
@@ -1245,7 +1245,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
|||||||
REQ_ARG( #func, 1, lightuserdata ); \
|
REQ_ARG( #func, 1, lightuserdata ); \
|
||||||
const Song *p = (const Song *) (lua_touserdata( L, -1 )); \
|
const Song *p = (const Song *) (lua_touserdata( L, -1 )); \
|
||||||
LUA_ASSERT( CheckPointer(p), ssprintf("%p is not a valid song", p) ); \
|
LUA_ASSERT( CheckPointer(p), ssprintf("%p is not a valid song", p) ); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
|
|
||||||
@@ -1272,7 +1272,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
|||||||
REQ_ARG( #func, 1, lightuserdata ); \
|
REQ_ARG( #func, 1, lightuserdata ); \
|
||||||
const Steps *p = (const Steps *) (lua_touserdata( L, -1 )); \
|
const Steps *p = (const Steps *) (lua_touserdata( L, -1 )); \
|
||||||
LUA_ASSERT( CheckPointer(p), ssprintf("%p is not a valid steps", p) ); \
|
LUA_ASSERT( CheckPointer(p), ssprintf("%p is not a valid steps", p) ); \
|
||||||
LUA_RETURN( call ); \
|
LUA_RETURN( call, L ); \
|
||||||
} \
|
} \
|
||||||
LuaFunction( func ); /* register it */
|
LuaFunction( func ); /* register it */
|
||||||
LuaFunction_Steps( StepsMeter, p->GetMeter() );
|
LuaFunction_Steps( StepsMeter, p->GetMeter() );
|
||||||
|
|||||||
Reference in New Issue
Block a user