mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
...
This commit is contained in:
parent
13debcd722
commit
f397917ff5
@ -172,7 +172,7 @@ void add_module_base64(VM* vm){
|
||||
PyObject* mod = vm->new_module("base64");
|
||||
|
||||
// b64encode
|
||||
vm->bind_static_method<1>(mod, "b64encode", [](VM* vm, ArgsView args){
|
||||
vm->bind_func<1>(mod, "b64encode", [](VM* vm, ArgsView args){
|
||||
Bytes& b = CAST(Bytes&, args[0]);
|
||||
std::vector<char> out(b.size() * 2);
|
||||
int size = base64_encode((const unsigned char*)b.data(), b.size(), out.data());
|
||||
@ -181,7 +181,7 @@ void add_module_base64(VM* vm){
|
||||
});
|
||||
|
||||
// b64decode
|
||||
vm->bind_static_method<1>(mod, "b64decode", [](VM* vm, ArgsView args){
|
||||
vm->bind_func<1>(mod, "b64decode", [](VM* vm, ArgsView args){
|
||||
Bytes& b = CAST(Bytes&, args[0]);
|
||||
std::vector<char> out(b.size());
|
||||
int size = base64_decode(b.data(), b.size(), (unsigned char*)out.data());
|
||||
|
@ -12,11 +12,11 @@ namespace pkpy {
|
||||
return OBJ_GET(Type, vm->_modules[__x0]->attr(__x1)); \
|
||||
} \
|
||||
static PyObject* register_class(VM* vm, PyObject* mod) { \
|
||||
PyObject* type = vm->new_type_object(mod, #name, vm->tp_object); \
|
||||
if(OBJ_NAME(mod) != #mod) { \
|
||||
auto msg = fmt("register_class() failed: ", OBJ_NAME(mod), " != ", #mod); \
|
||||
throw std::runtime_error(msg); \
|
||||
} \
|
||||
PyObject* type = vm->new_type_object(mod, #name, vm->tp_object); \
|
||||
T::_register(vm, mod, type); \
|
||||
type->attr()._try_perfect_rehash(); \
|
||||
return type; \
|
||||
@ -30,12 +30,13 @@ struct VoidP{
|
||||
|
||||
void* ptr;
|
||||
VoidP(void* ptr): ptr(ptr){}
|
||||
VoidP(): ptr(nullptr){}
|
||||
|
||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||
vm->bind_static_method<1>(type, "__new__", CPP_NOT_IMPLEMENTED());
|
||||
vm->bind_default_constructor<VoidP>(type);
|
||||
|
||||
vm->bind_static_method<1>(type, "__repr__", [](VM* vm, ArgsView args){
|
||||
VoidP& self = CAST(VoidP&, args[0]);
|
||||
vm->bind_method<0>(type, "__repr__", [](VM* vm, ArgsView args){
|
||||
VoidP& self = _CAST(VoidP&, args[0]);
|
||||
std::stringstream ss;
|
||||
ss << "<void* at " << self.ptr << ">";
|
||||
return VAR(ss.str());
|
||||
|
4
src/io.h
4
src/io.h
@ -47,9 +47,9 @@ struct FileIO {
|
||||
}
|
||||
|
||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||
vm->bind_static_method<2>(type, "__new__", [](VM* vm, ArgsView args){
|
||||
vm->bind_constructor<3>(type, [](VM* vm, ArgsView args){
|
||||
return VAR_T(FileIO,
|
||||
vm, CAST(Str&, args[0]).str(), CAST(Str&, args[1]).str()
|
||||
vm, CAST(Str&, args[1]).str(), CAST(Str&, args[2]).str()
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -381,7 +381,6 @@ inline std::vector<Str> StrName::_r_interned;
|
||||
|
||||
const StrName __class__ = StrName::get("__class__");
|
||||
const StrName __base__ = StrName::get("__base__");
|
||||
const StrName __new__ = StrName::get("__new__");
|
||||
const StrName __iter__ = StrName::get("__iter__");
|
||||
const StrName __next__ = StrName::get("__next__");
|
||||
const StrName __str__ = StrName::get("__str__");
|
||||
|
Loading…
x
Reference in New Issue
Block a user