This commit is contained in:
blueloveTH 2023-05-16 12:22:46 +08:00
parent d3d8d9a8e6
commit fcbe56b5a9
2 changed files with 15 additions and 0 deletions

BIN
prebuild

Binary file not shown.

View File

@ -677,6 +677,21 @@ inline void init_builtins(VM* _vm) {
return VAR(Str(self.str()));
});
_vm->bind_method<0>("bytes", "to_char_array", [](VM* vm, ArgsView args) {
const Bytes& self = _CAST(Bytes&, args[0]);
void* buffer = malloc(self.size());
memcpy(buffer, self.data(), self.size());
return VAR_T(VoidP, buffer);
});
_vm->bind_func<2>("bytes", "from_char_array", [](VM* vm, ArgsView args) {
const VoidP& data = _CAST(VoidP&, args[0]);
int size = CAST(int, args[1]);
std::vector<char> buffer(size);
memcpy(buffer.data(), data.ptr, size);
return VAR(Bytes(std::move(buffer)));
});
_vm->bind_method<1>("bytes", "__eq__", [](VM* vm, ArgsView args) {
const Bytes& self = _CAST(Bytes&, args[0]);
if(!is_type(args[1], vm->tp_bytes)) return VAR(false);