[NTLK] Shell arguments in NEWT/0?

Morgan Aldridge morgant at makkintosshu.com
Wed Jan 11 22:02:34 EST 2012

On Wed, Jan 11, 2012 at 12:45 PM, Morgan Aldridge
<morgant at makkintosshu.com> wrote:
> On Wed, Jan 11, 2012 at 8:41 AM, Matthias Melcher <mm at matthiasm.com> wrote:
>> On 11.01.2012, at 04:36, Morgan Aldridge wrote:
>>> Quick question for the few of you out there that have used NEWT/0--is
>>> that anyone other than Matthias, Eckhart, and Paul?--when calling it
>>> from the command line, do you have any access to the command line
>>> arguments (argv & argc; $0, $1, $2... & $#; or whatever) from the
>>> NewtonScript side? If so, how, if not, any idea how hard it'd be to
>>> add?
>> Ah, what a nice idea! I don;t think this exists, but it should be fairly easy to implement.
>> Solution 1:
>> Use DefGlobalFunction to define an access function the the arguments:
>>                NewtDefGlobalFunc(
>>                        NSSYM(GetVArgs),
>>                        GetVArgs,
>>                        0,
>>                        "GetVArgs()");
>> Then if the user calls this function, use the NewtCreate... functions to create an array of strings that you can return.
>> Solution 2:
>> Use NcSetGlobalVar(NSSYM(VArgs), NewtMakeArray(...)); to generate a globally accesible array of the command line parameters.
> Thanks! That gave me enough to look through the NEWT/0 code and I have
> a rough idea of what the above means and see that the arguments do, in
> fact, make it that far.
> I see the references to NSSYM0(_ARGV_) on the C side, so how does it
> become NSSYM(VArgs) or NSSYM(GetVArgs) on the NewtonScript side? Is
> there a translation somewhere that I missed or am I misunderstanding?

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:


    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!


More information about the NewtonTalk mailing list