2021-10-29 21:25:12 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Luau/Common.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
template<typename T>
|
2024-03-09 00:47:53 +00:00
|
|
|
struct [[nodiscard]] ScopedFValue
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
Luau::FValue<T>* value = nullptr;
|
|
|
|
T oldValue = T();
|
|
|
|
|
|
|
|
public:
|
2023-12-02 07:46:57 +00:00
|
|
|
ScopedFValue(Luau::FValue<T>& fvalue, T newValue)
|
2021-10-29 21:25:12 +01:00
|
|
|
{
|
2023-12-02 07:46:57 +00:00
|
|
|
value = &fvalue;
|
|
|
|
oldValue = fvalue.value;
|
|
|
|
fvalue.value = newValue;
|
2021-10-29 21:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopedFValue(const ScopedFValue&) = delete;
|
|
|
|
ScopedFValue& operator=(const ScopedFValue&) = delete;
|
|
|
|
|
|
|
|
ScopedFValue(ScopedFValue&& rhs)
|
|
|
|
{
|
|
|
|
value = rhs.value;
|
|
|
|
oldValue = rhs.oldValue;
|
|
|
|
|
|
|
|
rhs.value = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedFValue& operator=(ScopedFValue&& rhs)
|
|
|
|
{
|
|
|
|
value = rhs.value;
|
|
|
|
oldValue = rhs.oldValue;
|
|
|
|
|
|
|
|
rhs.value = nullptr;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedFValue()
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
value->value = oldValue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using ScopedFastFlag = ScopedFValue<bool>;
|
|
|
|
using ScopedFastInt = ScopedFValue<int>;
|