Crash course on extern?
Monkey Forums/Monkey Programming/Crash course on extern?
| ||
Hi All, I've managed to make a simple usage of extern with cpp files, but i feel I'm doing it in a clumsy way. Plus, there are some things i don't understand. Can somebody lecture me on extern usage? :) this is my test.monkey file this is my native/vector2.cpp class First of all, i couldn't compile this until i got rid of the vector2.h file and put all the code in the cpp file. Why is this happening? Monkey doesn't like .h files? Second, i see that some modules never declare any import and they just add native/nameofthefile.targetlanguage.extension. I'm missing something here for sure he he Does monkey figures out this automatically? Or I'm missing something? Is this "The conventional way" of doing things? Sorry for all those questions :) |
| ||
Hi, Monkey can't currently handle .h files, so you need to stick both your .h and your .cpp into one .cpp file. Not ideal, and I plan to fix it soon-ish. I guess as an interim solution you could rename your .h files to .cpp and import them separately from the monkey side, eg: Import "native/vector2_h.cpp" Import "native/vector.cpp" ...which'd probably work OK up to point, but ultimately imports are just pasted into one mega-source file so you need to keep that in mind. > native/nameofthefile.targetlanguage.extension You can use ${TARGET} and ${LANG} in import paths, eg: 'From mojo/app.monkey Import "native/mojo.${TARGET}.${LANG}" This may change in future though. I'd recommend sticking with #If TARGET=... |
| ||
Thanks again mark! Then i'll stick with #if TARGET and for the moment just put everything in the .cpp file. Will keep playing with the other native targets he he.. thanks :) Btw, it seems i cannot use static methods of a C++ class? I would like to make this from monkey: Vector2.fromPoints(..blah) But trans is just leaving fromPoints() alone... I just declared the fromPoints like this Function fromPoints(..blah) Anyway, this is just a silly thing i want to do, since there are other ways of doing this.. |