This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: java -Dplugins.dir=./jars kawa.repl


Note that Guile and Kawa do not take the same command-line arguments
(compare `kawa --help` and `guile --help`), so your usage of
"-e main -s" is not going to do what you're after.

You should read the Usage Reference section of the manual:
http://www.gnu.org/software/kawa/Running.html
particularly the sections on command-line arguments and "running
command scripts".

My own Kawa scripts usually start with something like this at the top:

> #!/bin/sh                                 # -*- scheme -*-
> exec java -Dkawa.command.name="$0" kawa.repl --script2 "$0" "$@"

If I need to set an environment variable or something, then I put that
before the exec and change the --scriptN argument appropriately:

> #!/bin/sh                                 # -*- scheme -*-
> export CLASSPATH=/path/to/kawa.jar:/path/to/other-stuff.jar

> exec java -Dkawa.command.name="$0" kawa.repl --script3 "$0" "$@"


--scriptN tells Kawa to disregard the first N lines of the file before
beginning to parse the file as Scheme, so you don't have to put !#
on the next line.

There is no command line argument to specify an entry point, it will
just start evaluating the contents of the file, so you don't need to
define a function called "main".

There is not a getopt facility (patches welcome), so you'll have to
iterate over the list returned by command-line or the vector
command-line-arguments.  There is a process-command-line-assignments
function which will handle simple definitions.
http://www.gnu.org/software/kawa/System-inquiry.html

Altogether, an executable Kawa script might look like:

> #!/bin/sh                                 # -*- scheme -*-
> exec java -Dkawa.command.name="$0" kawa.repl --script2 "$0" "$@"
> (let ((cl (command-line)))
>   (format #t "Hello from \"~a\"~%My arguments were:~%~{~a~%~}" (car cl)
>           (cdr cl)))

When I put that in /tmp/foo, chmod +x it, and then call it as
`/tmp/foo a b c d=3` I get:

> Hello from "/tmp/foo"
> My arguments were:
> a
> b
> c
> d=3


-Jamie

On Sep 30, 2015, at 6:33 PM, David Pirotte <david@altosw.be> wrote:

> Per,
> Jhope,
> 
>> ...
>> My advance: Don't try to change the plugins.dir after the JVM running Kawa has
>> started up.
>> ...
> 
> 	Thanks both
> 
> Now I want to script, here is an example:  I brutely copied the exec from guile,
> I could not find an example in the manual [I may have missed if,  though]
> 
> Could you tell me what I should do instead?
> 
> 	As I'm at it, does kawa has a module to parse args? I'm thinking of
> 	something similar to our (ice-9 getopt-long) in guile:
> 
> 	https://www.gnu.org/software/guile/manual/guile.html#getopt_002dlong
> 
> Thanks,
> David
> 
> 
> ;;; nl-mean starts here
> #!/bin/sh
> # -*- mode: scheme; coding: utf-8 -*-
> exec /opt/bin/kawa -Dplugins.dir=./jars -e main -s "$0" "$@"
> !#
> 
> (define (main args)
>  (display (command-line))
>  (newline)
>  (display args)
>  (newline))
> ;; nl-mean ends here
> 
> 	chmod a+x nl-mean
> 	./nl-mean . img1 png img2 30
> <string>:1:1: warning - no declaration seen for main
> <string>:1:1: unbound location: main
> ...

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]