Guest User

Nimrod setter example

a guest
May 27th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. # Blatantly stolen from tutorial page
  2.  
  3. type
  4. TSocket* = object of TObject
  5. FHost: int # cannot be accessed from the outside of the module
  6. # the `F` prefix is a convention to avoid clashes since
  7. # the accessors are named `host`
  8. TNewSockObj = object of TSocket
  9. FNewHost: int
  10.  
  11. # To define new setter for 'TNewSockObj' that would take object and int as param
  12. # and set 'FHost' and 'FNewHost' to the int, could I do:
  13.  
  14. proc `host=`*(s: var TNewSockObj, value: int) {.inline.}=
  15. s.FHost = value
  16. s.FNewHost = value
  17.  
  18. # or would I have to redefine both setters as methods?
  19.  
  20. # Originals:
  21. proc `host=`*(s: var TSocket, value: int) {.inline.} =
  22. ## setter of hostAddr
  23. s.FHost = value
  24.  
  25. proc host*(s: TSocket): int {.inline.} =
  26. ## getter of hostAddr
  27. s.FHost
  28.  
  29. var
  30. s: TSocket
  31. s.host = 34 # same as `host=`(s, 34)
Advertisement
Add Comment
Please, Sign In to add comment