Giter Club home page Giter Club logo

Comments (5)

endragor avatar endragor commented on August 12, 2024
  1. Don't use push/pop for specifying header, put it as a pragma in the corresponding proc/type.
  2. .importcpp expects pattern as a value.
  3. Use .compile pragma to compile .cpp file along with Nim files.
  4. Use --cincludes:DIR to specify where to look for the header file.

This information can be found in the Nim manual.

Try this:

{.compile: "FastNoise.cpp".}

type
  FastNoise* {.header: "FastNoise.h", importcpp: "FastNoise".} = object

proc GetValue*(this: FastNoise, x: cfloat, y: cfloat): cfloat {.header: "FastNoise.h", importcpp: "#.GetValue(@)".}

from godot-nim.

rama0x9 avatar rama0x9 commented on August 12, 2024
  1. Ok, but why?
  2. I thought the name is taken from the procedure name and you only need it when you want a different name?
  3. gotcha
  4. im having problems with this

i did a quick test with a simple non godot project with a structure like so:

C:/Test/main.nim
C:/Test/fastnoise.nim
C:/Test/lib/FastNoise.h
C:/Test/lib/FastNoise.cpp

fastnoise.nim has the code you have kindly posted, then i use
nim c --cincludes:"C:\Test\lib\" --run "C:\Test\main.nim"
i get this error:
Error: unhandled exception: cannot open: FastNoise.cpp [IOError]

It's beginner level, i know :) but working with godot and external libs is important for me, i need to get this going. I want to take a switch from C# godot because i really like nim so far.

And in an actual godot project, how to use --cincludes with "nake build"? maybe in the nakefile.nim somewhere? or do i need to compile it once with nim?

thanks for your time

from godot-nim.

rama0x9 avatar rama0x9 commented on August 12, 2024

ok, im one step further.
cincludes only with root folder
nim c --cincludes:"C:\Test" --run "C:\Test\main.nim"
and in fastnoise.nim the subfolder:
{.compile: "lib/FastNoise.cpp".}

new error:

In file included from C:\Test\nimcache\main.c:11:0:
C:\Test/lib/FastNoise.h:45:1: error: unknown type name 'class'
 class FastNoise
 ^~~~~
C:\Test/lib/FastNoise.h:46:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
C:\\Test\nimcache\main.c: In function 'GetNoise_9cku33tvANHm87a2gL2qUHQ':
C:\\Test\nimcache\main.c:80:2: error: unknown type name 'FastNoise'
  FastNoise obj;
  ^~~~~~~~~
C:\\Test\nimcache\main.c:87:11: error: request for member 'GetValue' in something not a structure or union
  T2_ = obj.GetValue(5.0000000000000000e+000, 8.0000000000000000e+000);

from godot-nim.

endragor avatar endragor commented on August 12, 2024

godot-nim-stub sample uses C backend to compile the code. You need to modify it to use C++. The line that compiles the main file is the last one in the build task of the nakefile: https://github.com/pragmagic/godot-nim-stub/blob/54e5d5c2526262b6e3a0b293676465b5bf615b88/nakefile.nim#L45

Change c to cpp and add any other parameters you need.

Re push/pop, I think they simply don't work in a way you used them. They can be used to override compiler settings, but not to assume that everything has a certain pragma on it.

And yeah, if you duplicate names it isn't necessary to specify them as .importcpp pragma values, but to be consistent with Nim style it's better to change the method name to lowercase. So in the end you should have something like this:

{.compile: "lib/FastNoise.cpp".}

type
  FastNoise* {.header: "FastNoise.h", importcpp.} = object

proc getValue*(this: FastNoise; x, y: cfloat): cfloat {.header: "FastNoise.h", importcpp: "GetValue".}

It's been a while since I last dealt with C++ interop, so might be something else that's needed here.

from godot-nim.

rama0x9 avatar rama0x9 commented on August 12, 2024

ok, fixing the test project above was simple, c to cpp
nim cpp --cincludes:"C:\Test\lib\" --run "C:\Test\main.nim" is working, GetValue does its job, nice

now to godot, not so easy though :/
changing c to cpp only gives error LNK2019: unresolved external symbol and nim64.dll: Fatal Error LNK1120: 1 unresolved externals
also Error: execution of an external program failed: 'vccexe.exe
im not importing fastnoise at all, just changing to cpp

from godot-nim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.