You can't using the "shell" program. It doesn't support passing command line
parameters to the script.
If you use the "d8" shell instead, it does work, if you write it as:
~/src/v8/d8 add.js -- 1 2 3
and access the parameters through the global "arguments" variable:
--- add.js ---
var res = 0;
for (var i = 0; i < arguments.length; i++) {
res += Number(arguments[i]);
}
print(res);
-- end --
(The elements of "arguments" are always strings.)
/L
On Mon, May 25, 2009 at 2:52 AM, Vincent Foley <[email protected]> wrote:
>
> Hello,
>
> If I call a small script like this:
>
> $ ~/src/v8/shell add.js 1 2 3
>
> How can I have access to the ["1", "2", "3"] array (often called argv
> in other languages)?
>
> Thank you.
>
> Vincent
> >
>
--
Lasse R.H. Nielsen / [email protected]'Faith without judgement merely
degrades the spirit divine'
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---