|
| 1 | +#include "UEPyFPropertiesImporter.h" |
| 2 | + |
| 3 | + |
| 4 | +#if ENGINE_MINOR_VERSION >= 25 |
| 5 | + |
| 6 | + |
| 7 | +static PyObject *ue_PyFPropertiesImporter_getattro(ue_PyFPropertiesImporter *self, PyObject *attr_name) |
| 8 | +{ |
| 9 | + EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer called")); |
| 10 | + PyObject *py_attr = PyObject_GenericGetAttr((PyObject *)self, attr_name); |
| 11 | + if (!py_attr) |
| 12 | + { |
| 13 | + EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer attr OK")); |
| 14 | + if (PyUnicodeOrString_Check(attr_name)) |
| 15 | + { |
| 16 | + const char *attr = UEPyUnicode_AsUTF8(attr_name); |
| 17 | + EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer attr is string %s"), UTF8_TO_TCHAR(attr)); |
| 18 | + if (attr[0] != '_') |
| 19 | + { |
| 20 | + // dont know what to do here |
| 21 | + // no - as far as I can see we cannot search for property classes anymore |
| 22 | + // we have to explicitly add them |
| 23 | + // - so do we need this - just import the explicit property wrap |
| 24 | + // actually this would have to be the property class wrap |
| 25 | + |
| 26 | + EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer field classes %d"), FFieldClass::GetAllFieldClasses().Num()); |
| 27 | + //for (const FFieldClass* FieldClass : FFieldClass::GetAllFieldClasses()) |
| 28 | + //{ |
| 29 | + // EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer field classes %s"), *FieldClass->GetName()); |
| 30 | + //} |
| 31 | + EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer field classes map %d"), FFieldClass::GetNameToFieldClassMap().Num()); |
| 32 | + |
| 33 | + // so apparently there is a map of all field classes and this is how we can look it up |
| 34 | + FName FieldTypeStr = FName(UTF8_TO_TCHAR(attr)); |
| 35 | + EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer looking for %s"), *FieldTypeStr.ToString()); |
| 36 | + FFieldClass** f_class_ptr = FFieldClass::GetNameToFieldClassMap().Find(FieldTypeStr); |
| 37 | + if (f_class_ptr) |
| 38 | + { |
| 39 | + EXTRA_UE_LOG(LogPython, Warning, TEXT("magic properties importer found class")); |
| 40 | + // swallow old exception |
| 41 | + PyErr_Clear(); |
| 42 | + // if we create python wrapper each time then think we dont want the extra inc ref |
| 43 | + // - PyObject_New has already incremented new python objects ref count |
| 44 | + // actually this may be OK - we only see this for import statements |
| 45 | + // which in general are only done once - so this wrapper will last for lifetime |
| 46 | + // of python script - except if we have multiple scripts we will get a different wrapper |
| 47 | + // in each script |
| 48 | + Py_RETURN_FFIELDCLASS_NOINC(*f_class_ptr); |
| 49 | + } |
| 50 | + |
| 51 | + //UClass *u_class = FindObject<UClass>(ANY_PACKAGE, UTF8_TO_TCHAR(attr)); |
| 52 | + //if (u_class) |
| 53 | + //{ |
| 54 | + // // swallow old exception |
| 55 | + // PyErr_Clear(); |
| 56 | + // Py_RETURN_UOBJECT(u_class); |
| 57 | + //} |
| 58 | + |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + return py_attr; |
| 63 | +} |
| 64 | + |
| 65 | +static PyTypeObject ue_PyFPropertiesImporterType = { |
| 66 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 67 | + "unreal_engine.FPropertiesImporter", /* tp_name */ |
| 68 | + sizeof(ue_PyFPropertiesImporter), /* tp_basicsize */ |
| 69 | + 0, /* tp_itemsize */ |
| 70 | + 0, /* tp_dealloc */ |
| 71 | + 0, /* tp_print */ |
| 72 | + 0, /* tp_getattr */ |
| 73 | + 0, /* tp_setattr */ |
| 74 | + 0, /* tp_reserved */ |
| 75 | + 0, /* tp_repr */ |
| 76 | + 0, /* tp_as_number */ |
| 77 | + 0, /* tp_as_sequence */ |
| 78 | + 0, /* tp_as_mapping */ |
| 79 | + 0, /* tp_hash */ |
| 80 | + 0, /* tp_call */ |
| 81 | + 0, /* tp_str */ |
| 82 | + (getattrofunc)ue_PyFPropertiesImporter_getattro, /* tp_getattro */ |
| 83 | + 0, /* tp_setattro */ |
| 84 | + 0, /* tp_as_buffer */ |
| 85 | + Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 86 | + "Unreal Engine FProperties Importer", /* tp_doc */ |
| 87 | + 0, /* tp_traverse */ |
| 88 | + 0, /* tp_clear */ |
| 89 | + 0, /* tp_richcompare */ |
| 90 | + 0, /* tp_weaklistoffset */ |
| 91 | + 0, /* tp_iter */ |
| 92 | + 0, /* tp_iternext */ |
| 93 | + 0, /* tp_methods */ |
| 94 | + 0, |
| 95 | + 0, |
| 96 | +}; |
| 97 | + |
| 98 | +void ue_python_init_fpropertiesimporter(PyObject *ue_module) |
| 99 | +{ |
| 100 | + ue_PyFPropertiesImporterType.tp_new = PyType_GenericNew; |
| 101 | + |
| 102 | + if (PyType_Ready(&ue_PyFPropertiesImporterType) < 0) |
| 103 | + return; |
| 104 | + |
| 105 | + Py_INCREF(&ue_PyFPropertiesImporterType); |
| 106 | + PyModule_AddObject(ue_module, "PropertiesImporter", (PyObject *)&ue_PyFPropertiesImporterType); |
| 107 | +} |
| 108 | + |
| 109 | +PyObject *py_ue_new_fpropertiesimporter() |
| 110 | +{ |
| 111 | + ue_PyFPropertiesImporter *ret = (ue_PyFPropertiesImporter *)PyObject_New(ue_PyFPropertiesImporter, &ue_PyFPropertiesImporterType); |
| 112 | + return (PyObject *)ret; |
| 113 | +} |
| 114 | + |
| 115 | + |
| 116 | +#endif |
0 commit comments