• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

execute_func

Status
Not open for further replies.
Level 13
Joined
Nov 7, 2014
Messages
571
execute_func - a simple alternative to vJass's function objects and a type safe ExecuteFunc(<function-name-string>) for escaping the oplimit

vJass allows you to call functions/methods with func.evaluate(<args>) and func.execute(<args>)

example:
JASS:
function expensive_function takes integer i returns integer
    local integer result = 21

    // a lot of work needs to be done here and there are
    set result = result + 1
    // many
    set result = result + 2
    // many
    // ....
    // many lines
    set result = result + 3

    return result
endfunction

function main takes nothing returns nothing
    // we don't want to hit the oplimit so we call .evaluate
    local integer i = expensive_function.evaluate(3000)
endfunction

The generated script by jasshelper could look like:
JASS:
globals
    //JASSHelper struct globals:
    trigger array st___prototype1
    integer f__result_integer
    integer f__arg_integer1
endglobals

function sc___prototype1_execute takes integer i,integer a1 returns nothing
    set f__arg_integer1=a1

    call TriggerExecute(st___prototype1[i])
endfunction
function sc___prototype1_evaluate takes integer i,integer a1 returns integer
    set f__arg_integer1=a1

    call TriggerEvaluate(st___prototype1[i])
 return f__result_integer
endfunction

function expensive_function takes integer i returns integer
    local integer result= 21

    // a lot of work needs to be done here
    // and there are
    set result=result + 1
    // many
    set result=result + 2
    // many
    // ....
    // many lines
    set result=result + 3

    return result
endfunction

function main takes nothing returns nothing
    // we don't want to hit the oplimit so we call .evaluate
    local integer i= sc___prototype1_evaluate(1,3000)

    call ExecuteFunc("jasshelper__initstructs32134833")
endfunction

//Struct method generated initializers/callers:
function sa___prototype1_expensive_function takes nothing returns boolean
 local integer i=f__arg_integer1

    local integer result= 21
    set result=result + 1
    set result=result + 2
    set result=result + 3
    set f__result_integer= result
    return true
endfunction

function jasshelper__initstructs32134833 takes nothing returns nothing
    set st___prototype1[1]=CreateTrigger()
    call TriggerAddAction(st___prototype1[1],function sa___prototype1_expensive_function)
    call TriggerAddCondition(st___prototype1[1],Condition(function sa___prototype1_expensive_function))
endfunction

So, some globals were added, 2 short functions were created and our function got copied
and a little bit modified so it all works correctly.
That's fine if we only had one function to .evaluate/.execute but if one is making
an average map (in terms of complexity) he would probably need to escape the oplimit
in a bit more places or use a library which would use .evaluate/.execute. And those generated
lines begin to add up.


What execute_func* allows, although less elegantly compared to .evaluate/.execute, is to call functions
that need to do a lot of work and could hit the oplimit.

The execute_func* "family" of functions work only with integers, reals and strings and only up to 3 parameters. (trying to avoid the combinatorial explosion...)

A simple naming convention is used:
JASS:
letter for type - type

i - integer
r - real
s - string
v - nothing (v for void, n could be confused for an iNteger)

When a function takes more than 1 parameter of the same type the letter of the type is
prepended with that count.

When a function doesn't take any parameters but returns an integer, real or a string the v letter is used in the
place of the parameters.

When a function returns nothing the v letter is not used, it's simply omitted.

Example usage:
JASS:
library executefuncDemo initializer init uses executefunc

function foo takes /*integer fooy*/ nothing returns nothing
    local integer fooy = ef_i1
    call BJDebugMsg("got foo: " + I2S(fooy))
endfunction

function pie takes nothing returns /*real*/ nothing
    set ef_ret_r = bj_PI + bj_E
endfunction

function repeat_string takes /*string s, integer count*/ nothing returns /*string*/ nothing
    local string s = ef_s1
    local integer count = ef_i1
    local string result = ""

    loop
        exitwhen count <= 0
        set result = result + s
        set count = count - 1
    endloop

    set ef_ret_s = result
endfunction

function init takes nothing returns nothing
    local real my_pie

    call execute_func_i(function foo, 5)

    // NOTE: even though our "made up" signature for repeat_string is
    // function repeat_string takes /*string s, integer count*/ nothing returns /*string*/ nothing
    // the order of the parameters of execute_func_* is fixed: i, r, s
    call BJDebugMsg(execute_func_is_s(function repeat_string, 10, "bar"))

    set my_pie = execute_func_v_r(function pie)
    call BJDebugMsg(R2S(my_pie))
endfunction

endlibrary

The execute_func module's code (although the library/module is called executefunc because vJass complains):
JASS:
library executefunc initializer execute_func_init

globals
    force ef_force = CreateForce()

    integer ef_i1 = 0
    integer ef_i2 = 0
    integer ef_i3 = 0
    integer ef_ret_i = 0

    real ef_r1 = 0
    real ef_r2 = 0
    real ef_r3 = 0
    real ef_ret_r = 0

    string ef_s1 = ""
    string ef_s2 = ""
    string ef_s3 = ""
    string ef_ret_s = ""
endglobals

// This should be safer than ExecuteFunc("<function-name>")
// because it doesn't take a string, which could have a typo and won't
// be caught by the compiler.
function execute_func takes code func returns nothing
    call ForForce(ef_force, func)
endfunction


// PARAMS COUNT: 0

// RETURN TYPE: integer

function execute_func_v_i takes code func returns integer
    call execute_func(func)
    return ef_ret_i
endfunction

// RETURN TYPE: real

function execute_func_v_r takes code func returns real
    call execute_func(func)
    return ef_ret_r
endfunction

// RETURN TYPE: string

function execute_func_v_s takes code func returns string
    call execute_func(func)
    return ef_ret_s
endfunction


// PARAMS COUNT: 1

// RETURN TYPE: nothing

function execute_func_i takes code func, integer i1 returns nothing
    set ef_i1 = i1
    call execute_func(func)
endfunction

function execute_func_r takes code func, real r1 returns nothing
    set ef_r1 = r1
    call execute_func(func)
endfunction

function execute_func_s takes code func, string s1 returns nothing
    set ef_s1 = s1
    call execute_func(func)
endfunction

// RETURN TYPE: integer

function execute_func_i_i takes code func, integer i1 returns integer
    set ef_i1 = i1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_r_i takes code func, real r1 returns integer
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_s_i takes code func, string s1 returns integer
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_i
endfunction

// RETURN TYPE: real

function execute_func_i_r takes code func, integer i1 returns real
    set ef_i1 = i1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_r_r takes code func, real r1 returns real
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_s_r takes code func, string s1 returns real
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_r
endfunction

// RETURN TYPE: string

function execute_func_i_s takes code func, integer i1 returns string
    set ef_i1 = i1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_r_s takes code func, real r1 returns string
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_s_s takes code func, string s1 returns string
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_s
endfunction


// PARAMS COUNT: 2

// RETURN TYPE: nothing

function execute_func_2i takes code func, integer i1, integer i2 returns nothing
    set ef_i1 = i1
    set ef_i2 = i2
    call execute_func(func)
endfunction

function execute_func_ir takes code func, integer i1, real r1 returns nothing
    set ef_i1 = i1
    set ef_r1 = r1
    call execute_func(func)
endfunction

function execute_func_is takes code func, integer i1, string s1 returns nothing
    set ef_i1 = i1
    set ef_s1 = s1
    call execute_func(func)
endfunction

function execute_func_2r takes code func, real r1, real r2 returns nothing
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
endfunction

function execute_func_rs takes code func, real r1, string s1 returns nothing
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
endfunction

function execute_func_2s takes code func, string s1, string s2 returns nothing
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
endfunction

// RETURN TYPE: integer

function execute_func_2i_i takes code func, integer i1, integer i2 returns integer
    set ef_i1 = i1
    set ef_i2 = i2
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_ir_i takes code func, integer i1, real r1 returns integer
    set ef_i1 = i1
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_is_i takes code func, integer i1, string s1 returns integer
    set ef_i1 = i1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_2r_i takes code func, real r1, real r2 returns integer
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_rs_i takes code func, real r1, string s1 returns integer
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_2s_i takes code func, string s1, string s2 returns integer
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_i
endfunction

// RETURN TYPE: real

function execute_func_2i_r takes code func, integer i1, integer i2 returns real
    set ef_i1 = i1
    set ef_i2 = i2
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_ir_r takes code func, integer i1, real r1 returns real
    set ef_i1 = i1
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_is_r takes code func, integer i1, string s1 returns real
    set ef_i1 = i1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_2r_r takes code func, real r1, real r2 returns real
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_rs_r takes code func, real r1, string s1 returns real
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_2s_r takes code func, string s1, string s2 returns real
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_r
endfunction

// RETURN TYPE: string

function execute_func_2i_s takes code func, integer i1, integer i2 returns string
    set ef_i1 = i1
    set ef_i2 = i2
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_ir_s takes code func, integer i1, real r1 returns string
    set ef_i1 = i1
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_is_s takes code func, integer i1, string s1 returns string
    set ef_i1 = i1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_2r_s takes code func, real r1, real r2 returns string
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_rs_s takes code func, real r1, string s1 returns string
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_2s_s takes code func, string s1, string s2 returns string
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_s
endfunction


// PARAMS COUNT: 3

// RETURN TYPE: nothing

function execute_func_3i takes code func, integer i1, integer i2, integer i3 returns nothing
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_i3 = i3
    call execute_func(func)
endfunction

function execute_func_2ir takes code func, integer i1, integer i2, real r1 returns nothing
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_r1 = r1
    call execute_func(func)
endfunction

function execute_func_2is takes code func, integer i1, integer i2, string s1 returns nothing
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_s1 = s1
    call execute_func(func)
endfunction

function execute_func_i2r takes code func, integer i1, real r1, real r2 returns nothing
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
endfunction

function execute_func_irs takes code func, integer i1, real r1, string s1 returns nothing
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
endfunction

function execute_func_i2s takes code func, integer i1, string s1, string s2 returns nothing
    set ef_i1 = i1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
endfunction

function execute_func_3r takes code func, real r1, real r2, real r3 returns nothing
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_r3 = r3
    call execute_func(func)
endfunction

function execute_func_2rs takes code func, real r1, real r2, string s1 returns nothing
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_s1 = s1
    call execute_func(func)
endfunction

function execute_func_r2s takes code func, real r1, string s1, string s2 returns nothing
    set ef_r1 = r1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
endfunction

function execute_func_3s takes code func, string s1, string s2, string s3 returns nothing
    set ef_s1 = s1
    set ef_s2 = s2
    set ef_s3 = s3
    call execute_func(func)
endfunction

// RETURN TYPE: integer

function execute_func_3i_i takes code func, integer i1, integer i2, integer i3 returns integer
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_i3 = i3
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_2ir_i takes code func, integer i1, integer i2, real r1 returns integer
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_2is_i takes code func, integer i1, integer i2, string s1 returns integer
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_i2r_i takes code func, integer i1, real r1, real r2 returns integer
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_irs_i takes code func, integer i1, real r1, string s1 returns integer
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_i2s_i takes code func, integer i1, string s1, string s2 returns integer
    set ef_i1 = i1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_3r_i takes code func, real r1, real r2, real r3 returns integer
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_r3 = r3
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_2rs_i takes code func, real r1, real r2, string s1 returns integer
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_r2s_i takes code func, real r1, string s1, string s2 returns integer
    set ef_r1 = r1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_i
endfunction

function execute_func_3s_i takes code func, string s1, string s2, string s3 returns integer
    set ef_s1 = s1
    set ef_s2 = s2
    set ef_s3 = s3
    call execute_func(func)
    return ef_ret_i
endfunction

// RETURN TYPE: real

function execute_func_3i_r takes code func, integer i1, integer i2, integer i3 returns real
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_i3 = i3
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_2ir_r takes code func, integer i1, integer i2, real r1 returns real
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_2is_r takes code func, integer i1, integer i2, string s1 returns real
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_i2r_r takes code func, integer i1, real r1, real r2 returns real
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_irs_r takes code func, integer i1, real r1, string s1 returns real
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_i2s_r takes code func, integer i1, string s1, string s2 returns real
    set ef_i1 = i1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_3r_r takes code func, real r1, real r2, real r3 returns real
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_r3 = r3
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_2rs_r takes code func, real r1, real r2, string s1 returns real
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_r2s_r takes code func, real r1, string s1, string s2 returns real
    set ef_r1 = r1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_r
endfunction

function execute_func_3s_r takes code func, string s1, string s2, string s3 returns real
    set ef_s1 = s1
    set ef_s2 = s2
    set ef_s3 = s3
    call execute_func(func)
    return ef_ret_r
endfunction

// RETURN TYPE: string

function execute_func_3i_s takes code func, integer i1, integer i2, integer i3 returns string
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_i3 = i3
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_2ir_s takes code func, integer i1, integer i2, real r1 returns string
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_r1 = r1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_2is_s takes code func, integer i1, integer i2, string s1 returns string
    set ef_i1 = i1
    set ef_i2 = i2
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_i2r_s takes code func, integer i1, real r1, real r2 returns string
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_r2 = r2
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_irs_s takes code func, integer i1, real r1, string s1 returns string
    set ef_i1 = i1
    set ef_r1 = r1
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_i2s_s takes code func, integer i1, string s1, string s2 returns string
    set ef_i1 = i1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_3r_s takes code func, real r1, real r2, real r3 returns string
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_r3 = r3
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_2rs_s takes code func, real r1, real r2, string s1 returns string
    set ef_r1 = r1
    set ef_r2 = r2
    set ef_s1 = s1
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_r2s_s takes code func, real r1, string s1, string s2 returns string
    set ef_r1 = r1
    set ef_s1 = s1
    set ef_s2 = s2
    call execute_func(func)
    return ef_ret_s
endfunction

function execute_func_3s_s takes code func, string s1, string s2, string s3 returns string
    set ef_s1 = s1
    set ef_s2 = s2
    set ef_s3 = s3
    call execute_func(func)
    return ef_ret_s
endfunction


function execute_func_init takes nothing returns nothing
    call ForceAddPlayer(ef_force, Player(15))
endfunction

endlibrary

And yes, that's a decent number of lines (~633), so if in your map you are using .evalute/.execute
only on a few functions and they are somewhat short, you should probably stick to .evalute/.execute instead.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
I guess not many people are aware that functions and methods in vJass have a .name field which
properly returns their name.

JASS:
private function Hi takes nothing returns nothing

endfunction

function ExecuteHi takes nothing returns nothing
    call ExecuteFunc(Hi.name)
endfunction

I think this library is not worth the effort. Also the amount of supported argument combinations
appear a bit random. I would rather hardcode it directly into my code or go with .evaluate / .execute

Triggers are also more performant than ExecuteFunc or ForForce.
I guess that's why Vexorian used them in the first place.

ExecuteFunc would allow TriggerSleepAction, while ForForce doesn't.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
I guess not many people are aware that functions and methods in vJass have a .name field which
properly returns their name.

JASS:
private function Hi takes nothing returns nothing

endfunction

function ExecuteHi takes nothing returns nothing
    call ExecuteFunc(Hi.name)
endfunction

This is an uncommonly-known feature of JassHelper, but does slaughter the need for this resource. Aside from that, ForForce(bj_FORCE_PLAYER[0], code) is already a perfectly-safe "ExecuteFunc" without even needing JassHelper tricks.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I guess not many people are aware that functions and methods in vJass have a .name field which
properly returns their name.

JASS:
private function Hi takes nothing returns nothing

endfunction

function ExecuteHi takes nothing returns nothing
    call ExecuteFunc(Hi.name)
endfunction

I had no clue about this either, but what's the point of using Hi.name?
Since you already wrote Hi you know the function name so what's the .name for?

The only reason I can think of would be something regarding the function name after compiling.
Since a function in a struct get some odd generated name, but that's not an issue if I recall since call function() gets compiled to call the renamed function automatically.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
I had no clue about this either, but what's the point of using Hi.name?
Since you already wrote Hi you know the function name so what's the .name for?
It should serve as code example for the .name field. That's all.

The .name field can be useful in scopes or for accessing the name of a private function.
JASS:
scope LessGood
    function MyFunc takes nothing returns nothing
    endfunction

    private function Func takes nothing returns nothing
        call ExecuteFunc("MyFunc")
    endfunction
endscope

scope MoreGood
    private function MyFunc takes nothing returns nothing
    endfunction

    private function Func takes nothing returns nothing
        call ExecuteFunc(MyFunc.name)
    endfunction
endscope
 
Level 9
Joined
Jun 21, 2012
Messages
432
This is an uncommonly-known feature of JassHelper, but does slaughter the need for this resource. Aside from that, ForForce(bj_FORCE_PLAYER[0], code) is already a perfectly-safe "ExecuteFunc" without even needing JassHelper tricks.

ForForce(bj_FORCE_PLAYER[0], code) This executes a function in another thread like that ExecuteFunc("func")? :cq:
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
ForForce(bj_FORCE_PLAYER[0], code) This executes a function in another thread like that ExecuteFunc("func")? :cq:

Not entirely the same. ExecuteFunc ignores precedence, allowing you to do odd things with your code unavailable without a JASS preparser such as vJass or manually programming triggers to point to parts of your code.

TriggerSleepAction only works with ExecuteFunc/TriggerExecute threads.
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
It should serve as code example for the .name field. That's all.

The .name field can be useful in scopes or for accessing the name of a private function.
JASS:
scope LessGood
    function MyFunc takes nothing returns nothing
    endfunction

    private function Func takes nothing returns nothing
        call ExecuteFunc("MyFunc")
    endfunction
endscope

scope MoreGood
    private function MyFunc takes nothing returns nothing
    endfunction

    private function Func takes nothing returns nothing
        call ExecuteFunc(MyFunc.name)
    endfunction
endscope

Performance-wise, it is better not to have long names in ExecuteFunc. Not sure if the Scope adds the prefix but if it does it is less good (I think you mean "worse" here).
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Is less good really incorrect english? I'm not a native speaker.
I thought that one can say for instance: "You achieved a less good result than him".

Yes the function name lenght matters in terms of speed.
On the other side it's irrelevant after using the map optimizer.
Ergo your assumption is partly wrong, at least for map makers.
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
Is less good really incorrect english? I'm not a native speaker.
I thought that one can say for instance: "You achieved a less good result than him".

Yes the function name lenght matters in terms of speed.
On the other side it's irrelevant after using the map optimizer.
Ergo your assumption is partly wrong, at least for map makers.

More Good: Better and More Bad: Worse. Also even if good and bad weren't exceptions, it woulda been Gooder and Badder, because they only have 1 syllable.

I'm not considering the map optimizer.
 
Even without optimizer: readability > speed.
I find it also silly to declare all variables with only one letter. (there are exceptions for sure, like "integer i" for loops)
We usually don't have to handle millions of actions in same operation thread and don't work on embedded systems where we need to care about each byte, so we should focus more on well written code than caring about each microoptimization.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I dont think this will work, this would require real ad hoc polymorphism supported inside the compiler rather than this, because it is very limiting, you do not support many many combinations(what if I want real, unit, unit?), and it is just massive copy pasta
 
Status
Not open for further replies.
Top