Skip to content

Instantly share code, notes, and snippets.

@weissi
Last active August 29, 2015 14:07
Show Gist options
  • Save weissi/2af52224667f9e6da1ed to your computer and use it in GitHub Desktop.
Save weissi/2af52224667f9e6da1ed to your computer and use it in GitHub Desktop.
int invoke_fun(int (*f)(void));
#include "invoke_fun.h"
int invoke_fun(int (*f)(void)) {
return f();
}
#ifndef __SwiftTestApp__invoke_fun__
#define __SwiftTestApp__invoke_fun__
int invoke_fun(int (*f)(void));
#endif
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