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