| 259 | } |
| 260 | |
| 261 | void* PythonEngine::getAs_impl(ScriptObject& obj, const std::type_info& ti) { |
| 262 | |
| 263 | auto val = std::any_cast<PythonObject>(obj.object); |
| 264 | |
| 265 | void* return_value = nullptr; |
| 266 | |
| 267 | const auto& type_name = getRegisteredTypeName(ti); |
| 268 | |
| 269 | auto* type = SWIG_Python_TypeQuery(type_name.c_str()); |
| 270 | |
| 271 | if (!type) { |
| 272 | throw std::runtime_error("Unable to find type in SWIG"); |
| 273 | } |
| 274 | |
| 275 | const auto result = SWIG_Python_ConvertPtr(val.obj_, &return_value, type, 0); |
| 276 | |
| 277 | if (!SWIG_IsOK(result)) { |
| 278 | throw std::runtime_error(fmt::format("Error getting object from SWIG/Python of supposed type {}, {}\n", ti.name(), type_name.c_str())); |
| 279 | } |
| 280 | |
| 281 | return return_value; |
| 282 | } |
| 283 | |
| 284 | bool PythonEngine::getAs_impl_bool(ScriptObject& obj) { |
| 285 | auto val = std::any_cast<PythonObject>(obj.object); |