Is there a better (i.e. faster) way to create a symbol in a C
extension than writing: rb_eval_string(":my_symbol")?
Thanks,
Paolo.
Is there a better (i.e. faster) way to create a symbol in a C
extension than writing: rb_eval_string(":my_symbol")?
Thanks,
Paolo.
From README.EXT:
:Identifier
You can get the symbol value from a string within C code by using
rb_intern(const char *name)
regards,
Brian
On 03/08/05, Paolo Capriotti <p.capriotti@gmail.com> wrote:
Is there a better (i.e. faster) way to create a symbol in a C
extension than writing: rb_eval_string(":my_symbol")?Thanks,
Paolo.
--
http://ruby.brian-schroeder.de/
Stringed instrument chords: http://chordlist.brian-schroeder.de/
Try this:
ID2SYM(rb_intern("my_symbol"))
In article <7993c66305080305224adfe2ce@mail.gmail.com>,
Is there a better (i.e. faster) way to create a symbol in a C
extension than writing: rb_eval_string(":my_symbol")?
=20
Thanks,
=20
Paolo.
=20
=20From README.EXT:
:Identifier
You can get the symbol value from a string within C code by using
rb_intern(const char *name)
regards,
Brian
--=20
http://ruby.brian-schroeder.de/Stringed instrument chords: http://chordlist.brian-schroeder.de/
Also, to speed things up in cases where you'll need to use the same
symbols over and over you can do the rb_intern in the Init function of
your extension, for example:
#include "ruby.h"
#include <math.h>
#include <stdio.h>
static int id_x;
static int id_y;
static int id_equal;
.... a lot of snippage ...
VALUE cACOMod;
VALUE cACOPoint;
VALUE cACOGraph;
void Init_ACO_Ext() {
printf("ACO_Ext initializing...\n");
cACOMod = rb_define_module("ACO");
cACOPoint = rb_define_class_under(cACOMod,"Point",rb_cObject);
cACOGraph = rb_define_class_under(cACOMod,"Graph",rb_cObject);
rb_define_alloc_func(cACOPoint, aco_point_alloc);
rb_define_method(cACOPoint,"initialize",aco_point_init,2);
rb_define_method(cACOPoint,"-",aco_point_diff,1);
rb_define_method(cACOPoint,"==",aco_point_equal,1);
rb_define_method(cACOPoint,"x",aco_point_getx,0);
rb_define_method(cACOPoint,"y",aco_point_gety,0);
//create your symbols ahead of time here:
id_x = rb_intern("x");
id_y = rb_intern("y");
id_equal = rb_intern("==");
}
Seems like it could help save some time if you use the symbols lots of
times in your accessor functions for example.
Phil
Brian Schröder <ruby.brian@gmail.com> wrote:
On 03/08/05, Paolo Capriotti <p.capriotti@gmail.com> wrote: