From: Jay Freeman (saurik) Date: Wed, 30 Sep 2009 08:24:36 +0000 (+0000) Subject: Connected the console back together. X-Git-Tag: v0.9.432~400 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/f430684b0366f515c835502514f5064c39aa35df Connected the console back together. --- diff --git a/Library.mm b/Library.mm index 8135429..29fffa5 100644 --- a/Library.mm +++ b/Library.mm @@ -72,6 +72,7 @@ #include #include #include +#include #include "Parser.hpp" #include "Cycript.tab.hh" @@ -934,11 +935,50 @@ void cy::parser::error(const cy::parser::location_type &loc, const std::string & } void CYConsole(FILE *fin, FILE *fout, FILE *ferr) { - cydebug = 1; - CYDriver driver(""); - cy::parser parser(driver); - if (parser.parse() == 0) - driver.source_->Part(std::cout); + //cydebug = 1; + + for (;;) { _pooled + CYDriver driver(""); + cy::parser parser(driver); + if (parser.parse() != 0) + continue; + + if (driver.source_ == NULL) { + fputs("driver.source == NULL\n", fout); + break; + } + + std::ostringstream str; + driver.source_->Part(str); + + JSStringRef script(JSStringCreateWithUTF8CString(str.str().c_str())); + + JSContextRef context(JSGetContext()); + + JSValueRef exception(NULL); + JSValueRef result(JSEvaluateScript(context, script, NULL, NULL, 0, &exception)); + JSStringRelease(script); + + if (exception != NULL) + result = exception; + + if (!JSValueIsUndefined(context, result)) { + CFStringRef json; + + @try { json: + json = JSValueToJSONCopy(context, result); + } @catch (id error) { + CYThrow(context, error, &result); + goto json; + } + + fputs([reinterpret_cast(json) UTF8String], fout); + CFRelease(json); + + fputs("\n", fout); + fflush(fout); + } + } } MSInitialize { _pooled