-
Notifications
You must be signed in to change notification settings - Fork 0
/
eigen.c
27 lines (23 loc) · 823 Bytes
/
eigen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <ruby.h>
#include <st.h>
#include <stdio.h>
VALUE eigen_predicate(VALUE self) {
if(FL_TEST(self, FL_SINGLETON)) return Qtrue;
else return Qfalse;
}
VALUE instance(VALUE self) {
st_data_t value;
if(FL_TEST(self, FL_SINGLETON)) value = rb_iv_get(self, "__attached__");
else rb_raise(rb_eRuntimeError, "this is not a singleton, call #instances instead");
return value;
}
VALUE eigen_Module;
VALUE singleton_instance_Module;
void Init_eigen() {
eigen_Module = rb_define_module("Eigen");
rb_define_method(eigen_Module, "eigen?", eigen_predicate, 0);
rb_include_module(rb_cClass, eigen_Module);
singleton_instance_Module = rb_define_module("SingletonInstance");
rb_define_method(singleton_instance_Module, "instance", instance, 0);
rb_include_module(rb_cClass, singleton_instance_Module);
}