예제 #1
0
 public virtual string GetTitle(NSJSFunctionCallbackInfo arguments)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     return(Console.Title);
 }
예제 #2
0
 public virtual void Clear(NSJSFunctionCallbackInfo arguments)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     Console.Clear();
 }
예제 #3
0
 public virtual string FormatString(NSJSFunctionCallbackInfo arguments)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     return(sprint(arguments, false));
 }
예제 #4
0
 public virtual void SetTitle(NSJSFunctionCallbackInfo arguments, string caption)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     Console.Title = caption ?? string.Empty;
 }
예제 #5
0
 public virtual void Assert(NSJSFunctionCallbackInfo arguments, bool condition, string message, string detailMessage)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     NSJSException.Throw(arguments.VirtualMachine, string.Format("assert failed\r\n{0}\r\n{1}", message, detailMessage));
     Assert(condition, message, detailMessage);
 }
예제 #6
0
        public IntPtr MarshalManagedToNative(object ManagedObj)
        {
            NSJSFunctionCallbackInfo info = (NSJSFunctionCallbackInfo)ManagedObj;

            if (info == null)
            {
                return(NULL);
            }
            return(info.Handle);
        }
예제 #7
0
 public virtual void SystemCall(NSJSFunctionCallbackInfo arguments, string cmd)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     if (!string.IsNullOrEmpty(cmd))
     {
         system(cmd);
     }
 }
예제 #8
0
 protected virtual void OutputMesage(NSJSFunctionCallbackInfo arguments, string message)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     if (!string.IsNullOrEmpty(message))
     {
         Console.Write(message);
     }
 }
예제 #9
0
 public virtual void Throw(NSJSFunctionCallbackInfo arguments, NSJSValue exception)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     if (exception == null)
     {
         throw new ArgumentNullException("exception");
     }
     NSJSException.Throw(exception);
 }
예제 #10
0
 public NSJSMessage(NSJSFunctionCallbackInfo arguments, NSJSValue message)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     this.Message   = message;
     this.Arguments = arguments;
 }
예제 #11
0
 private void wvsprintln(NSJSFunctionCallbackInfo arguments, bool newline)
 {
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     if (arguments.Length > 0)
     {
         string contents = null;
         if (newline)
         {
             contents = FormatLine(arguments);
         }
         else
         {
             contents = FormatString(arguments);
         }
         if (contents != null)
         {
             OutputMesage(arguments, contents);
         }
     }
 }
예제 #12
0
 public virtual void Log(NSJSFunctionCallbackInfo arguments)
 {
     wvsprintln(arguments, true);
 }
예제 #13
0
        private static string sprint(NSJSFunctionCallbackInfo arguments, bool newline)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }
            string contents = null;

            if (arguments.Length <= 0)
            {
                return(contents);
            }
            try
            {
                string format = arguments.Length > 0 ? ValueAuxiliary.ToString(arguments[0]) : null;
                if (format == null)
                {
                    format = newline ? Environment.NewLine : string.Empty;
                }
                else if (newline)
                {
                    format += Environment.NewLine;
                }
                int index    = -1;
                int previous = 0;
                int solt     = 1;
                do
                {
                    index = format.IndexOf('%', index + 1);
                    if (index > -1)
                    {
                        int ofs = index + 1;
                        for (int i = ofs; i < format.Length; i++)
                        {
                            char character = format[i];
                            char flags     = '\0';
                            char pending   = '\0';
                            int  width     = 0;
                            if (character == 'c')
                            {
                                if (solt >= arguments.Length)
                                {
                                    break;
                                }
                                int count = (index - previous);
                                count = count < 0 ? 0 : count;
                                string g = format.Substring(previous, count);
                                if (!string.IsNullOrEmpty(g))
                                {
                                    contents += g;
                                }
                                previous  = i + 1;
                                contents += unchecked ((char)ValueAuxiliary.ToInt64(arguments[solt++]));
                                index     = i;
                                break;
                            }
                            else if (character == '%')
                            {
                                int count = (i - previous);
                                count = count < 0 ? 0 : count;
                                string g = format.Substring(previous, count);
                                if (!string.IsNullOrEmpty(g))
                                {
                                    contents += g;
                                }
                                previous = i + 1;
                                index    = i;
                                break;
                            }
                            else if (character == 's')
                            {
                                if (solt >= arguments.Length)
                                {
                                    break;
                                }
                                int count = (index - previous);
                                count = count < 0 ? 0 : count;
                                string g = format.Substring(previous, count);
                                if (!string.IsNullOrEmpty(g))
                                {
                                    contents += g;
                                }
                                previous  = i + 1;
                                contents += ValueAuxiliary.ToString(arguments[solt++]);
                                index     = i;
                                break;
                            }
                            else if (character == 'i' || character == 'd' || character == 'u')
                            {
                                if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width))
                                {
                                    if (solt >= arguments.Length)
                                    {
                                        break;
                                    }
                                    int count = (index - previous);
                                    count = count < 0 ? 0 : count;
                                    string g = format.Substring(previous, count);
                                    if (!string.IsNullOrEmpty(g))
                                    {
                                        contents += g;
                                    }
                                    previous = i + 1;
                                    string s = NSJSString.Cast(arguments[solt++]).Value;
                                    if (flags == '+')
                                    {
                                        s = s.PadLeft(width, pending);
                                    }
                                    else
                                    {
                                        s = s.PadRight(width, pending);
                                    }
                                    contents += s;
                                    index     = i;
                                }
                                break;
                            }
                            else if (character == 'b')
                            {
                                if (solt >= arguments.Length)
                                {
                                    break;
                                }
                                int count = (index - previous);
                                count = count < 0 ? 0 : count;
                                string g = format.Substring(previous, count);
                                if (!string.IsNullOrEmpty(g))
                                {
                                    contents += g;
                                }
                                previous  = i + 1;
                                contents += "0b" + Convert.ToString(ValueAuxiliary.ToInt64(arguments[solt++]), 2);
                                index     = i;
                                break;
                            }
                            else if (character == 'o' || character == 'x' || character == 'X')
                            {
                                if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width))
                                {
                                    if (solt >= arguments.Length)
                                    {
                                        break;
                                    }
                                    int count = (index - previous);
                                    count = count < 0 ? 0 : count;
                                    string g = format.Substring(previous, count);
                                    if (!string.IsNullOrEmpty(g))
                                    {
                                        contents += g;
                                    }
                                    previous = i + 1;
                                    int    radix = character == 'o' ? 0x08 : 0x10;
                                    string s     = Convert.ToString(ValueAuxiliary.ToInt64(arguments[solt++]), radix);
                                    if (flags == '+')
                                    {
                                        s = s.PadLeft(width, pending);
                                    }
                                    else
                                    {
                                        s = s.PadRight(width, pending);
                                    }
                                    if (radix == 0x10)
                                    {
                                        s = "0x" + (character == 'X' ? s.ToUpper() : s);
                                    }
                                    contents += s;
                                    index     = i;
                                }
                                break;
                            }
                            else if (character == 'p' || character == 'P')
                            {
                                if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width))
                                {
                                    if (solt >= arguments.Length)
                                    {
                                        break;
                                    }
                                    int count = (index - previous);
                                    count = count < 0 ? 0 : count;
                                    string g = format.Substring(previous, count);
                                    if (!string.IsNullOrEmpty(g))
                                    {
                                        contents += g;
                                    }
                                    previous = i + 1;
                                    long   ptr = Environment.Is64BitProcess ? ValueAuxiliary.ToInt64(arguments[solt++]) : ValueAuxiliary.ToInt32(arguments[solt++]);
                                    string s   = ptr.ToString(character == 'p' ? "x2" : "X2");
                                    if (flags == '+')
                                    {
                                        s = s.PadLeft(width, pending);
                                    }
                                    else
                                    {
                                        s = s.PadRight(width, pending);
                                    }
                                    s         = "0x" + s;
                                    contents += s;
                                    index     = i;
                                }
                                break;
                            }
                            else if (character == 'f' || character == 'l' ||
                                     character == 'e' || character == 'g' ||
                                     character == 'E' || character == 'G') // lf
                            {
                                int mode = 0;                              // 0: 单精度浮点数,1:双精度浮点数,2:科学型浮点数数,3:常规型浮点数
                                int n    = i + 1;
                                if (n < format.Length && format[n] == 'f') // lf
                                {
                                    mode = 1;
                                    i++;
                                }
                                else if (character == 'e' || character == 'E')
                                {
                                    mode = 2;
                                }
                                else if (character == 'g' || character == 'G')
                                {
                                    mode = 3;
                                }
                                if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width))
                                {
                                    if (solt >= arguments.Length)
                                    {
                                        break;
                                    }
                                    int count = (index - previous);
                                    count = count < 0 ? 0 : count;
                                    string g = format.Substring(previous, count);
                                    if (!string.IsNullOrEmpty(g))
                                    {
                                        contents += g;
                                    }
                                    previous = i + 1;
                                    double num = ValueAuxiliary.ToDouble(arguments[solt++]);
                                    string s   = mode == 2 || mode == 3 ? num.ToString(character.ToString()) : num.ToString();
                                    if (flags == '+')
                                    {
                                        s = s.PadLeft(width, pending);
                                    }
                                    else
                                    {
                                        s = s.PadRight(width, pending);
                                    }
                                    contents += s;
                                    index     = i;
                                }
                                break;
                            }
                        }
                    }
                } while (index >= 0);
                if (format.Length > previous)
                {
                    string s = format.Substring(previous);
                    if (!string.IsNullOrEmpty(s))
                    {
                        contents += s;
                    }
                }
            }
            catch (Exception)
            {
                contents = null;
            }
            return(contents);
        }
예제 #14
0
 public virtual void PrintString(NSJSFunctionCallbackInfo arguments)
 {
     wvsprintln(arguments, false);
 }
예제 #15
0
 public object MarshalNativeToManaged(IntPtr pNativeData)
 {
     return(NSJSFunctionCallbackInfo.From(pNativeData));
 }