annotate R/scratch/namespaces.R @ 51:03b6934cdd63

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