If I have a class in a .gs file and a .gsp that references it, how do I compile it? Do I have to use vark? I couldn't find a 'gosuc' command but now I look at that more closely I figure it's not a great name for a compiler ;-)
Next question:
In groovy I can define a class, compile it, put it on the classpath and reference it from Java a though it was a Java class. Can we do this with a Gosu class, or do we need to implement something else to reference Java from Gosu?
Thanks in advance,
Andrew
--
You received this message because you are subscribed to the Google Groups "gosu-lang" group.
To post to this group, send email to gosu...@googlegroups.com.
To unsubscribe from this group, send email to gosu-lang+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gosu-lang?hl=en.
Thanks for your reply. So what have I done wrong here then :-(
main.gsp:
use abm.Person
var p = new Person("andrew", "myers", 37)
print (p.age)
===============
abm/Person.gs
package abm
class Person {
var _age : Integer as age
var _lastName : String as lastName
var _firstName : String as firstName
/* Constructs a new Person */
construct( firstName : String, lastName : String, age : Integer) {
_firstName = firstName
_lastName = lastName
_age = age
}
}
Output:
c:\Users\amyers\projects\gosu-dev\classes-tut\src>gosu main.gsp
gw.lang.parser.exceptions.ParseResultsException: program_.__Program__0
Errors:
No constructor found for class, Person [line:3 col:39] in
line 2:
line 3: var p = new Person("andrew", "myers", 37)
line 4:
Line Number: 3 Column: 39
"Person" is not a valid type. [line:3 col:13] in
line 2:
line 3: var p = new Person("andrew", "myers", 37)
line 4:
Line Number: 3 Column: 13
Not a statement. [line:1 col:1] in
line 1: use abm.Person
line 2:
Line Number: 1 Column: 1
Could not resolve symbol for : use [line:1 col:1] in
line 1: use abm.Person
line 2:
Line Number: 1 Column: 1
Expecting '=' for assignment statement. [line:1 col:9] in
line 1: use abm.Person
line 2:
Line Number: 1 Column: 9
Could not resolve symbol for : abm [line:1 col:5] in
line 1: use abm.Person
line 2:
Line Number: 1 Column: 5
No constructor found for class, Person [line:3 col:39] in
line 2:
line 3: var p = new Person("andrew", "myers", 37)
line 4:
Line Number: 3 Column: 39
"Person" is not a valid type. [line:3 col:13] in
line 2:
line 3: var p = new Person("andrew", "myers", 37)
line 4:
Line Number: 3 Column: 13
Could not resolve symbol for : p [line:5 col:8] in
line 4:
line 5: print (p.age)
Expected Type: Object
Line Number: 5 Column: 8
at gw.internal.gosu.parser.ParserBase.verifyParsedElement(ParserBase.jav
a:248)
at gw.internal.gosu.parser.GosuClassParser.parseDefinitions(GosuClassPar
ser.java:422)
at gw.internal.gosu.parser.GosuClass.compileDefinitionsIfNeeded(GosuClas
s.java:1650)
at gw.internal.gosu.parser.GosuClass.compileDefinitionsIfNeeded(GosuClas
s.java:1599)
at gw.internal.gosu.parser.GosuClass.isValid(GosuClass.java:897)
at gw.internal.gosu.parser.GosuProgram_Proxy.isValid(gw.internal.gosu.pa
rser.GosuProgram_Proxy:2)
at gw.internal.gosu.parser.GosuProgramParser.parseExpressionOrProgram(Go
suProgramParser.java:122)
at gw.lang.shell.Gosu.main(Gosu.java:149)
Definitely was a classpath issue. My .gsp was in the root of my
directory structure, and my classes in packages beneath that. When I
included:
classpath "."
all worked fine.
Also, I managed to call a gosu class which implements a Java interface
from Java as you described.
So I made progress ;)
If I can make time tomorrow, I'll stick some of the simple examples
I've done so far on github and write up a blog post, mainly for my own
benefit but it might help others down the track.
Andrew.
P.S. For the CF integration I was talking about earlier, I need to
think some more. I clearly don't want to have to write Java
interfaces for everything. I'm thinking there'll be a better way, but
I haven't quite figured it out yet.