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

96 lines
1.8 KiB
C++

#include <iostream>
#include <array>
#include "refl/refl.h"
#include "vertex.h"
#include "tstring.h"
#include <functional>
using namespace std;
using namespace refl;
struct vec3_parent {
virtual void norm(int x1, int& x2) {
x2 = x1 * x2;
cout << x2 << "vec3_parent::norm" << endl;
}
};
struct vec3 : public vec3_parent {
float x = 1;
float y = 2;
float z = 3;
string name{ "hellohellohellohellohellohello" };
void norm(int x1, int& x2)override {
x2 = x1 * x2;
cout << x2 << "vec3::norm" << endl;
}
virtual float norm1(float& x1) {
cout << x1 << "::norm1" << endl;
return x1;
}
static void norm2(int x1 = 10) {
cout << x1 << "::norm2" << endl;
}
static void norm3(int x1 = 10) {
x1 = x1 * 10;
cout << x1 << "::norm3" << endl;
}
using MyUClass = UClass_Custom;
static void BuildClass(MyUClass& cls) {
cls.parent = &TypeInfo<vec3_parent>::StaticClass;
cls.AttrNum = 3;
cls.FList = {
MakeMemberField(&vec3::x, "x"),
MakeMemberField(&vec3::y, "y"),
MakeMemberField(&vec3::z, "z"),
MakeMethodField(&vec3::norm, "norm", {8, 9}),
MakeMethodField(&vec3::norm1, "norm1",{(float)2.0})
};
}
};
int main() {
{
//T = > T*
int x = 1;
auto val = &x;
//T* = > T
//*val;
//x = 2;
*val = 2;
}
{
//T* = > T*
int x = 1, y = 2;
int* px = &x;
auto val = px;
//T* => T*
//val;
//px = &y;//做不到哈
val = &y;
}
{
//T* => T**
int x = 1, y = 2;
int* px = &x;
auto val = &px;
//T** = > T*;
//*val;
//px = &y;
*val = &y;
}
auto cls = &TypeInfo<vec3>::StaticClass;
int x = 2, y = 3;
int* q1;
void* q2 = &q1;
*(int**)q2 = &x;
ArgsView a(&y);
ArgsView b(x);
ArgsView c(&q1);
auto ov = cls->New();
ov.Invoke("norm", x);
ov.Invoke("norm", x);
ov.Invoke("norm", x, y);
auto f = ov.Invoke<float>("norm1");
vec3* v = (vec3*)ov.ptr;
ov.Invoke("norm1", (float)y);
delete v;
cout << "hello world\n";
}