mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
Update obj.h
This commit is contained in:
parent
44afa5b023
commit
300058b063
19
src/obj.h
19
src/obj.h
@ -181,28 +181,31 @@ void _check_py_class(VM* vm, const PyVar& var);
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
T py_pointer_cast(VM* vm, const PyVar& var);
|
T py_pointer_cast(VM* vm, const PyVar& var);
|
||||||
|
|
||||||
|
struct Discarded {};
|
||||||
|
|
||||||
template<typename __T>
|
template<typename __T>
|
||||||
__T py_cast(VM* vm, const PyVar& obj) {
|
__T py_cast(VM* vm, const PyVar& obj) {
|
||||||
|
using T = std::decay_t<__T>;
|
||||||
if constexpr(std::is_pointer_v<__T>){
|
if constexpr(std::is_pointer_v<__T>){
|
||||||
return py_pointer_cast<__T>(vm, obj);
|
return py_pointer_cast<__T>(vm, obj);
|
||||||
}
|
}else if constexpr(is_py_class<T>::value){
|
||||||
using T = std::decay_t<__T>;
|
|
||||||
if constexpr(is_py_class<T>::value){
|
|
||||||
_check_py_class<T>(vm, obj);
|
_check_py_class<T>(vm, obj);
|
||||||
return OBJ_GET(T, obj);
|
return OBJ_GET(T, obj);
|
||||||
|
}else{
|
||||||
|
return Discarded();
|
||||||
}
|
}
|
||||||
throw std::runtime_error("bad py_cast() call");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename __T>
|
template<typename __T>
|
||||||
__T _py_cast(VM* vm, const PyVar& obj) {
|
__T _py_cast(VM* vm, const PyVar& obj) {
|
||||||
|
using T = std::decay_t<__T>;
|
||||||
if constexpr(std::is_pointer_v<__T>){
|
if constexpr(std::is_pointer_v<__T>){
|
||||||
return py_pointer_cast<__T>(vm, obj);
|
return py_pointer_cast<__T>(vm, obj);
|
||||||
}
|
}else if constexpr(is_py_class<T>::value){
|
||||||
using T = std::decay_t<__T>;
|
|
||||||
if constexpr(is_py_class<T>::value){
|
|
||||||
return OBJ_GET(T, obj);
|
return OBJ_GET(T, obj);
|
||||||
|
}else{
|
||||||
|
return Discarded();
|
||||||
}
|
}
|
||||||
throw std::runtime_error("bad py_cast() call");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define VAR(x) py_var(vm, x)
|
#define VAR(x) py_var(vm, x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user