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
2010-05-20 12:07:33 +03:00

23 lines
542 B
C++

#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);
}
VALUE v8_str_new(VALUE clazz, VALUE str) {
HandleScope handles;
return V8_Ref_Create(clazz, String::New(RSTRING_PTR(str)));
}
VALUE v8_str_to_s(VALUE self){
HandleScope handles;
Local<String> str = V8_Ref_Get<String>(self);
return rb_str_new2(*String::AsciiValue(str));
}