OpenTTDDevBlackBook/NoAI/Adding a squirrel function

From OpenTTD
(Difference between revisions)
Jump to: navigation, search
(new page written)
 
(added regression test writing and execution)
Line 1: Line 1:
 
=Adding a squirrel function=
 
=Adding a squirrel function=
To add a new C++ function to Squirrel, add the function declaration to one of the classes in ''src/ai/api/ai_*.hpp''.
+
To make a new C++ function available to the Squirrel code of the NoAI framework, do
Also add an implementation in the ''.cpp'' file.
+
* Implement the function
To make Squirrel aware of the new function, generate a new Squirrel interface file with ''squirrel_export.sh''. Call that script from within the ''src/ai/api'' directory.
+
** Add the function declaration to one of the classes in ''src/ai/api/ai_*.hpp'',
 +
** Also add an implementation in the ''.cpp'' file,
 +
** To make Squirrel aware of the new function, generate a new Squirrel interface file with ''squirrel_export.sh''. Call that script from within the ''src/ai/api'' directory.
 +
* Recompile OpenTTD in the usual way to make the new function available to the NoAI framework.
 +
* Write test-cases for the new function in ''bin/ai/regression''.
 +
** In ''regression.nut'', add Squirrel code that tests your new function, and outputs results.
 +
** In ''regression.txt'', add the new expected output.
 +
* Run the regression test by executing ''bin/ai/regression/run.sh'' from the ''bin'' directory. When differences are found, they will be displayed.
  
Then recompile OpenTTD in the usual way to include the new function available to the NoAI framework.
+
When all works as expected, you can write some Squirrel code to enjoy using your new function.
 
+
Finally, write some Squirrel code to use your new function.
+

Revision as of 16:16, 29 July 2010

Adding a squirrel function

To make a new C++ function available to the Squirrel code of the NoAI framework, do

  • Implement the function
    • Add the function declaration to one of the classes in src/ai/api/ai_*.hpp,
    • Also add an implementation in the .cpp file,
    • To make Squirrel aware of the new function, generate a new Squirrel interface file with squirrel_export.sh. Call that script from within the src/ai/api directory.
  • Recompile OpenTTD in the usual way to make the new function available to the NoAI framework.
  • Write test-cases for the new function in bin/ai/regression.
    • In regression.nut, add Squirrel code that tests your new function, and outputs results.
    • In regression.txt, add the new expected output.
  • Run the regression test by executing bin/ai/regression/run.sh from the bin directory. When differences are found, they will be displayed.

When all works as expected, you can write some Squirrel code to enjoy using your new function.

Personal tools