Skip to content

Commit

Permalink
support more strict compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Aug 15, 2022
1 parent 4731c94 commit 106781e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lunacy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type
ltDotDotDot = "..."

proc `$`*(s: LuaStack): string
proc `$`*(value: LuaValue): string
func `$`*(value: LuaValue): string

proc popStack*(p: PState; expand = true): LuaStack

Expand Down Expand Up @@ -163,7 +163,7 @@ macro lua*(ast: untyped): PState =
template L*(s: LuaStack): PState = s.pos.L
template address*(s: LuaStack): LuaStackAddressValue = s.pos.address

proc hash*(s: LuaStack): Hash
func hash*(s: LuaStack): Hash

converter toCint*(si: int): cint =
si.cint
Expand Down Expand Up @@ -213,14 +213,14 @@ proc clean*(s: LuaStack): bool =

template dirty*(s: LuaStack): bool = not s.clean

proc hash*(tab: Table[LuaStack, LuaStack]): Hash =
func hash*(tab: Table[LuaStack, LuaStack]): Hash =
var h: Hash = 0
for key, value in tab.pairs:
h = h !& key.hash
h = h !& value.hash
result = !$h

proc hash*(v: LuaValue): Hash =
func hash*(v: LuaValue): Hash =
var h: Hash = 0
h = h !& v.kind.hash
case v.kind
Expand All @@ -236,22 +236,30 @@ proc hash*(v: LuaValue): Hash =
discard
result = !$h

proc hash*(s: LuaStack): Hash =
func hash*(s: LuaStack): Hash =
hash(s.value)

proc `==`*(a, b: LuaStack): bool =
func `==`*(a, b: LuaStack): bool =
if a.isNil or b.isNil:
a.isNil and b.isNil
else:
a.hash == b.hash

proc `==`*(a, b: LuaValue): bool =
func `==`*(a, b: LuaValue): bool =
if a.kind == b.kind:
a.hash == b.hash
else:
false

proc `$`*(a: LuaStackAddress): string =
func `<`*(a, b: LuaValue): bool =
if {a.kind, b.kind} == {TNumber}:
a.number < b.number
elif a.kind == b.kind:
a.hash < b.hash
else:
a.kind < b.kind

func `$`*(a: LuaStackAddress): string =
result = &"[{a.address}]"

proc init(s: var LuaStack) =
Expand Down Expand Up @@ -459,7 +467,7 @@ proc len*(s: LuaStack): int {.deprecated.} =
of TNone, TNil, TInvalid:
discard

proc `$`*(value: LuaValue): string =
func `$`*(value: LuaValue): string =
case value.kind
of TString:
result.add value.strung
Expand Down

0 comments on commit 106781e

Please sign in to comment.