首先為Human類添加了成員函數:
1 void PrintHello()
2 {
3 GetConsole()->WriteLine(L"Hello, I\'m "+Name+L".");
4 }
5
6 VUnicodeString GetName()
7 {
8 return Name;
9 }
10
11 VL_AutoPtr<Animal> GetPat(VInt Index)
12 {
13 return OtherPats[Index];
14 }
15
16 Bird GetTransportation(VInt Index)
17 {
18 return OtherTranspotationsList[Index];
19 }
20
21 VBool IsAllBird(VL_AutoPtr<Animal> aAnimal , VInt Index)
22 {
23 return VL_AutoPtr<Bird>(aAnimal) && VL_AutoPtr<Bird>(OtherPats[Index]);
24 }
25
26 void PrintIsAllBird(VL_AutoPtr<Animal> aAnimal , VInt Index)
27 {
28 GetConsole()->WriteLine(IsAllBird(aAnimal,Index)?L"all bird":L"not all bird");
29 }
2 {
3 GetConsole()->WriteLine(L"Hello, I\'m "+Name+L".");
4 }
5
6 VUnicodeString GetName()
7 {
8 return Name;
9 }
10
11 VL_AutoPtr<Animal> GetPat(VInt Index)
12 {
13 return OtherPats[Index];
14 }
15
16 Bird GetTransportation(VInt Index)
17 {
18 return OtherTranspotationsList[Index];
19 }
20
21 VBool IsAllBird(VL_AutoPtr<Animal> aAnimal , VInt Index)
22 {
23 return VL_AutoPtr<Bird>(aAnimal) && VL_AutoPtr<Bird>(OtherPats[Index]);
24 }
25
26 void PrintIsAllBird(VL_AutoPtr<Animal> aAnimal , VInt Index)
27 {
28 GetConsole()->WriteLine(IsAllBird(aAnimal,Index)?L"all bird":L"not all bird");
29 }
其次是注冊函數的代碼:
1 VL_BEGIN_SUB_CLASS(Human,Mammalian)
2 VL_ADD_CLASS_MEMBER(Name)
3 VL_ADD_CLASS_MEMBER(MainPat)
4 VL_ADD_CLASS_MEMBER(MainTransportation)
5 VL_ADD_CLASS_MEMBER(OtherPats)
6 VL_ADD_CLASS_MEMBER(OtherTranspotations)
7 VL_ADD_CLASS_MEMBER(OtherPatsList)
8 VL_ADD_CLASS_MEMBER(OtherTranspotationsList)
9 VL_ADD_CLASS_MEMBER(PatMap)
10 VL_ADD_CLASS_MEMBER(PatMultiMap)
11 VL_ADD_CLASS_METHOD(PrintHello)
12 VL_ADD_CLASS_METHOD(GetName)
13 VL_ADD_CLASS_METHOD(GetPat)
14 VL_ADD_CLASS_METHOD(GetTransportation)
15 VL_ADD_CLASS_METHOD(IsAllBird)
16 VL_ADD_CLASS_METHOD(PrintIsAllBird)
17 VL_END_CLASS(Human)
2 VL_ADD_CLASS_MEMBER(Name)
3 VL_ADD_CLASS_MEMBER(MainPat)
4 VL_ADD_CLASS_MEMBER(MainTransportation)
5 VL_ADD_CLASS_MEMBER(OtherPats)
6 VL_ADD_CLASS_MEMBER(OtherTranspotations)
7 VL_ADD_CLASS_MEMBER(OtherPatsList)
8 VL_ADD_CLASS_MEMBER(OtherTranspotationsList)
9 VL_ADD_CLASS_MEMBER(PatMap)
10 VL_ADD_CLASS_MEMBER(PatMultiMap)
11 VL_ADD_CLASS_METHOD(PrintHello)
12 VL_ADD_CLASS_METHOD(GetName)
13 VL_ADD_CLASS_METHOD(GetPat)
14 VL_ADD_CLASS_METHOD(GetTransportation)
15 VL_ADD_CLASS_METHOD(IsAllBird)
16 VL_ADD_CLASS_METHOD(PrintIsAllBird)
17 VL_END_CLASS(Human)
然后是調用函數的代碼。注意我們使用函數名進行調用,參數全部使用指針,而且調用完會自動釋放:
1 void PrintType(VL_InspectorManager::Ptr Manager , VL_ObjectType::Ptr Type)
2 {
3 VL_InspectorConverterManager Converter;
4 Converter.AddNormalConverter(new VL_InspectorReader);
5
6 VL_ObjectInspector::Ptr Inspector=Manager->GetInspector(L"VL_ObjectType");
7 GetConsole()->WriteLine(Converter.FindToStringConverter(Inspector)->ConvertToString(Inspector,Type.Object()));
8 }
9
10 //下面這里是main函數中的代碼片段
11 {
12 VL_AutoPtr<VL_StructInspector> HumanInspector=Manager->GetInspector(L"Human");
13 {
14 GetConsole()->WriteLine(L"開始調用函數:PrintHello");
15 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"PrintHello");
16 VL_List<VPointer , true> Parameters;
17 PrintResult(Method->Invoke(&human,Parameters));
18 }
19 {
20 GetConsole()->WriteLine(L"開始調用函數:GetName");
21 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"GetName");
22 VL_List<VPointer , true> Parameters;
23 PrintResult(Method->Invoke(&human,Parameters));
24 }
25 {
26 GetConsole()->WriteLine(L"開始調用函數:GetPat");
27 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"GetPat");
28 VL_List<VPointer , true> Parameters;
29 Parameters.Add(new int(0));
30 PrintResult(Method->Invoke(&human,Parameters));
31 }
32 {
33 GetConsole()->WriteLine(L"開始調用函數:GetTransportation");
34 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"GetTransportation");
35 VL_List<VPointer , true> Parameters;
36 Parameters.Add(new int(0));
37 PrintResult(Method->Invoke(&human,Parameters));
38 }
39 {
40 GetConsole()->WriteLine(L"開始調用函數:IsAllBird");
41 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"IsAllBird");
42 VL_List<VPointer , true> Parameters;
43 Parameters.Add(new Bird);
44 Parameters.Add(new int(0));
45 PrintResult(Method->Invoke(&human,Parameters));
46 }
47 {
48 GetConsole()->WriteLine(L"開始調用函數:PrintIsAllBird");
49 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"PrintIsAllBird");
50 VL_List<VPointer , true> Parameters;
51 Parameters.Add(new Bird);
52 Parameters.Add(new int(2));
53 PrintResult(Method->Invoke(&human,Parameters));
54 }
55 }
2 {
3 VL_InspectorConverterManager Converter;
4 Converter.AddNormalConverter(new VL_InspectorReader);
5
6 VL_ObjectInspector::Ptr Inspector=Manager->GetInspector(L"VL_ObjectType");
7 GetConsole()->WriteLine(Converter.FindToStringConverter(Inspector)->ConvertToString(Inspector,Type.Object()));
8 }
9
10 //下面這里是main函數中的代碼片段
11 {
12 VL_AutoPtr<VL_StructInspector> HumanInspector=Manager->GetInspector(L"Human");
13 {
14 GetConsole()->WriteLine(L"開始調用函數:PrintHello");
15 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"PrintHello");
16 VL_List<VPointer , true> Parameters;
17 PrintResult(Method->Invoke(&human,Parameters));
18 }
19 {
20 GetConsole()->WriteLine(L"開始調用函數:GetName");
21 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"GetName");
22 VL_List<VPointer , true> Parameters;
23 PrintResult(Method->Invoke(&human,Parameters));
24 }
25 {
26 GetConsole()->WriteLine(L"開始調用函數:GetPat");
27 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"GetPat");
28 VL_List<VPointer , true> Parameters;
29 Parameters.Add(new int(0));
30 PrintResult(Method->Invoke(&human,Parameters));
31 }
32 {
33 GetConsole()->WriteLine(L"開始調用函數:GetTransportation");
34 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"GetTransportation");
35 VL_List<VPointer , true> Parameters;
36 Parameters.Add(new int(0));
37 PrintResult(Method->Invoke(&human,Parameters));
38 }
39 {
40 GetConsole()->WriteLine(L"開始調用函數:IsAllBird");
41 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"IsAllBird");
42 VL_List<VPointer , true> Parameters;
43 Parameters.Add(new Bird);
44 Parameters.Add(new int(0));
45 PrintResult(Method->Invoke(&human,Parameters));
46 }
47 {
48 GetConsole()->WriteLine(L"開始調用函數:PrintIsAllBird");
49 VL_MethodInspector::Ptr Method=HumanInspector->GetMethod(L"PrintIsAllBird");
50 VL_List<VPointer , true> Parameters;
51 Parameters.Add(new Bird);
52 Parameters.Add(new int(2));
53 PrintResult(Method->Invoke(&human,Parameters));
54 }
55 }
最后是程序截圖:

于是可以開始做很多好玩的事情了。