2018-11-17 18:13:05 +00:00
|
|
|
using System.Linq;
|
2018-11-19 11:17:21 +00:00
|
|
|
using Upsilon.Evaluator;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 11:17:21 +00:00
|
|
|
public LuaType Get(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;
|
|
|
|
}
|
|
|
|
return new LuaNull();
|
2018-11-18 13:18:24 +00:00
|
|
|
}
|
2018-11-17 18:13:05 +00:00
|
|
|
}
|
|
|
|
}
|