diff --git a/stepmania/src/LuaFunctions.h b/stepmania/src/LuaFunctions.h index 13d6a69a2b..70389e0af8 100644 --- a/stepmania/src/LuaFunctions.h +++ b/stepmania/src/LuaFunctions.h @@ -11,11 +11,20 @@ extern "C" /* Argument helpers: */ #define LUA_ASSERT( expr, err ) if( !(expr) ) { Lua::Fail( L, err ); } -/* require exactly n arguments */ + +/* Require exactly "need" arguments. */ #define REQ_ARGS(func, need) { \ const int args = lua_gettop(L); \ LUA_ASSERT( args == need, ssprintf( func " requires exactly %i argument%s, got %i", need, need == 1? "":"s", args) ); \ } + +/* Require between minargs and maxargs arguments. */ +#define REQ_ARGS_BETWEEN(func, minargs, maxargs) { \ + 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) ); \ +} + /* argument n must be of type "type" */ #define REQ_ARG(func, n, type) { \ LUA_ASSERT( lua_is##type(L, n), ssprintf("Argument %i to " func " must be %s", n, #type) ); } @@ -67,6 +76,15 @@ int LuaFunc_##func( lua_State *L ) { \ } \ LuaFunction( func ); /* register it */ +/* Functions that take a single PlayerNumber argument and an optional integer: */ +#define LuaFunction_PlayerNumber_OptInt( func, def, call ) \ +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 ); \ +} /* Linked list of functions we make available to Lua. */ struct LuaFunctionList