Page 1 of 1
Confused with main-args
Posted: Tue Nov 20, 2007 5:21 am
by Cyril
Does it exist a reliable way to process command-line args of a newlisp script, working for both a script in a source form and a script linked with an interpreter in a single executable? In the first case real args starts from second, in the second -- from first. How to find a right one?
Posted: Tue Nov 20, 2007 8:48 am
by newdep
How many argsuments would you like to process?
I always count from the last to the first argument to workaround this..
(instead of starting at the first/second and counting forward)
Norman.
Posted: Wed Nov 21, 2007 4:40 am
by Cyril
newdep wrote:How many argsuments would you like to process?
If only I need a fixed number of args to process, I'll not ask this question here! Believe me, I was able to count backwards before elementary school. ;-) But if I need one obligatory and one optional argument?
Posted: Wed Nov 21, 2007 6:49 am
by HPW
C:\Programme\newlisp>testm
("testm")
newLISP v.9.2.5 on Win32, execute 'newlisp -h' for more info.
> (exit)
C:\Programme\newlisp>newlisp testm.lsp
("newlisp" "testm.lsp")
newLISP v.9.2.5 on Win32, execute 'newlisp -h' for more info.
> (exit)
So (=(first(main-args))"newlisp") should indicate you are running a script with the newlisp.exe. Then you set your offset for the parameter.
Edit: You must check also for a path and strip it out: (last(parse (first(main-args)) "\\"))
Posted: Wed Nov 21, 2007 8:20 am
by newdep
This is what i ment..(but not what you seek?) ->
You get always the absolute length and lists are limited to their length..
> $main-args
("newlisp" "bla" "one" "two" "three")
> (length $main-args)
5
> ($main-args -100)
"newlisp"
> ($main-args -10)
"newlisp"
> ($main-args -6)
"newlisp"
> ($main-args -5)
"newlisp"
>
Posted: Wed Nov 21, 2007 9:15 am
by alex