Interface/module issue

Monkey Forums/Monkey Programming/Interface/module issue

TwistedSage(Posted 2011) [#1]
Hi. I'm new to Monkey and I've ran into an issue with interfaces and imports.

If I create a module with an interface and another with an implementation class and I import both and then try to create an instance of the object it says it can't be found.

Thanks in advance :)

OJ

Sample code below (code to reproduce)

test.monkey
Strict

Import testinterface
Import testclass

' Main app entry point
Function Main:Int()

	Local tc:TestInterface = New TestClass
	tc.Test

End


testinterface.monkey
Interface TestInterface

	Method Test:Void()
	
End


testclass.monkey
Class TestClass Implements TestInterface

	Method Test:Void()		
	
	End
End



Rixarn(Posted 2011) [#2]
Not sure, because i donīt have monkey right now... but try adding an import.testinterface in the testclass.monkey file


TwistedSage(Posted 2011) [#3]
Already tried that. No go :(

Also, I suspect Monkey just expands include files directly in the source, so it should be alright without the import ;)


TwistedSage(Posted 2011) [#4]
Already tried that. No go :(

Also, I suspect Monkey just expands include files directly in the source, so it should be alright without the import ;)


TwistedSage(Posted 2011) [#5]
Edit causes doublepost? That's odd ;)


TwistedSage(Posted 2011) [#6]
Wierd stuff is going on here. Now it works for my example.
I shuffled some code around and added an 'Import testinterface' to the testclass.monkey file. And now it works?

Another related issue I found is that I get the same error if I try to use uppercase in modules (even on windows).

There is definitely something going on with class/modules/casing here :)

Could it be that naming your module the same as your class causes trouble?

Fact: You need to import interfaces in the module file containing your class.

Problem solved for now. Thank you :)


Dima(Posted 2011) [#7]
testclass.monkey is trying to implement something it has no clue about, so from TestClass's perspective there is no TestInterface, thus you have to import the file from anywhere that wants to know about the content of that file. Each file gets compiled separately, so working as intended.


TwistedSage(Posted 2011) [#8]
Yes. Actually the problem in my main project is that you use uppercase import names and theres a class of the same name all hell breaks loose :)


ziggy(Posted 2011) [#9]
Also, I suspect Monkey just expands include files directly in the source, so it should be alright without the import ;)

It does not. Each "module" (file) needs a complete scope of what's "visible" and what not.
test.monkey could do with importing only testclass.monkey, but testclass.monkey shoud import testinterface.monkey


TwistedSage(Posted 2011) [#10]
Ahh that's neat.