mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
add facile implementation of String js->ruby which assumes ascii encoding
This commit is contained in:
parent
f240e35b63
commit
35577e1e3f
2 changed files with 15 additions and 4 deletions
|
@ -2,6 +2,8 @@
|
|||
#define __ruby_data_h__
|
||||
|
||||
#include <ruby.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
template<class T, class R> class RubyDataSource {
|
||||
|
||||
|
@ -36,8 +38,8 @@ class RubyDest {
|
|||
RubyDest();
|
||||
~RubyDest();
|
||||
|
||||
VALUE pushString(const char* value, const char* name=0) {
|
||||
return Qnil;
|
||||
VALUE pushString(std::string value, const char* name=0) {
|
||||
return rb_str_new2(value.c_str());
|
||||
}
|
||||
|
||||
VALUE pushInt(int64_t value, const char* name=0) {
|
||||
|
|
13
v8_data.h
13
v8_data.h
|
@ -4,6 +4,7 @@
|
|||
#include "v8.h"
|
||||
#include "stdint.h"
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
template<class T, class R> class V8HandleSource {
|
||||
|
@ -30,8 +31,16 @@ template<class T, class R> class V8HandleSource {
|
|||
}
|
||||
|
||||
if(value->IsString()) {
|
||||
//v8::Local<v8:String::AsciiValue> strValue(value->ToString());
|
||||
return dest.pushString("", name);
|
||||
v8::Local<v8::String> str = value->ToString();
|
||||
char buffer[1024];
|
||||
int strlen = str->Length();
|
||||
std::string output;
|
||||
for (int total = 0; total < strlen;) {
|
||||
int written = str->WriteAscii(buffer, 0, 1024);
|
||||
output.append(buffer, written);
|
||||
total += written;
|
||||
}
|
||||
return dest.pushString(output, name);
|
||||
}
|
||||
|
||||
if(value->IsInt32()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue