Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const juliaCallback = RObject{ExtPtrSxp}()
function setup_callbacks()
julia_extptr_callback_ptr = @cfunction(julia_extptr_callback,Ptr{UnknownSxp},(Ptr{ListSxp},))
juliaCallback.p = makeNativeSymbolRef(julia_extptr_callback_ptr)

# helper to throw Julia errors on R side
reval("...stop_if_error <- function (obj) if (inherits(obj, 'error')) stop(obj) else obj")
end


Expand All @@ -124,15 +127,22 @@ Wrap a callable Julia object `f` an a R `ClosSxpPtr`.

Constructs the following R code

function(...) .External(juliaCallback, fExPtr, ...)
function(...) ...stop_if_error(.External(juliaCallback, fExPtr, ...))

"""
function sexp(::Type{RClass{:function}}, f)
fptr = protect(sexp(RClass{:externalptr}, f))
body = protect(rlang_p(Symbol(".External"),
juliaCallback,
fptr,
Const.DotsSymbol))
body = protect(
rlang_p(
Symbol("...stop_if_error"),
rlang_p(
Symbol(".External"),
juliaCallback,
fptr,
Const.DotsSymbol
)
)
)
nprotect = 2
local clos
try
Expand Down