On Tuesday, 15 April 2003 at 0:27:10 +0900, ts wrote: > >>>>> "J" == Jim Freeze <jim / freeze.org> writes: > > J> I don't know how to do that yet. > J> I have just declared them as static in my .c file. But, maybe that > J> doesn't matter. > > Something like this > > #include <ruby.h> > > static VALUE re_equal, re_space; > > static VALUE > tt_sub_bang(VALUE line) > { > VALUE sp = rb_str_new2(" "); > > rb_funcall(line, rb_intern("gsub!"), 2, re_equal, sp) > /* ... */ > return line; > } > > > void Init_tt() > { > re_equal = rb_reg_regcomp(rb_str_new2("\\s*=\\s")); > re_space = rb_reg_regcomp(rb_str_new2("\\s+")); > /* register the variable */ > rb_global_variable(&re_equal); > rb_global_variable(&re_space); > /* ... */ > } > > Cool, how did you know my code without me sending it to you? :) Here is my init function. I assume that I don't have to protect id's. void Init_netlistparser() { VALUE cNetlistParsr = rb_define_class("NetlistParser", rb_cObject); rb_define_method(cNetlistParsr, "initialize", np_initialize, 1); rb_define_method(cNetlistParsr, "each_statement", np_each_statement,1); id_strip_bang = rb_intern("strip!"); id_gsub_bang = rb_intern("gsub!"); re_equal = rb_reg_regcomp(rb_str_new2("\\s*=\\s*")); re_space = rb_reg_regcomp(rb_str_new2("\\s+")); str_space = rb_str_new2(" "); str_equal = rb_str_new2("="); rb_global_variable(&re_equal); rb_global_variable(&re_space); rb_global_variable(&str_space); rb_global_variable(&str_equal); } -- Jim Freeze ---------- Don't worry about the world coming to an end today. It's already tomorrow in Australia. -- Charles Schultz