1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/ext/v8/v8_str.cpp

24 lines
542 B
C++
Raw Normal View History

2009-12-07 16:06:06 +02:00
#include "v8_str.h"
#include "v8.h"
#include "v8_ref.h"
using namespace v8;
void rr_init_str() {
VALUE String = rr_define_class("String");
rr_define_singleton_method(String, "new", v8_str_new, 1);
rr_define_method(String, "to_s", v8_str_to_s, 0);
}
2009-12-07 16:06:06 +02:00
VALUE v8_str_new(VALUE clazz, VALUE str) {
HandleScope handles;
2010-02-11 17:14:47 -06:00
return V8_Ref_Create(clazz, String::New(RSTRING_PTR(str)));
2009-12-07 16:06:06 +02:00
}
VALUE v8_str_to_s(VALUE self){
HandleScope handles;
Local<String> str = V8_Ref_Get<String>(self);
2009-12-07 16:06:06 +02:00
return rb_str_new2(*String::AsciiValue(str));
}