Skip to main content

generate_method_c_wrapper

Function generate_method_c_wrapper 

Source
pub fn generate_method_c_wrapper(
    parsed_impl: &ParsedImpl,
    method: &ParsedMethod,
    r_wrappers_const: &Ident,
) -> TokenStream
Expand description

Generate a C-callable wrapper function for a single method in an impl block.

Produces a #[no_mangle] extern "C" function named C_{Type}__{method} that:

  1. Accepts SEXP arguments (including self_sexp for instance methods)
  2. Extracts &self / &mut self from an ErasedExternalPtr for instance methods
  3. Converts SEXP arguments to Rust types
  4. Calls the actual Rust method
  5. Converts the return value back to SEXP

Thread strategy is determined automatically: instance methods always run on the main thread (because self_ref is a non-Send borrow), while static methods use the worker thread unless unsafe(main_thread) is specified.

Also emits an R_CallMethodDef constant for R routine registration, and appends generated R wrapper code fragments to the r_wrappers_const string constant.

ยงArguments

  • parsed_impl - The parsed impl block providing type identity, cfg attrs, and options
  • method - The parsed method to generate a wrapper for
  • r_wrappers_const - Identifier of the const that accumulates R wrapper code fragments