Extending the TorqueScript syntax
by Sim Ops Studios (#0003) · in Torque Game Engine Advanced · 08/14/2007 (7:33 am) · 3 replies
Greetings!
We are attempting to extend the TorqueScript syntax to include a new optional parameter on the 'new' operator (denoting if the object should have a special identifier that we've implemented, or if it should use the standard ID-assignment system). To that end, we've been looking at the code in engine\console. We've tripped over the fact that the parser's core is compiled bison code, which isn't part of the default build process for the VC8 buildpath. We'd like to be able to re-compile this code, but we aren't sure quite how... The process outlined in this howto (http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1963) appears to be out-of-date, since the number of files and their contents doesn't seem to match up with what is described.
Does anyone know how to rebuild the parser? There is a bison.bat file in the engine\console directory, but the five arguments it takes are undocumented. Any advice on how to use that file (or how to simply re-build the bison content) would be very appreciated!
We are attempting to extend the TorqueScript syntax to include a new optional parameter on the 'new' operator (denoting if the object should have a special identifier that we've implemented, or if it should use the standard ID-assignment system). To that end, we've been looking at the code in engine\console. We've tripped over the fact that the parser's core is compiled bison code, which isn't part of the default build process for the VC8 buildpath. We'd like to be able to re-compile this code, but we aren't sure quite how... The process outlined in this howto (http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1963) appears to be out-of-date, since the number of files and their contents doesn't seem to match up with what is described.
Does anyone know how to rebuild the parser? There is a bison.bat file in the engine\console directory, but the five arguments it takes are undocumented. Any advice on how to use that file (or how to simply re-build the bison content) would be very appreciated!
About the author
#2
The SimObject class provides a function called ::processArguments(), which allows you to manage multiple/optional arguments provided within the TorqueScript new operator.
Examples of use can be found in TCPObject.
Keep in mind that by default, TorqueScript is going to use the first argument to name the object--arguments after the first are ignored by default, but re-implementing ::processArguments() for your class will allow you to send multiple arguments.
08/14/2007 (10:56 am)
However, you don't need to 'extend' TorqueScript for this...TorqueScript's new operator already does what you want.The SimObject class provides a function called ::processArguments(), which allows you to manage multiple/optional arguments provided within the TorqueScript new operator.
Examples of use can be found in TCPObject.
Keep in mind that by default, TorqueScript is going to use the first argument to name the object--arguments after the first are ignored by default, but re-implementing ::processArguments() for your class will allow you to send multiple arguments.
#3
The only difficulty with using the builtin constructor-argument system was that classes such as TCPObject are already making use of it; adding a new argument would mean giving values for all the previous arguments when we construct an object (instead of trusting to the default values), which we weren't sure we'd want to be doing. Perhaps if we're making parser changes, the better change would be Python-esque named arguments for the constructor? Then we can leverage the already-existent argument system (and remain compatible with the TorqueScript code already in place) but have our special argument also.
We appreciate the input!
08/14/2007 (11:28 am)
This is exactly what we were hoping for; thank you for the help!The only difficulty with using the builtin constructor-argument system was that classes such as TCPObject are already making use of it; adding a new argument would mean giving values for all the previous arguments when we construct an object (instead of trusting to the default values), which we weren't sure we'd want to be doing. Perhaps if we're making parser changes, the better change would be Python-esque named arguments for the constructor? Then we can leverage the already-existent argument system (and remain compatible with the TorqueScript code already in place) but have our special argument also.
We appreciate the input!
Torque Owner asmaloney (Andy)
Default Studio Name
2) create the following .bat file in TGEA/engine/console:
3) run the .bat file - this will create cmdgram.h, cmdgram.cpp, and CMDscan.cpp