zengine-old/engine/3rdparty/zlib/test/refl_01.cpp

59 lines
1.7 KiB
C++
Raw Normal View History

2024-04-03 17:58:02 +08:00
#include <iostream>
#include <array>
2024-04-08 21:01:50 +08:00
#include "refl/refl.h"
2024-04-03 17:58:02 +08:00
#include "vertex.h"
2024-04-04 18:18:04 +08:00
#include "tstring.h"
2024-04-05 16:03:58 +08:00
#include <functional>
2024-04-03 17:58:02 +08:00
using namespace std;
using namespace refl;
2024-04-04 18:18:04 +08:00
struct vec3_parent {
2024-04-07 21:15:34 +08:00
virtual void norm(int x1, int& x2) {
x2 = x1 * x2;
cout << x2 << "vec3_parent::norm" << endl;
}
2024-04-04 18:18:04 +08:00
};
struct vec3 : public vec3_parent {
float x = 1;
float y = 2;
float z = 3;
string name{ "hellohellohellohellohellohello" };
2024-04-08 21:01:50 +08:00
void norm(int x1, int& x2)override {
x2 = x1 * x2;
cout << x2 << "vec3::norm" << endl;
}
2024-04-06 23:50:17 +08:00
virtual float norm1(int x1 = 10) {
2024-04-05 16:03:58 +08:00
cout << x1 << "::norm1" << endl;
return x * y *z * x1;
}
2024-04-06 23:50:17 +08:00
static void norm2(int x1 = 10) {
2024-04-05 16:03:58 +08:00
cout << x1 << "::norm2" << endl;
}
2024-04-08 21:01:50 +08:00
static void norm3(int x1 = 10) {
x1 = x1 * 10;
2024-04-05 16:03:58 +08:00
cout << x1 << "::norm3" << endl;
2024-04-03 17:58:02 +08:00
}
2024-04-08 21:01:50 +08:00
using MyUClass = UClass_Custom;
static MyUClass BuildClass() {
MyUClass cls(type_name<vec3>().View(), sizeof(vec3), &TypeInfo<vec3_parent>::StaticClass);
auto& FList = cls.FList;
FList.reserve(6);
FList.push_back(cls.MakeMemberField<offsetof(vec3, x)>("x", &TypeInfo<float>::StaticClass));
FList.push_back(cls.MakeMemberField<offsetof(vec3, y)>("y", &TypeInfo<float>::StaticClass));
FList.push_back(cls.MakeMemberField<offsetof(vec3, z)>("z", &TypeInfo<float>::StaticClass));
cls.AttrNum = FList.size();
FList.push_back(cls.MakeMethodField(&vec3::norm, "norm"));
FList.push_back(cls.MakeMethodField(&vec3::norm, "norm1"));
cls.vtable.InitObject = &UClass::InitObject<vec3>;
cls.BuildClass();
2024-04-03 17:58:02 +08:00
return cls;
}
};
int main() {
2024-04-08 21:01:50 +08:00
auto cls = &TypeInfo<vec3>::StaticClass;
int x = 100, y = 2;
auto ov = cls->New();
2024-04-07 21:15:34 +08:00
ov.Invoke("norm", x, y);
2024-04-08 21:01:50 +08:00
vec3* v = (vec3*)ov.ptr;
delete v;
2024-04-07 21:15:34 +08:00
cout << "hello world\n";
2024-04-03 17:58:02 +08:00
}