Last active
August 29, 2015 14:07
-
-
Save weissi/2af52224667f9e6da1ed to your computer and use it in GitHub Desktop.
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
int invoke_fun(int (*f)(void)); |
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
#include "invoke_fun.h" | |
int invoke_fun(int (*f)(void)) { | |
return f(); | |
} |
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
#ifndef __SwiftTestApp__invoke_fun__ | |
#define __SwiftTestApp__invoke_fun__ | |
int invoke_fun(int (*f)(void)); | |
#endif |
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 Darwin | |
import Foundation | |
let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW) | |
let sym : UnsafeMutablePointer<Void> = dlsym(handle, "random") | |
let rawPointer = UnsafeMutablePointer<() -> Int32>(sym) | |
let opaquePtr : COpaquePointer = COpaquePointer(rawPointer) | |
let cFunPointer = CFunctionPointer<() -> Int32>(opaquePtr) | |
println(invoke_fun(cFunPointer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment