bugfixes; step one for 'var T' as return type support

This commit is contained in:
Araq 2011-07-28 00:53:52 +02:00
commit 2f066395ba
27 changed files with 234 additions and 68 deletions

View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2010 Dominik Picheta
# (c) Copyright 2011 Dominik Picheta
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -87,7 +87,7 @@ proc checkReply(smtp: TSMTP, reply: string) =
proc connect*(address: string, port = 25,
ssl = false, debug = false): TSMTP =
## Establishes a connection with a SMTP server.
## May fail with EInvalidReply or with a socket errors.
## May fail with EInvalidReply or with a socket error.
if not ssl:
result.sock = socket()
@ -125,7 +125,6 @@ proc sendmail*(smtp: TSMTP, fromaddr: string,
## Sends `msg` from `fromaddr` to `toaddr`.
## Messages may be formed using ``createMessage`` by converting the
## TMessage into a string.
## This function sends the QUIT command when finished.
smtp.debugSend("MAIL FROM:<" & fromaddr & ">\c\L")
smtp.checkReply("250")
@ -139,8 +138,9 @@ proc sendmail*(smtp: TSMTP, fromaddr: string,
smtp.debugSend(msg & "\c\L")
smtp.debugSend(".\c\L")
smtp.checkReply("250")
# quit
proc close*(smtp: TSMTP) =
## Disconnects from the SMTP server and closes the socket.
smtp.debugSend("QUIT\c\L")
if not smtp.ssl:
smtp.sock.close()
@ -201,6 +201,6 @@ when isMainModule:
smtp.auth("someone", "password")
smtp.sendmail("someone@gmail.com",
@["someone@yahoo.com", "someone@gmail.com"], $msg)
smtp.close()

View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2009 Andreas Rumpf
# (c) Copyright 2011 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.

View file

@ -92,6 +92,14 @@ proc `[]`*(t: PStringTable, key: string): string {.rtl, extern: "nstGet".} =
if index >= 0: result = t.data[index].val
else: result = ""
proc modGet*(t: PStringTable, key: string): var string {.
rtl, extern: "nstTake".} =
## retrieves the location at ``t[key]``. If `key` is not in `t`, the
## ``EInvalidValue`` exception is raised.
var index = RawGet(t, key)
if index >= 0: result = t.data[index].val
else: raise newException(EInvalidValue, "key does not exist: " & key)
proc hasKey*(t: PStringTable, key: string): bool {.rtl, extern: "nst$1".} =
## returns true iff `key` is in the table `t`.
result = rawGet(t, key) >= 0
@ -213,4 +221,6 @@ when isMainModule:
assert x["k"] == "v"
assert x["11"] == "22"
assert x["565"] == "67"
x.modGet("11") = "23"
assert x["11"] == "23"