7
7
# ' In order to use `cpp_register()` the `cli`, `decor`, `desc`, `glue`,
8
8
# ' `tibble` and `vctrs` packages must also be installed.
9
9
# ' @param path The path to the package root directory
10
+ # ' @param use_package If `TRUE`, uses `.Call("yourfunc", ..., PACKAGE="yourpackage")`
11
+ # ' to call C++ functions, otherwise (the default) uses ``.Call(`yourfunc`, ...)``.
10
12
# ' @param quiet If `TRUE` suppresses output from this function
11
13
# ' @return The paths to the generated R and C++ source files (in that order).
12
14
# ' @export
31
33
# '
32
34
# ' # cleanup
33
35
# ' unlink(dir, recursive = TRUE)
34
- cpp_register <- function (path = " ." , quiet = FALSE ) {
36
+ cpp_register <- function (path = " ." , use_package = FALSE , quiet = FALSE ) {
35
37
stop_unless_installed(get_cpp_register_needs())
36
38
37
39
r_path <- file.path(path , " R" , " cpp11.R" )
@@ -56,7 +58,7 @@ cpp_register <- function(path = ".", quiet = FALSE) {
56
58
57
59
init <- generate_init_functions(get_registered_functions(all_decorations , " cpp11::init" , quiet ))
58
60
59
- r_functions <- generate_r_functions(funs , package , use_package = FALSE )
61
+ r_functions <- generate_r_functions(funs , package , use_package = use_package )
60
62
61
63
dir.create(dirname(r_path ), recursive = TRUE , showWarnings = FALSE )
62
64
@@ -102,6 +104,8 @@ cpp_register <- function(path = ".", quiet = FALSE) {
102
104
103
105
extra_includes <- paste0(extra_includes , collapse = " \n " )
104
106
107
+ forceSymbols = if (use_package ) " " else " \n R_forceSymbols(dll, TRUE);"
108
+
105
109
brio :: write_lines(path = cpp_path , glue :: glue('
106
110
// Generated by cpp11: do not edit by hand
107
111
// clang-format off
@@ -118,8 +122,7 @@ cpp_register <- function(path = ".", quiet = FALSE) {
118
122
{init$declarations}
119
123
extern "C" attribute_visible void R_init_{package}(DllInfo* dll){{
120
124
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
121
- R_useDynamicSymbols(dll, FALSE);{init$calls}
122
- R_forceSymbols(dll, TRUE);
125
+ R_useDynamicSymbols(dll, FALSE);{init$calls}{forceSymbols}
123
126
}}
124
127
' ,
125
128
call_entries = glue :: glue_collapse(call_entries , " \n " )
0 commit comments