mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
fix a bug of dir
This commit is contained in:
parent
4a15d1c8f0
commit
418101df19
@ -122,17 +122,15 @@ void init_builtins(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bind_builtin_func<1>("dir", [](VM* vm, const pkpy::Args& args) {
|
_vm->bind_builtin_func<1>("dir", [](VM* vm, const pkpy::Args& args) {
|
||||||
std::vector<Str> names;
|
std::vector<Str> names;
|
||||||
|
if(args[0]->is_attr_valid()){
|
||||||
for (auto& [k, _] : args[0]->attr()) names.push_back(k);
|
for (auto& [k, _] : args[0]->attr()) names.push_back(k);
|
||||||
|
}
|
||||||
for (auto& [k, _] : vm->_t(args[0])->attr()) {
|
for (auto& [k, _] : vm->_t(args[0])->attr()) {
|
||||||
if (k.find("__") == 0) continue;
|
|
||||||
if (std::find(names.begin(), names.end(), k) == names.end()) names.push_back(k);
|
if (std::find(names.begin(), names.end(), k) == names.end()) names.push_back(k);
|
||||||
}
|
}
|
||||||
pkpy::List ret;
|
pkpy::List ret;
|
||||||
for (const auto& name : names) ret.push_back(vm->PyStr(name));
|
for (const auto& name : names) ret.push_back(vm->PyStr(name));
|
||||||
std::sort(ret.begin(), ret.end(), [vm](const PyVar& a, const PyVar& b) {
|
return vm->PyList(std::move(ret));
|
||||||
return vm->PyStr_AS_C(a) < vm->PyStr_AS_C(b);
|
|
||||||
});
|
|
||||||
return vm->PyList(ret);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bind_method<0>("object", "__repr__", [](VM* vm, const pkpy::Args& args) {
|
_vm->bind_method<0>("object", "__repr__", [](VM* vm, const pkpy::Args& args) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user