Tweaks for tests, allow for grabbing global scope variables
This commit is contained in:
@@ -82,5 +82,18 @@ namespace Upsilon.BaseTypes.Number
|
||||
|
||||
#endregion
|
||||
|
||||
public static explicit operator double(Number n)
|
||||
{
|
||||
if (n.IsFloat)
|
||||
return ((NumberDouble) n);
|
||||
return ((NumberLong) n).Value;
|
||||
}
|
||||
|
||||
public static explicit operator long(Number n)
|
||||
{
|
||||
if (n.IsFloat)
|
||||
return (long)((NumberDouble) n).Value;
|
||||
return ((NumberLong) n).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,5 +51,22 @@ namespace Upsilon.Evaluator
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGet(string variable, out LuaType obj)
|
||||
{
|
||||
foreach (var luaType in _variables)
|
||||
{
|
||||
if (luaType.Key.Name == variable)
|
||||
{
|
||||
obj = luaType.Value;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
if (_parentScope != null)
|
||||
if (_parentScope.TryGet(variable, out obj))
|
||||
return true;
|
||||
obj = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Upsilon.BaseTypes;
|
||||
using Upsilon.BaseTypes.Number;
|
||||
using Upsilon.Binder;
|
||||
@@ -12,13 +11,7 @@ namespace Upsilon.Evaluator
|
||||
private LuaType _value;
|
||||
private readonly EvaluationScope _scope;
|
||||
|
||||
public Evaluator(Diagnostics diagnostics, Dictionary<VariableSymbol, LuaType> vars)
|
||||
{
|
||||
_diagnostics = diagnostics;
|
||||
_scope = new EvaluationScope(vars);
|
||||
}
|
||||
|
||||
private Evaluator(Diagnostics diagnostics, EvaluationScope parentScope)
|
||||
internal Evaluator(Diagnostics diagnostics, EvaluationScope parentScope)
|
||||
{
|
||||
_diagnostics = diagnostics;
|
||||
_scope = new EvaluationScope(parentScope);
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Upsilon.Evaluator
|
||||
private readonly BlockStatementSyntax _parsed;
|
||||
public Diagnostics Diagnostics { get; }
|
||||
private Binder.Binder Binder { get; }
|
||||
public EvaluationScope Scope { get; }
|
||||
|
||||
public Script(string scriptString, Dictionary<VariableSymbol, LuaType> variables = null)
|
||||
{
|
||||
@@ -22,7 +23,8 @@ namespace Upsilon.Evaluator
|
||||
if (variables == null)
|
||||
variables = new Dictionary<VariableSymbol, LuaType>();
|
||||
Binder = new Binder.Binder(new BoundScope(variables, null), Diagnostics);
|
||||
Evaluator = new Evaluator( Diagnostics, variables);
|
||||
Scope = new EvaluationScope(variables);
|
||||
Evaluator = new Evaluator( Diagnostics, Scope);
|
||||
}
|
||||
|
||||
public BoundScript Bind()
|
||||
|
||||
Reference in New Issue
Block a user