Preprocessor in CS?
by Max Kielland · in Torque Game Builder · 10/18/2009 (8:45 pm) · 17 replies
Hello,
I have been searching a while now to see if there is a preprocessor for CS.
It would be nice to be able to do stuff like...
or to create macros.
I have been searching a while now to see if there is a preprocessor for CS.
It would be nice to be able to do stuff like...
#define DEBUG 1
#if DEBUG == 1
echo("debug mode");
#endifor to create macros.
#define MAKE_NAME(f,s) f SPC s
$Name = MAKE_NAME("first","second");About the author
Owner of MK Development www.mkdevelopment.se
#2
10/18/2009 (9:04 pm)
Hey, I may have missed your point about preprocessing it -- if so sorry about that. The way I set it up there will NOT function in the way you'd like when precompiling, but it WILL run when the .cs file is exec'd (typically during loadup for most script files).
#3
This is not the same thing.
(I know the examples above are stupid nonsense, but to illustrate what I mean)
if DEBUG is 0 any code within
Is removed and not compiled at all.
A macro is more like an alias for something you don't want to write 100 times. By doing a function you will waste a lot of time on a function call, while a macro is expanded like an inline.
A macro also don't need to be a full functional expression.
So is there a preprocessor in CS?
10/18/2009 (9:10 pm)
[EDIT] You beat me while I was answering ;)This is not the same thing.
(I know the examples above are stupid nonsense, but to illustrate what I mean)
if DEBUG is 0 any code within
#if DEBUG == 1 ... #endif
Is removed and not compiled at all.
A macro is more like an alias for something you don't want to write 100 times. By doing a function you will waste a lot of time on a function call, while a macro is expanded like an inline.
A macro also don't need to be a full functional expression.
So is there a preprocessor in CS?
#4
Scripts are for game play functionality, if you need the same thing 100 times, I would consider writting a script or C function to do it instead.
10/18/2009 (9:50 pm)
No, there is no preprocessor in scripts.Scripts are for game play functionality, if you need the same thing 100 times, I would consider writting a script or C function to do it instead.
#5
Anyway, I got my answer, no preprocessor for scripts...
- Thanks guys...
10/18/2009 (9:58 pm)
100 times was just an example to clarify why a function call was not appropriate (Gee, you guys are really marking words) =)Anyway, I got my answer, no preprocessor for scripts...
- Thanks guys...
#6
10/18/2009 (10:19 pm)
I have to wonder, given the source code, and access to the precompiler... How hard would it be to add such behavior to the precompiling?
#7
10/19/2009 (12:31 am)
The c preprocessor is a standalone program. You could just run it on your .cs files before loading them into Torque.
#8
The problem is that the preprocessor's output must be captured by Torque instead of the original one. This can be messy because of the exec() statements looking for the "original" cs files.
Hmm, but maybe if we keep all original cs file in a separate folder and then have the preprocessor to "copy" them to the original folder before Torque "compiles" them.
10/19/2009 (1:48 pm)
That was my thought too before I started to look for a built in preprocessor.The problem is that the preprocessor's output must be captured by Torque instead of the original one. This can be messy because of the exec() statements looking for the "original" cs files.
Hmm, but maybe if we keep all original cs file in a separate folder and then have the preprocessor to "copy" them to the original folder before Torque "compiles" them.
#10
Really?!? I had no idea that the soul purpose of scripting languages was to get rid of the preprocessor?!? Ohh Gee thanks!!! LOL ;)
Seriously, I normally use it for a lot more than switching code in and out. I found it very useful and miss it in CS.
Maybe I will try one day to do it with an external but have to do without it for now...
Thanks guys for showing interest...
10/19/2009 (3:17 pm)
@RonnyReally?!? I had no idea that the soul purpose of scripting languages was to get rid of the preprocessor?!? Ohh Gee thanks!!! LOL ;)
Seriously, I normally use it for a lot more than switching code in and out. I found it very useful and miss it in CS.
Maybe I will try one day to do it with an external but have to do without it for now...
Thanks guys for showing interest...
#11
I agree with you, Max, especially for using it in a debug build. Or take, for example, building a sprite on the fly. I don't want to call a function for something as trivial as a "new t2dStaticSprite", but I don't like typing in the same things over and over again.
It's okay, though. I already enjoy a huge boost in productivity due to TorqueScript that not having a pre-processor doesn't bother me.
10/19/2009 (4:27 pm)
If this were part of the standard compiling process in the engine, I'd be all over this. But if there's another step, it becomes too much work.I agree with you, Max, especially for using it in a debug build. Or take, for example, building a sprite on the fly. I don't want to call a function for something as trivial as a "new t2dStaticSprite", but I don't like typing in the same things over and over again.
It's okay, though. I already enjoy a huge boost in productivity due to TorqueScript that not having a pre-processor doesn't bother me.
#12
10/19/2009 (5:05 pm)
If you want a preprocessor, that's really the domain of a natively compiled language. Scripting is supposed to be simple and straight-forward.
#13
I agree with you that it must be easy, no extra fuzz. If Torsion supported Pre- and Post- Build it might be possible to do something without having the extra trouble.
I remember back in the old days that Borland C++ v5.02 could be adjusted to almost anything. We created a complete Motorola 68040 development environment with native compilers, debuggers and tracers within Borlands IDE. Maybe I should try to find that old version again =)
10/19/2009 (6:46 pm)
@WilliamI agree with you that it must be easy, no extra fuzz. If Torsion supported Pre- and Post- Build it might be possible to do something without having the extra trouble.
I remember back in the old days that Borland C++ v5.02 could be adjusted to almost anything. We created a complete Motorola 68040 development environment with native compilers, debuggers and tracers within Borlands IDE. Maybe I should try to find that old version again =)
#14
In fact, I wouldn't mind pre- and post-build steps anyway so that I can have it reset the preferences or delete the application data directory.
10/19/2009 (7:32 pm)
Oooh! I didn't think of Torsion. I wonder if that developer is reading this forum.In fact, I wouldn't mind pre- and post-build steps anyway so that I can have it reset the preferences or delete the application data directory.
#15
Maybe worth to drop a suggestion over there ;)
(I actually, a while ago, submitted a preprocessor feature request to Torsion)
10/19/2009 (8:01 pm)
I have not found any pre- or post- build options in Torsion. I think there is a Torsion Forum over in Add-Ons where I have seen SickHeadGames ppl.Maybe worth to drop a suggestion over there ;)
(I actually, a while ago, submitted a preprocessor feature request to Torsion)
#16
I'll try to submit a resource soon
12/16/2010 (5:14 pm)
We have developed our own preprocessor system for TorqueScript (TGE1.4+ -> TGB -> T3D1.1B3 compatible). It works well, though without macros support.I'll try to submit a resource soon
Torque 3D Owner Tim Scheiman
Ghost Ship Studios
$DEBUG_MODE = 1; if($DEBUG_MODE) echo("debug mode on");function MAKE_NAME(%f,%s) { return(%f SPC %s); } $Name = MAKE_NAME("first","second");Works about the same, no?
-T