Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Question] How to implement object methods? #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bbrodriges opened this issue Aug 23, 2018 · 2 comments
Open

[Question] How to implement object methods? #10

bbrodriges opened this issue Aug 23, 2018 · 2 comments
Labels
question Further information is requested

Comments

@bbrodriges
Copy link

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.

@bbrodriges bbrodriges changed the title How to implement object methods? [Question] How to implement object methods? Aug 23, 2018
@ncw
Copy link
Collaborator

ncw commented Aug 28, 2018

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.")

@ncw ncw added the question Further information is requested label Aug 28, 2018
@drew-512
Copy link
Contributor

recommend @sbinet close -- addressed w/ #163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants