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 CString modifier = lua_tostring( L, 2 );
|
||||
LUA_RETURN( PlayerIsUsingModifier( pn, modifier ) );
|
||||
LUA_RETURN( PlayerIsUsingModifier( pn, modifier ), L );
|
||||
}
|
||||
LuaFunction( UsingModifier );
|
||||
|
||||
|
||||
@@ -35,14 +35,14 @@ extern "C"
|
||||
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) ); \
|
||||
}
|
||||
#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: */
|
||||
/* Functions that take no arguments: */
|
||||
#define LuaFunction_NoArgs( func, call ) \
|
||||
int LuaFunc_##func( lua_State *L ) { \
|
||||
REQ_ARGS( #func, 0 ); \
|
||||
LUA_RETURN( call ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
@@ -51,7 +51,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
REQ_ARGS( #func, 1 ); \
|
||||
REQ_ARG( #func, 1, number ); \
|
||||
const int a1 = int(lua_tonumber( L, 1 )); \
|
||||
LUA_RETURN( call ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
@@ -62,7 +62,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
REQ_ARG( #func, 2, number ); \
|
||||
const int a1 = int(lua_tonumber( L, 1 )); \
|
||||
const int a2 = int(lua_tonumber( L, 2 )); \
|
||||
LUA_RETURN( call ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
@@ -72,7 +72,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
REQ_ARG( #func, 1, string ); \
|
||||
CString str; \
|
||||
LUA->PopStack( str ); \
|
||||
LUA_RETURN( call ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
@@ -85,7 +85,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
CString str2; \
|
||||
LUA->PopStack( str2 ); \
|
||||
LUA->PopStack( str1 ); \
|
||||
LUA_RETURN( call ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
@@ -95,7 +95,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
REQ_ARGS( #func, 1 ); \
|
||||
REQ_ARG_NUMBER_RANGE( #func, 1, 1, NUM_PLAYERS ); \
|
||||
const PlayerNumber pn = (PlayerNumber) (int(lua_tonumber( L, -1 ))-1); \
|
||||
LUA_RETURN( call ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
|
||||
@@ -53,29 +53,53 @@ const char *ChunkReaderString( lua_State *L, void *ptr, size_t *size )
|
||||
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 */
|
||||
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 */
|
||||
lua_pushboolean( L, out );
|
||||
}
|
||||
|
||||
|
||||
void LuaManager::PushStack( void *out )
|
||||
void LuaManager::PushStack( float val, lua_State *L )
|
||||
{
|
||||
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 )
|
||||
lua_pushlightuserdata( L, out );
|
||||
else
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -35,15 +35,20 @@ public:
|
||||
void Fail( const CString &err );
|
||||
|
||||
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 PushStack( int val );
|
||||
void PushStack( void *val );
|
||||
void PushStack( const CString &val );
|
||||
void PushStackNil();
|
||||
static void PushStack( bool val, lua_State *L = NULL );
|
||||
static void PushStack( float val, lua_State *L = NULL );
|
||||
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 );
|
||||
bool GetStack( int pos, int &out );
|
||||
void SetGlobal( const CString &sName );
|
||||
|
||||
|
||||
/* Run an expression. The result is left on the Lua stack. */
|
||||
bool RunExpression( const CString &str );
|
||||
lua_State *L;
|
||||
|
||||
@@ -1245,7 +1245,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
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 ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
|
||||
@@ -1272,7 +1272,7 @@ int LuaFunc_##func( lua_State *L ) { \
|
||||
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 ); \
|
||||
LUA_RETURN( call, L ); \
|
||||
} \
|
||||
LuaFunction( func ); /* register it */
|
||||
LuaFunction_Steps( StepsMeter, p->GetMeter() );
|
||||
|
||||
Reference in New Issue
Block a user