...not a polymorphic type
Monkey Forums/Monkey Programming/...not a polymorphic type
| ||
Hi all, I just try to introduce new classes for the GLFW target but run into some polymorphic trouble. Here's my class test.cpp class Test_Bla { static void Blub() { } }; Here's the Monkey interface testbla.monkey: Strict Private Import "test.cpp" Public Extern Class Bla = "Test_Bla" Method Blub:Void() End Class and here's my main code: Strict Import mojo Import testbla Function Main:Int() New TestApp() Return 0 End Function Class TestApp Extends App Field testbla:Bla = Null Method OnCreate:Int() SetUpdateRate(30) testbla = New Bla() Return 0 End Method Method OnUpdate:Int() If( KeyHit( KEY_ESCAPE ) ) Error "" End If Return 0 End Method Method OnSuspend:Int() Return 0 End Method Method OnResume:Int() Return 0 End Method Method OnRender:Int() Cls Return 0 End Method End Class For GLFW this fails compiling with: (ClCompile target) -> ..\main.cpp(204): error C2683: 'dynamic_cast' : 'Test_Bla' is not a polymorphic type [D:\Projekte\mnet\examples\test.build\glfw\vc2010\MonkeyGame.vcxproj] ..\main.cpp(191): error C2683: 'dynamic_cast' : 'Test_Bla' is not a polymorphic type [D:\Projekte\mnet\examples\test.build\glfw\vc2010\MonkeyGame.vcxproj] I understand the error message because line 204 of the main.cpp just tries to do a dynamic_cast which obviously doesn't work with a static object: gc_object *p=dynamic_cast<gc_object*>(rhs); But... how can I avoid it? How do you "diddy-guys" handle this for GLFW? |
| ||
I'd say it's this lineMethod Blub:Void()In your code it's a static method, a.k.a function in monkey. This will probably fix it, though I've never tested it or imported a function within a class. Function Blub:Void() Function Blub:Void() = "Test_Bla::Blub" Don't mind that last part. Anyways... |
| ||
Yep I know. "Avoiding" the creation of the class it works using something likeFunction Blub:Void() = "Test_Bla::Blub" directly to get access to the static method... But it would be nice to have a real object. In diddy it's just done via that function solution. |
| ||
Oh, you know what, looking in monkey/lang.monkey there's some pretty weird stuff going on that might help in finding the answer to this dilemma. Though I can't really say for sure, considering that's part of the core language. |
| ||
rofl, thanks! Will take a look! :)Class @Object Extends Null="Object" Ahem.... Alright. *gg* |
| ||
Guess what? That compiles:Class @Bla Extends Null = "Test_Bla" Function Blub:Void() End Class Uh oh... now I have to try if it not only compiles but runs as well. |
| ||
Fantastic. Thanks for pointing me to that, Goodlookinguy! Sockets for GLFW are working now (TCP Server as well as client), yay! Now to Android. :) |
| ||
Externed C++ classes need to extend public Object if you want to use any of the Monkey-related stuff (GC, etc.)class Foo : public Object { }; This was my experience from porting Lua, at least. |
| ||
Thanks Samah, it works with the code above. Might be some ugly void pointer stuff deriving from Null? LOL. |