Reflection is your best friend
BlitzMax Forums/BlitzMax Programming/Reflection is your best friend
| ||
OMG, reflection is teh best! I set up a type for all my application settings: Then to make actual settings I can use, I create an extended type like this: SuperStrict Import brl.reflection Import "Settings.bmx" Global configurationsettings:TConfigurationSettings=New TConfigurationSettings configurationsettings.start() Type TConfigurationSettings Extends TSettings {label="Configuration"} Field Trilinear_Filter:Int=1 {style=5} Field Anisotropic_Filter:Float {extra="1,16"} Field Texture_Quality:Int=4 {style=1 extra="Very low,Low,Medium,High,Very high"} Field Physics_Quality:Int=1 {style=1 extra="Fast,Normal,Exact"} Field Volumetric_Lighting:Int=0 {style=5} Field SSAO:Int=0 {style=5} EndType All I have to do is declare the field, and it is accessible by writing the configurationsettings.ssao variable, and the interface is automatically created. The setting is loaded, saved, and the user can edit it in a property grid gadget, and I don't have to manage any of that. When they edit the field with the property gadget, it is just automatically updated, and I can use that value right away without doing anything myself. Next up I am going to link gadgets so they control variables directly, with no need to actually evaluate the events. |
| ||
Yes, that's great. I remember someone did write also a XML serializer based on reflection, so the objects where stored using a XML based file format. |
| ||
Yes reflection is cool! I was working on a Reflection to database storage system got it to work with basic types. But needed a lot more work to get ... Arrays of objects interlinked objects binary objects e.g. images/databanks to work to correctly retrieve/recall and update a database. @Leadworkds What's with the {} curly brackets haven't seen them used with BMax before? |
| ||
What's with the {} curly brackets haven't seen them used with BMax before? That is metadata. |
| ||
Metadata is really cool and so is reflection. |
| ||
Interesting. How is metadata used here? Or in blitzmax in general? EDIT: nm , I did some digging and found an example. I did not know you could add 'secret' messages to fields or methods. MUST you need reflection to access the metadata? |
| ||
Yes. |
| ||
are metadata like c# annotations? |
| ||
And you thought you would never see {} in BlitzMax. |
| ||
are metadata like c# annotations? No. Metadata is strictly keys and values. Values may be literal strings or numbers (can't use the value of a constant), keys may be any valid identifier (last I checked). |
| ||
Indeed, reflection is extremely powerful. Yet using it for an upcoming project, wrote some of a powerful skripting thing with it.. got all in all a little disencouraged when learning to use lua, but kept working on it.. maybe ending summer theres something ready to show.. |
| ||
Josh you're brilliant! I downloaded your property grid awhile ago and added a bunch of new features and got the idea to do exactly this metadata+reflection! You always beat me to the punch with these great ideas! I wish I knew then what I know now. |