Skip to content

Instantly share code, notes, and snippets.

@onionhammer
Last active December 28, 2015 01:49
Show Gist options
  • Save onionhammer/7423812 to your computer and use it in GitHub Desktop.
Save onionhammer/7423812 to your computer and use it in GitHub Desktop.
Error
## Imports
import marshal
## Types
type TLog* = ref object
path: string
file: TFile
## Procedures
proc open*(path: string, mode: TFileMode = fmReadWrite): TLog =
new(result)
discard result.file.open(path, mode)
proc close*(log: TLog) =
log.file.close()
log.file = nil
proc write*[T](log: TLog, value: T) =
log.file.writeln($$value)
proc read*[T](log: TLog): T =
var line = log.file.readLine()
return to[T](line)
var log = open("log2.db")
log.write("hello world")
log.file.setFilePos(0)
echo "reading from log (1)"
echo read[string](log) #works
echo log.read[string]() #fails
echo "closing log"
log.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment