Skip to content

Instantly share code, notes, and snippets.

@dcampbell24
Created August 25, 2012 20:54
Show Gist options
  • Save dcampbell24/3470851 to your computer and use it in GitHub Desktop.
Save dcampbell24/3470851 to your computer and use it in GitHub Desktop.
julia ccall macro
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