Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to compile when export a string field: #145

Open
zhmt opened this issue Jan 6, 2025 · 12 comments
Open

Failed to compile when export a string field: #145

zhmt opened this issue Jan 6, 2025 · 12 comments

Comments

@zhmt
Copy link

zhmt commented Jan 6, 2025

Here is my class, I am trying to export first field "skillId"

type SkillBase3D* = ptr object of Node3D
  skillId* {.gdexport.}: string = "PlayerMeleeAttack"
  timecc* : float32
  status*: SkillStatus = coolingDown
  detectArea3D* : Area3D
  bulletCache*: Node
  bullets* :Node
  followingBullets*: Node3D
  detectedTargets*: HashSet[MyCharBase3D.MyCharBase3D] = initHashSet[MyCharBase3D.MyCharBase3D]()
  params*: SkillSetting

A error was reported when building with gdext 0.4.1:

G:\g7\Client\nim\libprj\bootstrap.nim(15, 25) template/generic instantiation of `execon` from here
G:\g7\Client\nim\libprj\bootstrap.nim(21, 3) template/generic instantiation of `register` from here
C:\Users\zhmt\.nimble\pkgs2\gdext-0.4.0-27e56b6de8c4b416694df1c97d4b5d3dc9972588\gdext\surface\userclass.nim(136, 3) template/generic instantiation of `processExports` from here
G:\g7\Client\nim\libprj\src\game\SkillBase3D.nim(51, 3) Error: undeclared identifier: 'skillId'
candidates (edit distance, scope distance); see '--spellSuggest':
 (4, 6): 'ceilDiv'
 (4, 6): 'ceili'
 (4, 6): 'failed'

The error will not be reported if "{.gdexport.}" is removed.

@zhmt
Copy link
Author

zhmt commented Jan 6, 2025

It is a base class, and it has a child class "SkillMeleeAttack".
If fields from "SkillMeleeAttack" are exported , everything goes OK.
It seems that fields from base class refused to bed exported.

@zhmt
Copy link
Author

zhmt commented Jan 6, 2025

Is it difficult to be fixed?

@panno8M
Copy link
Member

panno8M commented Jan 6, 2025

This code looks like correct. I will investigate.
Is gdext-nim/testproject/editor/nim/bootstrap.nim compilable?
Or can you create a minimum reproduction?

@zhmt
Copy link
Author

zhmt commented Jan 6, 2025

How to reproduce :
create A base class :

type SkillBase3D* = ptr object of Node3D
  skillId* {.gdexport.}: string = "PlayerMeleeAttack"

```nim
create a subclass:

type SkillMeleeAttack3D* = ptr object of SkillBase3D
duration* : float32 = 0.33

register them.

the build error should be reproduced.

@panno8M
Copy link
Member

panno8M commented Jan 6, 2025

Can you zip the project and send it to us?

If you don't want to publish it, please email it to me([email protected]). I promise to delete the data as soon as I finish my research.

@zhmt
Copy link
Author

zhmt commented Jan 6, 2025

nim.zip
I have created a minimum project, you can download it.
How to build:

cd nim
nim c --stackTrace:on --lineTrace:on .\libprj\bootstrap.nim

@panno8M
Copy link
Member

panno8M commented Jan 6, 2025

Thank you very much. I will do some research.

Btw this is a bit verbose, but try the following. (I just hard-coded what the gdexport pragma does internally)

type SkillBase3D* = ptr object of Node3D
  skillId*: string = "PlayerMeleeAttack"
  timecc* : float32
  status*: SkillStatus = coolingDown
  detectArea3D* : Area3D
  bulletCache*: Node
  bullets* :Node
  followingBullets*: Node3D
  detectedTargets*: HashSet[MyCharBase3D.MyCharBase3D] = initHashSet[MyCharBase3D.MyCharBase3D]()
  params*: SkillSetting

gdexport "skillId",
    proc (self: SkillBase3D): string = self.skillId,
    proc (self: SkillBase3D; value: string) = self.skillId = value

@zhmt
Copy link
Author

zhmt commented Jan 6, 2025

gdexport "skillId",
    proc (self: SkillBase3D): string = self.skillId,
    proc (self: SkillBase3D; value: string) = self.skillId = value

the hard-coded snippet works.

@panno8M
Copy link
Member

panno8M commented Jan 6, 2025

I found the cause of the problem, but it will take some time to fix the root cause.

It seems to be caused by a batting between the module name and the class name, so as a temporary measure, rename SkillBase3D.nim appropriately.

@zhmt
Copy link
Author

zhmt commented Jan 6, 2025

There are a few fields that need to be exported, so I'll hard-code them for now; it won't have much impact.

@panno8M
Copy link
Member

panno8M commented Jan 6, 2025

If you modify the module name (filename) to something other (gd***.nim is recommended) than the class name, the first snippet should work.

@zhmt
Copy link
Author

zhmt commented Jan 6, 2025

I renamed SkillBase3D.nim to gdSkillBase3D.nim , It works now.
Thanks!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants