mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
Make LuaSmartRef properly non-copyable
Broken since 06e2836726
, which added LuaSmartRef. That it had absolutely not followed the rule of five at all didn't use to be a problem because it had only ever been in vectors that got resized only once throughout the lifetime of the program >_>
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
#pragma once
|
||||
#include "LuaCompat.h"
|
||||
#include <utility>
|
||||
|
||||
class LuaSmartRef
|
||||
{
|
||||
int ref = LUA_REFNIL;
|
||||
|
||||
public:
|
||||
LuaSmartRef() = default;
|
||||
LuaSmartRef(const LuaSmartRef &other) = delete;
|
||||
~LuaSmartRef();
|
||||
|
||||
LuaSmartRef(LuaSmartRef &&other) noexcept : LuaSmartRef()
|
||||
{
|
||||
swap(*this, other);
|
||||
}
|
||||
|
||||
LuaSmartRef &operator =(LuaSmartRef other)
|
||||
{
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Assign(lua_State *L, int index); // Copies the value before getting reference, stack unchanged.
|
||||
void Clear();
|
||||
int Push(lua_State *L); // Always pushes exactly one value, possibly nil.
|
||||
@@ -20,4 +35,10 @@ public:
|
||||
{
|
||||
return ref != LUA_REFNIL;
|
||||
}
|
||||
|
||||
friend void swap(LuaSmartRef &one, LuaSmartRef &other)
|
||||
{
|
||||
using std::swap;
|
||||
swap(one.ref, other.ref);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user