using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using MoonSharp.Interpreter;
namespace RynthCore.Plugin.RynthLua;
///
/// UtilityBelt-style enum values for Lua.
///
/// Typed values (the enums in ): a table per value with
/// the raw fields __enum (the enum's name) and __value (its number), one table
/// per value per script, so == works by identity. They print as their name (flags as
/// "A, B"), compare and order with each other, add and subtract as numbers, concatenate as
/// text, and have ToNumber(), HasFlags(...), AddFlags(...) and
/// RemoveFlags(...) (the last two return typed values).
///
/// Plain-number enums get the same four helpers through a number metatable (numbers have no
/// fields otherwise; indexing a number with anything else is still an error).
///
internal static class LuaEnumValues
{
public const string EnumField = "__enum";
public const string ValueField = "__value";
private sealed class Def
{
public bool Flags;
public readonly Dictionary Names = new();
public readonly List<(string Name, long Value)> Members = new();
}
private sealed class Cache
{
public readonly Dictionary<(string, long), DynValue> Values = new();
public readonly Dictionary Metas = new(StringComparer.Ordinal);
}
private static readonly Dictionary Defs = new(StringComparer.Ordinal);
private static readonly object DefsLock = new();
private static readonly ConditionalWeakTable