public static VariableBase GetVariable(this Environment environment, string name) { VariableBase result = null; environment.Variables.TryGetValue(name, out result); return(result); }
public static object GetConstant(this Environment environment, string name) { object result = null; environment.Constants.TryGetValue(name, out result); return(result); }
///Wrap an object if wrapper available, within provided environment public static void Wrap(object o, Environment env) { var wrapper = DecoratorFactory.GetDecorator <IExpressionDecorator>(o); if (wrapper != null) { wrapper.Wrap(env); } }
static GlobalEnvironment() { env = new StagPoint.Eval.Environment(); env.AddConstant("Mathf", typeof(Mathf)); env.AddConstant("Vector2", typeof(Vector2)); env.AddConstant("Vector3", typeof(Vector3)); env.AddConstant("Quaternion", typeof(Quaternion)); env.AddConstant("Color", typeof(Color)); env.AddConstant("Slate", typeof(GlobalEnvironment)); }
public static void AddBoundProperty(this Environment environment, string name, object target, string propertyName) { var property = target.GetType().RTGetProperty(propertyName); if (property != null && !property.RTIsStatic()) { var boundVariable = new BoundVariable(name, target, property); environment.AddVariable(boundVariable); } }
public static void AddStaticMethod(this Environment environment, string name, System.Type type, string methodName) { var method = type.RTGetMethod(methodName); if (method != null && method.IsStatic) { var boundVariable = new BoundVariable(name, null, method); environment.AddVariable(boundVariable); } }
public static void AddStaticProperty(this Environment environment, string name, System.Type type, string propertyName) { var property = type.RTGetProperty(propertyName); if (property != null && property.RTIsStatic()) { var boundVariable = new BoundVariable(name, null, property); environment.AddVariable(boundVariable); } }
public static void AddBoundMethod(this Environment environment, string name, object target, string methodName) { var method = target.GetType().RTGetMethod(methodName); if (method != null && !method.IsStatic) { var boundVariable = new BoundVariable(name, target, method); environment.AddVariable(boundVariable); } }
///Compile an expression within target environment public static void CompileExpression(string scriptExpression, Environment environment, AnimatedParameter animParam, out Exception compileException, out Expression compiledExpression) { compiledExpression = null; compileException = null; if (string.IsNullOrEmpty(scriptExpression)) { return; } var expectedType = animParam.animatedType; try { compiledExpression = StagPoint.Eval.EvalEngine.Compile(scriptExpression, environment); if (compiledExpression.Type == typeof(void)) { throw new System.Exception(string.Format("Expression must return a value of type '{0}'", expectedType.FriendlyName())); } var value = compiledExpression.Execute(); if (value is object[]) { var arr = (value as object[]).Cast <float>().ToArray(); var requiredLength = animParam.parameterModel.RequiredCurvesCount(); if (arr.Length != requiredLength) { throw new System.Exception(string.Format("Result Expression Array returns '{0}' values, but '{1}' values are required.", arr.Length, requiredLength)); } } else { var valueType = value.GetType(); if (!expectedType.RTIsAssignableFrom(valueType)) { throw new System.Exception(string.Format("Result Expression Type is '{0}', but '{1}' is required.", valueType.FriendlyName(), expectedType.FriendlyName())); } } } catch (System.Exception exc) { compileException = exc; compiledExpression = null; } }
public static void AddStaticMethod(this Environment environment, string name, System.Type type, MethodInfo method) { var boundVariable = new BoundVariable(name, null, method); environment.AddVariable(boundVariable); }
public static void AddStaticProperty(this Environment environment, string name, System.Type type, PropertyInfo property) { var boundVariable = new BoundVariable(name, null, property); environment.AddVariable(boundVariable); }
public static void AddBoundMethod(this Environment environment, string name, object target, MethodInfo method) { var boundVariable = new BoundVariable(name, target, method); environment.AddVariable(boundVariable); }
public static void AddBoundProperty(this Environment environment, string name, object target, PropertyInfo property) { var boundVariable = new BoundVariable(name, target, property); environment.AddVariable(boundVariable); }
public static void AddDelegateMethod <T1, T2, T3, T4>(this Environment environment, string name, Action <T1, T2, T3, T4> callback) { environment.AddBoundMethod(name, callback.Target, callback.Method); }
///---------------------------------------------------------------------------------------------- public static void AddVariable(this Environment environment, string name, object target) { environment.AddVariable(name, target, target.GetType()); }
public static void AddDelegateMethod <TResult, T1, T2, T3, T4>(this Environment environment, string name, Func <T1, T2, T3, T4, TResult> callback) { environment.AddBoundMethod(name, callback.Target, callback.Method); }
public static void AddBoundMethod(this Environment environment, string name, object target, string methodName) { AddBoundMethod(environment, name, target, target.GetType().RTGetMethod(methodName)); }
public static void AddBoundProperty(this Environment environment, string name, object target, string propertyName) { AddBoundProperty(environment, name, target, target.GetType().RTGetProperty(propertyName)); }