diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs index 14eaf17707..816b45c8f5 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs @@ -7,7 +7,7 @@ using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { [Description("A library for setting and retrieving dynamic data that will be saved and loaded with savestates")] - public sealed class UserDataLibrary : LuaLibraryBase + public sealed class UserDataLibrary : DelegatingLuaLibrary { public UserDataLibrary(Lua lua) : base(lua) { } @@ -19,48 +19,22 @@ namespace BizHawk.Client.EmuHawk [LuaMethodExample("userdata.set(\"Unique key\", \"Current key data\");")] [LuaMethod("set", "adds or updates the data with the given key with the given value")] - public void Set(string name, object value) - { - if (value != null) - { - var t = value.GetType(); - if (!t.IsPrimitive && t != typeof(string)) - { - throw new InvalidOperationException("Invalid type for userdata"); - } - } - - Global.UserBag[name] = value; - } + public void Set(string name, object value) => APIs.UserData.Set(name, value); [LuaMethodExample("local obuseget = userdata.get( \"Unique key\" );")] [LuaMethod("get", "gets the data with the given key, if the key does not exist it will return nil")] - public object Get(string key) - { - return Global.UserBag.ContainsKey(key) - ? Global.UserBag[key] - : null; - } + public object Get(string key) => APIs.UserData.Get(key); [LuaMethodExample("userdata.clear( );")] [LuaMethod("clear", "clears all user data")] - public void Clear() - { - Global.UserBag.Clear(); - } + public void Clear() => APIs.UserData.Clear(); [LuaMethodExample("if ( userdata.remove( \"Unique key\" ) ) then\r\n\tconsole.log( \"remove the data with the given key.Returns true if the element is successfully found and removed; otherwise, false.\" );\r\nend;")] [LuaMethod("remove", "remove the data with the given key. Returns true if the element is successfully found and removed; otherwise, false.")] - public bool Remove(string key) - { - return Global.UserBag.Remove(key); - } + public bool Remove(string key) => APIs.UserData.Remove(key); [LuaMethodExample("if ( userdata.containskey( \"Unique key\" ) ) then\r\n\tconsole.log( \"returns whether or not there is an entry for the given key\" );\r\nend;")] [LuaMethod("containskey", "returns whether or not there is an entry for the given key")] - public bool ContainsKey(string key) - { - return Global.UserBag.ContainsKey(key); - } + public bool ContainsKey(string key) => APIs.UserData.ContainsKey(key); } }