Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

LuaFunctions.h File Reference

#include "LuaManager.h"
#include "RageUtil.h"
#include <lua.h>
#include <lualib.h>

Go to the source code of this file.

Classes

struct  LuaFunctionList

Defines

#define LUA_ASSERT(expr, err)   if( !(expr) ) { LUA->Fail( err ); }
#define REQ_ARGS(func, need)
#define REQ_ARGS_BETWEEN(func, minargs, maxargs)
#define REQ_ARG(func, n, type)
#define REQ_ARG_NUMBER_RANGE(func, n, minimum, maximum)
#define LUA_RETURN(expr)   { LUA->PushStack( expr ); return 1; }
#define LuaFunction_NoArgs(func, call)
#define LuaFunction_Int(func, call)
#define LuaFunction_IntInt(func, call)
#define LuaFunction_Str(func, call)
#define LuaFunction_StrStr(func, call)
#define LuaFunction_PlayerNumber(func, call)
#define LuaFunction_PlayerNumber_OptInt(func, def, call)
#define LuaFunction(func)   static LuaFunctionList g_##func( #func, LuaFunc_##func )

Variables

LuaFunctionListg_LuaFunctionList


Define Documentation

#define LUA_ASSERT expr,
err   )     if( !(expr) ) { LUA->Fail( err ); }
 

#define LUA_RETURN expr   )     { LUA->PushStack( expr ); return 1; }
 

#define LuaFunction func   )     static LuaFunctionList g_##func( #func, LuaFunc_##func )
 

#define LuaFunction_Int func,
call   ) 
 

Value:

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 ); \ } \ LuaFunction( func ); /* register it */

#define LuaFunction_IntInt func,
call   ) 
 

Value:

int LuaFunc_##func( lua_State *L ) { \ REQ_ARGS( #func, 2 ); \ REQ_ARG( #func, 1, number ); \ REQ_ARG( #func, 2, number ); \ const int a1 = int(lua_tonumber( L, 1 )); \ const int a2 = int(lua_tonumber( L, 2 )); \ LUA_RETURN( call ); \ } \ LuaFunction( func ); /* register it */

#define LuaFunction_NoArgs func,
call   ) 
 

Value:

int LuaFunc_##func( lua_State *L ) { \ REQ_ARGS( #func, 0 ); \ LUA_RETURN( call ); \ } \ LuaFunction( func ); /* register it */

#define LuaFunction_PlayerNumber func,
call   ) 
 

Value:

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 ); \ } \ LuaFunction( func ); /* register it */

#define LuaFunction_PlayerNumber_OptInt func,
def,
call   ) 
 

Value:

int LuaFunc_##func( lua_State *L ) { \ REQ_ARGS_BETWEEN( #func, 1, 2 ); \ REQ_ARG_NUMBER_RANGE( #func, 1, 1, NUM_PLAYERS ); \ const PlayerNumber pn = (PlayerNumber) (int(lua_tonumber( L, 1 ))-1); \ int a1 = def; \ LUA->GetStack( L, 2, a1 ); \ }

#define LuaFunction_Str func,
call   ) 
 

Value:

int LuaFunc_##func( lua_State *L ) { \ REQ_ARGS( #func, 1 ); \ REQ_ARG( #func, 1, string ); \ CString str; \ LUA->PopStack( str ); \ LUA_RETURN( call ); \ } \ LuaFunction( func ); /* register it */

#define LuaFunction_StrStr func,
call   ) 
 

Value:

int LuaFunc_##func( lua_State *L ) { \ REQ_ARGS( #func, 2 ); \ REQ_ARG( #func, 1, string ); \ REQ_ARG( #func, 2, string ); \ CString str1; \ CString str2; \ LUA->PopStack( str2 ); \ LUA->PopStack( str1 ); \ LUA_RETURN( call ); \ } \ LuaFunction( func ); /* register it */

#define REQ_ARG func,
n,
type   ) 
 

Value:

{ \ LUA_ASSERT( lua_is##type(L, n), ssprintf("Argument %i to " func " must be %s", n, #type) ); }

#define REQ_ARG_NUMBER_RANGE func,
n,
minimum,
maximum   ) 
 

Value:

{ \ REQ_ARG(func, n, number); \ 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 REQ_ARGS func,
need   ) 
 

Value:

{ \ const int args = lua_gettop(L); \ LUA_ASSERT( args == need, ssprintf( func " requires exactly %i argument%s, got %i", need, need == 1? "":"s", args) ); \ }

#define REQ_ARGS_BETWEEN func,
minargs,
maxargs   ) 
 

Value:

{ \ const int args = lua_gettop(L); \ LUA_ASSERT( args < minargs, ssprintf( func " requires between %i and %i argument%s, got %i", \ minargs, maxargs, maxargs == 1? "":"s", args) ); \ }


Variable Documentation

LuaFunctionList* g_LuaFunctionList
 


Generated on Thu Jan 27 20:57:42 2005 for StepMania by doxygen 1.3.7