Fixes for require
This commit is contained in:
parent
520cd1ffcc
commit
7996420ee5
|
@ -62,18 +62,20 @@ namespace Upsilon.BaseTypes.ScriptFunction
|
|||
}
|
||||
}
|
||||
|
||||
object result;
|
||||
try
|
||||
{
|
||||
var result = method.Invoke(_object, objects.ToArray());
|
||||
if (_directTypeManipulation)
|
||||
return (ScriptType)result;
|
||||
return result.ToScriptType();
|
||||
result = method.Invoke(_object, objects.ToArray());
|
||||
}
|
||||
catch (TargetInvocationException e)
|
||||
{
|
||||
if (e.InnerException != null) throw e.InnerException;
|
||||
throw;
|
||||
}
|
||||
if (_directTypeManipulation)
|
||||
return (ScriptType)result;
|
||||
return result.ToScriptType();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Upsilon.Evaluator;
|
||||
|
||||
namespace Upsilon.BaseTypes.UserData
|
||||
{
|
||||
|
@ -11,7 +12,17 @@ namespace Upsilon.BaseTypes.UserData
|
|||
public UserDataMethodPart(MethodInfo method)
|
||||
{
|
||||
Method = method;
|
||||
Parameters = method.GetParameters().Select(x => new UserDataMethodParameter(x)).ToArray();
|
||||
var pars = method.GetParameters();
|
||||
var ls = new List<UserDataMethodParameter>();
|
||||
foreach (var parameter in pars)
|
||||
{
|
||||
if (parameter.ParameterType == typeof(Script))
|
||||
continue;
|
||||
if (parameter.ParameterType == typeof(EvaluationScope))
|
||||
continue;
|
||||
ls.Add(new UserDataMethodParameter(parameter));
|
||||
}
|
||||
Parameters = ls.ToArray();
|
||||
}
|
||||
|
||||
public MethodInfo Method { get; }
|
||||
|
|
|
@ -13,7 +13,9 @@ namespace Upsilon.Binder
|
|||
GreaterEquals,
|
||||
Greater,
|
||||
LessEquals,
|
||||
Less
|
||||
Less,
|
||||
And,
|
||||
Or
|
||||
}
|
||||
|
||||
private Type LeftType { get; }
|
||||
|
@ -59,6 +61,10 @@ namespace Upsilon.Binder
|
|||
new BoundBinaryOperator(OperatorKind.Equality, Type.Boolean),
|
||||
new BoundBinaryOperator(OperatorKind.Inequality, Type.Boolean),
|
||||
|
||||
// Boolean chaining
|
||||
new BoundBinaryOperator(OperatorKind.And, Type.Boolean),
|
||||
new BoundBinaryOperator(OperatorKind.Or, Type.Boolean),
|
||||
|
||||
// String operators
|
||||
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.String, Type.String),
|
||||
new BoundBinaryOperator(OperatorKind.Addition, Type.String, Type.Number, Type.String),
|
||||
|
@ -114,6 +120,12 @@ namespace Upsilon.Binder
|
|||
case SyntaxKind.GreaterEquals:
|
||||
kind = OperatorKind.GreaterEquals;
|
||||
break;
|
||||
case SyntaxKind.AndKeyword:
|
||||
kind = OperatorKind.And;
|
||||
break;
|
||||
case SyntaxKind.OrKeyword:
|
||||
kind = OperatorKind.Or;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown binary operator token: " + operatorToken);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace Upsilon.Binder.VariableSymbols
|
|||
if (!functionParameter.ValidTypes.HasFlag(callingParameter.Type))
|
||||
{
|
||||
return (false,
|
||||
$"Unexpected variable passed to internal function at position {i + 1}. " +
|
||||
$"Unexpected variable passed to internal function at variable {i + 1}. " +
|
||||
$"Expected one of the following: {functionParameter.ValidTypes.ToString()}, got: '{callingParameter.Type}'",
|
||||
callingParameter);
|
||||
}
|
||||
|
|
|
@ -359,6 +359,10 @@ namespace Upsilon.Evaluator
|
|||
ThrowException($"Can't find operator for types '{left.Type}' and '{right.Type}'", e.Span);
|
||||
return new ScriptNull();
|
||||
|
||||
case BoundBinaryOperator.OperatorKind.And:
|
||||
return new ScriptBoolean((ScriptBoolean) left && (ScriptBoolean) right);
|
||||
case BoundBinaryOperator.OperatorKind.Or:
|
||||
return new ScriptBoolean((ScriptBoolean) left || (ScriptBoolean) right);
|
||||
default:
|
||||
throw new Exception("Invalid Binary Operator: " + e.Operator);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace Upsilon
|
|||
public static Script ContinueWith(Script script, BoundScript bound)
|
||||
{
|
||||
var s = Script.ContinueWith(script, bound);
|
||||
s.Parse();
|
||||
s.Evaluate();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,9 @@ namespace Upsilon.StandardLibraries
|
|||
|
||||
[StandardLibraryScriptFunction("require", "Loads a module from the module path, using the given script loader.",
|
||||
true)]
|
||||
public ScriptType Require(Script script, string file)
|
||||
public ScriptType Require(Script script, ScriptString fileName)
|
||||
{
|
||||
var file = fileName.Value;
|
||||
var loader = script.Options.ScriptLoader;
|
||||
if (loader != null)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue