Esempio n. 1
0
 public virtual ktClass CreateObject(ktValue Value)
 {
     return CreateObject(Value.ToString());
 }
Esempio n. 2
0
        protected ktValue HandleNew(ktList Statement)
        {
            ktValue NewValue = ktValue.Null;
            ktClass NewObj = null;

#if Debug
	ktDebug.Log( "HandleNew:" + Statement.Get_R() );
#endif

            if ((Statement == null) || (Statement.GetCount() == 0) ||
                (Statement.First == null) || (Statement.First.Node == null) ||
                (Statement.First.Node.Value == null) ||
                ((Statement.First.First != null) && (
                        (Statement.First.First.Node == null) || (Statement.First.First.Node.Value == null)))
               )
            {
                throw new ktError("ktBlock::HandleNew: Didn't get enough information to create a new object!", ktERR.MISSING);
            }

            ktToken Token = (ktToken)Statement.First.Node.Value;
            ktString Name = new ktString();
            ktList Arguments = null;

            if (Token.Type == ktTokenType.Id)
            {
                Name = Token.Value;
            }
            else if ((Token.Type == ktTokenType.CompStatement) ||
                      (Token.Type == ktTokenType.Statement))
            {
                Token = (ktToken)Statement.First.First.Node.Value;
                Name = Token.Value;

                Arguments = GetArguments(Statement.First.Last);
            }

            NewObj = (ktClass)MakeObjectOf(Name, (object)null);

            if (Arguments != null)
            {
                ktDebug.Log("NO: " + NewObj.Export() + ";;Args:" + Arguments.Get_R());
                try
                {
                    NewObj.RunMethod("constructor", Arguments);
                }
                catch (ktError Err)
                {
                    ktDebug.Log("NEW_CONS:ERR:" + Err.ToString());
                    if (Err.ErrorNumber == ktERR.NOTFOUND)
                    {
                        throw new ktError("The class " + Name + " is missing an constructor!", ktERR.NOTFOUND);
                    }
                    else
                    {
                        throw Err;
                    }
                }
            }

            NewValue = new ktValue("", Name, NewObj, false, false);
            ktDebug.Log("NV: " + NewValue.ToString());
            return NewValue;
        }
Esempio n. 3
0
        /// <summary>
        /// Set the value of a variable
        /// </summary>
        /// <param name="Name">The name of the variable to set</param>
        /// <param name="Value">The value to give the variable</param>
        /// <param name="Add">Add the variable if it doesn't exists</param>
        /// <param name="Copy">Copy the value</param>
        /// <param name="IgnoreConstant">Ignore whether the var is constant (only used externally!)</param>
        /// <param name="ABKT">Is this variable added by KT/a script</param>
        /// <returns></returns>
        public bool SetVariable(ktString Name, ktValue Value, bool Add, bool Copy,
                                    bool IgnoreConstant, bool ABKT)
        {
            // Nothing to use??
            if (Name.IsEmpty() || (Value == null))
            {
                return false;
            }
#if Debug
	ktDebug.Log( "SetVariable( " + Name + ", " + Value.ToString() + ", " + Add.ToString() + ", " + Copy.ToString() + " )" );
#endif

            if (Copy)
            {
                Value = Value.CopyValue();
                Value.Name = Name;
            }

            ktValue Var = null;
            // Catch errors...
            try
            {
                // try to get Variable
                Var = GetVariable(Name);

                if ((!IgnoreConstant) && (Var.Constant))
                {
                    throw new ktError("You are trying to assign a value to " + Name +
                                        ", which is a constant!", ktERR.CONST);
                }

                // Set value...
                Var.SetValue(Value);
            }
            catch (ktError Err)
            {
                // If the error is due to nonexisting var??
                if ((Err.ErrorNumber == ktERR.NOTDEF) || (Err.ErrorNumber == ktERR.NOTFOUND))
                {
                    // Should we add?
                    if (Add)
                    {
                        // Set name
                        Value.Name = Name;
                        // Add...
                        return AddVariable(Value, ABKT);
                    }
                }

                // If we reach this, something went wrong or we just wasn't alloweed to add
                //  the variable...
                throw Err;
            }

            // Ok!?!?!
            return true;
        }
Esempio n. 4
0
 public override ktClass CreateObject(ktValue Value)
 {
     return new ktStringClass(Value.ToString());
 }