mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
40 lines
714 B
C
40 lines
714 B
C
|
// 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 <stdexcept>
|
||
|
|
||
|
namespace Luau
|
||
|
{
|
||
|
|
||
|
struct RecursionCounter
|
||
|
{
|
||
|
RecursionCounter(int* count)
|
||
|
: count(count)
|
||
|
{
|
||
|
++(*count);
|
||
|
}
|
||
|
|
||
|
~RecursionCounter()
|
||
|
{
|
||
|
LUAU_ASSERT(*count > 0);
|
||
|
--(*count);
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
int* count;
|
||
|
};
|
||
|
|
||
|
struct RecursionLimiter : RecursionCounter
|
||
|
{
|
||
|
RecursionLimiter(int* count, int limit)
|
||
|
: RecursionCounter(count)
|
||
|
{
|
||
|
if (limit > 0 && *count > limit)
|
||
|
throw std::runtime_error("Internal recursion counter limit exceeded");
|
||
|
}
|
||
|
};
|
||
|
|
||
|
} // namespace Luau
|