~ehmry/nim_tox

e705a3a9b79022e9cf55fab308c90bff96eb0029 — Emery Hemingway 1 year, 11 months ago acebed4 v0.1.0
Equality operator for index types, its good for tables
1 files changed, 20 insertions(+), 20 deletions(-)

M src/toxcore.nim
M src/toxcore.nim => src/toxcore.nim +20 -20
@@ 96,15 96,15 @@ assert(TOX_FILE_ID_LENGTH == (int)file_id_length())
assert(TOX_MAX_FILENAME_LENGTH == (int)max_filename_length())
assert(TOX_MAX_HOSTNAME_LENGTH == (int)max_hostname_length())

template toxArrayType(name, N: untyped) =
  ## Generate a array type definition with hex conversions.
  type name* = object
template toxArrayType(T, N: untyped) =
  ## Generate an array type definition with hex conversions.
  type T* = object
    bytes*: array[N, uint8]
  func `$`*(x: name): string =
  func `$`*(x: T): string =
    result = newStringOfCap(N*2)
    for b in x.bytes:
      result.add b.toHex
  func `to name`*(s: string): name =
  func `to T`*(s: string): T =
    doAssert(s.len == N*2)
    let raw = parseHexStr s
    for i in 0..<N:


@@ 131,22 131,19 @@ func isValid*(id: Address): bool =
    odd = odd xor id.bytes[i]
  (even or odd) == 0

type
  Core* = distinct pointer
    ## Opaque C type wrapped by the `Tox` object.
  Friend* = distinct uint32
    ## Token for referencing friends.
  NoSpam* = distinct uint32
    ## Cookie attached to Tox addresses and friend requests.
  MessageId* = distinct uint32
    ## Token for referencing application messages.
  FileTransfer* = distinct uint32
    ## Token for referencing file transfers.
  Conference* = distinct uint32
    ## Token for referencing conferences.
  Peer* = uint32
    ## Token for referencing conference peers.
template toxIndexType(T: untyped) =
  ## Generate a index type definition with equality comparison.
  type T* = distinct uint32
  proc `==` * (x, y: T): bool {.borrow.}

toxIndexType Friend
toxIndexType NoSpam
toxIndexType MessageId
toxIndexType FileTransfer
toxIndexType Conference
toxIndexType Peer

type
  TOX_CONNECTION* = enum
    ## Connection state.
    TOX_CONNECTION_NONE,


@@ 201,6 198,9 @@ type
    TOX_CONFERENCE_TYPE_AV

type
  Core* = distinct pointer
    ## Opaque C type wrapped by the `Tox` object.

  tox_log_cb* = proc (
    core: Core; level: TOX_LOG_LEVEL; file: cstring; line: uint32;
    `func`: cstring; message: cstring; user_data: pointer) {.cdecl.}