view R/rdc/R/bind.R @ 61:c5a69c454963 default tip

- allow use of 'None' with 'Z' - bumped version to 1.4 (be in sync current dyncall version)
author Tassilo Philipp
date Mon, 03 Apr 2023 19:06:07 +0200
parents 0cfcc391201f
children
line wrap: on
line source

#
# bind library by import string
#

eatws <- function(x) gsub("[ \n\t]*","",x)

bind1 <- function(symbol, signature, libh, callvm, envir=parent.frame() )
{
  funcptr <- rdcFind(libh, symbol)  
  f <- function(...) NULL
  body(f) <- substitute( dcCall( callvm, funcptr, signature, ... ), list(funcptr=funcptr, signature=signature) )  
  assign( symbol, f, envir=envir )
}

rdcBind <- function(libname, sigs, callvm, envir=parent.frame() )
{
  libh <- rdcLoad(libname)
  sigs <- eatws(sigs)
  sigs <- strsplit(sigs, ";")[[1]]
  sigs <- strsplit(sigs, "\\(")
  for (i in seq(along=sigs)) bind1(sigs[[i]][[1]], sigs[[i]][[2]], libh, callvm, envir )  
}