Upsilon/Upsilon/BaseTypes/LuaTable.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2018-11-17 18:13:05 +00:00
using System.Linq;
2018-11-19 15:22:13 +00:00
using Upsilon.Binder;
2018-11-19 11:17:21 +00:00
using Upsilon.Evaluator;
using Upsilon.Text;
2018-11-17 18:13:05 +00:00
namespace Upsilon.BaseTypes
{
2018-11-19 11:17:21 +00:00
internal class LuaTable : LuaType, IIndexable, IScopeOwner
2018-11-17 18:13:05 +00:00
{
2018-11-19 11:17:21 +00:00
public EvaluationScope EvaluationScope { get; }
2018-11-17 18:13:05 +00:00
2018-11-19 11:17:21 +00:00
public LuaTable(EvaluationScope scope)
2018-11-17 18:13:05 +00:00
{
2018-11-19 11:17:21 +00:00
EvaluationScope = scope;
2018-11-17 18:13:05 +00:00
}
public override Type Type => Type.Table;
public override object ToCSharpObject()
{
2018-11-19 11:49:48 +00:00
return EvaluationScope.Variables.ToDictionary(x => x.Key, x => x.Value.ToCSharpObject());
2018-11-17 18:13:05 +00:00
}
public LuaType Get(Diagnostics diagnostics, TextSpan span, string s, EvaluationScope scope)
2018-11-18 13:18:24 +00:00
{
2018-11-19 11:49:48 +00:00
if (EvaluationScope.TryGet(s, out var o))
2018-11-19 11:17:21 +00:00
{
return o;
}
diagnostics.LogError("Cannot find member 's' on Table", span);
2018-11-19 11:17:21 +00:00
return new LuaNull();
2018-11-18 13:18:24 +00:00
}
2018-11-19 15:22:13 +00:00
public void Set(Diagnostics diagnostics, TextSpan span, string s, LuaType value)
2018-11-19 15:22:13 +00:00
{
EvaluationScope.Set(new VariableSymbol(s, value.Type, false), value);
2018-11-19 15:22:13 +00:00
}
2018-11-17 18:13:05 +00:00
}
}