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); } }
internal Unifiable SystemExecute(Unifiable cmd, Unifiable langu, Request user) { if (IsNullOrEmpty(langu)) { langu = GlobalSettings.grabSetting("systemlang") ?? "bot"; } else { langu = ToLower(Trim(langu)); } Unifiable s = "The system tag should be doing '" + cmd + "' lang=" + langu; writeToLog(s.AsString()); SystemExecHandler handler; if (SettingsDictionaryReal.TryGetValue(ExecuteHandlers, langu, out handler)) { try { object o = handler(cmd, user); return(Unifiable.Create(o)); } catch (Exception e) { writeToLog(e); return(Unifiable.Empty); } } else { try { object self = user; ScriptInterpreter parent = null; ScriptInterpreter si = ScriptManager.LoadScriptInterpreter(langu, self, parent); object o = ScriptManager.EvalScriptInterpreter(cmd.ToValue(user.CurrentQuery), langu, self, parent, writeToLog); string siStr = si.Str(o); return(Unifiable.Create(siStr)); } catch (Exception e) { writeToLog(e); } } writeToLog(s); return(Unifiable.Empty); }
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); } }