aboutsummaryrefslogtreecommitdiff
path: root/src/field.nim
diff options
context:
space:
mode:
authorJulien Dessaux2021-10-05 22:39:45 +0200
committerJulien Dessaux2021-10-05 22:39:45 +0200
commita952eaabb7f33072d2b4e474903156266d8a3a29 (patch)
treede6e2ec1a8d9f8589834c0eb488ee401cb084ef7 /src/field.nim
parentImplemented Funge-98 IO procedures (diff)
downloadnimfunge98-a952eaabb7f33072d2b4e474903156266d8a3a29.tar.gz
nimfunge98-a952eaabb7f33072d2b4e474903156266d8a3a29.tar.bz2
nimfunge98-a952eaabb7f33072d2b4e474903156266d8a3a29.zip
Refactoring
Diffstat (limited to 'src/field.nim')
-rw-r--r--src/field.nim12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/field.nim b/src/field.nim
index 8d609f7..e15d7b4 100644
--- a/src/field.nim
+++ b/src/field.nim
@@ -69,11 +69,13 @@ func Get*(f: Field, x, y: int): int =
func IsIn*(f: Field, x, y: int): bool =
return x >= f.x and y >= f.y and x < f.x+f.lx and y < f.y+f.ly
-proc Load*(f: var Field, filename: string): bool =
+proc Load*(filename: string): ref Field =
var file: File
if not open(file, filename):
- return false
+ return nil
defer: file.close()
+ var f: ref Field
+ new(f)
f.lines.add(Line())
var l = addr f.lines[0]
var trailingSpaces = 0
@@ -83,7 +85,7 @@ proc Load*(f: var Field, filename: string): bool =
if n <= 0:
if f.ly == 0:
if l.l == 0: # we got en empty file!
- return false
+ return nil
f.x = l.x
if l.l > 0:
inc f.ly
@@ -98,7 +100,7 @@ proc Load*(f: var Field, filename: string): bool =
if data[i] == '\n' or data[i] == '\r':
if f.ly == 0:
if l.l == 0:
- return false
+ return nil
f.x = l.x
inc f.ly
if f.x > l.x:
@@ -130,7 +132,7 @@ proc Load*(f: var Field, filename: string): bool =
inc l.l
inc i
f.lines = f.lines[0..<f.ly]
- return true
+ return f
func Set*(f: var Field, x, y, v: int) =
if v == int(' '):