diff --git a/stepmania/src/LuaReference.cpp b/stepmania/src/LuaReference.cpp index 00d3fd9e38..91b481b8df 100644 --- a/stepmania/src/LuaReference.cpp +++ b/stepmania/src/LuaReference.cpp @@ -42,9 +42,14 @@ LuaReference &LuaReference::operator=( const LuaReference &cpy ) Unregister(); - /* Make a new reference. */ - lua_rawgeti( LUA->L, LUA_REGISTRYINDEX, cpy.m_iReference ); - m_iReference = luaL_ref( LUA->L, LUA_REGISTRYINDEX ); + if( cpy.m_iReference == LUA_NOREF ) + m_iReference = LUA_NOREF; + else + { + /* Make a new reference. */ + lua_rawgeti( LUA->L, LUA_REGISTRYINDEX, cpy.m_iReference ); + m_iReference = luaL_ref( LUA->L, LUA_REGISTRYINDEX ); + } return *this; } @@ -72,6 +77,11 @@ bool LuaReference::IsSet() const return m_iReference != LUA_NOREF; } +bool LuaReference::IsNil() const +{ + return m_iReference == LUA_REFNIL; +} + int LuaReference::GetLuaType() const { this->PushSelf( LUA->L ); diff --git a/stepmania/src/LuaReference.h b/stepmania/src/LuaReference.h index 427fb8e56c..25f7ba6b29 100644 --- a/stepmania/src/LuaReference.h +++ b/stepmania/src/LuaReference.h @@ -25,6 +25,7 @@ public: /* Return true if set. (SetFromNil() counts as being set.) */ bool IsSet() const; + bool IsNil() const; void Unset() { Unregister(); } /* Return the referenced type, or LUA_TNONE if not set. */