view R/scratch/namespaces.R @ 28:edbbd467f50a

python binding: - update to dyncall 1.1 - Python 3 support (supports both, Python 2 and 3) - using the Capsule API over PyCObject, when available - support for python unicode strings (for both, Python 2 and 3) - doc cleanup ruby binding: - doc cleanup
author Tassilo Philipp
date Tue, 07 Apr 2020 21:16:37 +0200
parents 0cfcc391201f
children
line wrap: on
line source


makeNamespace <- function(name, version = NULL, lib = NULL) {
	impenv <- new.env(parent = .BaseNamespaceEnv, hash = TRUE)
	attr(impenv, "name") <- paste("imports", name, sep = ":")
	env <- new.env(parent = impenv, hash = TRUE)
	name <- as.character(as.name(name))
	version <- as.character(version)
	info <- new.env(hash = TRUE, parent = baseenv())
	assign(".__NAMESPACE__.", info, envir = env)
	assign("spec", c(name = name, version = version), 
			envir = info)
	setNamespaceInfo(env, "exports", new.env(hash = TRUE, 
					parent = baseenv()))
	setNamespaceInfo(env, "imports", list(base = TRUE))
	setNamespaceInfo(env, "path", file.path(lib, name))
	setNamespaceInfo(env, "dynlibs", NULL)
	setNamespaceInfo(env, "S3methods", matrix(NA_character_, 
					0L, 3L))
	assign(".__S3MethodsTable__.", new.env(hash = TRUE, 
					parent = baseenv()), envir = env)
	.Internal(registerNamespace(name, env))
	env
}

install <- function()
{
  name <- "GL"
  ns   <- makeNamespace(name)
  info <- ns$.__NAMESPACE__.
  # info$DLLs <- dyn.load("")
  with(ns,
    {
      dynbind("GL","glBegin()v;")
      .onUnload <- function()
      {
        .dynunload(.lib)
      }
    }
  )
  # ns$.packageName <- "stdio"
  namespaceExport( ns, ls(ns) )
  # attach(ns, name="dynport:GL")
  attachNamespace(ns)
}
install()


unloadNamespace("stdio")


# retrieve list of shared libraries loaded

library.dynam()
.dynLibs()
# load a specified library

.sys.lib.loc <- c("/opt/local/lib", "/opt/lib", "/usr/local/lib", "/usr/lib")

findLibPath <- function(name, lib.loc=.sys.lib.loc)
{
  for(i in lib.loc) {
	trypath <- file.path(i, paste("lib", name,.Platform$dynlib.ext,sep="") )
	if ( file.exists(trypath) ) return(trypath)
  }
  NULL
}

tests <- c("GL","SDL","expat")

sapply( tests, findLibPath )