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); }
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); }; }
/// <summary> /// Get a module... /// </summary> public ktModule GetModule(ktString Name) { if (Name.IsEmpty()) { return null; } ktModule Module = null; if (m_Modules != null) { ktNode Node = m_Modules.GetNode(Name); if ((Node != null) && (Node.Value != null)) { Module = (ktModule)Node.Value; } } if (Module == null) { throw new ktError("kactalk::GetModule() : There's no module with the name '" + Name + "'!", ktERR.NOTDEF); } return Module; }
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; }
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); } }
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("_"); }
public virtual ktValue _RunMethod(ktString Name, ktList Arguments) { //ktDebug.Log( "ktClass::_RM( " + Name + " );" ); if (Name.IsEmpty()) { throw new ktError("Didn't get the name of the method to run in class '" + m_Name + "'.", ktERR.NOTSET); } if (m_Methods == null) { throw new ktError("Couldn't find the method '" + Name + "' in class '" + m_Name + "'.", ktERR._404); } ktNode Node = m_Methods.GetNode(Name); if ((Node == null) || (Node.Value == null)) { throw new ktError("Couldn't find the method '" + Name + "' in class '" + m_Name + "'.", ktERR._404); } ktValue Value = ktValue.Null; ktFunction Func = (ktFunction)Node.Value; Value = Func.Run(Arguments); return Value; }
public virtual ktValue SetProperty(ktString Name, ktValue Value) { if (Name.IsEmpty()) { throw new ktError("Didn't get the name of the property to change in class '" + m_Name + "'.", ktERR.NOTSET); } if (m_Properties == null) { m_Properties = new ktList(); } ktNode Node = m_Properties.GetNode(Name); if ((Node == null) || (Node.Value == null)) { if (m_AddIfNotSet) { return AddProperty(Name, Value); } else { throw new ktError("Couldn't find the property '" + Name + "' in class '" + m_Name + "'.", ktERR._404); } } else { ktValue Prop = (ktValue)Node.Value; if (Prop.Constant) { throw new ktError("The property '" + Name + "' in class '" + m_Name + "' is a constant and can't be changed.", ktERR.CONST); } else if (Value == null) { // HUM??? Prop.Value = null; } else { Prop.SetValue(Value); } return Prop; } }
public ktValue GetProperty(ktString Name, bool Copy) { ktValue Value = ktValue.Null; if (Name.IsEmpty()) { return Value; } //ktDebug.Log( "GetProperty( " + Name + " )" ); switch (Name.AsLower()) { case "as_class": case "class": { return new ktValue(Name, "ktClass", CreateClass(), true, true); } default: { //ktDebug.Log( "Default" ); Value = _GetProperty(Name, Copy); break; } } //ktDebug.Log( "Val = " + ((Value == null) ? "NULL" : Value.ToString() ) + " )" ); return Value; }
/// <summary> /// Export the list... /// </summary> public override string Export() { ktString Str = new ktString("("); ktString Name = new ktString(), Value = new ktString(); bool First = true; Reset(); foreach (ktList List in this) { Name = ""; Value = ""; if (!First) { Str += ", \n"; } else { First = false; } if (List.Node != null) { Name = List.Node.Name; Value = List.Node.ExportValue(); } if (!Name.IsEmpty()) { if ((!Value.IsEmpty()) && (Value != ":null") && (!List.IsEmpty())) { //Name = "[\"" + Name + "\"," + Value + "]"; } else { //Name = "\"" + Name + "\""; //Name.Append( new ktString( Name.Len() ) ); } } else if (!Value.IsEmpty()) { Name = Value; Value = ""; } if (!List.IsEmpty()) { Value = List.Export(); } else if ((Value.IsEmpty()) && (Name.IsEmpty())) { Value = ":null"; //Value = "\"" + Value + "\""; } if (!Name.IsEmpty()) { Str += Name; if (!Value.IsEmpty()) { Str += " => " + Value; } } else { Str += Value; } } Str += ")"; return Str; //return Get_R( Prefix, false ); }
protected void CallCallback(ktString Method) { if (Method.IsEmpty() || (m_Callback == null)) { return; } ktList Args = new ktList(); Args.Add("Name", Name); Args.Add("Value", this); try { m_Callback.RunMethod("_" + Method, Args); } catch (ktError Err) { if ((Err.ErrorNumber != ktERR._404) && (Err.ErrorNumber != ktERR.NOTDEC)) { throw Err; } } }
public bool SetName(ktString Name) { if (Name.IsEmpty()) { return false; } m_Name = Name; return true; }
public static ktList Replace(ktList Replacements, ktString Haystack) { ktList Results = new ktList(); ktString Pattern = new ktString(); ktString Replacement = new ktString(); ktRE_MatchEvaluator Ev = null; ktNode Node; ktString Result = ""; object First = null, Second = null; Replacements.Reset(); foreach (ktList Post in Replacements) { if (Post.IsEmpty()) { if ((Post.Node != null) && (Post.Node.Value != null)) { Pattern = Post.Node.Name; if ((Post.Node.Value.GetType() == typeof(ktString)) || (Post.Node.Value.GetType() == typeof(string))) { Replacement = Post.Node.Value.ToString(); Results.Add(Replace(Pattern, Haystack, Replacement)); } else if (Post.Node.Value.GetType() == typeof(ktRE_MatchEvaluator)) { Ev = (ktRE_MatchEvaluator)Post.Node.Value; Results.Add(Replace(Pattern, Haystack, Ev)); } else if (Post.Node.Value.GetType() == typeof(ktRegEx)) { //ktRegEx RE = (ktRegEx)Post.Node.Value; if (Pattern.IsEmpty()) { //Results.Add( RE.Replace( Haystack, Ev ) ); } else { //Results.Adâ€d( Replace( Pattern, Haystack, Ev ) ); } } } } else if (Post.Count == 2) { if ((Node = Post.GetNode(0)) != null) { First = Node.Value; if ((Node = Post.GetNode(1)) != null) { Second = Node.Value; } } if (Second != null) { if (First.GetType() == typeof(ktRegEx)) { Result = HandleRegExFirst((ktRegEx)First, Second, Haystack); Results.Add(Result); } else if (First.GetType() == typeof(ktString[])) { ktString[] Patterns = (ktString[])First; foreach (ktString P in Patterns) { Result = HandleStringFirst(P, Second, Haystack); Results.Add(Result); } } else if (First.GetType() == typeof(ktList)) { ktList Patterns = (ktList)First; foreach (ktList P in Patterns) { if ((P.Node != null) && (P.Node.Value != null)) { Pattern = P.Node.Value.ToString(); Result = HandleStringFirst(Pattern, Second, Haystack); Results.Add(Result); } } } else /*if ((First.GetType() == typeof( ktString )) || (First.GetType() == typeof( string )))*/ { Result = HandleStringFirst(First.ToString(), Second, Haystack); Results.Add(Result); } } } } return Results; }
/// <summary> /// Scan/Parse the script into tokens /// </summary> public bool Scan(ktString Script, ktString Name) { bool Ret = true; Script.Replace("\r\n", "\n",true); // Initiate the lineno. m_CurLine = 1; m_CharPos = 1; // .. and name m_Name = Name; if (m_Tokens != null) { m_Tokens.Clear(); m_Tokens = null; } // Init... ktString Line = new ktString(); int Pos = 0; Script.Trim(); ktRegEx RE = new ktRegEx(ktToken.Separators); // ... the block-stack if (m_BlockStack != null) { m_BlockStack.Clear(); m_BlockStack = null; } m_BlockStack = new ktList(); // ... the token-list if (m_Tokens != null) { m_Tokens.Clear(); m_Tokens = null; } m_Tokens = new ktList(); m_Tokens.Node = new ktNode("ktTStatement", new ktToken(ktTokenType.Statement, "", 0, 0)); // ... the token-stack if (m_TokenStack != null) { m_TokenStack.Clear(); m_TokenStack = null; } m_TokenStack = new ktList(); // ... the lines (??) if (m_Lines != null) { m_Lines.Clear(); m_Lines = null; } m_Lines = new ktList(); m_Lines.Node = new ktNode(Name, m_CurToken = new ktToken(ktTokenType.Program, Name, 0, 0)); // ... the line-stack if (m_LineStack != null) { m_LineStack.Clear(); m_LineStack = null; } m_LineStack = new ktList(); if (m_MainBlock == null) { m_MainBlock = new ktBlock(new ktList()); } else { if (m_MainBlock.Lines != null) { m_MainBlock.Lines.Clear(); } m_MainBlock.ClearKTSymbols(); } m_MainBlock.SetMain(this); m_BlockStack.Add("ktTBlock", m_MainBlock); /* In the "original scanner" (C++), we took one line (terminated by \n) * at a time and worked on, now we just go through the line. * And We hope that it will be much "leaner"! */ // Go on until the there's nothing left... while (!Script.IsEmpty()) { // Get the position for the next separator Pos = RE.Find(Script); // If there was none... if (Pos < 0) { // Take it to the end... Pos = Script.Len(); } else if (Pos == 0) { Pos++; } // Get the next "token" Line = Script.SubStr(0, Pos); // If it's the start of a comment if ((Line == "/") && (Script.StartsWith("//") || Script.StartsWith("/*"))) { Line = Script.SubStr(0, 2); Pos++; } else if ((Line == "*") && (Script.StartsWith("*/"))) { Line = "*/"; Pos++; } ReactOnToken(Line, m_CurLine, ref m_CharPos); if (Line == "\n") { m_CurLine++; m_CharPos = 1; } else { m_CharPos += Line.Len(); } // Remove the "token", we just worked on... Script.Remove(0, Pos); } #if ParseDebug || DebugXML ktDebug.Log("XML111111:"); ktDebug.Log(ktXML.FromList(m_TokenStack).AsXML()); ktDebug.Log("=================="); ktDebug.Log(ktXML.FromList(m_Tokens).AsXML()); #endif if (!m_Tokens.IsEmpty()) { if (m_AllowMissingEOL) { ((ktToken)m_Tokens.Node.Value).Type = ktTokenType.Line; ((ktToken)m_Tokens.Node.Value).Name = m_Tokens.Node.Name = "ktTLine"; m_LineStack.AddList(m_Tokens); m_Tokens = null; } else { throw new ktError("Expected a ktTEOL at line " + m_CurLine.ToString() + " but didn't find one!", ktERR.MISSING); } } if (m_BlockStack.Count > 1) { throw new ktError("Expecting ktTEOB (}) at " + m_CharPos.ToString() + ", line " + m_CurLine.ToString() + ".", ktERR.MISSING); } //ktToken.OnlyExportValue = false; //ktDebug.Log( m_LineStack.Get_R( ) ); //ktToken.OnlyExportValue = false; #if ParseDebug || DebugXML ktDebug.Log( "XML:" ); ktDebug.Log( ktXML.FromList(m_LineStack).AsXML() ); ktDebug.Log( "==================" ); ktDebug.Log( ktXML.FromList(m_Lines).AsXML() ); #endif /* ktDebug.Log( "?+++++\n" + m_Tokens.Get_R( "\t", true ) ); ktDebug.Log( "?+++++\n" + m_CurToken.Export if (m_CurToken != null) { if (m_CurToken.Type == ktTokenType.List) { throw new ktError( "Expected a ktTEndPar at line " + m_CurLine.ToString() + " but didn't find one!", ktERR.MISSING ); } else if (m_CurToken.Type == ktTokenType.String) { throw new ktError( "Expected a ktTStringQuot at line " + m_CurLine.ToString() + " but didn't find one!", ktERR.MISSING ); } else if (m_CurToken.Type == ktTokenType.Block) { throw new ktError( "Expected a ktTEndOfBlock at line " + m_CurLine.ToString() + " but didn't find one!", ktERR.MISSING ); } } else if ((m_Tokens != null) && (!m_Tokens.IsEmpty())) { throw new ktError( "Expected a ktTEOL at line " + m_CurLine.ToString() + " but didn't find one!", ktERR.MISSING ); } */ // MakeATree( ); // MakeAOpTree( ); if ((m_BlockStack == null) || (m_BlockStack.IsEmpty())) { return Ret; } ktBlock Block = (ktBlock)(m_BlockStack.Pop().Node.Value); #if ParseDebug ktDebug.Log( "BLOCK1:" + ktXML.FromList(Block.Lines).AsXML() );r #endif MakeATree(); #if ParseDebug ktDebug.Log("BLOCK2:" + ktXML.FromList(m_Lines).AsXML()); #endif Block.Lines = MakeAOpTree(); m_LineStack.Clear(); m_LineStack = null; // Add Current "statement"/"post" to the block and theń switch them //Temp.AddList( m_Tokens ); //m_Tokens = Temp; #if ParseDebug ktDebug.Log( "BLOCK:" + ((Block == m_MainBlock) ? "MAIN":"NOT_MAIN") ); #endif /*ktList Temp = null; if (LastBlockLines == null) { throw new ktError( "No Last Block Lines!", ktERR.MISSING ); } LastBlockLines.Add( "ktTBlock", new ktToken( Block, m_CurToken.LineNo, m_CurToken.CharPos ) );*/ #if ParseDebug || DebugXML ktDebug.Log( "XML_After Tree:" + ktXML.FromList(Block.Lines).AsXML() ); ktDebug.Log( "XML_After Tree:" + Block.Lines.Get_R( "\t", true ) ); #endif //ktDebug.Log( m_Lines.Export() ); return Ret; }
/// <summary> /// Get a variable /// </summary> public ktValue GetVariable(ktString Name) { if (Name.IsEmpty()) { return null; } ktValue Var = null; try { if (m_Variables != null) { ktNode Node = m_Variables.GetNode(Name); if ((Node != null) && (Node.Value != null)) { Var = (ktValue)Node.Value; } } } catch (ktError E) { if (!((E.ErrorNumber == ktERR.NOTFOUND) || (E.ErrorNumber == ktERR.NOTDEF))) { throw E; } } if (Var == null) { throw new ktError("kactalk::GetVariable() : There's no variable with the name '" + Name + "'!", ktERR.NOTDEF); } return Var; }
public virtual ktContext GetContext(ktString Name) { if (Name.IsEmpty()) { throw new ktError("Didn't get the name of the context to get in the module '" + m_Name + "'.", ktERR.NOTSET); } if (m_Contexts == null) { throw new ktError("Couldn't find the context '" + Name + "', in module '" + m_Name + "'.", ktERR.NOTFOUND); } ktNode Node = null; try {/* Node = m_Contexts.GetNode( Name ); Node.HasError(); // Error Trigger??*/ ktContext Con = null; m_Contexts.Reset(); foreach (ktList CL in m_Contexts) { if ((CL == null) || (CL.Node == null) || (CL.Node.Value == null) || (CL.Node.Value.GetType() == typeof(ktContext))) { continue; } Con = (ktContext)CL.Node.Value; if ((Con.Name == Name) || (Con.Aliases.Contains(":" + Name + ":"))) { return Con; } } Node.HasError(); // Error Trigger?? } catch (Exception) { throw new ktError("Couldn't find the context '" + Name + "', in module '" + m_Name + "'.", ktERR.NOTFOUND); } return (ktContext)Node.Value; }
public virtual ktFunction GetMethod(ktString Name) { if (Name.IsEmpty()) { throw new ktError("Didn't get the name of the method to find in class '" + m_Name + "'.", ktERR.NOTSET); } if (m_Methods == null) { throw new ktError("Couldn't find the method '" + Name + "' in class '" + m_Name + "'.", ktERR._404); } ktNode Node = m_Methods.GetNode(Name); if ((Node == null) || (Node.Value == null)) { throw new ktError("Couldn't find the method '" + Name + "' in class '" + m_Name + "'.", ktERR._404); } ktFunction Func = (ktFunction)Node.Value; return Func; }
protected ktValue HandleCompAssignment(ktList Target, ktValue Value) { bool Constant = false, Hard = false; ktString Name = new ktString(), ClassName = null; ktToken Token = null; ktClass Class = null; #if Debug ktDebug.Log( "HCAHCAHCAHCAHCAHCAHCAHCAHCAHCAHCAHCAHCAHCA" ); #endif ktDebug.Log("HCA: V:" + Value.Export() + "\n" + Target.Get_R()); Target.Reset(); foreach (ktList L in Target) { if ((L.Node == null) || (L.Node.Value == null)) { continue; } Token = (ktToken)L.Node.Value; #if Debug ktDebug.Log( "HCA:" + Token.ToString() ); #endif switch (Token.Type) { case ktTokenType.Const: { if (Constant) { throw new ktError("Unexpected " + Token.ToString() + " on line " + Token.LineNo.ToString() + " by character " + Token.CharPos.ToString() + "!", ktERR.UNEXP); } Constant = true; break; } case ktTokenType.Hard: { if (Hard) { throw new ktError("Unexpected " + Token.ToString() + " on line " + Token.LineNo.ToString() + " by character " + Token.CharPos.ToString() + "!", ktERR.UNEXP); } Hard = true; break; } case ktTokenType.Id: { if (!Name.IsEmpty()) { try { Class = GetClass(Name); ClassName = Name; Hard = true; } catch (Exception) { throw new ktError("Unexpected " + Token.ToString() + " (" + Token.Value + ") on line " + Token.LineNo.ToString() + " by character " + Token.CharPos.ToString() + "!", ktERR.UNEXP); } } Name = Token.Value; break; } } } Value.Constant = Constant; Value.HardType = Hard; if (!Value.IsNull()) { ((ktClass)Value.Value).HardType = Hard; ((ktClass)Value.Value).IsConstant = Constant; } if (Class != null) { ktList Arg = new ktList(); ktClass Obj = Class.CreateObject(); Obj.HardType = Hard; Obj.IsConstant = Constant; if (!Value.IsNull()) { Arg.Add(Value); Obj.RunMethod("Assign", Arg); } Value = new ktValue(Name, ClassName, Obj, Hard, Constant); } SetVariable(Name, true, Value, true, true); return Value; }
public 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("RunM Arg:" + Arguments.Get_R()); ktValue Value = ktValue.Null; //ktDebug.Log( "ktClass::RM( " + Name + " );" ); try { Value = _RunMethod(Name, Arguments); } catch (Exception Err) { Value = (ktValue)Arguments.First.Node.Value; if (Name == "Export") { return new ktValue("", "ktString", kacTalk.Main.MakeObjectOf("ktString", Export()), true, true); } else if (Name.AsLower() == "tostring") { return new ktValue("", "ktString", kacTalk.Main.MakeObjectOf("ktString", ToString()), true, true); } else if (Name.AsLower() == "operator~") { return new ktValue("", "ktString", kacTalk.Main.MakeObjectOf("ktString", ToString() + Value.ToString()), true, true); } else if (Name.AsLower().StartsWith("to", out Name)) { } throw Err; } return Value; }
public ktValue GetVariable(ktString Name) { if (Name.IsEmpty()) { return null; } ktValue Var = null; try { if (m_Variables != null) { ktNode Node = m_Variables.GetNode(Name); if ((Node != null) && (Node.Value != null)) { Var = (ktValue)Node.Value; } } } catch (Exception) { } if (Var == null) { if (m_Parent != null) { Var = m_Parent.GetVariable(Name); } else if (m_Main != null) { Var = m_Main.GetVariable(Name); } } return Var; }
public virtual ktValue _GetProperty(ktString Name, bool Copy) { ktValue Value = ktValue.Null; if (Name.IsEmpty()) { return Value; } if (m_Properties == null) { throw new ktError("Couldn't find the property '" + Name + "' in class '" + m_Name + "'.", ktERR._404); } ktNode Node = m_Properties.GetNode(Name); if ((Node == null) || (Node.Value == null)) { throw new ktError("Couldn't find the property '" + Name + "' in class '" + m_Name + "'.", ktERR._404); //return Value; } if (Copy) { Value = new ktValue((ktValue)Node.Value); } else { Value = (ktValue)Node.Value; } return Value; }
/// <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; }
/// <summary> /// Returns a property of this class, matching 'Name'. /// </summary> 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) { case "MathMode": { return new ktValue(Name, "bool", m_Value.MakeObjectOf("ktBool", m_Value.MathMode), true, false, this); } } throw new ktError("Couldn't find the property '" + Name + "' in class '" + m_Name + "'.", ktERR._404); }
public ktValue RunFunction(ktString Name, ktList Arguments) { ktValue Ret = ktValue.Null; ktNode Node = null; bool NotFound = false; #if Debug ktDebug.Log( "RFRFRFRFRFRFRFRFRFRFRFRRFRF" ); #endif if (Name.IsEmpty()) { throw new ktError("ktBlock::RunFunction() : Didn't get the name of the method to run.", ktERR.NOTSET); } if ((m_Functions == null) || (m_Functions.Count == 0)) {//ktDebug.Log( "HC::NFunc!!\n"); NotFound = true; } else { Node = m_Functions.GetNode(Name); if (Node != null) { ktFunction Meth = (ktFunction)Node.Value; return Meth.Run(Arguments); } else { NotFound = true; } } if (NotFound) { if (m_Parent != null) { return m_Parent.RunFunction(Name, Arguments); } else if (m_Main != null) { return m_Main.RunFunction(Name, Arguments); } else { throw new ktError("ktBlock::RunFunction() : Couldn't find the function '" + Name + ".", ktERR.NOTFOUND); } } return Ret; }
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); }
public ktFunction GetFunction(ktString Name) { ktFunction Func = null; ktNode Node = null; bool NotFound = false; #if Debug ktDebug.Log( "GFGFGFGFGFGFGFGFGFGFGFGGFGF(" + Name + ")" ); #endif if (Name.IsEmpty()) { throw new ktError("ktBlock::GetFunction() : Didn't get the name of the method to find.", ktERR.NOTSET); } if ((m_Functions == null) || (m_Functions.Count == 0)) {//ktDebug.Log( "HC::NFunc!!\n"); NotFound = true; } else { Node = m_Functions.GetNode(Name); if (Node != null) { Func = (ktFunction)Node.Value; } else { NotFound = true; } } if (NotFound) { if (m_Parent != null) { Func = m_Parent.GetFunction(Name); } else if (m_Main != null) { Func = m_Main.GetFunction(Name); } else { throw new ktError("ktBlock::GetFunction() : Couldn't find the function '" + Name + ".", ktERR.NOTFOUND); } } return Func; }
public ktClass GetClass(ktString Name) { if (Name.IsEmpty()) return null; ktNode Node = null; if (m_Classes != null) Node = m_Classes.GetNode(Name); if (Node == null) { if (m_Parent != null) { return m_Parent.GetClass(Name); } else if (m_Main != null) { return m_Main.GetClass(Name); } } return (ktClass)Node.Value; }
public ktIntObj MakeObjectOf(ktString Name, object Value) { if (Name.IsEmpty()) { return null; } if (m_Main != null) { try { ktClass Class = m_Main.GetClass(Name); if (Class == null) { return null; } /**#if Debug ktDebug.Log( "=0==0====00===0000==0000==0000===0000==0" ); #endif/**/ ktClass Class2 = Class.CreateObject(Value); return Class2; } catch (ktError Err) { #if Debug Console.WriteLine( "MOOo:ERR" ); ktDebug.Log( Err.ToString( ) ); ktDebug.Log( Err.StackTrace ); #endif return null; } } return null; }
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(); }
/// <summary> /// Get a context /// </summary> public ktContext GetContext(ktString Name) { if (Name.IsEmpty() || (m_Modules == null)) { return null; } ktContext Context = null; ktModule Module = null; m_Modules.Reset(); //while ((Curr) && (!Context)) { foreach (ktList ML in m_Modules) { if ((ML.Node == null) || (ML.Node.Value == null)) { continue; } Module = (ktModule)ML.Node.Value; try { Context = Module.GetContext(Name); if (Context != null) { return Context; } } catch (ktError Err) { if (Err.ErrorNumber != ktERR.NOTFOUND) { throw Err; } } } if (Context == null) { throw new ktError("Couldn't find the context '" + Name + "'.", ktERR.NOTFOUND); } return Context; }