Skip to content

Instantly share code, notes, and snippets.

@jmhodges
Created August 7, 2010 23:32
Show Gist options
  • Save jmhodges/513321 to your computer and use it in GitHub Desktop.
Save jmhodges/513321 to your computer and use it in GitHub Desktop.
#include <ruby.h>
#include <node.h>
int main(int argc, char **argv) {
ruby_init();
ruby_script("embedded");
// The bizness
rb_thread_t th = ALLOC(struct rb_thread); \
th->last_status = 0;
rb_p(th->last_status);
return 0;
}
// Eliding many variable sets in this
#define THREAD_ALLOC(th) do {\
th = ALLOC(struct rb_thread);\
\
th->last_status = 0;\
} while (0)
// Wait for it.
static rb_thread_t
rb_thread_alloc(klass)
VALUE klass;
{
rb_thread_t th;
struct RVarmap *vars;
THREAD_ALLOC(th);
th->thread = Data_Wrap_Struct(klass, thread_mark, thread_free, th);
for (vars = th->dyna_vars; vars; vars = vars->next) {
if (FL_TEST(vars, DVAR_DONT_RECYCLE)) break;
FL_SET(vars, DVAR_DONT_RECYCLE);
}
return th;
}
static void
rb_thread_restore_context_0(rb_thread_t th, int exit)
{
static rb_thread_t tmp;
static int ex;
static VALUE tval;
// And here we are. Now, the question is: uh, what?
rb_last_status = th->last_status;
ruby_safe_level = th->safe;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment