|
|
#2641 | |
|
( ~)>
Respected User
Join Date: Feb 2005
Posts: 959
![]() ![]()
|
I was hoping for a second I would be able to do stuff like this:
__________________
But I guess the overhead is too much to get people to use it. It could allow some nice generators if it was inlined however. |
|
|
|
|
| Sponsored Links - Login to hide this ad! |
|
|
|
|
#2642 |
|
User
Join Date: Mar 2009
Posts: 1,079
![]()
|
Increasing numeric variables with $var++; syntax?
__________________I guess you won't at ZINC, because it is, as the name suggests, not c. |
|
|
|
|
|
#2643 | |
|
User
Join Date: Apr 2008
Posts: 189
|
Quote:
i see! i never thought that they will be so powerfull :) then implement it as u think is the best and ill be happy! Greets! ~DD |
|
|
|
|
|
|
#2644 |
|
User
Respected User
Join Date: Apr 2002
Posts: 2,372
|
Actually Vex,
I think in your example that you can do, you should do it in C# fashion and create basically a static variable x and assign it before usage. dream code below:: Zinc:int x = 0x10034; ForGroup(g, function() { if x < GetHandleId(GetEnumUnit()) BJDebugMsg("Less than x"))}; could translate to... JASS:globals integer AnonyFunc_0001_x endglobals function AnonyFunc_0001 takes nothing returns nothing if(AnonyFunc_0001_x < GetHandleId(GetEnumUnit()) then call BJDebugMsg("Less than x")); endif enfunction // in that caller local integer x = 5; set AnonyFunc_0001_x = x; call ForGroup(g, function AnonyFunc_0001) Last edited by weaaddar : 10-14-2009 at 03:16 AM. |
|
|
|
|
|
#2645 |
|
Free Software Terrorist
Technical Director
|
that only happens when the function is going to be called right away, that's only true for ForGroup mostly. For timers and triggers, it would involve attaching and a lot of incredibly annoying things. Would have to decide between allowing it for ForGroup and dissallowing it for the rest, or doing it for the whole deal and then turn the task incredibly complicated (yet still impossible when you want it for function interfaces or assigning code variables (or using local arrays)
__________________So, the question is, I either implement anonymous funcs as a way to implement functions in line without further usage of locals or things like that (I guess you would still be able to use private globals and static members) Or I just don't add anonymous functions. ForGroup with static locals could turn into another construct , reminds me of this: http://www.wc3c.net/showthread.php?t=100417&page=3 |
|
|
|
|
|
#2646 |
|
Free Software Terrorist
Technical Director
|
The closest thing to a correctly working multi-purpose anonymous function would be... an anonymous trigger.
__________________ Zinc:
integer x= 3,y=5,z=8;
trigger trig = trigger {
BJDebugMsg(I2S(x)+I2S(y)+I2S(z));
};
TriggerExecute(trig);
JASS:function trig000 takes nothing returns nothing local integer t__ = GetHandleId( GetTriggeringTrigger() ) call BJDebugMsg( I2S(LoadHashTableInt(ht, t__, 0 ) ) + I2S(LoadHashTableInt(ht, t__, 1 ))+I2S( LoadHashTableInt(ht, t__, 2 ) )); endfunction ... local integer x=3 local integer y=5 local integer z=8 local trigger trig = CreateTrigger() call TriggerAddAction(trig, function trig000) call SaveHashTableInt(ht, GetHandleId(trig), 0, x) call SaveHashTableInt(ht, GetHandleId(trig), 0, y) call SaveHashTableInt(ht, GetHandleId(trig), 0, z) |
|
|
|
|
|
#2647 |
|
User
Respected User
Join Date: Apr 2002
Posts: 2,372
|
Which is fine really. Anyway there is no guarantee that the value set by the anony func should be ported forward after all, you've just now compiled a call-by-value entity. I'll verify the c# behavior later. And please the calling method for integer is like SaveInteger...
DestroyTrigger is fine, provided you destroy the triggeraction as well. edit c# does forward port the value. [zinc] int x = 5; Func<int> f =(() => x = x - 1); Console.WriteLine(f()); Console.WriteLine(x); Console.Read(); [/jass] prints 4 newline 4. I suppose the Jass could be handled as such... Zinc:global integer Anony_Func_x; integer Anony_Func_RetVal; trigger Anony_Func_Trigger; triggeraction Anony_Func_TriggerAction; endglobals function Anony_Func_X takes nothing returns nothing set Anony_Func_x = Anony_Func_x-1 set Anony_Func_RetVal = Anony_Func_x endfunction //in the caller... local integer x = 5 set Anony_Func_X = x Anony_Func_Trigger = CreateTrigger() Anony_Func_TriggerAction = TriggerAddAction(trig, function Anony_Func_x) call ExecuteTrigger(Anony_Func_Trigger) set x = Anony_Func_x call DestroyTriggerAction(Anony_Func_TriggerAction) call DestroyTrigger(Anony_Func_Trigger) call BJDeubgMsg(I2S(Anony_Func_RetVal)) call BJDebugMsg(I2S(Anony_Func_x)) I do see a need for both Anonymous functions (for Forgroup/ForForce/Boolexprs and all other code takers that tend to be quiet trivial), and anonymous triggers. The ideal would be both to be implemented, but I can see how its tricky. Last edited by weaaddar : 10-14-2009 at 12:10 PM. |
|
|
|
|
|
#2648 |
|
Free Software Terrorist
Technical Director
|
I think I could just make it so if you use it a local inside an anonymous function it only works if you call it instantly... What I really like about the anonymous functions right now is to have a better code structure.
__________________The user would have to destroy the trigger, some how we'll also need a hook to recycle the stuff. So a type is kind of necessary. I really, really hate dynamic triggers ... Because I learned to distrust DestroyTrigger, the leak is one thing, but the fact that it can screw up the handle stack when you do not use it correctly (and lack of documentation means we'll never know we used it correctly...) Is very lame. Anonymous triggers' flexibility also bounds us to triggers and hashtables, where there are really much faster ways to do that stuff. So, how about I make anonymous functions, let use locals only when it is run right away, and be done with it? |
|
|
|
|
|
#2649 |
|
Free Software Terrorist
Technical Director
|
z.5
|
|
|
|
|
|
#2650 | ||
|
User
Join Date: Apr 2008
Posts: 189
|
Quote:
yeah i as well like that new code structure with anonymous functions! i just want em even if u dont allow locals in them! Quote:
i agree with this! ~DD Last edited by Dark_Dragon : 10-14-2009 at 03:24 PM. |
||
|
|
|
|
|
#2651 |
|
User
Join Date: Oct 2006
Posts: 1,490
|
thistype doesn't seem to be supported in static ifs :
JASS:struct S static constant boolean B = true method m1 takes nothing returns nothing static if S.B then // true call BJDebugMsg("true") else // false call BJDebugMsg("false") endif endmethod endstruct JASS:function s__S_m1 takes integer this returns nothing // true call BJDebugMsg("true") // true endfunction JASS:struct S static constant boolean B = true method m1 takes nothing returns nothing static if thistype.B then // true call BJDebugMsg("true") else // false call BJDebugMsg("false") endif endmethod endstruct JASS:function s__S_m1 takes integer this returns nothing // false call BJDebugMsg("false") // false endfunction Also, as you can see the 2 comments are not added but the right comment is still doubled after the end of the static if. Last edited by Troll-Brain : 10-14-2009 at 03:49 PM. |
|
|
|
|
|
#2652 | |
|
requires vJass
Code Moderator
|
Quote:
|
|
|
|
|
|
|
#2653 |
|
Free Software Terrorist
Technical Director
|
Troll-brain: Yes, that was expected. thistype support will get added later.
__________________ |
|
|
|
|
|
#2654 | |
|
User
Join Date: Oct 2006
Posts: 1,490
|
Quote:
|
|
|
|
|
|
|
#2655 |
|
Free Software Terrorist
Technical Director
|
I can say it is not caused by the static if phase, but something that happens later, will take a look when there's more time.
__________________ |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
|
Donate |