Я имею ту же ошибку, что и здесь
исходный код для Main:
Py_Initialize();
try {
auto sys_module {bp::import("sys")};
auto sys_path {sys_module.attr("path")};
sys_path.attr("append")("bin");
bp::import("py_lib");
auto module_test {bp::import("module_test").attr("__dict__")};
const char* ident = bp::extract< const char* >( module_test["Ident"]() );
const char* newgameplay = bp::extract< const char* >( module_test["NewGamePlay"]() );
printf("Loading Script: %s\n", ident);
auto py_interface_inst {module_test[newgameplay]()};
const auto is_subclass {bp::is_subclass
bp::extract extractor {py_interface_inst};
if (extractor.check()) {
auto cpp = extractor();
cpp->FunctionCall();
}
} catch (const boost::python::error_already_set&) {
PyErr_Print();
}
return 0;
< /code>
код деформирования модуля: < /p>
Код: Выделить всё
class Base
{
public:
Base() {};
virtual void FunctionCall() {std::cout get_override("FunctionCall"))
f();
else Base::FunctionCall();
}
};
BOOST_PYTHON_MODULE(PY_MODULE_NAME)
{
class_("Base")
.def("FunctionCall", &Base::FunctionCall, &BaseWrap::FunctionCall)
;
class_("Hello")
;
class_("HelloDerived")
;
}
< /code>
и файл кода Python < /p>
import sys
import py_lib
def Ident():
return "Alpha"
def NewGamePlay():
return "NewAlpha"
def NewAlpha():
import py_lib
class Alpha(py_lib.Base):
def __init__(self):
super().__init__()
print("Made new Alpha!")
def FunctionCall(self):
print("This is function test Alpha!")
base : py_lib.Base = py_lib.Base()
derived : py_lib.Base = Alpha()
for el in [base, derived]:
el.FunctionCall()
return Alpha()
< /code>
во время отладки кажется, что экстрактор не работает на функции Python < /p>
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
< /code>
Это в функции < /p>
// ..\boost_1.84.0\libs\python\src\object\class.cpp
BOOST_PYTHON_DECL void*
find_instance_impl(PyObject* inst, type_info type, bool null_shared_ptr_only)
{
if (!Py_TYPE(Py_TYPE(inst)) ||
!PyType_IsSubtype(Py_TYPE(Py_TYPE(inst)), &class_metatype_object))
return 0;
instance* self = reinterpret_cast(inst);
...
Я использую MSVC143 для компиляции, cmake для построения и повышения 1.84 для Boost :: python .
, в то время как базовый код> Code> Code code Создан. Конечно. Спасибо
Подробнее здесь: https://stackoverflow.com/questions/796 ... ction-fail
Мобильная версия