Add `IUserDataApi.Keys`/`userdata.get_keys`
This commit is contained in:
parent
c2d5a9c931
commit
cba206efec
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -6,6 +8,14 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
private readonly IMovieSession _movieSession;
|
||||
|
||||
#if NET6_0
|
||||
public IReadOnlySet<string> Keys
|
||||
=> throw new NotImplementedException();
|
||||
#else
|
||||
public IReadOnlyCollection<string> Keys
|
||||
=> _movieSession.UserBag.Keys.ToList();
|
||||
#endif
|
||||
|
||||
public UserDataApi(IMovieSession movieSession) => _movieSession = movieSession;
|
||||
|
||||
/// <exception cref="InvalidOperationException">type of <paramref name="value"/> cannot be used in userdata</exception>
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
namespace BizHawk.Client.Common
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public interface IUserDataApi : IExternalApi
|
||||
{
|
||||
#if NET6_0
|
||||
IReadOnlySet<string> Keys { get; }
|
||||
#else
|
||||
IReadOnlyCollection<string> Keys { get; }
|
||||
#endif
|
||||
|
||||
void Set(string name, object value);
|
||||
object Get(string key);
|
||||
void Clear();
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using NLua;
|
||||
|
||||
// ReSharper disable UnusedMember.Global
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -37,5 +40,11 @@ namespace BizHawk.Client.Common
|
|||
[LuaMethod("containskey", "returns whether or not there is an entry for the given key")]
|
||||
public bool ContainsKey([LuaArbitraryStringParam] string key)
|
||||
=> APIs.UserData.ContainsKey(key);
|
||||
|
||||
[LuaMethodExample("console.writeline(#userdata.get_keys());")]
|
||||
[LuaMethod("get_keys", "returns a list-like table of valid keys")]
|
||||
[return: LuaArbitraryStringParam]
|
||||
public LuaTable GetKeys()
|
||||
=> _th.ListToTable((List<string>) APIs.UserData.Keys); //HACK cast will succeed as long as impl. returns Dictionary<K, V>.Keys.ToList() as IROC<K>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue