예제 #1
0
 public ktRequestObject(ktString obj, ktString memb, Dictionary<ktString, ktString> args, ktTalkFormat form = ktTalkFormat._DEFUALT)
 {
     Object = obj;
     Member = memb;
     Arguments = args;
     Format = form;
 }
예제 #2
0
 /// <summary>
 /// Constructor for the error class (mostely used when throwing errors)
 /// </summary>
 /// <param name="Error">The error message</param>
 /// <param name="ErrorNum">The error number</param>
 /// <param name="LineNo">The line on which the error was thrown</param>
 /// <param name="CharPos">The character by which the error was thrown</param>
 public ktError(ktString Error, ktERR ErrorNum, int LineNo, int CharPos)
     : base(Error)
 {
     m_Num = ErrorNum;
     m_LineNo = LineNo;
     m_CharPos = CharPos;
 }
예제 #3
0
 public ktRequestObject(ktString obj, ktString memb, ktTalkFormat form = ktTalkFormat._DEFUALT)
 {
     Object = obj;
     Member = memb;
     Arguments = null;
     Format = form;
 }
예제 #4
0
        public ktTalkerChannel(ktTalker Parent)
            : base("ktTalkerChannel",0)
        {
            m_URI = "";
            m_Key = "";
            m_Initiated = false;

            m_TalkerParent = Parent;
        }
예제 #5
0
        public bool SetVariable(ktString Name, ktValue Value, bool Add, bool Copy, bool IgnoreConstant)
        {
            // Nothing to use??
            if (Name.IsEmpty() || (Value == null) || (m_Block == null))
            {
                return false;
            }

            return m_Block.SetVariable(Name, Value, Add, Copy, IgnoreConstant);
        }
예제 #6
0
        public ktModule(ktString Name, ktString Filename, bool Load)
            : base("ktIntObj", 0)
        {
            m_Name = Name;
            m_Filename = Filename;

            if (Load)
            {
            }
        }
예제 #7
0
 public ktContext(ktString Name)
     : base("ktContext", 0)
 {
     m_Name = Name;
     m_Parent = null;
     m_Aliases = null;
     m_Variables = null;
     m_Functions = null;
     m_AddIfNotSet = true;
 }
예제 #8
0
 public override int Compare(ktString op, ktList arguments)
 {
     if (arguments.Count == 1)
     {
         return Compare(op, (ktValue)arguments.FirstNode.Value);
     }
     else
     {
         throw new ktError("Compare for more than 1 value is not implemented in '" + this.m_Name + "'!");
     }
 }
예제 #9
0
        public ktValue(ktString Name, ktString Type, ktIntObj Object,
                       bool HardType, bool Constant, ktClass CallbackClass)
            : base("ktValue", 0)
        {
            m_Object = Object;

            SetName(Name);
            SetType(Type);
            SetHardType(HardType);
            SetConstant(Constant);
            SetCallback(CallbackClass);
        }
예제 #10
0
 public ktContext(ktString Name, ktString Aliases, ktList Classes,
     ktList Variables, ktList Functions, ktContext Parent,
     bool AddIfNotSet)
     : base("ktContext", 0)
 {
     m_Name = Name;
     m_Parent = Parent;
     m_Aliases = Aliases;
     m_Variables = Variables;
     m_Functions = Functions;
     m_AddIfNotSet = AddIfNotSet;
 }
예제 #11
0
 public ktClass(ktString Name, ktClass Parent, ktList Properties, ktList Methods,
                bool AddIfNotSet, bool IsClass_, bool HardType = false, bool IsConstant = false)
     : base("ktClass", 0)
 {
     m_Name = Name;
     m_Parent = Parent;
     m_Properties = Properties;
     m_Methods = Methods;
     m_AddIfNotSet = AddIfNotSet;
     m_IsClass = IsClass_;
     m_HardType = HardType;
     m_IsConstant = IsConstant;
 }
예제 #12
0
        public ktValue(ktString Name, ktString Type, ktIntObj Object,
                       bool HardType, bool Constant)
            : this(Name, Type, Object, HardType, Constant, null)
        {
            /*
            SetName( Name );
            SetType( Type );
            SetHardType( HardType );
            SetConstant( Constant );
            SetCallback( CallbackClass );*/

              //  m_Object = Object;
        }
예제 #13
0
        public override bool Initiate(ktString URI, ktString APIKey)
        {
            m_Initiated = true;
            m_URI = URI;
            m_Key = APIKey;

            OpenConnection();

            CheckVersion();
            RequestAvailableObjects();

            CloseConnection();

            return true;
        }
예제 #14
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);
            };
        }
예제 #15
0
        public ktTalker( ktString InfoStr, ktTalkerChannel TalkerChannel = null )
            : base("ktTalker", 0)
        {
            m_InfoMap = ParseInfoString(InfoStr);

            m_APIKey = GetProperty("KEY");
            m_URI = GetProperty("URI");

            if (TalkerChannel != null)
            {
                m_Channel = TalkerChannel;
            }
            else
            {
                ktString Channel = "";
                if (m_InfoMap.ContainsKey("CHANNEL"))       Channel = m_InfoMap["CHANNEL"];
                else if (m_InfoMap.ContainsKey("PROTO"))    Channel = m_InfoMap["PROTO"];
                else if (m_InfoMap.ContainsKey("PROTOCOL")) Channel = m_InfoMap["PROTOCOL"];

                if (Channel.IsEmpty())
                {
                    throw new ktError("ktTalker wasn't given a channel!");
                }

                try
                {
                    Type type = Type.GetType("ktTalkers.ktTalker" + Channel.Capitalize() + "Channel");
                    object[] args = { this };

                    m_Channel = (ktTalkerChannel)Activator.CreateInstance(type,args);
                }
                catch (Exception Exc)
                {
                    if ((Exc is ArgumentNullException) || (Exc is ArgumentException) || (Exc is NotSupportedException)
                            || (Exc is InvalidComObjectException) || (Exc is TypeLoadException))
                    {
                        throw new ktError("ktTalker couldn't create a Channel object for '" + Channel + "'!");
                    }
                    else
                    {
                        throw Exc;
                    }
                }
            }
        }
예제 #16
0
        public override int Compare(ktString op, ktValue val)
        {
            int ret = 0;
            bool bVal = val.ToBool();

            switch (op)
            {
                case "<>":
                case "!=":
                case "op<>":
                case "op!=":
                case "operator<>":
                case "operator!=":
                case "ne":
                case "isnotequal":
                case "notequal":
                    {
                        ret = (m_value != bVal) ? 1 : 0;
                        break;
                    }
                case "==":
                case "op==":
                case "operator==":
                case "isequal":
                case "equal":
                case "eq":
                    {
                        ret = (m_value == bVal) ? 1 : 0;
                        break;
                    }
                default:
                    {
                        throw new ktError("Couldn't find the method '" +
                                          op + "' in class '" + m_Name + "'.", ktERR._404);
                    }
            }

            return ret;
        }
예제 #17
0
        public override ktValue _RunMethod(ktString Name, ktList Arguments)
        {
            ktValue Value = ktValue.Null;

            switch (Name.AsLower())
            {
                case "run":
                case "_run":
                case "execute":
                case "_execute":
                case "_func_call":
                    {
                        Value = Run( Arguments );
                        break;
                    }
                default:
                    {
                        throw new ktError("Couldn't find the method '" +
                                          Name + "' in class '" + m_Name + "'.", ktERR._404);
                    }
            }

            return Value;
        }
예제 #18
0
        public override ktValue SetProperty(ktString Name, ktValue Value)
        {
            if ((Name == "this") || (Name == "_this") ||
                (Name == "object") || (Name == "_object") ||
                (Name == "_") || (Name.IsEmpty()))
            {
                /*try {
                    m_Value = Convert.ToInt32( Value.ToString() );
                } catch (Exception E) {
                    if (E.GetType() == typeof( System.FormatException )) {
                        throw new ktError( "kactalkClass::CreateObject: Cant make '" + Value + "' into an integer", ktERR.WRONGTYPE );
                    }
                }*/
            } /*else if (Name == "MathMode") {
            //				m_Value.MathMode = (((ktClass)Value.Value).ToString().ToLower() == "true");
                m_Value.MathMode = Value.ToBool();
            } */else
            {
                throw new ktError("Couldn't find the property '" +
                                  Name + "' in class '" + m_Name + "'.", ktERR._404);
            }

            return GetProperty("_");
        }
예제 #19
0
        internal void AddAvailableObject(ktString o)
        {
            if (m_AvailableObjects == null)
                m_AvailableObjects = new ktList();

            m_AvailableObjects.Add(o);
        }
예제 #20
0
 public void AddExtraParameter(ktString name, ktString value)
 {
     m_ExtraParams.Add(name, value);
 }
예제 #21
0
 public ktString GetProperty( ktString Key )
 {
     try
     {
         return m_InfoMap[Key];
     } catch (Exception)
     {
         return "";
     }
 }
예제 #22
0
        public object ToType(ktString Type)
        {
            if (m_Object == null)
            {
                return null;
            }

            try
            {
                ktClass Class = (ktClass)m_Object;

                return Class.RunMethod("To" + Type).ToType(Type);
            }
            catch (Exception)
            {
            }

            switch (Type.AsLower())
            {
                case "bool":
                    {
                        if (m_Object.GetType() == typeof(bool))
                        {
                            return m_Object;
                        }
                        else if (m_Object.GetType() == typeof(int))
                        {
                            return ((int)m_Object) != 0;
                        }
                        else if (m_Object.GetType() == typeof(float))
                        {
                            return ((float)m_Object) != 0.0f;
                        }
                        else if (m_Object.GetType() == typeof(double))
                        {
                            return ((double)m_Object) != 0.0;
                        }
                        else if (m_Object.GetType() == typeof(char))
                        {
                            return ((char)m_Object) != 0;
                        }
                        else if (m_Object.GetType() == typeof(string))
                        {
                            return ((string)m_Object) != "false";
                        }
                        else if (m_Object.GetType() == typeof(ktString))
                        {
                            return ((ktString)m_Object) != "false";
                        }
                        else if (m_Object.GetType() == typeof(ktList))
                        {
                            return !((ktList)m_Object).IsEmpty();
                        }
                        else
                        {
                            return m_Object.ToString() != "false";
                        }
                    }
                case "int":
                case "integer":
                    {
                        try
                        {
                            if (m_Object.GetType() == typeof(bool))
                            {
                                return (((bool)m_Object) ? 1 : 0);
                            }
                            else if (m_Object.GetType() == typeof(int))
                            {
                                return m_Object;
                            }
                            else if (m_Object.GetType() == typeof(float))
                            {
                                return (int)((float)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(double))
                            {
                                return (int)((double)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(char))
                            {
                                return (int)((char)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(string))
                            {
                                return Convert.ToInt32(((string)m_Object));
                            }
                            else if (m_Object.GetType() == typeof(ktString))
                            {
                                return ((ktString)m_Object).ToInt();
                            }
                            else
                            {
                                return Convert.ToInt32(m_Object.ToString());
                            }
                        }
                        catch (Exception Err)
                        {
                            if (Err.GetType() == typeof(System.FormatException))
                            {
                                throw new ktError("ktObjectWrapper::ToType: Cant make '" + Value.ToString() + "' into an integer", ktERR.WRONGTYPE);
                            }
                            else
                            {
                                throw Err;
                            }
                        }
                    }
                case "float":
                    {
                        try
                        {
                            if (m_Object.GetType() == typeof(bool))
                            {
                                return (((bool)m_Object) ? 1.0f : 0.0f);
                            }
                            else if (m_Object.GetType() == typeof(int))
                            {
                                return (float)((int)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(float))
                            {
                                return m_Object;
                            }
                            else if (m_Object.GetType() == typeof(double))
                            {
                                return (float)((double)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(char))
                            {
                                return (float)((char)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(string))
                            {
                                return Convert.ToSingle(((string)m_Object));
                            }
                            else if (m_Object.GetType() == typeof(ktString))
                            {
                                return ((ktString)m_Object).ToFloat();
                            }
                            else
                            {
                                return Convert.ToSingle(m_Object.ToString());
                            }
                        }
                        catch (Exception Err)
                        {
                            if (Err.GetType() == typeof(System.FormatException))
                            {
                                throw new ktError("ktObjectWrapper::ToType: Cant make '" + m_Object.ToString() + "' into an " + Type, ktERR.WRONGTYPE);
                            }
                            else
                            {
                                throw Err;
                            }
                        }
                    }
                case "double":
                    {
                        try
                        {
                            if (m_Object.GetType() == typeof(bool))
                            {
                                return (((bool)m_Object) ? 1.0 : 0.0);
                            }
                            else if (m_Object.GetType() == typeof(int))
                            {
                                return (double)((int)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(float))
                            {
                                return (double)((float)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(double))
                            {
                                return m_Object;
                            }
                            else if (m_Object.GetType() == typeof(char))
                            {
                                return (double)((char)m_Object);
                            }
                            else if (m_Object.GetType() == typeof(string))
                            {
                                return Convert.ToDouble(((string)m_Object));
                            }
                            else if (m_Object.GetType() == typeof(ktString))
                            {
                                return ((ktString)m_Object).ToDouble();
                            }
                            else
                            {
                                return Convert.ToDouble(m_Object.ToString());
                            }
                        }
                        catch (Exception Err)
                        {
                            if (Err.GetType() == typeof(System.FormatException))
                            {
                                throw new ktError("ktValue::ToType: Cant make '" + m_Object.ToString() + "' into an " + Type, ktERR.WRONGTYPE);
                            }
                            else
                            {
                                throw Err;
                            }
                        }
                    }
                default:
                    {
                        return m_Object;
                    }

            }

            //(((ktClass)Value.Value).ToString().ToLower() == "true")
            //			return null;
        }
예제 #23
0
        public static Dictionary<ktString, ktString> ParseInfoString( ktString InfoStr )
        {
            int p = 0, p2 = 0;
            ktString property;
            ktString prop_name, prop_value;

            Dictionary<ktString, ktString> InfoMap = new Dictionary<ktString, ktString>();

            while (!InfoStr.IsEmpty())
            {
                p = InfoStr.IndexOf(';');
                if (p < 0)
                {
                    property = InfoStr;
                    p = InfoStr.Length() - 1;
                }
                else
                {
                    property = InfoStr.SubString(0, p).Trim();
                }
                p2 = property.IndexOf('=');
                prop_name = property.SubString(0, p2).AsUpper();
                prop_value = property.SubString(p2 + 1);

                InfoMap.Add(prop_name, prop_value);

                InfoStr.Remove(0, p + 1);
                InfoStr = InfoStr.Trim();
            }

            return InfoMap;
        }
예제 #24
0
 public bool SetVariable(ktString Name, ktValue Value)
 {
     return SetVariable(Name, Value, true);
 }
예제 #25
0
 public bool SetVariable(ktString Name, ktValue Value, bool Add, bool Copy)
 {
     return SetVariable(Name, Value, Add, Copy, false);
 }
예제 #26
0
        public override ktClass CreateObject(ktString Value)
        {
            /*int I = 0;

            try {
                I = Value.ToInt();
            } catch (Exception E) {
                if (E.GetType() == typeof( System.FormatException )) {
                    throw new ktError( "kactalkClass::CreateObject: Cant make '" + Value + "' into an integer", ktERR.WRONGTYPE );
                }
            }*/

            return new ktRunStatementClass(new ktRunStatement());
        }
예제 #27
0
        public override ktValue _RunMethod(ktString Name, ktList Arguments)
        {
            if (Name.IsEmpty())
            {
                throw new ktError("Didn't get the name of the method to run in class '" +
                                m_Name + "'.", ktERR.NOTSET);
            }
            //ktDebug.Log( ";Name::"+ Name + ";;;;_\n" );
            if (Name == "_PropertyChanged")
            {
                if ((Arguments == null) || (Arguments.GetCount() != 2))
                {
                    throw new ktError("kactalk::_PropertyChanged() : Didn't get the two nnede arguments!",
                                      ktERR.MISSING);
                }
            #if Debug
            ktDebug.Log( "Args::" + Arguments.Get_R( "\t", true ) );
            #endif

                Name = Arguments.Get("Name").Node.Value.ToString();
                ktValue Value = (ktValue)Arguments.Get("Value").Node.Value;

                SetProperty(Name, Value);

                return ktValue.Null;
            }
            else /*if (Name.StartsWith( "operator", out Name )) {
                return HandleOperator( Name, Arguments );
            } else */
            {
                throw new ktError("Couldn't find the method '" +
                                  Name + "' in class '" + m_Name + "'.", ktERR._404);
            }
        }
예제 #28
0
 public ktXMLNode(ktString N)
     : base(N)
 {
     //ktDebug.Log( "ktXMLNode( " + N + " )" );
 }
예제 #29
0
        public ktString AsXML(bool IncludeDeclaration, ktString Prefix)
        {
            // Define the variable to store the xml-structure
            ktString XML = new ktString();

            // Should we include the XML-declaration
            if (IncludeDeclaration)
            {
                // Do so...
                XML = Prefix + "<?xml version=\"" + m_Version + "\" encoding=\"" + m_Encoding + "\"?>\n";
            }

            // Define...
            ktString StartElm = "", EndElm = "", Content = "", Name = "";
            bool First = true;

            // If the list has info...
            if (m_Node != null)
            {
                // Add beginning
                StartElm = Prefix + "<";
                EndElm = "</";

                Name.SetValue(m_Node.Name);
                Name.Trim();

                // No name??
                if (Name.IsEmpty())
                {
                    StartElm += "NN";
                    EndElm += "NN";
                    // Yippie, name...
                }
                else
                {
                    // Add name
                    StartElm += Name;
                    EndElm += Name;
                }

                // Add end...
                StartElm += ">";
                EndElm += ">";

                // If the list has a value
                if (m_Node.Value != null)
                {
                    // Special, just for blocks...
                    if (m_Node.Value.GetType() == typeof(ktBlock))
                    {
                        ktList L = ((ktBlock)m_Node.Value).Lines;
                        if (L != null)
                        {
                            // Get it...
                            Content = ktXML.FromList(L).AsXML(IncludeDeclaration, m_Prefix + Prefix);
                        }
                    }
                    else if ((m_Node.Value.GetType() == typeof(ktToken)) &&
                              (((ktToken)m_Node.Value).Type == ktTokenType.Block))
                    {
                        if (((ktToken)m_Node.Value).Block == null)
                        {
                            goto EndOfNode;
                        }
                        ktList L = ((ktToken)m_Node.Value).Block.Lines;
                        if (L != null)
                        {
                            // Get it...
                            Content = ktXML.FromList(L).AsXML(IncludeDeclaration, m_Prefix + Prefix);
                        }
                    }
                    else
                    {
                        // Get it...
                        Content = m_Node.Value.ToString();
                    }
                }
                // No node info...
            }
            else
            {
                // Use default...
                StartElm = Prefix + "<POST>";
                EndElm = "</POST>";
            }

            EndOfNode:

            // Little "hack" if it,s the "first level"
            if (Prefix.IsEmpty())
            {
                First = false;
            }

            // Go thrugh the child nodes
            foreach (ktXML N in this)
            {
                // If it's the first
                if (First)
                {
                    // If content isn't empty
                    if (!Content.IsEmpty())
                    {
                        // Add approiate prefixes...
                        Content = Prefix + m_Prefix + Content + "\n"/* + Prefix*/;
                    }
                    // No more first...
                    First = false;
                }

                // Get the childs xml-structure (extended prefix and no XML-decl.)
                Content += N.AsXML(false, Prefix + m_Prefix) + "\n";
            }

            // Remove trialing newlines
            Content.Trim(ktStripType.trailing, "\n");

            // If the "content"/structure contains newlines or elements
            if ((!Content.IsEmpty()) && (Content.Contains("\n") || Content.Contains("<")))
            {
                // Add newline after start-element
                StartElm = StartElm + "\n";

                // hum... Add newline if the content doesn't end with one!?
                if ((!Content.StartsWith("\n")) && (Content.Last() != '\n'))
                {
                    Prefix.Prepend("\n");
                }

                // Add Prefix before end-element and a newline after..
                EndElm = Prefix + EndElm + "\n";
            }

            // Put together start content/childs and end element...
            XML += StartElm + Content + EndElm;

            // Done.. Return the structure
            return XML;// + Get_R();
        }
예제 #30
0
        public override ktValue _GetProperty(ktString Name, bool Copy)
        {
            //ktDebug.Log( "kactalkclass::_GP( " + Name+ " )" );
            if ((Name == "this") || (Name == "_this") ||
                (Name == "object") || (Name == "_object") ||
                (Name == "_") || (Name.IsEmpty()))
            {
                return new ktValue(m_Name, "kactalk", this, true, false);
            }/*
            switch (Name) {
            }*/

            throw new ktError("Couldn't find the property '" +
                              Name + "' in class '" + m_Name + "'.", ktERR._404);
        }