Skip to content

Instantly share code, notes, and snippets.

@nasser
Created April 4, 2012 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasser/2304065 to your computer and use it in GitHub Desktop.
Save nasser/2304065 to your computer and use it in GitHub Desktop.
Generic Ruby Embedding API
/**
* VM supplies rb_ctx and rb_obj definitions here
*/
#include "vm_specific.h"
extern "C" {
/**
* Create a embedded ruby context
*/
rb_ctx rb_create_ctx();
/**
* Requires a ruby file (like require 'file' in ruby)
*
* Returns true if it executed without exception, false if there was an error.
* Finding out what went wrong will be defined later.
*/
int rb_require_file(rb_ctx ctx, const char * file);
/**
* Evaulate a ruby file
*
* Returns true if it executed without exception, false if there was an error.
* Finding out what went wrong will be defined later.
*/
int rb_eval_file(rb_ctx ctx, const char * file);
/**
* Evaluate a ruby string
*
* Returns true if it executed without exception, false if there was an error.
* Finding out what went wrong will be defined later.
*/
int rb_eval(rb_ctx ctx, const char * code);
/**
* Send a message to an object
*
* Send +msg+ to object +recv+ with arguments specified by +argc+ and the
* variadic parameters that follow. All arguments *must* be of type rb_obj.
*/
rb_obj rb_send(rb_ctx ctx, rb_obj recv, const char* msg, int argc, ...);
/**
* Clean up a context
*/
void rb_close_ctx(rb_ctx ctx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment