Zezombye / overpy

High-level language for the Overwatch Workshop with support for compilation and decompilation.
GNU General Public License v3.0
180 stars 28 forks source link

Idea: Define member applied to specific types and new macro declarations prototype. #294

Open nathan130200 opened 2 years ago

nathan130200 commented 2 years ago

TL;DR

An way to declare arguments in #!defineMember like macros, introducing (new keyword? "macro") or using subroutines like declaration def, with explicit types where macro should apply.


Detailed

New feature that will have 3rd param in #!defineMember ` so we can call

Structure: #!defineMember <name> simple_expression|(complex expression) <type?> Where:

Example:

#!defineMember tpToCenter (teleport(__this__, vect(0, 0, 0))) Player

Another example:

And if possible declaring params like virtual functions in #!defineMember or new preprocessor

macro keepOnPayload(Player, forceRespawn):
    if self.isDead() and forceRespawn:
        self.respawn()
    self.teleport(getPayloadPosition())

Notes

Where self is value to current 'injected' value. In this example self refer to player that invoked. self = eventPlayer for example.

So we can attach and call dynamic macro that will be translated as actions:

rule "respawn bot if needed":
    @Event eachPlayer
    @Condition eventPlayer.isDead()
    @Condition eventPlayer.isDummy()
    eventPlayer.keepOnPayload(true)
    wait(1)
    goto RULE_START
Zezombye commented 2 years ago

I forgot to reply but this is basically the AST macro thing I've had in my head for a while (I made a mistake following C's path, lul)

I think I will replace #!defineMember by "A.B", basically if the define name has a dot, assume the first member is the type and the second is the name.

The multi-line macros will use inline def, however I gotta think about the single-line macros, I thought about inline lambda somefunc(x): x+2 but it clashes with python's lambda syntax where the function name isn't specified. And for constants, inline const DEBUG_MODE = true.

nathan130200 commented 2 years ago

Thanks for reply, yeah i suggest for some complex macros that we must transfer variable name to invocation.

For example #!defineMember isPlayerValidForScoring(condition) eventPlayer.someVar == true we can use eventPlayer as usually but when i will invoke this macro on attacker/victim values will not work.

So for replacement we can transfer direct variable name #!defineMacro myFunc(param1, param2) this.param3 = [param1, param2] where this. is everything before . after invoke this macro.

So: eventPlayer.botEntity.myFunc(1, 2), this. will be translated as eventPlayer.botEntity

Or something similar to match with overpy syntax.

Also offtopic/non related to this suggestion is declare temporary variable names for for loop reserve an global/player variable called _opyForLoopIndexex when all non declared variables to for loop will automatically grab an index, then use While(...) and End; to peform an looping. Its like OSTW does but more simple