Permalink
Browse files

added some global funcs, RCLASS_GET() useful when messing with ICLASS…

…ES that dont have any methods
  • Loading branch information...
1 parent 6382889 commit 5c1b4eac45164fcf5f62a8a3d49b062864be8727 @banister committed Oct 25, 2010
Showing with 61 additions and 5 deletions.
  1. +9 −0 README.rdoc
  2. +4 −4 Rakefile
  3. +47 −0 ext/mult/mult.c
  4. +1 −1 lib/mult/version.rb
View
9 README.rdoc
@@ -20,6 +20,15 @@ Methods:
* has_flag?
* flags
* flags=
+* RCLASS_GET^
+* RCLASS_SET^
+* RCLASS_SUPER_GET^
+* RCLASS_SUPER_SET^
+* IVAR_SET^
+* IVAR_GET^
+
+(^ indicates global function, e.g: RCLASS_SUPER_GET(klass) #=> superclass_of_klass)
+
Constants:
----------
View
8 Rakefile
@@ -20,12 +20,12 @@ spec = Gem::Specification.new do |s|
s.date = Time.now.strftime '%Y-%m-%d'
s.require_path = 'lib'
s.homepage = "http://banisterfiend.wordpress.com"
- #s.platform = 'i386-mingw32'
- s.platform = Gem::Platform::RUBY
- s.extensions = FileList["ext/**/extconf.rb"]
+ s.platform = 'i386-mswin32'
+ #s.platform = Gem::Platform::RUBY
+ #s.extensions = FileList["ext/**/extconf.rb"]
s.has_rdoc = 'yard'
s.files = ["Rakefile", "README.rdoc", "LICENSE", "lib/mult.rb", "lib/mult/version.rb"] +
- # ["lib/1.8/mult.#{dlext}", "lib/1.9/mult.#{dlext}"] +
+ ["lib/1.8/mult.#{dlext}", "lib/1.9/mult.#{dlext}"] +
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
end
View
47 ext/mult/mult.c
@@ -1,3 +1,4 @@
+
#include <ruby.h>
#include "compat.h"
@@ -9,6 +10,17 @@ typedef struct {
/* return the actual class of an object */
static VALUE
+global_get_class(VALUE self, VALUE klass) {
+ return CLASS_OF(klass);
+}
+
+static VALUE
+global_set_class(VALUE self, VALUE klass, VALUE new_klass) {
+ KLASS_OF(klass) = new_klass;
+ return klass;
+}
+
+static VALUE
get_class(VALUE self) {
return CLASS_OF(self);
}
@@ -22,6 +34,18 @@ set_class(VALUE self, VALUE klass) {
/* get the actual super class of an object */
static VALUE
+global_get_super(VALUE self, VALUE klass)
+{
+ return RCLASS_SUPER(klass);
+}
+
+static VALUE
+global_set_super(VALUE self, VALUE klass, VALUE sup)
+{
+ return RCLASS_SUPER(klass) = sup;
+}
+
+static VALUE
get_super(VALUE self)
{
return RCLASS_SUPER(self);
@@ -42,6 +66,12 @@ is_singleton(VALUE self, VALUE klass) {
/* get a raw instance var */
static VALUE
+global_get_ivar(VALUE self, VALUE klass, VALUE sym)
+{
+ return rb_ivar_get(klass, rb_to_id(sym));
+}
+
+static VALUE
get_ivar(VALUE self, VALUE sym)
{
return rb_ivar_get(self, rb_to_id(sym));
@@ -54,6 +84,12 @@ set_ivar(VALUE self, VALUE sym, VALUE val)
return rb_ivar_set(self, rb_to_id(sym), val);
}
+static VALUE
+global_set_ivar(VALUE self, VALUE klass, VALUE sym, VALUE val)
+{
+ return rb_ivar_set(klass, rb_to_id(sym), val);
+}
+
/* get the attached class if receiver is a singleton class */
static VALUE
get_attached(VALUE self)
@@ -133,9 +169,16 @@ Init_mult() {
cRubyTable = rb_define_class("RubyTable", rb_cObject);
+
+ rb_define_method(rb_cObject, "RCLASS_GET", global_get_class, 1);
+ rb_define_method(rb_cObject, "RCLASS_SET", global_set_class, 2);
+
rb_define_method(rb_cObject, "actual_class", get_class, 0);
rb_define_method(rb_cObject, "actual_class=", set_class, 1);
+ rb_define_method(rb_cObject, "IVAR_GET", global_get_ivar, 2);
+ rb_define_method(rb_cObject, "IVAR_SET", global_set_ivar, 3);
+
rb_define_method(rb_cObject, "ivar_get", get_ivar, 1);
rb_define_method(rb_cObject, "ivar_set", set_ivar, 2);
@@ -144,6 +187,10 @@ Init_mult() {
rb_define_method(rb_cModule, "iv_tbl", get_iv_tbl, 0);
rb_define_method(rb_cModule, "iv_tbl=", set_iv_tbl, 1);
+
+ rb_define_method(rb_cObject, "RCLASS_SUPER_GET", global_get_super, 1);
+ rb_define_method(rb_cObject, "RCLASS_SUPER_SET", get_super, 1);
+
rb_define_method(rb_cModule, "actual_super", get_super, 0);
rb_define_method(rb_cModule, "actual_super=", set_super, 1);
View
2 lib/mult/version.rb
@@ -1,3 +1,3 @@
module Mult
- VERSION = "0.2.2"
+ VERSION = "0.2.5"
end

0 comments on commit 5c1b4ea

Please sign in to comment.