HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

meh?

02-19-2009, 03:07 PM#1
Vexorian
Another silly idea:

Collapse JASS:
struct aaaa 

    string msg
    method onTime takes nothing returns nothing
        call BJDebugMsg(this.msg)        
    endmethod

    method test1 takes nothing returns nothing
        set this.msg="=????"
        call TimerStart(NewTimer(), 1.00, true, method this.onTime)

    endmethod

    static method test2 takes nothing returns nothing
     local timer t=NewTimer()
     local aaaa  A = aaaa.create()

        set A.msg="/ / / / /"
        call TimerStart(t, 6.00, false, method A.onTime)

    endmethod


endstruct


Becomes into:
Collapse JASS:
function __SetTimerData takes timer t, integer x returns timer
     call SetTimerData(t,x)
     return t
endfunction

struct aaaa
    string msg
    method onTime takes nothing returns nothing
        call BJDebugMsg(this.msg)
    endmethod
    static method __onTime takes nothing returns nothing
     local aaaa this = GetTimerData(GetExpiredTimer())
        call BJDebugMsg(this.msg)
    endmethod

    method test1 takes nothing returns nothing
        set this.msg="=????"
        call TimerStart(__SetTimerData(NewTimer(),this), 1.00, true, function aaaa.__onTime)

    endmethod

    static method test2 takes nothing returns nothing
     local timer t=NewTimer()
     local aaaa  A = aaaa.create()

        set A.msg="/ / / / /"
        call SetTimerData(t, A)
        call TimerStart(t, 6.00, false, function aaaa.__onTime)

    endmethod

endstruct

02-19-2009, 06:18 PM#2
Anitarf
Sounds too specific, and requires a specific library. It's really not that hard to do local aaaa this=aaaa(GetTimerData(GetExpiredTimer())) at the start of a static method.
02-19-2009, 07:37 PM#3
xombie
Actually, Vex, wow. I really like this. Good stuff mang. +rep even though it means nothing to you haha. This makes it a little bit easier to unify method names so that it looks a little better.
02-19-2009, 07:40 PM#4
akolyt0r
ani is right there ...

only when you would have a more comprehensive idea to enable users to use nonstatic methods for all callbacks (additionally ForGroup and ForForce callbacks), it would be worth to implement such a feature ...but since there is no way to do this (as far i know) that will not happen.
02-19-2009, 07:56 PM#5
peq
I would use a similar syntax to f.evaluate() and f.execute().

Collapse JASS:
struct aaaa 

    string msg
    method onTime takes nothing returns nothing
        call BJDebugMsg(I2S(GetTimerData(GetExpiredTimer())) + " -- " + this.msg)        
    endmethod

    method test1 takes nothing returns nothing
        set this.msg="=????"
        call this.onTime.timed(1.00, false)
    endmethod

    static method test2 takes nothing returns nothing
     local aaaa  A = aaaa.create()
        set A.msg="/ / / / /"
        call a.onTime.timed(6.0, false)
    endmethod


endstruct

The Problem with the syntax you suggested is, that its very specific as Antiarf said and doesnt work where you expect it to work (Condition(method A.filter) or ForGroup(g, method A.enum)).

But the idea is very nice as we do not have to write static functions which do not behave static at all.
02-19-2009, 08:09 PM#6
Vexorian
Quote:
ani is right there ...

only when you would have a more comprehensive idea to enable users to use nonstatic methods for all callbacks (additionally ForGroup and ForForce callbacks), it would be worth to implement such a feature ...but since there is no way to do this (as far i know) that will not happen.

It is possible to make it work with ForGroup and ForForce, the problem is that I can't think of a good use whatsoever for that, you'll often want to pass a bunch of stuff not just this, unlike timers in which it is more intuitive.

Quote:
I would use a similar syntax to f.evaluate() and f.execute().
I thought of that but my idea was stupid (Overcomplicated to implement). It is better to just need timeout as argument and require the method to take nothing. Hmnn:

Collapse JASS:
struct aaaa 

    string msg
    method onTime takes nothing returns nothing
        call BJDebugMsg(I2S(GetTimerData(GetExpiredTimer())) + " -- " + this.msg)        
    endmethod

    method test1 takes nothing returns nothing
        set this.msg="=????"
        call this.onTime.timeOut(1.00)
    endmethod

    static method test2 takes nothing returns nothing
     local aaaa  A = aaaa.create()
        set A.msg="/ / / / /"
        call a.onTime.timeLoop(1.05) //The catch is , how to make the loop stop?
    endmethod


endstruct
Well , for some reason I like x.method better. Closures! Might as well make it work for groups, Conditions and triggers don't really need this unless you are using dynamic triggers and thus I hope nobody would even try to use them that way.

Quote:
Sounds too specific, and requires a specific library.
I can't think of a more saner way to do this than to require a TimerUtils interface.

Quote:
It's really not that hard to do local aaaa this=aaaa(GetTimerData(GetExpiredTimer())) at the start of a static method.
This is for the abstraction.
02-19-2009, 10:55 PM#7
Anitarf
Well, if it's for abstraction then NewTimer and ReleaseTimer should be automated completely. Maybe something like

Collapse JASS:
struct foo
    method bar takes nothing returns whatever
    endmethod

    static method create takes nothing returns foo
        local foo this = foo.allocate()
        call .bar.delayed(5.0)
        return this
    endmethod
endstruct
The .delayed keyword or whatever it would be called could then also be used on all static methods and function interfaces that take nothing, since it'd be the same as calling it on regular methods minus the attaching.

The only question is, could you do call .bar.delayed(5.0) from within the bar method, since that'd be a simple way to get it to loop?
02-19-2009, 11:06 PM#8
xombie
There is a .delayed keyword?
02-19-2009, 11:15 PM#9
Anitarf
No, I just made it up.
02-19-2009, 11:44 PM#10
xombie
I see.
02-20-2009, 11:30 AM#11
peq
Quote:
Originally Posted by Vexorian
It is possible to make it work with ForGroup and ForForce,
Collapse JASS:
        call a.onTime.timeLoop(1.05) //The catch is , how to make the loop stop?

Maybe a new pseudo-native to stop the loop

Collapse JASS:
call stopTimeLoop()
compiles to
Collapse JASS:
call PauseTimer(GetExpiredTimer())
call ReleaseTimer(GetExpiredTimer())

But often I use TT or something like that for periodic things, so maybe you should add an way to use methods with function interfaces so they could be used in systems like TT.