2023-03-09 19:40:14 +00:00
|
|
|
namespace tlang
|
|
|
|
{
|
|
|
|
public class MemberGetVariableValue : GetVariableValue
|
|
|
|
{
|
|
|
|
public Node Parent {get;set;}
|
|
|
|
public MemberGetVariableValue(Node parent,string text) : base(text)
|
|
|
|
{
|
|
|
|
Parent = parent;
|
|
|
|
}
|
2023-03-09 23:57:16 +00:00
|
|
|
public override void SetValue(IScopeEnvironment nodeEnv, TObject value)
|
|
|
|
{
|
|
|
|
var res=Parent.Execute(nodeEnv);
|
|
|
|
var dict = res as TDictionary;
|
|
|
|
if(dict != null)
|
|
|
|
{
|
|
|
|
if(dict.MemberExists($"set{Name}"))
|
|
|
|
{
|
|
|
|
var mbm= dict[$"set{Name}"] as ICallable;
|
|
|
|
if(mbm != null)
|
|
|
|
{
|
|
|
|
mbm.Call(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
dict[Name] = value;
|
|
|
|
}
|
2023-03-09 19:40:14 +00:00
|
|
|
|
2023-03-09 23:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-09 19:40:14 +00:00
|
|
|
public override TObject Execute(IScopeEnvironment nodeEnv)
|
|
|
|
{
|
|
|
|
var res=Parent.Execute(nodeEnv);
|
|
|
|
|
|
|
|
var dict = res as TDictionary;
|
|
|
|
var integer = res as TNumber;
|
|
|
|
var array = res as TArray;
|
2023-03-09 23:57:16 +00:00
|
|
|
var str = res as TString;
|
|
|
|
|
2023-03-09 19:40:14 +00:00
|
|
|
if(array != null)
|
|
|
|
{
|
|
|
|
if(Name == "length" || Name == "count")
|
|
|
|
{
|
|
|
|
return new TNumber(array.Items.Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(dict != null)
|
|
|
|
{
|
|
|
|
if(dict.MemberExists($"get{Name}"))
|
|
|
|
{
|
|
|
|
var mbm= dict[$"get{Name}"] as ICallable;
|
|
|
|
if(mbm != null)
|
|
|
|
return mbm.Call();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dict.MemberExists(Name))
|
|
|
|
{
|
|
|
|
return dict[Name];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(integer != null)
|
2023-03-09 23:57:16 +00:00
|
|
|
{
|
|
|
|
if(Name == "abs")
|
|
|
|
{
|
|
|
|
return new TNumber(Math.Abs(integer.Value));
|
|
|
|
}
|
|
|
|
if(Name == "int")
|
|
|
|
{
|
|
|
|
return new TNumber(Math.Round(integer.Value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(str != null)
|
2023-03-09 19:40:14 +00:00
|
|
|
{
|
|
|
|
|
2023-03-09 23:57:16 +00:00
|
|
|
if(Name == "number")
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
if(Name == "ittr")
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
if(Name == "length" || Name == "count")
|
|
|
|
{
|
|
|
|
return new TNumber(str.Value.Length);
|
|
|
|
}
|
|
|
|
if(Name == "list")
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2023-03-09 19:40:14 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 23:57:16 +00:00
|
|
|
|
2023-03-09 19:40:14 +00:00
|
|
|
return new TUninit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|