Fix issues with latest Nim devel compiler
This commit is contained in:
parent
1955c8d3ec
commit
626b66b8d7
6 changed files with 36 additions and 41 deletions
|
|
@ -102,7 +102,8 @@ replace.cdecl = "cdecl"
|
|||
|
||||
[n.prepare]
|
||||
git = "https://github.com/switchbrew/libnx"
|
||||
#execute = """cd ${output}; make;"""
|
||||
execute.lin = """cd ${output}; make;"""
|
||||
execute.mac = """cd ${output}; make;"""
|
||||
|
||||
[n.post]
|
||||
reset=true
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ proc init() =
|
|||
if code.failed:
|
||||
raiseEx(
|
||||
AccountInitError,
|
||||
"Error, account api could not be initialized: " & code.description
|
||||
"Error, account api could not be initialized", code
|
||||
)
|
||||
enabled = true
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ proc getImageSize*(profile: AccountProfile): int =
|
|||
result = 0
|
||||
let code = accountProfileGetImageSize(profile.unsafeAddr, res.addr).newResult
|
||||
if code.failed:
|
||||
raiseEx(AccountImageSizeError, "Error, could not get image size: " & code.description)
|
||||
raiseEx(AccountImageSizeError, "Error, could not get image size", code)
|
||||
result = res.int
|
||||
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ proc imageSize*(user: User): int =
|
|||
let res = accountProfileGetImageSize(prof.addr, size.addr).newResult
|
||||
|
||||
if res.failed:
|
||||
raiseEx(AccountImageSizeError, "Error, could not get image size: " & res.description)
|
||||
raiseEx(AccountImageSizeError, "Error, could not get image size", res)
|
||||
|
||||
result = size.int
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ proc getProfileHelper(userID: u128): AccountProfile =
|
|||
let res = accountGetProfile(result.addr, userID).newResult
|
||||
|
||||
if res.failed:
|
||||
raiseEx(AccountUserProfileError, "Error, could not get user profile: " & res.description)
|
||||
raiseEx(AccountUserProfileError, "Error, could not get user profile", res)
|
||||
|
||||
|
||||
proc loadImage*(user: User): AccountImage =
|
||||
|
|
@ -128,7 +128,7 @@ proc loadImage*(user: User): AccountImage =
|
|||
|
||||
if res.failed:
|
||||
prof.close()
|
||||
raiseEx(AccountImageLoadError, "Error, could not load image: " & res.description)
|
||||
raiseEx(AccountImageLoadError, "Error, could not load image", res)
|
||||
|
||||
prof.close()
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ proc getUser*(userID: u128): User =
|
|||
let res = accountProfileGet(prof.addr, userData.addr, profBase.addr).newResult
|
||||
|
||||
if res.failed:
|
||||
raiseEx(AccountUserDataError, "Error, could not get user data: " & res.description)
|
||||
raiseEx(AccountUserDataError, "Error, could not get user data", res)
|
||||
|
||||
result.username = profBase.username.join("")
|
||||
result.lastEdited = profBase.lastEditTimestamp
|
||||
|
|
@ -173,7 +173,7 @@ proc getActiveUser*(): User =
|
|||
var res = accountGetActiveUser(userID.addr, selected.addr).newResult
|
||||
|
||||
if res.failed:
|
||||
raiseEx(AccountActiveUserError, "Error, could not get active user ID: " & res.description)
|
||||
raiseEx(AccountActiveUserError, "Error, could not get active user ID", res)
|
||||
|
||||
if not selected:
|
||||
raiseEx(AccountUserNotSelectedError, "No user currently selected!")
|
||||
|
|
@ -189,7 +189,7 @@ proc getActiveUser*(): User =
|
|||
res = accountProfileGet(prof.addr, userData.addr, profBase.addr).newResult
|
||||
|
||||
if res.failed:
|
||||
raiseEx(AccountUserDataError, "Error, could not get user data: " & res.description)
|
||||
raiseEx(AccountUserDataError, "Error, could not get user data", res)
|
||||
|
||||
result.username = profBase.username.join("")
|
||||
result.lastEdited = profBase.lastEditTimestamp
|
||||
|
|
@ -209,7 +209,7 @@ proc getProfile*(user: User): Profile =
|
|||
if res.failed:
|
||||
raiseEx(
|
||||
AccountUserProfileError,
|
||||
"Error, could not get account profile: " & res.description
|
||||
"Error, could not get account profile", res
|
||||
)
|
||||
|
||||
result.service = newService(prof.s)
|
||||
|
|
@ -224,7 +224,7 @@ proc getUserCount*(): int32 =
|
|||
if res.failed:
|
||||
raiseEx(
|
||||
AccountUserCountError,
|
||||
"Error, could not get user count: " & res.description
|
||||
"Error, could not get user count", res
|
||||
)
|
||||
result = count
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ proc listAllUsers*(): seq[User] =
|
|||
if res.failed:
|
||||
raiseEx(
|
||||
AccountUserListError,
|
||||
"Error, could not list users: " & res.description
|
||||
"Error, could not list users", res
|
||||
)
|
||||
|
||||
for i in 0 ..< usersReturned.int:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import macros, strutils, sets
|
||||
import libnx/wrapper/cons
|
||||
import libnx/utils
|
||||
import macros, strutils
|
||||
|
||||
|
||||
type
|
||||
|
|
@ -64,7 +64,7 @@ proc toConsole(pconsole: ptr PrintConsole): Console =
|
|||
result.tabSize = pconsole.tabSize
|
||||
result.fg = pconsole.fg
|
||||
result.bg = pconsole.bg
|
||||
result.flags = {}
|
||||
result.flags = initSet[Style]()
|
||||
|
||||
result.pcon.PrintChar = proc (con: pointer, c: cint): bool {.cdecl.} =
|
||||
let console = cast[ptr PrintConsole](con).toConsole()
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ proc initializeVibrationDevices*(
|
|||
if rc.failed:
|
||||
raiseEx(
|
||||
VibrationInitError,
|
||||
"Could not init vibration for controller #$ with type #$" %
|
||||
"Could not init vibration for controller $# with type $#" %
|
||||
[$controller, $ctype]
|
||||
)
|
||||
for i in 0 ..< numDevices:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import strutils
|
||||
import
|
||||
libnx/wrapper/result,
|
||||
libnx/wrapper/types
|
||||
|
|
@ -5,7 +6,7 @@ import
|
|||
type
|
||||
|
||||
Module {.pure.} = enum
|
||||
Invalid = 0, # This is just so the nim compiler is happy
|
||||
Success = 0,
|
||||
Kernel = 1,
|
||||
Libnx = 345,
|
||||
LibnxNvidia = 348
|
||||
|
|
@ -13,16 +14,8 @@ type
|
|||
Result* = ref object
|
||||
code*: uint32
|
||||
module*: string
|
||||
description*: string
|
||||
case kind*: Module
|
||||
of Module.Kernel:
|
||||
kernelError*: KernelError
|
||||
of Module.Libnx:
|
||||
libnxError*: LibnxError
|
||||
of Module.LibnxNvidia:
|
||||
libnxNvidiaError*: LibnxNvidiaError
|
||||
else:
|
||||
discard
|
||||
kind*: Module
|
||||
error*: string
|
||||
|
||||
KernelError* {.pure.} = enum
|
||||
Timeout = 117
|
||||
|
|
@ -98,8 +91,6 @@ proc newResult*(code: uint32): Result =
|
|||
result = new(Result)
|
||||
|
||||
result.code = code
|
||||
if code.R_SUCCEEDED:
|
||||
return
|
||||
|
||||
let moduleCode = code.R_MODULE
|
||||
let module = Module(moduleCode)
|
||||
|
|
@ -108,20 +99,18 @@ proc newResult*(code: uint32): Result =
|
|||
|
||||
let descCode = code.R_DESCRIPTION
|
||||
|
||||
var description = ""
|
||||
var error = "Unknown error: module: $# description: $#" %
|
||||
[$moduleCode, $descCode]
|
||||
try:
|
||||
case module
|
||||
of Module.Invalid:
|
||||
discard
|
||||
of Module.Success:
|
||||
return
|
||||
of Module.Kernel:
|
||||
result.kernelError = KernelError(descCode)
|
||||
description = $result.kernelError
|
||||
error = $KernelError(descCode)
|
||||
of Module.Libnx:
|
||||
result.libnxError = LibnxError(descCode)
|
||||
description = $result.libnxError
|
||||
error = $LibnxError(descCode)
|
||||
of Module.LibnxNvidia:
|
||||
result.libnxNvidiaError = LibnxNvidiaError(descCode)
|
||||
description = $result.libnxNvidiaError
|
||||
error = $LibnxNvidiaError(descCode)
|
||||
except:
|
||||
echo "Converting to result failed: " & getCurrentExceptionMsg()
|
||||
echo "Code: " & $code
|
||||
|
|
@ -130,4 +119,4 @@ proc newResult*(code: uint32): Result =
|
|||
echo "DescCode: " & $descCode
|
||||
|
||||
result.module = $module
|
||||
result.description = description
|
||||
result.error = error
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import macros, strutils, math
|
||||
import macros, strutils, math, hashes
|
||||
import libnx/results
|
||||
|
||||
|
||||
proc hash*(obj: SomeOrdinal): Hash =
|
||||
## Allow hashing of enums with holes
|
||||
result = cast[int](obj)
|
||||
|
||||
proc size*(enumTy: typedesc): int =
|
||||
# Returns the number of items in a bit set enum
|
||||
log2(float64(enumTy.high)).int + 1
|
||||
|
|
@ -90,8 +95,8 @@ type
|
|||
data*: ptr UncheckedArray[T]
|
||||
|
||||
template raiseEx*(ty: untyped, message: string, rc: Result): untyped =
|
||||
## Raise an exception with a result description
|
||||
raise newException(ty, message & ": " & rc.description)
|
||||
## Raise an exception with a result error
|
||||
raise newException(ty, message & ": " & rc.error)
|
||||
|
||||
template raiseEx*(ty: untyped, message: string): untyped =
|
||||
## Raise an exception
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue