Last active
December 28, 2015 01:49
-
-
Save onionhammer/7423812 to your computer and use it in GitHub Desktop.
Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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