Created
March 4, 2010 21:06
-
-
Save paukul/322112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ruby.h" | |
#include "erl_interface.h" | |
#include <stdlib.h> | |
#include <string.h> | |
VALUE ErlNode = Qnil; | |
int node_count = 0; | |
/* prototypes */ | |
void Init_erl_node(); | |
/* ruby methods */ | |
static VALUE erl_node_init(VALUE self, VALUE url, VALUE cookie); | |
/* internal methods */ | |
static void declare_attr_accessors(); | |
/* implementation */ | |
static VALUE erl_node_init(VALUE self, VALUE url, VALUE cookie){ | |
rb_iv_set(self, "@url", url); | |
rb_iv_set(self, "@cookie", cookie); | |
rb_iv_set(self, "@nodename", rb_str_new2(sprintf("c_%i", ++node_count))); | |
} | |
void Init_erl_node(){ | |
ErlNode = rb_define_class("ErlNode", rb_cObject); | |
declare_attr_accessors(); | |
/* instance methods */ | |
rb_define_method(ErlNode, "initialize", erl_node_init, 2); | |
} | |
static void declare_attr_accessors(){ | |
ID attr_accessor = rb_intern("attr_accessor"); | |
char *i_vars[3] = {"url", "cookie", "nodename"}; | |
VALUE params[3]; | |
int i = 0; | |
for(; i <= 2; i++){ | |
params[i] = ID2SYM(rb_intern(i_vars[i])); | |
} | |
rb_funcall2(ErlNode, attr_accessor, 3, params); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment