mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
change bind_property
This commit is contained in:
parent
0ec01abdeb
commit
4083d16a38
@ -460,7 +460,7 @@ public:
|
|||||||
// new style binding api
|
// new style binding api
|
||||||
PyObject* bind(PyObject*, const char*, const char*, NativeFuncC, UserData userdata={}, BindType bt=BindType::DEFAULT);
|
PyObject* bind(PyObject*, const char*, const char*, NativeFuncC, UserData userdata={}, BindType bt=BindType::DEFAULT);
|
||||||
PyObject* bind(PyObject*, const char*, NativeFuncC, UserData userdata={}, BindType bt=BindType::DEFAULT);
|
PyObject* bind(PyObject*, const char*, NativeFuncC, UserData userdata={}, BindType bt=BindType::DEFAULT);
|
||||||
PyObject* bind_property(PyObject*, Str, NativeFuncC fget, NativeFuncC fset=nullptr);
|
PyObject* bind_property(PyObject*, const char*, NativeFuncC fget, NativeFuncC fset=nullptr);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Type _find_type_in_cxx_typeid_map(){
|
Type _find_type_in_cxx_typeid_map(){
|
||||||
|
@ -1204,14 +1204,15 @@ PyObject* VM::bind(PyObject* obj, const char* sig, const char* docstring, Native
|
|||||||
return f_obj;
|
return f_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* VM::bind_property(PyObject* obj, Str name, NativeFuncC fget, NativeFuncC fset){
|
PyObject* VM::bind_property(PyObject* obj, const char* name, NativeFuncC fget, NativeFuncC fset){
|
||||||
PyObject* _0 = heap.gcnew<NativeFunc>(tp_native_func, fget, 1, false);
|
PyObject* _0 = heap.gcnew<NativeFunc>(tp_native_func, fget, 1, false);
|
||||||
PyObject* _1 = vm->None;
|
PyObject* _1 = vm->None;
|
||||||
if(fset != nullptr) _1 = heap.gcnew<NativeFunc>(tp_native_func, fset, 2, false);
|
if(fset != nullptr) _1 = heap.gcnew<NativeFunc>(tp_native_func, fset, 2, false);
|
||||||
int pos = name.index(":");
|
std::string_view name_sv(name);
|
||||||
if(pos > 0) name = name.substr(0, pos).strip();
|
int pos = name_sv.find(':');
|
||||||
|
if(pos > 0) name_sv = name_sv.substr(0, pos);
|
||||||
PyObject* prop = VAR(Property(_0, _1));
|
PyObject* prop = VAR(Property(_0, _1));
|
||||||
obj->attr().set(name, prop);
|
obj->attr().set(StrName(name_sv), prop);
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user