public bool Run(GcMachine m, string[] param) { if (m.GetLocalIDByName(param[1]) == -1) { System.Console.WriteLine("Local varible " + param[1] + "do not exist."); } else { Varible v = m.GetLocalByID(m.GetLocalIDByName(param[1])); string st = "Local varible " + param[1] + ":"; if (v.type == VarType.TYPE_NUMBER) { st += v.num.ToString(); } else if (v.type == VarType.TYPE_STRING) { st = st + "\"" + m.GetString(v.pointer).Replace("\n", "").Replace("\r", "") + "\""; } else { st += "(function)"; } System.Console.WriteLine(st); } return(false); }
public Varible invoke(GcMachine m, int numParams) //Note that the interface has changed { Delegate func = new Delegate(m_cw.Write); Varible v; string str = ""; for (int i = 1; i <= numParams; ++i) //param have ID from 1 to numParams(possibly 0) { v = m.GetLocalByID(i); //How to access each param, do not specify ID less than 1 or greater than numParams if (v.type == VarType.TYPE_NUMBER) { str += v.num.ToString(); } else if (v.type == VarType.TYPE_STRING) { str += v.str; } else { throw new RuntimeException("Type mismatch"); //You can throw any runtime exception too. } } str += "\n"; m_cw.Dispatcher.Invoke( func, System.Windows.Threading.DispatcherPriority.ContextIdle, str); return(new Varible(0.0)); //You can return any number here. }
public Varible invoke(GcMachine m, int numParams) //Note that the interface has changed { Varible v; for (int i = 1; i <= numParams; ++i) //param have ID from 1 to numParams(possibly 0) { v = m.GetLocalByID(i); //How to access each param, do not specify ID less than 1 or greater than numParams if (v.type == VarType.TYPE_NUMBER) { System.Console.Write(v.num.ToString()); //How to access number } else if (v.type == VarType.TYPE_STRING) { System.Console.Write(m.GetString(v.pointer)); //For string ,you must use getString method to convert a string-pointer to actual string } else { throw new RuntimeException("Type mismatch"); //You can throw any runtime exception too. } } System.Console.Write("\n"); return(new Varible(0.0)); //You can return any number here. }