Created
May 7, 2018 10:58
-
-
Save saagarjha/bfecf23d9b383e753a5fc53bc982ce78 to your computer and use it in GitHub Desktop.
A small command line calculator for macOS, using Calculate.framework
This file contains 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 | |
let handle = dlopen("/System/Library/PrivateFrameworks/Calculate.framework/Calculate", RTLD_LAZY) | |
let CalculatePerformExpression = unsafeBitCast(dlsym(handle, "CalculatePerformExpression"), to: | |
(@convention(c) (UnsafePointer<CChar>, Int, Int, UnsafePointer<CChar>) -> Bool).self) | |
let expression = Array(CommandLine.arguments.dropFirst()).joined(separator: " ") | |
let answer = Array<CChar>(repeating: 0, count: 100) | |
if CalculatePerformExpression(expression, 16, 1, answer) { | |
print(String(cString: answer)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment