• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Get pointer on functions?

Status
Not open for further replies.
Same we can't pass functions are arguments huh? besides ones that take nothing and return nothing, or only return boolean
Trigger evaluation pauses the current thread from being executed until the evaluation is done. You can use simple global variables to pass arguments, as long as there is only one TriggerCondition per trigger and no TriggerSleepActions.
 
I meant literal function objects, aka; a function variable type.
You can use the code object to pass a function. However, you can not have functions with arguments when doing this.
So no, it's not possible. But there's no real downside to using triggerconditions, as I can't think of a real reason why someone would need dynamic functions, so why care?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
JASS:
function GetCodeId takes code c returns integer
    return GetHandleId(Condition(c))
endfunction

under the condition you do not destroy boolexprs (unless they are created by And() or Or())

@Zwiebelchen: If you want to use native functions like ForGroup, TimerStart, ForForce and have a trigger instead of code parameter, you would need to redirect it.

There is one way to dynamically receive code, which is to generate a function

JASS:
function $funcName$_GetCode takes nothing returns nothing
    set GLOBAL_CODE_VAR = function $funcName$
endfunction

for each other function, wrap it in a trigger and store it, then execute the trigger when needed.
 
Level 14
Joined
Dec 12, 2012
Messages
1,007
JASS:
function GetCodeId takes code c returns integer
    return GetHandleId(Condition(c))
endfunction

Cool, that does work, thanks! But:

under the condition you do not destroy boolexprs (unless they are created by And() or Or())

What does that mean? That I can't destroy boolexprs when using this function? Why? And what has And() or Or() to do with this?
 
@Zwiebelchen: If you want to use native functions like ForGroup, TimerStart, ForForce and have a trigger instead of code parameter, you would need to redirect it.
Sure you would, but then you'd still not use dynamic functions.

Redirecting a static function via the code object works. I never said it doesn't. Just saying that you can not create an array of codes or return a code variable or execute it without using the trigger workaround or directly passing it to another operation with a code input parameter.
But then I also fail to see why you would ever need dynamic functions...
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
What does that mean? That I can't destroy boolexprs when using this function? Why? And what has And() or Or() to do with this?

Condition() creates a boolexpr object to a given function but if one already exists, it is returned, which is why the function above works. This also means destroying the boolexpr via DestroyBoolExpr() discards the id and the next Condition() call may result in another.

And() and Or() create a combination of two boolexprs and allocate a new object everytime. Since they are not recycled, of course you should destroy those.
 
Just use vjass's function interface. It basically does what you were suggested but is much more convenient.

Example :
JASS:
function interface UnitCode takes unit whichUnit returns nothing

function UnitCodeSample1 takes unit whichUnit returns nothing
    call KillUnit(whichUnit)
endfunction

function UnitCodeSample2 takes unit whichUnit returns nothing
    call RemoveUnit(whichUnit)
endfunction

function Execute takes UnitCode c, unit u returns nothing
    call c.evaluate(u)
endfunction

function Run takes nothing returns nothing
    call Execute(UnitCodeSample1, gg_unit_hfoo_666)
endfunction
 
Status
Not open for further replies.
Top