[NTLK] Shell arguments in NEWT/0?

Morgan Aldridge morgant at makkintosshu.com
Sun Jan 22 14:00:03 EST 2012


On Thu, Jan 12, 2012 at 3:39 AM, Matthias Melcher <mm at matthiasm.com> wrote:
>
> On 12.01.2012, at 04:02, Morgan Aldridge wrote:
>
>> Wow, I totally misunderstood your previous email. Those solutions were
>> on the C-side. After more review of the NEWT/0 code, it looks like
>> solution #2 is already implemented in NewtInitARGV() in
>> src/newt_core/NewtEnv.c. I was able to whip up the following script to
>> test and it works:
>>
>>    #!/usr/local/bin/newt
>>
>>    print("'_ARGV_ exists? ");
>>    if GlobalVarExists('_ARGV_) then print("Yes.\n") else print("No.\n");
>>
>>    foreach slot, value in GetGlobalVar('_ARGV_) do print(slot && ":"
>> && value && "\n");
>>
>> So, if I run `./test.ns some test arguments` I get the following output:
>>
>>    '_ARGV_ exists? Yes.
>>    0 : some
>>    1 : test
>>    2 : arguments
>>
>> Very cool! Thanks for pointing me in the right direction!
>
> Great! I did not see that, but I am not too surprised that this was actually already implemented.

Turns out NEWT/0 also implements a special global function, GetEnv(),
that allows getting environment variables too! Very cool. This means
NewtonScript can be used for CGIs too.

I've posted this info to my site too, in case anyone is interested:

<http://www.makkintosshu.com/journal/command-line-arguments-in-newtonscript-and-newt0>
<http://www.makkintosshu.com/journal/environment-variables-in-newtonscript-and-newt0>

Morgan
---
http://makkintosshu.com/
http://seriesparts.com/
http://rikuwoiku.com/
http://unna.org/



More information about the NewtonTalk mailing list