iinsertNameHere / catnap

A highly customizable systemfetch written in nim
https://catnap-fetch.xyz
MIT License
152 stars 8 forks source link

[FollowUp] Unable to build catnip #42

Closed JustBuddy closed 7 months ago

JustBuddy commented 7 months ago

Describe the bug Follow up to #41 Trying to "nim setup" the latest build. I did a fresh clone of this repository.

➜  catnip git:(main) nim setup
Building in release mode
/home/pi/catnip/src/catniplib/drawing/render.nim(43, 10) template/generic instantiation of `setStat` from here
/home/pi/catnip/src/catniplib/generation/stats.nim(22, 42) Error: undeclared field: 'runeLen' for type system.string [type declared in /usr/lib/nim/lib/system.nim(34, 3)]
stack trace: (most recent call last)
/usr/lib/nim/lib/system/nimscript.nim(429, 18)
/home/pi/catnip/config.nims(62, 16) setupTask
/home/pi/catnip/config.nims(40, 12) releaseTask
/home/pi/catnip/config.nims(13, 9) compile
/usr/lib/nim/lib/system/nimscript.nim(273, 7) exec
/usr/lib/nim/lib/system/nimscript.nim(273, 7) Error: unhandled exception: FAILED: nim c --cincludes:/home/pi/catnip/src/extern --verbosity:0 -d:release --outdir:/home/pi/catnip/bin /home/pi/catnip/src/catnip.nim [OSError]

Device: OS: Linux Debian 12 WM: ssh

iinsertNameHere commented 7 months ago

@JustBuddy I can't reproduce the problem. runeLen should be defined as it is part of "unicode", which is imported. It compiles just fine for me.

JustBuddy commented 7 months ago

@iinsertNameHere Dunno, I am not doing anything unusual here.

Error after commit 7c7b05f

➜  catnip git:(main) nim setup
Building in release mode
/home/pi/catnip/src/catniplib/drawing/render.nim(43, 10) template/generic instantiation of `setStat` from here
/home/pi/catnip/src/catniplib/generation/stats.nim(21, 46) Error: undeclared field: 'runeLen' for type system.string [type declared in /usr/lib/nim/lib/system.nim(34, 3)]
stack trace: (most recent call last)
/usr/lib/nim/lib/system/nimscript.nim(429, 18)
/home/pi/catnip/config.nims(62, 16) setupTask
/home/pi/catnip/config.nims(40, 12) releaseTask
/home/pi/catnip/config.nims(13, 9) compile
/usr/lib/nim/lib/system/nimscript.nim(273, 7) exec
/usr/lib/nim/lib/system/nimscript.nim(273, 7) Error: unhandled exception: FAILED: nim c --cincludes:/home/pi/catnip/src/extern --verbosity:0 -d:release --outdir:/home/pi/catnip/bin /home/pi/catnip/src/catnip.nim [OSError]
iinsertNameHere commented 7 months ago

@JustBuddy Dose replacing the stats.nim files content with the following fix the issue?

from "../common/definitions" import Stats, Stat, Color
import "../common/parsetoml"
import std/unicode

proc newStat*(icon: string, name: string, color: Color): Stat =
    ## Create a new Stat object
    result.icon = icon
    result.name = name
    result.color = color

proc newStats*(): Stats =
    ## Create a new Stats object
    result.maxlen = 0

proc testFunc(x: TomlValueRef): int =
    unicode.runeLen(x.getStr())

template setStat*(stats: var Stats, stat_name: untyped, rawstat: TomlValueRef): untyped =
    ## Template function that generates a Stat object an parses it to the related stats field
    if rawstat == nil: # Set to empty stat
        stats.`stat_name` = newStat("", "", "")
    else:
        # Merge icon with stat name and color
        let l = uint(rawstat["icon"].testFunc() + rawstat["name"].testFunc() + 1)
        if l > stats.maxlen:
            stats.maxlen = l
        stats.`stat_name` = newStat(rawstat["icon"].getStr(), rawstat["name"].getStr(), rawstat["color"].getStr())
        if astToStr(stat_name) == "colors": stats.color_symbol = rawstat["symbol"].getStr()
JustBuddy commented 7 months ago

@iinsertNameHere did some testing by rolling back to past commits and trying to build those.

Last working: d9ca2de First broken: 308a12e (runeLen)

JustBuddy commented 7 months ago

@JustBuddy Dose replacing the stats.nim files content with the following fix the issue?

from "../common/definitions" import Stats, Stat, Color
import "../common/parsetoml"
import std/unicode

proc newStat*(icon: string, name: string, color: Color): Stat =
    ## Create a new Stat object
    result.icon = icon
    result.name = name
    result.color = color

proc newStats*(): Stats =
    ## Create a new Stats object
    result.maxlen = 0

proc testFunc(x: TomlValueRef): int =
    unicode.runeLen(x.getStr())

template setStat*(stats: var Stats, stat_name: untyped, rawstat: TomlValueRef): untyped =
    ## Template function that generates a Stat object an parses it to the related stats field
    if rawstat == nil: # Set to empty stat
        stats.`stat_name` = newStat("", "", "")
    else:
        # Merge icon with stat name and color
        let l = uint(rawstat["icon"].testFunc() + rawstat["name"].testFunc() + 1)
        if l > stats.maxlen:
            stats.maxlen = l
        stats.`stat_name` = newStat(rawstat["icon"].getStr(), rawstat["name"].getStr(), rawstat["color"].getStr())
        if astToStr(stat_name) == "colors": stats.color_symbol = rawstat["symbol"].getStr()

Unfortunately not, new error:

➜  catnip git:(main) ✗ nim setup
Building in release mode
/home/pi/catnip/src/catniplib/drawing/render.nim(43, 10) template/generic instantiation of `setStat` from here
/home/pi/catnip/src/catniplib/generation/stats.nim(24, 37) Error: attempting to call undeclared routine: 'testFunc'
stack trace: (most recent call last)
/usr/lib/nim/lib/system/nimscript.nim(429, 18)
/home/pi/catnip/config.nims(62, 16) setupTask
/home/pi/catnip/config.nims(40, 12) releaseTask
/home/pi/catnip/config.nims(13, 9) compile
/usr/lib/nim/lib/system/nimscript.nim(273, 7) exec
/usr/lib/nim/lib/system/nimscript.nim(273, 7) Error: unhandled exception: FAILED: nim c --cincludes:/home/pi/catnip/src/extern --verbosity:0 -d:release --outdir:/home/pi/catnip/bin /home/pi/catnip/src/catnip.nim [OSError]
iinsertNameHere commented 7 months ago

@JustBuddy Okay, i got an idea. As i don't understand this meta programing shit and how templates work, I will just implement the same thing but with a normal proc and tables. Give me a sec ;)

iinsertNameHere commented 7 months ago

@JustBuddy Try now

JustBuddy commented 7 months ago

@JustBuddy Try now

@iinsertNameHere Builds correctly now, thank you. ^^

Issue can be closed.

iinsertNameHere commented 7 months ago

Nice, np!