v8r -- the javascript interpreter using v8 I'm working on does this...
http://code.google.com/p/v8r/source/browse/trunk/samples/v8r.cc
-- Start by defining something like --
int xARGC = 0;
v8::Local<v8::Array> xARGV;
v8::Handle<v8::Value> ExternalGetArgv(const v8::Arguments& args) {
v8::Context::Scope context_scope(gblContext);
v8::HandleScope handle_scope;
return xARGV;
}
v8::Handle<v8::Value> ExternalGetArgc(const v8::Arguments& args) {
v8::Context::Scope context_scope(gblContext);
v8::HandleScope handle_scope;
return v8::Integer::New(xARGC);
}
-- Then to get the args in the array (this is inside the main()) --
xARGC = argc - 2;
if ( xARGC > 0 ) {
xARGV = v8::Array::New(argc);
int x = 0;
for(int i = 2; i <= argc; i++) {
if ( NULL != argv[i] ) {
v8::Handle<v8::Number> y = v8::Number::New( x );
v8::Handle<v8::String> s = v8::String::New( argv[i] );
xARGV->Set( y, s);
x++;
}
}
}
This example is used in v8r and chops off the first two args becuase
they contain v8r and the script being executed.
Enjoy,
Matt
On Sep 2, 5:54 pm, "Brett C." <
bcan...@gmail.com> wrote:
> I was looking at samples/shell.cc and noticed that it is missing any
> way to get command-line arguments (e.g. Rhino provides an argumentsarraythat leaves off the executable). I thought I could quickly
> modify shell.cc, but when I looked at the public API I noticed that
> all v8::Arrayprovides as a public API is New(), Cast() and Length().
> There does not seem to be any direct way to manipulate thearrayto
> add values.
>
> What would be the best way to go about setting argv to an 'arguments'arrayas a global variable? Or is the best alternative a function that