GetClass() always returns null
Monkey Forums/Monkey Programming/GetClass() always returns null
| ||
It seems GetClass isn't working as it always returns null in 70g. Even in the following primitive sample, it still returns null:Strict Import reflection Class MyClass End Class Function Main:Int () Local c:MyClass = New MyClass() Print(GetClass(c).Name) Return 0 End Am I using the function wrong or is this a known bug? |
| ||
Try to set the reflection filter to include your file. |
| ||
I just noticed the documentation on the filters. Doh! I just jumped from 63b to 70g, and it seems its changed quite a bit since then. So by adding: #REFLECTION_FILTER="myapp\*" I got the simple program in my original post to work, however, I can't seem it get it to work for the class I actually want to use reflection for. I added the same filter to the top of the file but GetClass() is still returning null. My file is at "myapp/props/player.Monkey". Is there something more I need to do? EDIT: By doing the following: Local c:Player = New Player() Print(GetClass(c).Name) I'm getting "monkey.lang.Object". |
| ||
The filter needs the name of the module you want to reflect, something like...'----- File test.monkey ----- 'reflect both this (test) module and player module to reflection filter. #REFLECTION_FILTER="test|player" Import reflection Import player Function Main() Local p:=New Player Print GetClass( p ).Name End '----- File player.monkey ----- Class Player End Another way to do it would be to add something like... #REFLECTION_FILTER+="player" ...to the top of player.monkey, so the player module 'adds itself' to the reflection filter. |