PDA

View Full Version : LScript: Platform preprocessor



Phil
12-17-2012, 07:58 AM
So, I'm a little puzzled here. If I do something like this :



@if (platform == MAC64)
@define mac 1
supportedplatform = 1;
@end
@if (platform == MACUB)
@define mac 1
supportedplatform = 1;
@end

@if (platform == WIN32)
@define win 1
supportedplatform = 1;
@end

@if (platform == WIN64)
@define win 1
supportedplatform = 1;
@end

@if (platform == INTEL)
@define win 1
supportedplatform = 1;
@end


and later check supportedplatform with something like this :



if (!supportedplatform)
error("Unsupported platform: " + platform().asStr());


I get the error displayed. This is very odd. Even if I put 'var ' before each variable definition, it fails. According to the limited documentation available, I would expect this to work.

Any ideas?

Matt
12-17-2012, 09:39 AM
supportedplatform is a global right?

Phil
12-17-2012, 09:56 AM
Example script that triggers this issue on all platforms I've checked so far (WIN32, WIN64, MACUB, MAC64)



@asyncspawn
@warnings
@script master
@name "Test Platform Example"

@if (platform == MAC64)
@define mac 1
var supportedplatform = 1;
@end
@if (platform == MACUB)
@define mac 1
var supportedplatform = 1;
@end

@if (platform == WIN32)
@define win 1
var supportedplatform = 1;
@end

@if (platform == WIN64)
@define win 1
var supportedplatform = 1;
@end

@if (platform == INTEL)
@define win 1
var supportedplatform = 1;
@end

create
{
}

destroy
{
}

options
{
if(!supportedplatform)
error("Not supported");
}


This code could be simplified if the preprocessor permits something like this, but there's no indication in the documentation that it does :



@if (platform == MACUB || platform == MAC64)


On the off-chance, I tried this, to see what happens. It also fails to define the 'check' variable, so I cannot determine if the combination conditional works.



@asyncspawn
@warnings
@script master
@name "Test Preprocessor"

@define A 1
@define B 1

@if (A == 1 && B == 0)
var check = "1_0";
@end
@if (A == 1 && B == 1)
var check = "1_1";
@end

@if (A == 0 && B ==1)
var check = "0_1";
@end

create
{
}

destroy
{
}

options
{
if(!check)
error("Not defined");
else
info(check);
}

sami
12-17-2012, 04:23 PM
I may be missing the point of your problem here - is it that var does not appear to work inside an @if? It doesn't work for me either on 11.03. But, I don't get the problem. This, below does work, and the reason the var doesn't work, I would guess, is because the @if acts like a different scope - this is not a php style include, but rather a different code block perhaps - so that vars declared in an @if seem only to be valid within that @if block. if, however, you use a global defined before your @if block, it does appear to set the value correctly. I can't think of a case where I'd need to create a var for a specific platform that I wouldn't care if it was unused for other platforms, but maybe you have a situation for that? Why not try it like this?



@asyncspawn
@warnings
@script master
@name "Test Platform Example"

var supportedplatform = -1;

@if platform == MAC64
supportedplatform = 1;
@end

@if platform == MACUB
supportedplatform = 2;
@end

@if platform == WIN32
supportedplatform = 3;
@end

@if platform == WIN64
supportedplatform = 4;
@end

@if platform == INTEL
supportedplatform = 5;
@end

create
{
}

destroy
{
}

options
{
info("supportedplatform = " + supportedplatform);
runtimePlatform = platform();
info("runtimePlatform = " + runtimePlatform + " : INTEL = true or false = " +(platform() == INTEL));
info("runtimePlatform = " + runtimePlatform + " : WIN32 = true or false = " +(platform() == WIN32));
info("runtimePlatform = " + runtimePlatform + " : WIN64 = true or false = " +(platform() == WIN64));
info("runtimePlatform = " + runtimePlatform + " : MACUB = true or false = " +(platform() == MACUB));
info("runtimePlatform = " + runtimePlatform + " : MAC64 = true or false = " +(platform() == MAC64));
}

Phil
12-17-2012, 04:39 PM
Oh, now that would be peculiar. I tended to think that, as a preprocessor, scope wouldn't apply. Strange. :D I'll give it a whirl :)

EDIT : Doesn't seem to help here. Odd.

sami
12-17-2012, 05:01 PM
I found the parenthesis were confusing the @if - so I tried it without and it appears that the && B== part gets thrown out entirely. In this case check = "0_1"



@asyncspawn
@warnings
@script master
@name "Test Platform Example"



@define A 0
@define B 0


var check = "X_X";

@if A == 0 && B == 0
check = "0_0";
@end

@if A == 1 && B == 1
check = "1_1";
@end

@if A == 0 && B == 1
check = "0_1";
@end

create
{
}

destroy
{
}


options
{
if(!check)
info("Not defined");
else
info(check);
}


However, you are right, something funky is going on. I tried this and it prints ABZeroZeroTest = 1 and check is still not defined. So even though the defines are working, there is something goofy about the @if 's either being processed before or perhaps just not allowing any expressions?



@asyncspawn
@warnings
@script master
@name "Test Platform Example"



@define A 0
@define B 0

@define ABZeroZeroTest (A == 0 && B == 0)
@define ABZeroOneTest (A == 0 && B == 1)
@define ABOneZeroTest (A == 1 && B == 0)
@define ABOneOneTest (A == 1 && B == 1)

var check;

@if ABZeroZeroTest == 1
check = "0_0";
@end

@if ABZeroOneTest == 1
check = "0_1";
@end

@if ABOneZeroTest == 1
check = "1_0";
@end

@if ABOneOneTest == 1
check = "1_1";
@end

create
{
}

destroy
{
}

options
{

info("ABZeroZeroTest = " + ABZeroZeroTest);
info("ABZeroOneTest = " + ABZeroOneTest);
info("ABOneZeroTest = " + ABOneZeroTest);
info("ABOneOneTest = " + ABOneOneTest);
if(!check)
info("check Not defined");
else
info("check = " + check);
}


- - - Updated - - -


Oh, now that would be peculiar. I tended to think that, as a preprocessor, scope wouldn't apply. Strange. :D I'll give it a whirl :)

EDIT : Doesn't seem to help here. Odd.

Sorry are you saying the code I posted in post #4 doesn't work for you? It works over here... hmmm? Also, I am entirely speculating about the @if scope thing, mainly becauase declaring a global outside the @if allowed the @if code to set the value.

Phil
12-17-2012, 05:36 PM
I pinged NT and got told that WIN32 and WIN64 were never defined for the preprocessor, and also that parentheses are not supported by the preprocessor.

I think that's where it's going wrong - I was expecting WIN32 and/or WIN64 to be available, just like they are under platform().

sami
12-17-2012, 09:53 PM
Good to know (I was going to ask where in the docs you've seen MACUB etc connected to platform), but sure, but it's not just that... My 2nd example in post #6 above shows that the defined expression doesn't work in the @if (I also tried a var'ed global in place of the define and that expression also didn't work). So that part is still a mystery to me..