forked from AustinBrunkhorst/CPP-Reflection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionsAndMethods.cpp
More file actions
35 lines (23 loc) · 945 Bytes
/
Copy pathFunctionsAndMethods.cpp
File metadata and controls
35 lines (23 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "TestReflectionModule.h"
#include "TestTypes.h"
#include "TestProperties.h"
#include "TypeCreator.h"
using namespace ursine::meta;
int main(void)
{
MetaInitialize( UsingModule( TestModule ) );
Type soundEffectType = typeof( SoundEffect );
Field volumeField = soundEffectType.GetField( "volume" );
// the runtime supports overloading, but by default returns the first overload
Method loadMethod = soundEffectType.GetMethod( "Load" );
// creates an instance of a sound effect
Variant effect = TypeCreator::Create( soundEffectType );
// effect.volume is now 85
volumeField.SetValue( effect, 85.0f );
// 85 -- can also use GetValue<float>( )
float volumeValue = volumeField.GetValue( effect ).ToFloat( );
std::cout << "SoundEffect.volume: " << volumeValue << std::endl;
// effect.Load is called
loadMethod.Invoke( effect, std::string { "Explosion.wav" } );
return 0;
}