R/handles.r

Defines functions print.lldb_handle acquire.handle get.default.handle assign.handle set.default.handle

Documented in get.default.handle set.default.handle

lldb_state <- new.env()

#' @method print lldb_handle
#' @export
print.lldb_handle <- function(x, ...){
	class(x) <- NULL
	ptr <- capture.output(x)
	cat(paste("An lldb handle:", ptr, "\n"))
}

acquire.handle <- function(handle){
	if (!is.null(handle)){
		check.is.handle(handle)
		handle
	} else {
		get.default.handle()
	}
}

#' Default Handles
#' 
#' Functions to get and set the default handle.
#' 
#' @param handle
#' The return from \code{lldb.load()}.
#' 
#' @return
#' \code{get.default.handle()} returns the default handle if set, and errors
#' otherwise. \code{set.default.handle()} sets the global default handle value.
#' 
#' @seealso \code{\link{lldb.load}}
#' 
#' @name handles
#' @rdname handles
NULL

#' @rdname handles
#' @export
get.default.handle <- function(){
	if (!exists("handle", envir=lldb_state)){
		stop("no default handle set")
	}
	get("handle", envir=lldb_state)
}

# internal use
assign.handle <- function(handle){
	assign("handle", handle, envir=lldb_state)
}

#' @rdname handles
#' @export
set.default.handle <- function(handle){
	check.is.handle(handle)
	assign.handle(handle)
	invisible()
}
heckendorfc/lldbR documentation built on March 16, 2020, 12:24 a.m.