preprocess when loading an extension?

Daniele NieroDaniele Niero Posts: 233 ✭✭
edited August 2016 in KL Programming

Hi,

I was wondering if there is any way to do some sort of preprocess when loading an extension.
I'l try to explain better.
Imagine I want to have a function returning a value that depends by some sort of environment setting. For example a function that returns the up axis used, Y or Z.

In C++ I would do something on this line:

#ifdef Y_UP
Vec3 getUpAxis() {
    return Vec3(0.0, 1.0, 0.0);
}
#else
Vec3 getUpAxis() {
    return Vec3(0.0, 0.0, 1.0);
}
#endif

I noticed we can do something similar with an extension version.
From documentation:

/*
** Example: Conditional Compilation using Preprocessor Statements
*/

EXT_VER_IF Fabric : "< 2.0.0"
foo() {
  report("Version is < 2.0.0");
}
EXT_VER_ENDIF

EXT_VER_IF Fabric : ">= 2.0.0"
foo() {
  report("Version is >= 2.0.0");
}
EXT_VER_ENDIF

operator entry() {
  foo();
}

/*
** Output:
Version is >= 2.0.0
*/

If the second example could be done using an= environment variable, for example, that would be incredibly useful.

Cheers,
Daniele

Tagged:

Comments

  • HelgeHelge Moderator, Fabric Employee Posts: 314 Fabric Employee

    Hey Daniele,

    you could do this with a singleton. Store the option in a singleton and then in every of these calls switch the logic based on the singleton value.

    Feel free to submit a feature request for "getenv", it's trivial to add and probably really useful.

    I hope this helps!

    Research Engineer @ Fabric Software

  • Daniele NieroDaniele Niero Posts: 233 ✭✭

    Hi Helge,

    Thanks for the answer.
    I was actually thinking about the singleton, but the resolution of which function will be called will be resolved at run time, right?
    Or maybe there won't be two function but only one with an IF to chose what to return.

    Although this is completely fine, I was hoping more about a mechanism that allow to register, at loading time, the right function. Sure, this has also a down-side: If I want to use a different convention I must restart everything.

    Either ways, a getenv is useful indeed, I will file a request.

    Cheers,
    Daniele

  • HelgeHelge Moderator, Fabric Employee Posts: 314 Fabric Employee

    Well KL is a compiled language, so there's no runtime loading of functions. The preprocessor type statements you found concerning extension version control are quite an exception.

    Maybe you should also file a request concerning more concise control over the preprocessor, too :smile:

    Research Engineer @ Fabric Software

Sign In or Register to comment.