示例#1
0
        private static FunctionReturnValue FileSelectFolder(CallFrame frame, Variant[] args)
        {
            try
            {
                int options = (int)args[2];
                using FolderBrowserDialog ofd = new()
                      {
                          Description         = args[0].ToString(),
                          SelectedPath        = args[3].ToString(),
                          RootFolder          = Environment.SpecialFolder.MyComputer,
                          ShowNewFolderButton = options.HasFlag(1),
                          AutoUpgradeEnabled  = true,
                      };
                DialogResult result;

                if (args[5].IsDefault)
                {
                    result = ofd.ShowDialog();
                }
                else
                {
                    result = ofd.ShowDialog(WindowWrapper.FromHWND(args[5]));
                }

                if (result is DialogResult.OK)
                {
                    return(Variant.FromString(ofd.SelectedPath));
                }
            }
            catch
            {
            }

            return(FunctionReturnValue.Error("", 1, Variant.Null));
        }
示例#2
0
 public static FunctionReturnValue ThreadIsRunning(CallFrame frame, Variant[] args)
 {
     if (args[0].TryResolveHandle(frame.Interpreter, out ThreadHandle? handle))
     {
         return((Variant)handle.Thread.IsRunning);
     }
     else
     {
         return(FunctionReturnValue.Error(1));
     }
 }
 private static FunctionReturnValue _Degree(CallFrame frame, Variant[] args)
 {
     if (args[0].IsNumber)
     {
         return(Variant.FromNumber(args[0].ToNumber() * 57.2957795130823));
     }
     else
     {
         return(FunctionReturnValue.Error(1));
     }
 }
示例#4
0
 // SerialOpen( <port-name>, <baud-rate> [, <parity-bits> = 0 [, <data-bits> = 8 [, <stop-bits> = 1]]] )
 //  success: handle
 //  failure: zero, @error = -1
 private static FunctionReturnValue SerialOpen(CallFrame frame, Variant[] args)
 {
     try
     {
         return(frame.Interpreter.GlobalObjectStorage.Store(new SerialPort(args[0].ToString(), (int)args[1], (Parity)(int)args[2], (int)args[3], (StopBits)(int)args[4])));
     }
     catch
     {
         return(FunctionReturnValue.Error(-1));
     }
 }
        public Function(int id, string name)
        {
            ID          = id;
            Name        = name;
            CodeLines   = new CodeLines(this);
            Parameters  = new FunctionParameters(this);
            ReturnValue = new FunctionReturnValue(this);
            Variables   = new FunctionVariables(this);

#if NAV2016
            EventPublisherObject = new ObjectReference();
#endif
        }
示例#6
0
        private static FunctionReturnValue GUICreate(CallFrame frame, Variant[] args)
        {
            try
            {
                Form window = new()
                {
                    Text = args[0].ToString(),
                };

                if ((int)args[1] is int width and > 0)
                {
                    window.Width = width;
                }

                if ((int)args[2] is int height and > 0)
                {
                    window.Height = height;
                }

                if ((int)args[3] is int left and > 0)
                {
                    window.Width = left;
                }

                if ((int)args[4] is int top and > 0)
                {
                    window.Height = top;
                }

                if ((int)args[5] >= 0)
                {
                    NativeInterop.SetWindowLongPtr(window.Handle, -16, (nint)args[5]); // style
                }
                if ((int)args[6] >= 0)
                {
                    NativeInterop.SetWindowLongPtr(window.Handle, -20, (nint)args[6]); // ex-style
                }
                if ((int)args[7] >= 0)
                {
                    NativeInterop.SetParent(window.Handle, (nint)args[7]);
                }

                return(Variant.FromHandle(window.Handle));
            }
            catch
            {
                return(FunctionReturnValue.Error(1));
            }
        }
 private static FunctionReturnValue _MathCheckDiv(CallFrame frame, Variant[] args)
 {
     if (!args[0].IsNumber && !args[1].IsNumber)
     {
         return(FunctionReturnValue.Error(-1, 1, 0));
     }
     else if ((int)args[1] == 0 || (int)args[0] % (int)args[1] == 0)
     {
         return(Variant.FromNumber(1));
     }
     else
     {
         return(Variant.FromNumber(2));
     }
 }
 private static FunctionReturnValue _Min(CallFrame frame, Variant[] args)
 {
     if (!args[0].IsNumber)
     {
         return(FunctionReturnValue.Error(1));
     }
     else if (!args[1].IsNumber)
     {
         return(FunctionReturnValue.Error(2));
     }
     else
     {
         return(Variant.FromNumber(Math.Min(args[0].ToNumber(), args[1].ToNumber())));
     }
 }
示例#9
0
        public static FunctionReturnValue ThreadWait(CallFrame frame, Variant[] args)
        {
            if (args[0].TryResolveHandle(frame.Interpreter, out ThreadHandle? handle))
            {
                handle.Runner.Wait();

                FunctionReturnValue result = handle.Runner.Result;

                frame.Interpreter.GlobalObjectStorage.Delete(args[0]);

                return(result);
            }
            else
            {
                return(FunctionReturnValue.Error(1));
            }
        }
示例#10
0
        public static FunctionReturnValue ThreadKill(CallFrame frame, Variant[] args)
        {
            if (args[0].TryResolveHandle(frame.Interpreter, out ThreadHandle? handle))
            {
                Variant running = handle.Thread.IsRunning;

                handle.Thread.Stop();
                handle.Runner.Wait();
                frame.Interpreter.GlobalObjectStorage.Delete(args[0]);

                return(running);
            }
            else
            {
                return(FunctionReturnValue.Error(1));
            }
        }
示例#11
0
        public static string GetTypeName(FunctionReturnValue functionReturnValue)
        {
            switch (functionReturnValue.Type)
            {
            case FunctionReturnValueType.Text:
                return(functionReturnValue.DataLength.HasValue ? string.Format("{0}[{1}]", functionReturnValue.Type, functionReturnValue.DataLength) : functionReturnValue.Type.ToString());

            case FunctionReturnValueType.Code:
            case FunctionReturnValueType.Binary:
                return($"{functionReturnValue.Type}[{functionReturnValue.DataLength}]");

            case FunctionReturnValueType.Guid:
                return("GUID");

            default:
                return(functionReturnValue.Type.ToString());
            }
        }
示例#12
0
        private static FunctionReturnValue _SendMessage(CallFrame frame, Variant[] args)
        {
            nint result;

            NativeInterop.SetLastError(0);

            if (args[3].IsString)
            {
                result = NativeInterop.SendMessage((nint)args[0], (int)args[1], (nint)args[2], args[3].ToString());
            }
            else
            {
                result = NativeInterop.SendMessage((nint)args[0], (int)args[1], (nint)args[2], (nint)args[3]);
            }

            if (NativeInterop.GetLastError() is int error and not 0)
            {
                return(FunctionReturnValue.Error(Variant.EmptyString, error, Variant.Zero));
            }
示例#13
0
        private static FunctionReturnValue FileOpenDialog(CallFrame frame, Variant[] args)
        {
            try
            {
                int options = (int)args[3];
                using OpenFileDialog ofd = new()
                      {
                          Title            = args[0].ToString(),
                          InitialDirectory = args[1].ToString(),
                          Filter           = args[2].ToString(),
                          FileName         = args[4].ToString(),
                          CheckFileExists  = options.HasFlag(1),
                          CheckPathExists  = options.HasFlag(2),
                          Multiselect      = options.HasFlag(4),
                      };
                DialogResult result;

                if (args[5].IsDefault)
                {
                    result = ofd.ShowDialog();
                }
                else
                {
                    result = ofd.ShowDialog(WindowWrapper.FromHWND(args[5]));
                }

                if (result is DialogResult.OK && options.HasFlag(8) && !File.Exists(ofd.FileName))
                {
                    using (FileStream fs = File.Create(ofd.FileName))
                        fs.Close();
                }

                return(FunctionReturnValue.Success(
                           ofd.FileNames is { Length: > 1 } names?names.StringJoin("|") : ofd.FileName,
                               (int)result
                           ));
            }
            catch
            {
                return(FunctionReturnValue.Error(1));
            }
        }
示例#14
0
        private static FunctionReturnValue ClipGet(CallFrame frame, Variant[] args)
        {
            try
            {
                string value = Clipboard.GetText();

                if (string.IsNullOrEmpty(value))
                {
                    return(FunctionReturnValue.Error(1));
                }
                else
                {
                    return((Variant)value);
                }
            }
            catch
            {
                return(FunctionReturnValue.Error(Clipboard.ContainsText() ? 3 : 2));
            }
        }
示例#15
0
        public static void Write(this FunctionReturnValue functionReturnValue, CSideWriter writer)
        {
            if (!functionReturnValue.Type.HasValue)
            {
                return;
            }

            if (!string.IsNullOrEmpty(functionReturnValue.Name))
            {
                writer.Write(" {0}", functionReturnValue.Name);
            }

            writer.Write(" : ");

            if (!string.IsNullOrEmpty(functionReturnValue.Dimensions))
            {
                writer.Write("ARRAY [{0}] OF ", functionReturnValue.Dimensions);
            }

            writer.Write(GetTypeName(functionReturnValue));
        }
示例#16
0
        private static FunctionReturnValue FileSaveDialog(CallFrame frame, Variant[] args)
        {
            try
            {
                int options = (int)args[3];
                using SaveFileDialog ofd = new()
                      {
                          Title            = args[0].ToString(),
                          InitialDirectory = args[1].ToString(),
                          Filter           = args[2].ToString(),
                          FileName         = args[4].ToString(),
                          CheckFileExists  = options.HasFlag(1),
                          CheckPathExists  = options.HasFlag(2),
                          OverwritePrompt  = options.HasFlag(16),
                      };
                DialogResult result;

                if (args[5].IsDefault)
                {
                    result = ofd.ShowDialog();
                }
                else
                {
                    result = ofd.ShowDialog(WindowWrapper.FromHWND(args[5]));
                }

                return(FunctionReturnValue.Success(
                           ofd.FileNames is { Length: > 1 } names?names.StringJoin("|") : ofd.FileName,
                               (int)result
                           ));
            }
            catch
            {
                return(FunctionReturnValue.Error(1));
            }
        }