当前位置: 首页>>代码示例>>C#>>正文


C# ScriptProcessor类代码示例

本文整理汇总了C#中ScriptProcessor的典型用法代码示例。如果您正苦于以下问题:C# ScriptProcessor类的具体用法?C# ScriptProcessor怎么用?C# ScriptProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScriptProcessor类属于命名空间,在下文中一共展示了ScriptProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteMethod

        internal override SObject ExecuteMethod(ScriptProcessor processor, string methodName, SObject caller, SObject This, SObject[] parameters)
        {
            InitializeStatic();

            AddObjectPrototypeAsExtends(processor);

            bool isStaticCall = ReferenceEquals(caller, this);

            // Call any static function defined in this prototype:
            if (_prototypeMembers.ContainsKey(methodName) && _prototypeMembers[methodName].IsStatic)
            {
                if (_prototypeMembers[methodName].IsFunction)
                {
                    var cFunction = (SFunction)_prototypeMembers[methodName].Data;
                    return cFunction.Call(processor, caller, this, parameters); // For a static method, the "This" attribute is the prototype.
                }
                else
                {
                    return processor.ErrorHandler.ThrowError(ErrorType.TypeError, ErrorHandler.MESSAGE_TYPE_NOT_A_FUNCTION, methodName);
                }
            }

            // Call the super class prototype, if one exists:
            if (Extends != null)
            {
                return Extends.ExecuteMethod(processor, methodName, caller, This, parameters);
            }

            return processor.ErrorHandler.ThrowError(ErrorType.ReferenceError, ErrorHandler.MESSAGE_REFERENCE_NOT_DEFINED, methodName);
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:30,代码来源:Prototype.cs

示例2: GetVariable

 /// <summary>
 /// Returns the content of a variable, or Undefined, if the variable does not exist.
 /// </summary>
 public static SObject GetVariable(ScriptProcessor processor, string identifier)
 {
     if (processor.Context.IsVariable(identifier))
         return processor.Context.GetVariable(identifier).Data;
     else
         return processor.Undefined;
 }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:10,代码来源:ScriptContextManipulator.cs

示例3: AddOperator

        internal static string AddOperator(ScriptProcessor processor, SObject left, SObject right)
        {
            if (left is SString || right is SString)
            {
                string strLeft, strRight;

                if (left is SString)
                    strLeft = ((SString)left).Value;
                else
                    strLeft = left.ToString(processor).Value;

                if (right is SString)
                    strRight = ((SString)right).Value;
                else
                    strRight = right.ToString(processor).Value;

                return strLeft + strRight;
            }
            else
            {
                var numbers = GetNumericOperatorParameters(processor, left, right);

                return SNumber.ConvertToScriptString(numbers.Item1 + numbers.Item2);
            }
        }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:25,代码来源:ObjectOperators.cs

示例4: Create

        public static SObject Create(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            Prototype prototype = null;

            if (parameters.Length > 0)
            {
                var protoParam = parameters[0];
                if (protoParam.TypeOf() == LITERAL_TYPE_STRING)
                {
                    prototype = processor.Context.GetPrototype(((SString)protoParam).Value);
                }
                else if (IsPrototype(protoParam.GetType()))
                {
                    prototype = (Prototype)protoParam;
                }
                else
                {
                    return processor.ErrorHandler.ThrowError(ErrorType.TypeError, ErrorHandler.MESSAGE_REFERENCE_NO_PROTOTYPE, protoParam.TypeOf());
                }
            }

            if (prototype != null)
            {
                var instParams = new SObject[parameters.Length - 1];
                Array.Copy(parameters, 1, instParams, 0, parameters.Length - 1);

                return processor.Context.CreateInstance(prototype, instParams);
            }
            else
            {
                return processor.ErrorHandler.ThrowError(ErrorType.TypeError, ErrorHandler.MESSAGE_REFERENCE_NO_PROTOTYPE, LITERAL_UNDEFINED);
            }
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:33,代码来源:ObjectPrototype.cs

示例5: IndexerSet

        public static SObject IndexerSet(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var arr = (SArray)instance;

            if (parameters.Length >= 2)
            {
                var accessor = (int)parameters[0].ToNumber(processor).Value;

                if (accessor >= 0)
                {
                    if (accessor < arr.ArrayMembers.Length)
                    {
                        arr.ArrayMembers[accessor] = parameters[1];
                    }
                    else
                    {
                        var arrMembers = arr.ArrayMembers;
                        Array.Resize(ref arrMembers, accessor + 1);
                        arrMembers[accessor] = parameters[1];
                        arr.ArrayMembers = arrMembers;
                    }
                }
            }

            return processor.Undefined;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:26,代码来源:ArrayPrototype.cs

示例6: ToNumber

 internal override SNumber ToNumber(ScriptProcessor processor)
 {
     if (Value)
         return processor.CreateNumber(1);
     else
         return processor.CreateNumber(0);
 }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:7,代码来源:SBool.cs

示例7: GetMember

        internal override SObject GetMember(ScriptProcessor processor, SObject accessor, bool isIndexer)
        {
            if (isIndexer && accessor.TypeOf() == LITERAL_TYPE_NUMBER)
            {
                if (IndexerGetFunction != null)
                {
                    return IndexerGetFunction.Call(processor, this, this, new SObject[] { accessor });
                }
                else
                {
                    return processor.Undefined;
                }
            }

            string memberName;
            if (accessor is SString)
                memberName = ((SString)accessor).Value;
            else
                memberName = accessor.ToString(processor).Value;

            if (Members.ContainsKey(memberName))
            {
                return Members[memberName];
            }
            else if (Prototype != null && Prototype.HasMember(processor, memberName))
            {
                return Prototype.GetMember(processor, accessor, isIndexer);
            }
            else if (SuperClass != null)
            {
                return SuperClass.GetMember(processor, accessor, isIndexer);
            }

            return processor.Undefined;
        }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:35,代码来源:SProtoObject.cs

示例8: HasMember

 internal override bool HasMember(ScriptProcessor processor, string memberName)
 {
     if (_prototypeMembers.ContainsKey(memberName))
         return true;
     else
         return base.HasMember(processor, memberName);
 }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:7,代码来源:Prototype.cs

示例9: ErrorPrototype

        public ErrorPrototype(ScriptProcessor processor) : base("Error")
        {
            Constructor = new PrototypeMember(CLASS_METHOD_CTOR, new SFunction(constructor));

            AddMember(processor, new PrototypeMember(MEMBER_NAME_MESSAGE, processor.Undefined));
            AddMember(processor, new PrototypeMember(MEMBER_NAME_TYPE, processor.Undefined));
            AddMember(processor, new PrototypeMember(MEMBER_NAME_LINE, processor.Undefined));
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:8,代码来源:ErrorPrototype.cs

示例10: Parse

        /// <summary>
        /// Parses a string as an array.
        /// </summary>
        internal new static SObject Parse(ScriptProcessor processor, string exp)
        {
            // Format: [item1, item2, ... itemn]

            if (Regex.IsMatch(exp, REGEX_EMPTY_ARRAY)) return processor.CreateArray(0);

            exp = exp.Remove(exp.Length - 1, 1).Remove(0, 1).Trim(); // Remove [ and ].

            var elements = new List<SObject>();

            var elementStart = 0;
            var index = 0;
            var depth = 0;
            StringEscapeHelper escaper = new LeftToRightStringEscapeHelper(exp, 0);
            string element;

            while (index < exp.Length)
            {
                var t = exp[index];
                escaper.CheckStartAt(index);

                if (!escaper.IsString)
                {
                    if (t == '{' || t == '[' || t == '(')
                    {
                        depth++;
                    }
                    else if (t == '}' || t == ']' || t == ')')
                    {
                        depth--;
                    }
                    else if (t == ',' && depth == 0)
                    {
                        element = exp.Substring(elementStart, index - elementStart);
                        
                        if (string.IsNullOrWhiteSpace(element))
                            elements.Add(processor.Undefined);
                        else
                            elements.Add(processor.ExecuteStatement(new ScriptStatement(element)));

                        elementStart = index + 1;
                    }
                }

                index++;
            }

            element = exp.Substring(elementStart, index - elementStart);

            if (string.IsNullOrWhiteSpace(element))
                elements.Add(processor.Undefined);
            else
                elements.Add(processor.ExecuteStatement(new ScriptStatement(element)));

            return processor.CreateArray(elements.ToArray());
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:59,代码来源:SArray.cs

示例11: constructor

        private static SObject constructor(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var arr = (SArray)instance;

            var length = (int)((SNumber)parameters[0]).Value;
            arr.ArrayMembers = new SObject[length];

            Array.Copy(parameters, 1, arr.ArrayMembers, 0, parameters.Length - 1);
            return arr;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:10,代码来源:ArrayPrototype.cs

示例12: Translate

        /// <summary>
        /// Translates a .Net object to a script object.
        /// </summary>
        public static SObject Translate(ScriptProcessor processor, object objIn)
        {
            // todo: C# 7: put a swtich statement type match instead of aweful if case blocks.
            if (objIn == null)
            {
                return TranslateNull(processor);
            }

            if (objIn.GetType() == typeof(SObject) || objIn.GetType().IsSubclassOf(typeof(SObject)))
            {
                // this is already an SObject, return it.
                return (SObject)objIn;
            }

            if (objIn is sbyte || objIn is byte || objIn is short || objIn is ushort || objIn is int || objIn is uint || objIn is long || objIn is ulong || objIn is float || objIn is double)
            {
                return TranslateNumber(processor, Convert.ToDouble(objIn));
            }
            else if (objIn is string || objIn is char)
            {
                return TranslateString(processor, objIn.ToString()); // ToString will return just the string for the string type, and a string from a char.
            }
            else if (objIn is bool)
            {
                return TranslateBool(processor, (bool)objIn);
            }
            else if (objIn is Type)
            {
                return TranslatePrototype(processor, (Type)objIn);
            }
            else if (objIn.GetType().IsArray)
            {
                return TranslateArray(processor, (Array)objIn);
            }
            else if (objIn is BuiltInMethod || objIn is DotNetBuiltInMethod)
            {
                return TranslateFunction((Delegate)objIn);
            }
            else if (objIn is ScriptRuntimeException)
            {
                return TranslateException((ScriptRuntimeException)objIn);
            }
            else if (objIn is NetUndefined)
            {
                return TranslateUndefined(processor);
            }
            else if (objIn is ExpandoObject)
            {
                return TranslateExpandoObject(processor, objIn as ExpandoObject);
            }
            else
            {
                return TranslateObject(processor, objIn);
            }
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:58,代码来源:ScriptInAdapter.cs

示例13: constructor

        private static SObject constructor(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var obj = (SNumber)instance;

            if (parameters[0] is SNumber)
                obj.Value = ((SNumber)parameters[0]).Value;
            else
                obj.Value = parameters[0].ToNumber(processor).Value;

            return obj;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:11,代码来源:NumberPrototype.cs

示例14: SetMember

 internal override void SetMember(ScriptProcessor processor, SObject accessor, bool isIndexer, SObject value)
 {
     if (processor.Context.HasCallback(CallbackType.SetMember))
     {
         var callback = (DSetMember)processor.Context.GetCallback(CallbackType.SetMember);
         var task = Task.Factory.StartNew(() => callback(processor, ModuleName, accessor, isIndexer, value));
         task.Wait();
     }
     else
     {
         processor.ErrorHandler.ThrowError(ErrorType.APIError, ErrorHandler.MESSAGE_API_NOT_SUPPORTED);
     }
 }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:13,代码来源:SAPIUsing.cs

示例15: constructor

        private static SObject constructor(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var obj = (SError)instance;

            if (parameters.Length > 0)
            {
                SString message;

                if (parameters[0] is SString)
                    message = (SString)parameters[0];
                else
                    message = parameters[0].ToString(processor);

                obj.Members[MEMBER_NAME_MESSAGE].Data = message;
            }

            if (parameters.Length > 1)
            {
                SString errorType;

                if (parameters[1] is SString)
                    errorType = (SString)parameters[1];
                else
                    errorType = parameters[1].ToString(processor);

                obj.Members[MEMBER_NAME_TYPE].Data = errorType;
            }
            else
            {
                obj.Members[MEMBER_NAME_TYPE].Data = processor.CreateString("UserError");
            }

            if (parameters.Length > 2)
            {
                SNumber errorLine;

                if (parameters[2] is SNumber)
                    errorLine = (SNumber)parameters[2];
                else
                    errorLine = parameters[2].ToNumber(processor);

                obj.Members[MEMBER_NAME_LINE].Data = errorLine;
            }
            else
            {
                obj.Members[MEMBER_NAME_LINE].Data = processor.CreateNumber(-1);
            }

            return obj;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:50,代码来源:ErrorPrototype.cs


注:本文中的ScriptProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。