gpython
gpython copied to clipboard
[Question] How to implement object methods?
I want to try to implement hashlib (PR will follow).
For now I have implemented Type, module, module method and some "magic methods", but I cannot figure out how to implement object methods such as update, hexdigest etc.
Here is my WIP implementation.
Thanks in advance.
This isn't particularly elegant at the moment, but see py/generator.go for an example. You basically add the method objects to the type's Dict by hand.
GeneratorType.Dict["send"] = MustNewMethod("send", func(self Object, value Object) (Object, error) {
return self.(*Generator).Send(value)
}, 0, "send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")
recommend @sbinet close -- addressed w/ https://github.com/go-python/gpython/pull/163