]> git.saurik.com Git - cycript.git/blob - Application.mm
This is getting seriously hot.
[cycript.git] / Application.mm
1 #include <iostream>
2 #include <string>
3
4 #include <CoreFoundation/CoreFoundation.h>
5 #include <CoreFoundation/CFLogUtilities.h>
6
7 #include <Foundation/Foundation.h>
8
9 #include <JavaScriptCore/JSBase.h>
10 #include <JavaScriptCore/JSValueRef.h>
11 #include <JavaScriptCore/JSObjectRef.h>
12 #include <JavaScriptCore/JSContextRef.h>
13 #include <JavaScriptCore/JSStringRef.h>
14 #include <JavaScriptCore/JSStringRefCF.h>
15
16 #define _trace() do { \
17 CFLog(kCFLogLevelNotice, CFSTR("_trace(%u)"), __LINE__); \
18 } while (false)
19
20 JSContextRef JSGetContext(void);
21 CFStringRef JSValueToJSONCopy(JSContextRef ctx, JSValueRef value);
22
23 int main() {
24 for (;;) {
25 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
26
27 std::cout << ">>> " << std::flush;
28
29 std::string line;
30 if (!std::getline(std::cin, line))
31 break;
32
33 JSStringRef script(JSStringCreateWithUTF8CString(line.c_str()));
34
35 JSValueRef exception;
36 JSValueRef result(JSEvaluateScript(JSGetContext(), script, NULL, NULL, 0, &exception));
37 if (result == NULL)
38 result = exception;
39 JSStringRelease(script);
40
41 if (!JSValueIsUndefined(JSGetContext(), result)) {
42 CFStringRef json(JSValueToJSONCopy(JSGetContext(), result));
43 std::cout << [reinterpret_cast<const NSString *>(json) UTF8String] << std::endl;
44 CFRelease(json);
45 }
46
47 [pool release];
48 }
49
50 return 0;
51 }