private static bool IsCodeMatch(SimObject obj, object smatch) { ScriptInterpreter interp = GetScriptInterpreter(); lock (interp) { interp.Intern("this", obj); interp.Intern("thisClient", WorldObjects.GridMaster.client); string res = interp.Str(interp.Eval(smatch)); if (res.ToLower().StartsWith("t")) { return(true); } return(false); } }
public override bool BooleanOnEvent(string eventName, string[] paramNames, Type[] paramTypes, params object[] parameters) { if (Interpreter == null) { return(true); } eventName = eventName.ToLower(); Cons eval; if (!Interpreter.IsSubscriberOf(eventName)) { return(true); } if (EventArgsInDictionary) { Dictionary <String, object> eventArgs = new Dictionary <string, object>(); for (int i = 0; i < paramNames.Length; i++) { eventArgs.Add(paramNames[i], CoerceArg(parameters[i], paramTypes[i])); } eval = new Cons(eventName, new Cons(eventArgs, null)); } else { //todo return(true); Cons invokeMe = null; for (int i = paramNames.Length - 1; i >= 0; i--) { invokeMe = new Cons(CoerceArg(parameters[i], paramTypes[i]), invokeMe); } eval = new Cons(Interpreter.GetSymbol(eventName.ToLower()), invokeMe); } // right now most events are void but there is one that is boolean which means we may as well eturn true for all try { object o = Interpreter.Eval(eval); } catch (Exception e) { DLRConsole.DebugWriteLine(eval + " Caused"); DLRConsole.DebugWriteLine(e); } return(true); }
public void taskTick() { if (taskInterperter == null) { // Abort self Thread.CurrentThread.Abort(); return; } // string lastcode = ""; string codeString = null; try { // see if there is anything to process if (taskQueue.Count == 0) { return; } KeyValuePair <object, CogbotEvent> thisTask; // if so then process it //Interpreter lispInterperter = new Interpreter(); lock (taskQueue) { thisTask = taskQueue.Dequeue(); } // setup the local context //lastcode = thisTask.code; //string serverMessage = ""; // thisTask.results = "'(unevaluated)"; //taskInterperter.Intern("thisTask", thisTask); //should make the following safer ... //taskInterperter.Intern("tcpReader", tcpStreamReader); //taskInterperter.Intern("tcpWriter", tcpStreamWriter); //a safer way is to have a serverMessage string that is sent to the Client // in a more thread safe async way //taskInterperter.Intern("serverMessage", serverMessage); //taskInterperter.Intern("Client",Command.Client); // EVALUATE !!! codeString = taskInterperter.Str(thisTask.Key); Object x = taskInterperter.Eval(thisTask.Key); // thisTask.results = taskInterperter.Str(x); //lock (lBotMsgSubscribers) //{ // foreach (BotMessageSubscriber ms in lBotMsgSubscribers) // { // if (ms is Utilities.BotTcpServer) // { // //((Utilities.BotTcpServer)ms).taskTick(thisTask.results); // } // } //} if (false) { // WriteLine(" taskcode: " + lastcode + " --> " + thisTask.results); //WriteLine(" taskTick Results>" + thisTask.results); //WriteLine(" taskTick continueTask=" + thisTask.requeue.ToString()); } // Should we do again ? //if (thisTask.requeue == true) //{ // if (!lastcode.Equals(thisTask.code)) // { // // not the same so must "re-compile" // thisTask.codeTree = genLispCodeTree(thisTask.code); // } // lock (taskQueue) // { // taskQueue.Enqueue(thisTask); // } //} return; } catch (Exception e) { DLRConsole.DebugWriteLine("!Exception: " + e.GetBaseException().Message); DLRConsole.DebugWriteLine("error occured: " + e.Message); DLRConsole.DebugWriteLine(" Stack: " + e.StackTrace.ToString()); DLRConsole.DebugWriteLine(" LispCode: " + codeString); } }