Skip to content

Commit

Permalink
FIX hardcoded length
Browse files Browse the repository at this point in the history
  • Loading branch information
ninovanhooff committed Oct 24, 2024
1 parent 19efc78 commit 5c20364
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/playdate/scoreboards.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ proc invokeAddScoreCallback(score: PDScorePtr, errorMessage: ConstChar) {.cdecl,
emptyValue = emptyPDScore
)

proc seqBuilder[T, U](rawField: ptr UncheckedArray[T], itemBuilder: proc (item: T): U {.raises: [].}): seq[U] =
let length = 10 # todo
proc seqBuilder[T, U](rawField: ptr UncheckedArray[T], length: cuint, itemBuilder: proc (item: T): U {.raises: [].}): seq[U] =
privateAccess(SDKArray)
let cArray = SDKArray[T](data: rawField, len: length)
let cArray = SDKArray[T](data: rawField, len: length.int)
var newSeq = newSeq[U](length)
for i in 0 ..< length:
let item = cArray[i]
Expand All @@ -132,6 +131,7 @@ proc invokeScoresCallback(scoresList: PDScoresListPtr, errorMessage: ConstChar)
privateAccess(SDKArray)
var scoresSeq = seqBuilder(
rawField = scoresList.scores,
length = scoresList.count,
itemBuilder = scoreBuilder
)

Expand All @@ -149,6 +149,7 @@ proc invokeBoardsListCallback(boardsList: PDBoardsListPtr, errorMessage: ConstCh
privateAccess(SDKArray)
var boardsSeq = seqBuilder(
rawField = cast[ptr UncheckedArray[PDBoardRaw]](boardsList.boards),
length = boardsList.count,
itemBuilder = proc (board: PDBoardRaw): PDBoard =
newPDBoard(boardID = $board.boardID, name = $board.name)
)
Expand Down

0 comments on commit 5c20364

Please sign in to comment.