Comments are closed
cJass on the Google Code.
Our BugTracker (recommend to post bugreports and features request there).
Beta tester notes.
all times are GMT +03:00Latest posts
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 20 21 22 23 24 25 26 27
posted at 01/10/09 09:37weaaddar
This is not possible directly, but there is one way for now:
<div class="code"><b>define</b>
{
GetHashCode(T) = GetHashCode_##T
Real2Hash(v) = StringHash(R2S(v));
InitHasher(T,HashMethod) =
{
int GetHashCode(T)(T value)
{
return HashMethod;
}
}
}
InitHasher(real,Real2Hash(value))</div>
<div class="code"><b>define</b>
{
GetHashCode(T) = GetHashCode_##T
Real2Hash(v) = StringHash(R2S(v));
InitHasher(T,HashMethod) =
{
int GetHashCode(T)(T value)
{
return HashMethod;
}
}
}
InitHasher(real,Real2Hash(value))</div>
~VD
posted at 01/10/09 04:36Dark Dragon
Strange. This code works just fine:
<div class="code">#include "test.j"
<div class="code">#include "test.j"
integer test (handle x) {
return integer(x)
}</div>
whereas test.j contains
<div class="code">#guard TEST_J
return integer(x)
}</div>
whereas test.j contains
<div class="code">#guard TEST_J
define {
integer = integ ## er
integer(x) = GetHandleId(x)
}</div>
~VD
integer = integ ## er
integer(x) = GetHandleId(x)
}</div>
~VD
posted at 01/10/09 03:48Mooglefrooglian
Strange. I've just added this "Map Meta Data Library" to my test map and it compiles just fine. If it's not modified in any way, then it shouldn't cause errors. If it IS modified, then I should have a look at it, or I can do nothing to help you.
~VD
posted at 01/10/09 03:16Dark Dragon
Thanks, now I hope it's over for real.
@Mooglefrooglian:
I'll wait for your map tomorrow.
I'll wait for your map tomorrow.
~VD
posted at 01/10/09 03:14Mooglefrooglian
Send me your test map to EvilGreedyStalker@gmail.com and I'll see what's the matter tomorrow. I can say nothing from the mess you provided, I need original code =)
~VD
posted at 01/10/09 03:11Mooglefrooglian
Can you provide more code please? Just your <div class="code">
private constant string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-+= \\!@#$%^&*()/?>.<,;:'\"{}[]|`~"</div> works well.
private constant string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-+= \\!@#$%^&*()/?>.<,;:'\"{}[]|`~"</div> works well.
~VD
posted at 01/10/09 03:10Van Damm
posted at 01/10/09 03:00Dark Dragon
SOMENAME is any name you like, elegible to be a variable name (alphanumeric symbols or _ sign).
All predefined macros return values without quotes so you can easily do smth like
<div class="code">void fx () {
int i_##FUNCNAME = 0
}</div>
which will become
<div class="code">
function fx takes nothing returns nothing
local integer i_fx = 0
endfunction</div>
<div class="code">void fx () {
int i_##FUNCNAME = 0
}</div>
which will become
<div class="code">
function fx takes nothing returns nothing
local integer i_fx = 0
endfunction</div>
Anyways, to convert the predefined macro to string, there are two ways:
1. <span class="code">define stringize(x) = `x`</span> and use it with predefined macros like <span class="code">stringize(FUNCNAME)</span>
2. <div class="code">#include "cj_print.j"
void test() {
printf("%v",FUNCNAME)
<i>// you can use any other function from cj_print
// or even sprintf if you want to get a string</i>
}</div>
printf("%v",FUNCNAME)
<i>// you can use any other function from cj_print
// or even sprintf if you want to get a string</i>
}</div>
~VD
posted at 01/10/09 02:57Mooglefrooglian
Sorry, that's ADOLF's over-optimization. Please surround your return value with curly brackets for now (like this <span class="code">return ('A05B')</span>) it will work until ADOLF fixes the bug.
~VD
posted at 01/10/09 02:54Dark Dragon
posted at 01/10/09 02:48Mooglefrooglian
<span class="code">#error "text"</span> is for usage with conditional compilation like
<div class="code">define TEST = 1
<div class="code">define TEST = 1
#if TEST
...
#else
#error "Not implemented"
#endif</div>
It will stop compilation and show the message.
...
#else
#error "Not implemented"
#endif</div>
It will stop compilation and show the message.
<span class="code">#guard SOMENAME</span> is to be written at the beginning of external files, which you include. So then if you include them more than once, the parser will detect that and include only once. So this is our version of include guard or MSVC's #pragma once.
And you're correct about the FUNCNAME
~VD
posted at 01/10/09 02:37Dark Dragon
If you <span class="code">define smth = smthelse</span> at any point, it will affect the whole map code (if the define is not private).
Then the map code is parsed from the beginning: all occurrences of <span class="code">smth</span> are replaced to <span class="code">smthelse</span> until the parser meets <span class="code">setdef</span> directive (eg <span class="code">setdef smth = smthother</span>).
After this point, all occurrences of <span class="code">smth</span> will be replaced to <span class="code">smthother</span> until other <span class="code">setdef</span> or <span class="code">undef</span> occurs.
If then the parser meets <span class="code">undef smth</span>, after this directive all occurrences of <span class="code">smth</span> will be left as they are until there is other <span class="code">setdef</span> in the future =)
Then the map code is parsed from the beginning: all occurrences of <span class="code">smth</span> are replaced to <span class="code">smthelse</span> until the parser meets <span class="code">setdef</span> directive (eg <span class="code">setdef smth = smthother</span>).
After this point, all occurrences of <span class="code">smth</span> will be replaced to <span class="code">smthother</span> until other <span class="code">setdef</span> or <span class="code">undef</span> occurs.
If then the parser meets <span class="code">undef smth</span>, after this directive all occurrences of <span class="code">smth</span> will be left as they are until there is other <span class="code">setdef</span> in the future =)
So your code
<div class="code">void smth() {}
<div class="code">void smth() {}
define smth = blah
setdef smth = smth_else
setdef smth = smth_else
int smth = 0
undef smth
real smth = 0.</div>
will be translated to:
<div class="code">nothing blah() {}
integer smth_else = 0
real snth = 0.0</div>
~VD
undef smth
real smth = 0.</div>
will be translated to:
<div class="code">nothing blah() {}
integer smth_else = 0
real snth = 0.0</div>
~VD
posted at 01/10/09 02:26Dark Dragon
Your code won't work, I've described why in my reply to Mooglefrooglian's post. Please read it first =)
~VD
posted at 01/10/09 01:40Mooglefrooglian
posted at 01/10/09 00:58Mooglefrooglian
Sorry, I misunderstood you. You cannot place any functions before the globals block, so for now you have only one way of doing what you want - import custom common.j or blizzard.j into your map and write your hook function there.
The other way for now is to create a define, that overrides your hooked function to return null and then initialize the variables manually, but I think this is now exactly what you want.
Your request is rather non-typical and ADOLF said that he'll think on the way of making this possible.
Thanks,
~VD
~VD
posted at 30/09/09 22:43Dark Dragon
Yeah, that was long ago before we fixed define arguments. Now it's better to do like ADOLF said.
~VD
posted at 30/09/09 22:28ADOLF
for safe I recommend this:
<span class="code">define while (expr) = whilenot !(expr)</span>
~adic
posted at 30/09/09 21:30Dark Dragon
posted at 30/09/09 17:20Guest
OK, now I get what you're trying to do. <s>For now there is a small limitation with overloaded defines with no arguments, but it will be fixed in the future versions.</s>
Now (in 1.3.4.32) you can do so:
<div class="code">define {
UnitData = Unit##Data
UnitData(u) = Unit##Data(GetUnitUserData(u))
}
<div class="code">define {
UnitData = Unit##Data
UnitData(u) = Unit##Data(GetUnitUserData(u))
}
struct UnitData extends array {
inte ger ID = xxx
inte ger Type = xxx
...
...
}
inte ger ID = xxx
inte ger Type = xxx
...
...
}
nothing Test () {
UnitData = UnitData(GetTriggerUnit())
}</div>and it will work as expected.
UnitData = UnitData(GetTriggerUnit())
}</div>and it will work as expected.
~VD
posted at 30/09/09 16:17Guest
I see no reason in your defines. Can you explain, what you're trying to accomplish?
~VD
posted at 30/09/09 16:14Dark Dragon
posted at 30/09/09 07:52Mooglefrooglian
You can do it as soon as you also hook the one, used in GUI. It's <span class="code">CreateTimerBJ()</span>
~VD
posted at 30/09/09 04:05Dark Dragon
posted at 30/09/09 03:52Dark Dragon
<s>I'll now look into this</s>
Dunno what's the matter, but this is because of postfix increment. I'll tell ADOLF and this will be fixed.
Dunno what's the matter, but this is because of postfix increment. I'll tell ADOLF and this will be fixed.
~VD
<s>
<span class="code">whilenot !(this.qn-- > 0) { this.qi[this.qn] = null; this.in[this.qn] = null }</span>
<span class="code">whilenot !(this.qn-- > 0) { this.qi[this.qn] = null; this.in[this.qn] = null }</span>
works. hmm... where is my debugger?)
EDIT:
<span class="code">whilenot not(this.qn-- > 0) { this.qi[this.qn] = null; this.in[this.qn] = null }</span>
crash! omg
</s>
</s>
EDIT: fixed in 1.3.4.30 =)
~ADOLF