Created
September 30, 2022 18:15
-
-
Save thesubtlety/4d369127773fe45d69c65852faaa7548 to your computer and use it in GitHub Desktop.
Obj JXA runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <Appkit/AppKit.h> | |
#import <CoreFoundation/CoreFoundation.h> | |
#import <OSAKit/OSAKit.h> | |
#import <Cocoa/Cocoa.h> | |
#import <OSAKit/OSALanguage.h> | |
#import <Foundation/NSString.h> | |
#include <string.h> | |
//jxarunner file.js | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSString *filepath = [NSString stringWithFormat:@"%s", argv[1]]; | |
//NSLog(@"Got: %@", filepath); | |
NSFileManager *filemgr; | |
NSData *databuffer; | |
filemgr = [NSFileManager defaultManager]; | |
databuffer = [filemgr contentsAtPath: filepath ]; | |
NSString *code = [[NSString alloc] initWithData:databuffer encoding:NSASCIIStringEncoding]; | |
//NSLog(@"Contents: %@", code); | |
OSALanguage *lang = [OSALanguage languageForName:@"JavaScript"]; | |
OSAScript *script = [[OSAScript alloc] initWithSource:code language:lang]; | |
NSDictionary *__autoreleasing compileError; | |
NSDictionary *__autoreleasing runError; | |
[script compileAndReturnError:&compileError]; | |
NSAppleEventDescriptor *res = [script executeAndReturnError:&runError]; | |
//NSLog(@"compileError: %@", compileError); | |
//NSLog(@"runerr: %@", runError); | |
NSLog(@"res: %@", res); | |
return 0; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment