Skip to content

Instantly share code, notes, and snippets.

@kosugi
Created November 29, 2012 05:17
Show Gist options
  • Select an option

  • Save kosugi/4166950 to your computer and use it in GitHub Desktop.

Select an option

Save kosugi/4166950 to your computer and use it in GitHub Desktop.
execute objc code fragment
#! /bin/bash
#
# exec-objc.sh <<'EOD'
# NSLog(@"this script compile and execute objective-c code fragment");
# EOD
#
SRC=$(mktemp exec-objc-src.XXXXXXXX)
OUT=$(mktemp exec-objc-out.XXXXXXXX)
trap 'rm -f ${SRC} ${OUT}' EXIT
cat >>${SRC} <<'EOD'
#import <Foundation/Foundation.h>
void doIt() {
EOD
cat >>${SRC} </dev/stdin
cat >>${SRC} <<'EOD'
}
int main() {
@autoreleasepool {
doIt();
}
return 0;
}
EOD
clang -Wall -x objective-c -std=c99 -fobjc-arc "$@" -framework Foundation -o ${OUT} ${SRC} && PATH=.:$PATH ${OUT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment