another reflection question
Monkey Forums/Monkey Programming/another reflection question
| ||
hi, Reflection is cool, but I cannot find this in the docs: Where should I use the reflection filter? Should it be used in each file that imports reflection? Or should it only be used in the main file? Or should it only be used in the main include file of a module? When I use the filter in the main import file of a module, as such: Strict #REFLECTION_FILTER="src.test" Import reflection Import src.assert Import src.test Import src.testsuite Import src.testfunction then the application crashes (see below) When I use the filter in each included file before the import statement, it does not seem to work; compilation takes a long time, it seems to reflect all classes. When I use the filter in just the main file and remove it from the included files, I get this error: Parsing... Semanting... Translating... Building... ERROR: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. ERROR:terminate called after throwing an instance of 'char const*' TRANS FAILED: TRANS Failed to execute '"D:/Development/MyProjects/Monkey/mutated-monkey/wdw/unittest/sample/simple_test.build/stdcpp/main_winnt"', return code=3 Abnormal program termination. Exit code: -1 This is all using the stdcpp target. |
| ||
anyone? |
| ||
can someone help me with this? I am stuck :) |
| ||
Im not sure how to use the filter either, Ive tried a for an hour or two to get certain classes to reflect with no luck hopefully the next update will see some fixes if you remove the filter entirely all classes are reflected, does that help? |
| ||
Yes, things then work, BUT compiling takes a long time, as everything is reflected, which also adds unnecessary overhead to my program. |
| ||
Hi, Use #REFLECTION_FILTER once at the top of your main file. Like other app config settings, it can only be set once so setting it again in 'sub modules' wont have any effect. The filter is like a file filter and should include all modules you want reflected. Try uncommenting the various filters in the example below and see what gets reflected: ' 'File untitled1.monkey - main file ' #REFLECTION_FILTER="untitled1" '#REFLECTION_FILTER="untitled2" '#REFLECTION_FILTER="untitled1|untitled2" '#REFLECTION_FILTER="untitled1|untitled2|mojo.graphics" '#REFLECTION_FILTER="untitled*" Import reflection Import mojo Import untitled2 Class C End Function Main() For Local c:=Eachin GetClasses() Print c.Name Next End ' 'File untitled2.monkey ' Class D End |
| ||
I have a file called worldmapclass.monkey in that file is a class called world_map i use this reflection filter in the main file: #REFLECTION_FILTER="worldmapclass.world_map" but when I try to print the object name it says "Object" here is the first file: Strict #REFLECTION_FILTER="worldmapclass.world_map" Import reflection Import worldmapclass Function Main:Int() world_map.inst=New world_map Local clas:=GetClass(world_map.inst) Print clas.Name+" class name" Return 0 End Function here is the second file: Class world_map Global inst:world_map End Class |
| ||
Hi, The filter only applies to modules, not individual decls within a module - ie: you can only reflect all or none of a module. |
| ||
oh ok thanks |
| ||
Thanks Mark, I will give this a go this weekend and post back here. |