wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
224 stars 30 forks source link

Discuss: Compiletime replacements for functions #385

Closed muzzel closed 9 years ago

muzzel commented 9 years ago

Idea: add an annotation that allows the user to define a replacement for a function, which is used when the function is executed in compiletime.

Example:

function bla()
    doSomething()

@compiletimereplacement function bla()
    doSomethingElse()

When bla() is executed during runtime, the normal doSomething() version is used. If bla() is executed in compiletime, the doSomethingElse() version is used. If there is no @compiletimereplacement defined for a function, the normal version is used for both runtime and compiletime.

Someone should probably come up with a shorter name for the annotation :p

peq commented 9 years ago

Why not something like this?

function bla()
    if compiletime
        doSomething()
    else
        doSomethingElse()

I am planning to add something like compiletime as a built-in constant, see discussion in #365

muzzel commented 9 years ago

Yea that works too, just thought it might be comfortable.

But I didnt notice that it completely destroys readability (similar to vJass hooks), so its a bad idea anyway.