Skip to content

Commit

Permalink
Error fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Maškarinec <[email protected]>
  • Loading branch information
marekmaskarinec committed Mar 17, 2024
1 parent 41a8ee7 commit d3c82fb
Show file tree
Hide file tree
Showing 5 changed files with 3,109 additions and 63 deletions.
13 changes: 1 addition & 12 deletions examples/platformer/global.um
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ const (
)

fn readall*(path: str): str {
f := std.fopen(path, "r")
const blockSize = 16
res := ""

for ok := true; ok {
var buff: [blockSize + 1]char
ok = std.fread(f, ^[blockSize]char(&buff)) == 1
res += str([]char(buff))
}

std.fclose(f)
return res
return std.freadall(std.fopen(path, "r").item0).item0

This comment has been minimized.

Copy link
@vtereshkov

vtereshkov Mar 19, 2024

Contributor

@marekmaskarinec std.freadall() expects the input file to be opened as "rb".

See also: vtereshkov/umka-lang#367

}

fn timeStr*(ms: int): str {
Expand Down
2 changes: 1 addition & 1 deletion examples/space-shooter/enemy.um
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn handle*() {
if global.hp == 0 {
if global.score > global.hi {
global.hi = global.score
f := std.fopen("score", "w")
f := std.fopen("score", "w").item0
fprintf(f, "%d", global.hi)
std.fclose(f)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/space-shooter/main.um
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fn init*() {
sound.init()
global.hp = 10

f := std.fopen("score", "r")
if (f != null) {
f, err := std.fopen("score", "r")
if err.code != 0 {
fscanf(f, "%d", &global.hi)
std.fclose(f)
}
Expand Down
Loading

0 comments on commit d3c82fb

Please sign in to comment.