diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 10c4766bf0..9afe216b6f 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -620,6 +620,24 @@ int LuaHelpers::TypeError( Lua *L, int iArgNo, const char *szName ) } } +namespace +{ + int lua_pushvalues( lua_State *L ) + { + int iArgs = lua_tointeger( L, lua_upvalueindex(1) ); + for( int i = 0; i < iArgs; ++i ) + lua_pushvalue( L, lua_upvalueindex(i+2) ); + return iArgs; + } +} + +void LuaHelpers::PushValueFunc( lua_State *L, int iArgs ) +{ + int iTop = lua_gettop( L ) - iArgs + 1; + lua_pushinteger( L, iArgs ); + lua_insert( L, iTop ); + lua_pushcclosure( L, lua_pushvalues, iArgs+1 ); +} LuaFunctionList::LuaFunctionList( RString name_, lua_CFunction func_ ) { diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index 28826924d2..5ef320fd59 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -76,6 +76,10 @@ namespace LuaHelpers /* If sStr begins with @, evaluate the rest as an expression and store the result over sStr. */ bool RunAtExpressionS( RString &sStr ); + /* Pops the last iArgs arguments from the stack, and return a function that returns + * those values. */ + void PushValueFunc( lua_State *L, int iArgs ); + template void Push( lua_State *L, T *pObject );