CreateString() private method

Creates an instance of the string primitive.
private CreateString ( string value ) : SString
value string
return Pokemon3D.Scripting.Types.SString
Example #1
0
        public static SObject NameOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
                return processor.Undefined;

            if (parameters[0] is SProtoObject)
            {
                var protoObj = (SProtoObject)parameters[0];
                return processor.CreateString(protoObj.IsProtoInstance ? protoObj.Prototype.Name : protoObj.TypeOf());
            }
            else
            {
                return processor.CreateString(parameters[0].TypeOf());
            }
        }
Example #2
0
        public static SObject NameOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
            {
                return(processor.Undefined);
            }

            if (parameters[0] is SProtoObject)
            {
                var protoObj = (SProtoObject)parameters[0];
                return(processor.CreateString(protoObj.IsProtoInstance ? protoObj.Prototype.Name : protoObj.TypeOf()));
            }
            else
            {
                return(processor.CreateString(parameters[0].TypeOf()));
            }
        }
Example #3
0
        public static SObject ToPrimitive(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
            {
                return(processor.Undefined);
            }

            if (parameters[0] is SString)
            {
                return(processor.CreateString(((SString)parameters[0]).Value));
            }
            else if (parameters[0] is SNumber)
            {
                return(processor.CreateNumber(((SNumber)parameters[0]).Value));
            }
            else if (parameters[0] is SBool)
            {
                return(processor.CreateBool(((SBool)parameters[0]).Value));
            }
            else
            {
                return(parameters[0]); // returns the input object, if no conversion was conducted.
            }
        }
Example #4
0
        public static SObject ToPrimitive(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
                return processor.Undefined;

            if (parameters[0] is SString)
                return processor.CreateString(((SString)parameters[0]).Value);
            else if (parameters[0] is SNumber)
                return processor.CreateNumber(((SNumber)parameters[0]).Value);
            else if (parameters[0] is SBool)
                return processor.CreateBool(((SBool)parameters[0]).Value);
            else
                return parameters[0]; // returns the input object, if no conversion was conducted.
        }
Example #5
0
 public static SObject TypeOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters) =>
     parameters.Length == 0 ? processor.Undefined : processor.CreateString(parameters[0].TypeOf());
Example #6
0
 public static SObject TypeOf(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters) =>
 parameters.Length == 0 ? processor.Undefined : processor.CreateString(parameters[0].TypeOf());
Example #7
0
        /// <summary>
        /// Throws an error with the given <see cref="ErrorType"/> and error message.
        /// </summary>
        public SObject ThrowError(ErrorType errorType, string message, params object[] messageArgs)
        {
            var strErrorType     = errorType.ToString();
            var formattedMessage = string.Format(message, messageArgs);

            var errorObject = _processor.Context.CreateInstance("Error", new SObject[] { _processor.CreateString(formattedMessage),
                                                                                         _processor.CreateString(errorType.ToString()),
                                                                                         _processor.CreateNumber(_processor.GetLineNumber()) });

            return(ThrowError(errorObject));
        }