comparison R/scratch/namespaces.R @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1
2 makeNamespace <- function(name, version = NULL, lib = NULL) {
3 impenv <- new.env(parent = .BaseNamespaceEnv, hash = TRUE)
4 attr(impenv, "name") <- paste("imports", name, sep = ":")
5 env <- new.env(parent = impenv, hash = TRUE)
6 name <- as.character(as.name(name))
7 version <- as.character(version)
8 info <- new.env(hash = TRUE, parent = baseenv())
9 assign(".__NAMESPACE__.", info, envir = env)
10 assign("spec", c(name = name, version = version),
11 envir = info)
12 setNamespaceInfo(env, "exports", new.env(hash = TRUE,
13 parent = baseenv()))
14 setNamespaceInfo(env, "imports", list(base = TRUE))
15 setNamespaceInfo(env, "path", file.path(lib, name))
16 setNamespaceInfo(env, "dynlibs", NULL)
17 setNamespaceInfo(env, "S3methods", matrix(NA_character_,
18 0L, 3L))
19 assign(".__S3MethodsTable__.", new.env(hash = TRUE,
20 parent = baseenv()), envir = env)
21 .Internal(registerNamespace(name, env))
22 env
23 }
24
25 install <- function()
26 {
27 name <- "GL"
28 ns <- makeNamespace(name)
29 info <- ns$.__NAMESPACE__.
30 # info$DLLs <- dyn.load("")
31 with(ns,
32 {
33 dynbind("GL","glBegin()v;")
34 .onUnload <- function()
35 {
36 .dynunload(.lib)
37 }
38 }
39 )
40 # ns$.packageName <- "stdio"
41 namespaceExport( ns, ls(ns) )
42 # attach(ns, name="dynport:GL")
43 attachNamespace(ns)
44 }
45 install()
46
47
48 unloadNamespace("stdio")
49
50
51 # retrieve list of shared libraries loaded
52
53 library.dynam()
54 .dynLibs()
55 # load a specified library
56
57 .sys.lib.loc <- c("/opt/local/lib", "/opt/lib", "/usr/local/lib", "/usr/lib")
58
59 findLibPath <- function(name, lib.loc=.sys.lib.loc)
60 {
61 for(i in lib.loc) {
62 trypath <- file.path(i, paste("lib", name,.Platform$dynlib.ext,sep="") )
63 if ( file.exists(trypath) ) return(trypath)
64 }
65 NULL
66 }
67
68 tests <- c("GL","SDL","expat")
69
70 sapply( tests, findLibPath )
71
72