]> git.saurik.com Git - cycript.git/blame - Application.mm
This is starting to look better.
[cycript.git] / Application.mm
CommitLineData
62ca2b82
JF
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
20JSContextRef JSGetContext(void);
21CFStringRef JSValueToJSONCopy(JSContextRef ctx, JSValueRef value);
22
23int 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 CFStringRef json(JSValueToJSONCopy(JSGetContext(), result));
42 std::cout << [reinterpret_cast<const NSString *>(json) UTF8String] << std::endl;
43 CFRelease(json);
44
45 [pool release];
46 }
47
48 return 0;
49}