Skip to content

sergeysova/v8stdio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

v8stdio

utilities for v8 development

install

Using a C package manager like cpm you can install v8stdio into the deps/ directory of your project. It also installs to /usr/local/include and /usr/local/lib by default.

$ cpm install jwerle/v8stdio

Just link in your compilation

$ g++ -I/usr/local/include/v8 -lv8 -lv8stdio program.cc -o program

building and linking to your project from source

Change to v8stdio root directory

$ cd v8stdio/

Install libv8stdio with make. requires g++

You can set the PREFIX variable to be whatever you would like. Defaults to /usr/local/

$ make install

You can now link v8stdio to your project

$ g++ -I/usr/local/include/v8 -lv8 -lv8stdio program.cc -o program

node-gyp

You can include v8stdio in your node.js addon by simply including it in the "sources" array in your binding.gyp file

{
	"targets": [
		{
			"target_name": "myaddon",
			"sources": [
				"deps/v8stdio.h", "deps/v8stdio.cc",
				"src/myaddon.cc"
			]
		}
	]
}

usage

To expose the stdout and stderr objects to your JavaScript environment in v8 you must attached it to an object like global object.

Attaching to the global object

v8stdio::AttachTo(v8stdio::Init(), v8::Context::GetCurrent()->Global());

Attaching to a target object

v8::Handle<v8::Object> target = v8::Object::New();
v8stdio::AttachTo(v8stdio::Init(), target);

stdout in javascript

stdio.stdout.write("hello world\n");

stderr in javascript

stdio.stderr.write("Error!\n");

api

v8::Handle<v8::Object> v8stdio::Init ()

Initializes the stdout and stderr objects

example

v8::Handle<v8::Object> stdiov = v8stdio::Init();

void v8stdio::AttachTo (v8::Handle<v8::Object> stdio, v8::Handle<v8::Object> target)

Attaches stdio object to a given object

example

v8stdio::AttachTo(stdiov, global);

v8::Handle<v8::Object> v8stdio::StdOut::Init (v8::Handle<v8::Object> stdout_)

Initializes the StdOut object

example

v8::Local<v8::Object> stdout_ = v8stdio::StdOut::Init(v8::Object::New());

v8::Handle<v8::Value> v8stdio::StdOut::v8Write (const v8::Arguments &args)

Callback for JavaScript bindings to perform a write to stdout

example*

target->Set(
	v8::String::New("write"),
	v8::FunctionTemplate::New((v8::FunctionCallback) v8stdio::StdOut::v8Write)->GetFunction()
);

v8::Handle<v8::Object> v8stdio::StdErr::Init (v8::Handle<v8::Object> stdout_)

Initializes the StdErr object

example

v8::Local<v8::Object> stdout_ = v8stdio::StdErr::Init(v8::Object::New());

v8::Handle<v8::Value> v8stdio::StdErr::v8Write (const v8::Arguments &args)

Callback for JavaScript bindings to perform a write to stderr

example*

target->Set(
	v8::String::New("write"),
	v8::FunctionTemplate::New((v8::FunctionCallback) v8stdio::StdErr::v8Write)->GetFunction()
);

license

MIT

About

stdio bindings for v8

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 86.0%
  • Makefile 11.2%
  • JavaScript 2.8%