Interface/module issue
Monkey Forums/Monkey Programming/Interface/module issue
| ||
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 |
| ||
Not sure, because i donīt have monkey right now... but try adding an import.testinterface in the testclass.monkey file |
| ||
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 ;) |
| ||
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 ;) |
| ||
Edit causes doublepost? That's odd ;) |
| ||
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 :) |
| ||
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. |
| ||
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 :) |
| ||
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 |
| ||
Ahh that's neat. |