Ruby: ruby(1) implementation

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

Macros | Functions
ruby(1) implementation
CRuby Embedding APIs

## Macros
#define | RUBY_INIT_STACK
| A convenience macro to call ruby_init_stack().

## Functions
void | ruby_sysinit (int *argc, char ***argv)
| Initializes the process for libruby.
void | ruby_init (void)
| Calls ruby_setup() and check error.
void * | ruby_options (int argc, char **argv)
| Processes command line arguments and compiles the Ruby source to execute.
int | ruby_executable_node (void *n, int *status)
| Checks the return value of ruby_options().
int | ruby_run_node (void *n)
| Runs the given compiled source and exits this process.
void | ruby_show_version (void)
| Prints the version information of the CRuby interpreter to stdout.
void | ruby_show_copyright (void)
| Prints the copyright notice of the CRuby interpreter to stdout.

## Detailed Description

A part of the implementation of ruby(1) command. Other programs that embed Ruby interpreter do not always need to use these functions.

## Macro Definition Documentation

## ◆ RUBY_INIT_STACK

#define RUBY_INIT_STACK

Value:
VALUE variable_in_this_stack_frame; \
ruby_init_stack(&variable_in_this_stack_frame);
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40

A convenience macro to call ruby_init_stack().

Must be placed just after variable declarations.

Definition at line 131 of file interpreter.h.

## Function Documentation

## ◆ ruby_executable_node()

int ruby_executable_node | ( | void * | n,
|  | int * | status )

Checks the return value of ruby_options().

ruby_options() sometimes returns a special value to indicate this process should immediately exit. This function checks if the case. Also stores the exit status that the caller have to pass to exit(3) into `*status`.

Parameters

  [in] | n | A return value of ruby_options().
  [out] | status | Pointer to the exit status of this process.

Return values

  0 | The given value is such a special value.
  otherwise | The given opaque pointer is actually a compiled source.

Definition at line 304 of file eval.c.

Referenced by ruby_run_node().

## ◆ ruby_init()

void ruby_init | ( | void |  | ) |

Calls ruby_setup() and check error.

Prints errors and calls exit(3) if an error occurred.

Definition at line 99 of file eval.c.

## ◆ ruby_options()

void * ruby_options | ( | int | argc,
|  | char ** | argv )

Processes command line arguments and compiles the Ruby source to execute.

This function does:

- Processes the given command line flags and arguments for `ruby(1)`
- Compiles the source code from the given argument, `-e` or `stdin`, and
- Returns the compiled source as an opaque pointer to an internal data structure

Parameters

  [in] | argc | Process main's `argc`.
  [in] | argv | Process main's `argv`.

Returns
  An opaque pointer to the compiled source or an internal special value. Pass it to ruby_executable_node() to detect which.

See also
  ruby_executable_node

Definition at line 112 of file eval.c.

## ◆ ruby_run_node()

int ruby_run_node | ( | void * | n | ) |

Runs the given compiled source and exits this process.

Parameters

  [in] | n | Opaque "node" pointer.

Return values

  EXIT_SUCCESS | Successfully run the source.
  EXIT_FAILURE | An error occurred.

Definition at line 321 of file eval.c.

## ◆ ruby_show_copyright()

void ruby_show_copyright | ( | void |  | ) |

Prints the copyright notice of the CRuby interpreter to stdout.

Definition at line 179 of file version.c.

## ◆ ruby_show_version()

void ruby_show_version | ( | void |  | ) |

Prints the version information of the CRuby interpreter to stdout.

Definition at line 165 of file version.c.

## ◆ ruby_sysinit()

void ruby_sysinit | ( | int * | argc,
|  | char *** | argv )

Initializes the process for libruby.

This function assumes this process is `ruby(1)` and it has just started. Usually programs that embed CRuby interpreter may not call this function, and may do their own initialization.

Parameters

  [in] | argc | Pointer to process main's `argc`.
  [in] | argv | Pointer to process main's `argv`.

Warning
  `argc` and `argv` cannot be `NULL`.

Definition at line 2797 of file ruby.c.