Esempio n. 1
0
        public ktDelegateFunction(ktString Name, ktFunction_Double_Delegate Delegate)
            : base(Name, null, null, ktValue.Null)
        {
            m_Arguments = new ktList();
            m_Arguments.Add(new ktValue("D", "double",
                                              kacTalk.Main.GetClass("double"),
                                              true, true));

            m_Delegate = delegate(ktList Args)
            {
                if ((Args == null) || (Args.FirstNode == null) ||
                    (Args.FirstNode.Value == null))
                {
                    throw new ktError("Didn't get an argument for '" +
                                      Name + "'!", ktERR.MISSING);
                }
                //ktDebug.Log( "ktDF::DOUBLE(" +Args.FirstNode.Value.ToString() + ")" );
                ktString S_In = new ktString(Args.FirstNode.Value.ToString());
                double D_In = 0.0;
                double D_Out = 0.0;

                try
                {
                    if (System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator == ",")
                    {
                        S_In.Replace(".", ",", true);
                    }

                    D_In = S_In.ToDouble();
                }
                catch (Exception E)
                {
                    if (E.GetType() == typeof(System.FormatException) && !S_In.IsEmpty())
                    {
                        throw new ktError("ktDouble::CreateObject: Cant make '" + S_In + "' into an double", ktERR.WRONGTYPE);
                    }
                }
                ktDebug.Log("D_In: " + D_In.ToString());
                D_Out = Delegate(D_In);
                ktDebug.Log("D_Out: " + D_Out.ToString());

                return new ktValue("return", "double",
                                   kacTalk.Main.MakeObjectOf("double", D_Out),
                                   true, true);
            };
        }
Esempio n. 2
0
 public ktDelegateFunction(ktString Name, ktFunction_NoArg_Delegate Delegate)
     : base(Name, null, null, ktValue.Null)
 {
     m_Delegate = delegate(ktList Args) { return Delegate(); };
 }
Esempio n. 3
0
 public ktDelegateFunction(ktString Name, ktFunction_Delegate Delegate)
     : base(Name, null, null, ktValue.Null)
 {
     m_Delegate = Delegate;
 }