#include #include #include "refl/uclass.h" #include "vertex.h" #include "tstring.h" #include 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 { using UClass = class vec3_UClass; float x = 1; float y = 2; float z = 3; string name{ "hellohellohellohellohellohello" }; virtual float norm1(int x1 = 10) { cout << x1 << "::norm1" << endl; return x * y *z * x1; } static void norm2(int x1 = 10) { cout << x1 << "::norm2" << endl; } void norm3(int x1 = 10) { x1 = x * y * z; cout << x1 << "::norm3" << endl; } }; struct vec3_UClass : public UClass { public: array FList; int32_t AttrNum; using UClass::UClass; const FieldPtr* GetField(const Name& name, bool isMethod)const override { // 指定开始位置的迭代器 auto start = FList.begin(); if (isMethod) { start += AttrNum; } auto end = FList.end(); for (auto it = start; it != end; ++it) { if (it->name == name) { return &*it; } } return nullptr; } void InitObject(void* ptr)const override { vec3 obj{}; std::construct_at((vec3*)ptr, obj); } static vec3_UClass BuildClass() { vec3_UClass cls(type_name().View(), sizeof(vec3), &TypeInfo::StaticClass); //offsetof(vec3, x) 很坑,相当坑 cls.AttrNum = 3; cls.FList[0] = cls.MakeMemberField("x", &TypeInfo::StaticClass); cls.FList[1] = cls.MakeMemberField("y", &TypeInfo::StaticClass); cls.FList[2] = cls.MakeMemberField("z", &TypeInfo::StaticClass); cls.FList[3] = cls.MakeMethodField(&vec3::norm, "norm"); cls.FList[4] = cls.MakeMethodField(&vec3::norm1, "norm1"); //cls.FList[5] = cls.MakeMethodField(&vec3::norm2, "norm2"); return cls; } }; template void printt(void* ptr, std::vector& ArgsList) { using MethodType = void (*)(Args...); MethodType fptr = (MethodType)ptr; { auto param = ArgsList.rbegin(); fptr(param++->cast_to()...); //fptr((Args)param++->val...); } /* { auto param = ArgsList.begin(); auto val1 = (++param); auto val2 = (++param); auto val3 = (++param); fptr(val1->cast_to(), val1->cast_to(), val1->cast_to(); } */ //fptr((++param)->val, (int)(++param)->val, (int&)(++param)->val); //fptr(std::forward((Args)(++param)->val)...); int x = 1; x = x + 1; } int main() { auto cls = &TypeInfo::StaticClass; auto cls2 = &TypeInfo::StaticClass; auto cls3 = &TypeInfo::StaticClass; auto cls4 = &TypeInfo::StaticClass; auto cls5 = &TypeInfo::StaticClass; vec3 v; int x = 1, y = 2; std::vector ArgsList; ArgsList.emplace_back(); ArgsList.emplace_back(v); ArgsList.emplace_back(x); ArgsList.emplace_back(y); auto ptr1 = &vec3::norm; using MethodType = void (*)(void*, int, int&); MethodType ptr2 = *(MethodType*)&ptr1; using R = int; using RetType = void*; auto ttt = sizeof(void*); RetType ret; //ptr2(&v, x , y); auto ov = cls->New((void*)& v); ov.Invoke("norm", x, y); printt(*(void**)&ptr1, ArgsList); //ptr2(x, y); cout << "hello world\n"; }