• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] compiled name of function inside module

Level 17
Joined
Mar 21, 2011
Messages
1,604
Hello guys, weird question:

JASS:
struct st extends array
    static method foo takes nothing returns nothing
        call BJDebugMsg("foo")
    endmethod
    implement mo
endstruct

module mo
    static method foo2 takes nothing returns nothing
        call BJDebugMsg("foo2")
    endmethod
endmodule

How do i call foo2 with
JASS:
native ExecuteFunc takes string funcName returns nothing

You can call foo with the following string:
JASS:
call ExecuteFunc("s__st_foo")

however, you cannot call foo2 this way. The compiler says the function is called "s__st_mo__foo", but that does not work.
Anyone knows what's going on here? The function has to have some name. Thanks!
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,223
You can try looking it up in the resulting JASS script. As long as it is not considered private it should be reachable by the generated name. Private functions will purposely be re-named when trying to reference them by name.

As Pyrogasm suggested, I recommend to try and use the high level syntax to refer to and manipulate functions/methods rather than trying to use their machine generated actual name.
 
Level 17
Joined
Mar 21, 2011
Messages
1,604
Is there some reason you can’t use .execute() or .evaluate() here? I think this is a use case for the string constants SCOPE_PREFIX and SCOPE_PRIVATE if you must use ExecuteFunc.
I created my own foreach function for my LinkedList and didn't come up with a better solution 😅
JASS:
        method foreach takes string functionName returns nothing
            local Node node = this.root
            loop
                exitwhen node == 0
                set EnumListElement = node.value
                call ExecuteFunc(functionName)
                set node = node.next
            endloop
        endmethod

You can try looking it up in the resulting JASS script. As long as it is not considered private it should be reachable by the generated name. Private functions will purposely be re-named when trying to reference them by name.

As Pyrogasm suggested, I recommend to try and use the high level syntax to refer to and manipulate functions/methods rather than trying to use their machine generated actual name.
You were right, when setting the function public, its name changes to "s__st_foo" instead of "s__st_mo__foo" and is reachable through ExecuteFunc().
I still wonder why it works for a private function inside a struct, NOT a module.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,223
I still wonder why it works for a private function inside a struct, NOT a module.
Reading the manual might shed some light. But otherwise it is likely due to some assumption vJASS makes, or that the private name space protection system accidently misses your use case allowing it through.
 
Top