Created
August 25, 2012 20:54
-
-
Save dcampbell24/3470851 to your computer and use it in GitHub Desktop.
julia ccall macro
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
macro ccallWrap(lib, fnSym, retType, argTypes) | |
argTypes = eval(argTypes) | |
assertOp = :(sym::Type).head | |
args = [gensym() for i in 1:length(argTypes)] | |
fnArgs = [Expr(assertOp, {args[i], argTypes[i]}, Any) | |
for i in 1:length(argTypes)] | |
dlsymExpr = Expr(:call, {:dlsym, lib, fnSym}, Any) | |
ccallExpr = Expr(:call,{:ccall, dlsymExpr, retType, argTypes, args...},Any) | |
fnBody = Expr(:block, {ccallExpr}, Any) | |
fnCall = Expr(:call,{eval(fnSym), fnArgs...}, Any) | |
ccallFn = Expr(:function, {fnCall, fnBody}, Any) | |
line1 = Expr(:line, {1}, Any) | |
fnBlock = Expr(:block, {line1, Expr(:global, {eval(fnSym)}, Any), ccallFn}, Any) | |
fnBlock | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment