view R/rdc/R/bind.R @ 58:e4bf6e44fbf5

fixes to test code
author Tassilo Philipp
date Mon, 08 Feb 2021 10:15:27 +0100
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 )  
}