#include or not #included?

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
echoism
GamingTools Subscriber
Posts: 11
Joined: Tue Jan 25, 2005 6:05 pm

#include or not #included?

Post by echoism » Mon Dec 19, 2005 11:56 pm

With lavishscript, is it possible to use preprocessor directives to determine if a file was included or ran directly?

I want to create scripts with conditional main() functions, such that main() would only get declared if the file was invoked directly as a script, as opposed to being included in another script.

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Tue Dec 20, 2005 2:16 am

Code: Select all

#if ${Script.Name.Equal[myfile.iss]}
function main()
{
}
#endif
If it doesnt work, let me know. :)

echoism
GamingTools Subscriber
Posts: 11
Joined: Tue Jan 25, 2005 6:05 pm

Post by echoism » Tue Dec 20, 2005 2:56 pm

That didn't work.
I created a script called test2include.iss

Code: Select all

#define TESTER ALL
#if ${TESTER.Equal[ALL]}
#echo TEST TRUE
#else
#echo TEST FALSE
#endif

#if ${Script.Name.Equal[test2include.iss]}
function main()
{
	echo Main Test TRUE
}
#else
function main()
{
	echo Main Test FALSE
}
#endif
Output was:

Code: Select all

C:\Program Files\InnerSpace\Scripts\test2include.iss(5): TEST FALSE
Main Test FALSE
It seems, that preprocessors wont use datatypes ( ${} ) at all. I also tried to #define a constant, and compare that to another #defined constant, but wasn't able to do that either. It seems to only do numeric comparison (which, doesn't surprise me).

What I'd like, is to have something like:

Code: Select all

#ifndef _INCLUDED_
function main()
...
#endif
But to my knowledge, there isn't a built-in define to do that. Or, is there? Documentation seemed sketchy.

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Tue Dec 20, 2005 6:49 pm

It seems, that preprocessors wont use datatypes ( ${} ) at all. I also tried to #define a constant, and compare that to another #defined constant, but wasn't able to do that either. It seems to only do numeric comparison (which, doesn't surprise me).
The preprocessor DOES in fact process data sequences. The part that didnt work was it wasnt actually in the scope of the Script at that particular time. I fixed this today in build 3353.

#if and such DO only do numeric comparisons, exactly the same way if, while, math.Calc, etc do it. But, you can use data sequences to compare strings too.

echoism
GamingTools Subscriber
Posts: 11
Joined: Tue Jan 25, 2005 6:05 pm

Post by echoism » Wed Dec 21, 2005 12:12 pm

Should I be able to use:
#echo ${Script.Name}

(or, is that, ${Script.Filename}?

When I do this, the preprocessor just echos ${Script.Name}, it doesn't seem to process the data sequence.

I'm running 3353, btw.

Post Reply