pragmagic / godot-nim

Nim bindings for Godot Engine
https://pragmagic.github.io/godot-nim/
Other
497 stars 27 forks source link

Error when exporting `seq[T]` #84

Open arunvickram opened 3 years ago

arunvickram commented 3 years ago

I'm running into an issue where I have an object subclassing a resource:

import godot
import godotapi/resource
import source/party/skill

type SkillsList = seq[Skill]

gdobj Job of Resource:
  var jobName* {.gdExport.}: string = ""
  var skills* {.gdExport.}: seq[string] = @[ ]

The error I'm getting is:

nim/godotnim.nim(769, 9) Error: type mismatch: got <typeof(nil)> but expected 'seq[string]'

I looked into it and it's referencing this proc:

proc fromVariant*[T](s: var seq[T], val: Variant): ConversionResult =
  if val.getType() == VariantType.Nil:
    s = nil
  elif val.getType() == VariantType.Array:
    let arr = val.asArray()
    var newS = newSeq[T](arr.len)
    for idx, item in arr:
      mixin fromVariant
      let convResult = fromVariant(newS[idx], item)
      if convResult != ConversionResult.OK:
        return convResult
    shallowCopy(s, newS)
  else:
    result = ConversionResult.TypeError

and the line it's through an error on is the s = nil. I'm not sure how gdobj gets to the point where it assumes that val is VariantType.Nil, but that seems to be causing the issue.

Xzayler commented 2 years ago

Did you manage to fix it? I'm having the same problem exactly. I know it's a very old issue but I'm lost.

arunvickram commented 2 years ago

I haven't yet, I just moved on