On Saturday, 22 October 2016 at 20:51:14 UTC, Jonathan M Davis wrote:
On Saturday, October 22, 2016 20:35:27 WhatMeWorry via Digitalmars-d-learn wrote:
[...]

Just put it in a separate module and then import it. e.g.

file: mypackage/constants.d
==================
module mypackage.constants;

GLfloat[] vertices =
[
      // Positions          // Texture Coords
      -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
       0.5f, -0.5f, -0.5f,  1.0f, 0.0f,
                   .....
               (lots and lots of values)
                   .....
];
==================

file: main.d
==================
import mypackage.constants;

void main()
{
    auto v = vertices;
}
==================

Probably the key thing to remember is that when you compile your program, all of the modules that are part of your program rather than a separate library need to be compiled into it. Simply importing them isn't enough - though using either rdmd or dub make that easier.

This is the official documentation's page on modules:

http://dlang.org/spec/module.html

This is the chapter from Al's book that covers modules:

http://ddili.org/ders/d.en/modules.html

And you'd almost certainly benefit from simply reading Ali's book as a whole:

http://ddili.org/ders/d.en/index.html

- Jonathan M Davis

Ok, but now I'm getting these error in my new mypackage/constants.d

..\common\vertex_data.d(5,15): Error: undefined identifier 'GLfloat'
..\common\vertex_data.d(53,12): Error: undefined identifier 'vec3'

Is there a way to just suck in the text from say a .txt file that would not be compiled before inclusion in main.d?




Reply via email to