• 🏆 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!

[vJASS] Private isn't working as it should

Status
Not open for further replies.
Level 16
Joined
Mar 3, 2006
Messages
1,564
While I was learning some vJASS, I stumbled upon this strange thing:

this is what I typed in the trigger:

JASS:
scope human
private function f takes nothing returns nothing
endfunction
endscope

scope nightelf
private function f takes nothing returns nothing
endfunction
endscope

scope orcs
private function f takes nothing returns nothing
endfunction
endscope

scope undead
private function f takes nothing returns nothing
endfunction
endscope
and the generated script is:

JASS:
// scope human begins
function human___f takes nothing returns nothing
endfunction
// scope human ends

// scope nightelf begins
function nightelf___f takes nothing returns nothing
endfunction
// scope nightelf ends

// scope orcs begins
function orcs___f takes nothing returns nothing
endfunction
// scope orcs ends

// scope undead begins
function undead___f takes nothing returns nothing
endfunction
// scope undead endss
from what I understand private works by adding scopename(random digit)__ , now all I see is the scopename___ (3 underscores) why is that ?
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
the purpose of scopes and libraries mainly for encapsualtion/order of code's placement
and you can declare functions with the same name without colliding each other, as for
your question why there are underscores(2 or 3), well the Jasshelper answers it...
A double _ is used because we decided that it is the way to recognize preprocessor-generated variables/functions, so you should avoid to use double __ in your human-declarated identifier names. Being able to recognize preprocessor-generated identifiers is useful when reading the output file (for example when PJass returns syntax errors).
 
Level 7
Joined
Apr 30, 2011
Messages
359
you're wrong . . .

for library/scopes:
- they are capsules to place your codes
- private things inside it will have its name become LIBRARY_Name + SCOPE_PRIVATE + THING_Name
- public things inside it will have its name become LIBRARY_Name + "_" + THING_Name
- things with no private/public prefix will be counted as a public one, but here's the difference:
JASS:
library X
    public function Y takes nothing returns nothing
    endfunction
    
    function Z takes nothing returns nothing
    endfunction
endlibrary

library A requires X
    function XYZ takes nothing returns nothing
        // do nothing, but shows how those encapsulation works
        call X_Y() // public
        call Z() // non-public, and not private too
    endfunction
endlibrary
and it's not always "___" (3 underscores), but it can be 2 (if i heard it right)
to detect it, use SCOPE_PRIVATE
and logically, because it's a SCOPE_PRIVATE variable that's located on each encapsulations, the number of underscores for a library/scope is always the same, but can be different with other libraries/scopes
 
Level 16
Joined
Aug 7, 2009
Messages
1,403
By reading the JASSHelper manual you could have easily avoided opening another useless thread. http://www.wc3c.net/vexorian/jasshelpermanual.html#lib

The way private work is actually by automatically prefixing scopename(random digit)__ to the identifier names of the private members. The random digit is a way to let it be truly private so people can not even use them by adding the preffix themselves. A double _ is used because we decided that it is the way to recognize preprocessor-generated variables/functions, so you should avoid to use double __ in your human-declarated identifier names. Being able to recognize preprocessor-generated identifiers is useful when reading the output file (for example when PJass returns syntax errors).

Tis language was made for a game; it's evolved a lot already and it's way better than it used to be. It's not the compiler's task to protect the coder from himself.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
That is not an issue, since i hardly see why you would use the "jassified" code instead of the vJass one.
Get the fact that vJass is full of "hacks", while it's good to see how the jass code is generated behind the scene, you must not directly use this "hidden" jass code.

After all, vJass is "just" a jass preprocessor.
 
Level 7
Joined
Apr 30, 2011
Messages
359
its just an identifier anyway for the processor, for sure 95% of humans dont want to name their function like this...
function blah___hh takes...

worst thing:
JASS:
library ONE
    private scope TWO
        private function THREE takes nothing returns nothing
        endfunction
    endscope
endlibrary

// manual naming
function ONE___TWO___THREE takes nothing returns nothing
endfunction
 
Status
Not open for further replies.
Top