1 using MoonSharp.Interpreter;
2 using MoonSharp.Interpreter.Interop;
4 using System.Collections.Generic;
6 using System.Reflection;
10 partial class LuaCsSetup
16 protected Dictionary<string, TStore>
store;
18 public TStore
Set(
string name, TStore value) =>
store[name] = value;
23 public abstract bool Equals(T value);
30 public override bool Equals(
string value) =>
Name == value;
40 private HashSet<LuaModStore> luaModInterface;
41 private HashSet<CsModStore> csModInterface;
45 luaModInterface =
new HashSet<LuaModStore>();
46 csModInterface =
new HashSet<CsModStore>();
54 var msDesc = (StandardUserDataDescriptor)msType;
56 typeof(StandardUserDataDescriptor).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).ToList().ForEach(m =>
59 m.Name.Contains(
"Register")
62 msDesc.AddMember(m.Name, new MethodMemberDescriptor(m, InteropAccessMode.Default));
68 luaModInterface.Clear();
69 csModInterface.Clear();
74 if (luaModInterface.Any(i => i.Equals(modName)))
80 var newHandle =
new LuaModStore(
new Dictionary<string, DynValue>());
81 if (luaModInterface.Add(newHandle))
return newHandle;
87 if (csModInterface.Any(i => i.Equals(mod)))
89 LuaCsLogger.
HandleException(
new ArgumentException($
"'{mod.GetType().FullName}' entry already registered"), LuaCsMessageOrigin.CSharpMod);
93 var newHandle =
new CsModStore(
new Dictionary<string, object>());
94 if (csModInterface.Add(newHandle))
return newHandle;
99 var result = csModInterface.Where(i => i.Mod.GetType().FullName == modName).FirstOrDefault();
102 if (!result.Mod.IsDisposed)
return result;
105 csModInterface.Remove(result);
static void HandleException(Exception ex, LuaCsMessageOrigin origin)
CsModStore(Dictionary< string, object > store)
override bool Equals(ACsMod value)
LuaModStore(Dictionary< string, DynValue > store)
override bool Equals(string value)
Dictionary< string, TStore > store
TStore Set(string name, TStore value)
ModStore(Dictionary< string, TStore > store)
abstract bool Equals(T value)
CsModStore GetCsStore(string modName)
CsModStore Register(ACsMod mod)
LuaModStore Register(string modName)
LuaModStore GetLuaStore(string modName)