BizHawk/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs

67 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel;
using LuaInterface;
2017-05-09 18:19:55 +00:00
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 UserDataLibrary(Lua lua)
: base(lua) { }
public UserDataLibrary(Lua lua, Action<string> logOutputCallback)
: base(lua, logOutputCallback) { }
public override string Name => "userdata";
2017-04-15 20:37:30 +00:00
[LuaMethodAttributes(
"set",
2017-05-09 18:19:55 +00:00
"adds or updates the data with the given key with the given value")]
public void Set(string name, object value)
{
Global.UserBag[name] = value;
}
[LuaMethodAttributes(
"get",
2017-05-09 18:19:55 +00:00
"gets the data with the given key, if the key does not exist it will return nil")]
public object Get(string key)
{
if (Global.UserBag.ContainsKey(key))
{
return Global.UserBag[key];
}
return null;
}
[LuaMethodAttributes(
"clear",
2017-05-09 18:19:55 +00:00
"clears all user data")]
public void Clear()
{
Global.UserBag.Clear();
}
[LuaMethodAttributes(
"remove",
2017-05-09 18:19:55 +00:00
"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);
}
2015-07-02 18:29:19 +00:00
[LuaMethodAttributes(
"containskey",
2017-05-09 18:19:55 +00:00
"returns whether or not there is an entry for the given key")]
2015-07-02 18:29:19 +00:00
public bool ContainsKey(string key)
{
return Global.UserBag.ContainsKey(key);
}
}
}