WeiDUorg / weidu

WeiDU is a program used to develop, distribute and install modifications for games based on the Infinity Engine.
http://www.weidu.org
GNU General Public License v2.0
90 stars 20 forks source link

[Feature Request] CLEAR_VARIABLE #172

Closed 4Luke4 closed 4 years ago

4Luke4 commented 4 years ago

Pretty much what the title states.

Is there any particular reason why there's no CLEAR_VARIABLE command? I mean, we have both CLEAR_ARRAYS and CLEAR_ARRAY so why is there no way to clear a specific variable? Or just some variables (e.g. MATLAB-style: clear var1 ... varN or clear -regexp ^Mon ^Tue ^Wed)?

Guess the same holds for CLEAR_INLINED and CLEAR_CODES, i.e.: there should be a way to clear a specific inlined file (or the listed inlined files) and/or a specific function (or the listed functions).

FredrikLindgren commented 4 years ago

I rather feel variable-scopes is the proper way to handle this. If you need one or more variables to not exist after some code has executed, that's arguably a sign you should have used a function. If you need set up throw-away variables for some purpose, there is also WITH_SCOPE.

4Luke4 commented 4 years ago

If you need to set up throw-away variables for some purpose, there is also WITH_SCOPE.

Good to know, that's what I was looking for... So basically that command is equivalent to launch a function that returns nothing, right?

FredrikLindgren commented 4 years ago

Any variables set inside the scope and any changes made are discarded when the scope exits, so it's a bit like a function, yes.

FredrikLindgren commented 4 years ago

So that obviates the need for CLEAR_VARIABLE, then?

What's the use cases for the proposed changes to CLEAR_INLINED and CLEAR_CODES? For either, you can achieve the desired effect by using the present actions and re-including the stuff you did not want cleared. Is clearing specific inlined files or functions something you'd ever actually do? Functions you never call are a non-issue, functions you want to re-implement do not need to be cleared first, inlined files you do not load are likewise a non-issue and if you shadowing real files you are arguably doing it wrong. Is there something I'm overlooking?

4Luke4 commented 4 years ago

So that obviates the need for CLEAR_VARIABLE, then?

Yes. I'm currently using it to check for the presence of AUTO_EVAL_STRINGS.

// "x" and "y" are meant to be temporary vars, so let us wrap them around WITH_SCOPE (I no longer need them after that check...)
WITH_SCOPE BEGIN
    OUTER_TEXT_SPRINT "y" "x"
    OUTER_TEXT_SPRINT "z" "y"
    ACTION_IF !("%%z%%" STRING_EQUAL "x") BEGIN
        FAIL "AUTO_EVAL_STRINGS is not set"
    END
END

Anyway, as I realized afterwards, that is equivalent to launch a function with no return value and no input.

Is clearing specific inlined files or functions something you'd ever actually do?

Yeah, probably not. To be honest, I opened this issue because I thought about MATLAB where you can indeed clear specific items from the memory. However, that's probably not necessary in WeiDU...

4Luke4 commented 2 years ago

Is there something I'm overlooking?

@FredrikLindgren What can you tell me about multi-dimensional arrays...?