-->
<!--<?xml-stylesheet type="text/xsl" href="/home/ondra/src/docbook-xsl-1.68.1/xhtml/docbook.xsl" ?>-->
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V5.0/EN" "http://www.oasis-open.org/docbook/xml/5.0/docbook.dtd">
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
<article xml:lang="en">
-<artheader>
+<articleinfo>
<title>SuperTux Scripting Documentation</title>
<author><firstname>Ondra</firstname><surname>Hosek</surname></author>
-</artheader>
+</articleinfo>
<para>Since May 2005, SuperTux sports a Squirrel scripting interface useful for level designers who want to add some interactive pep to their levels. This document poses as a reference article for those who want to explore the various objects of the SuperTux scripting model.</para>
<sect1><title>What is Squirrel?</title>
-<para>One of your first questions might be, "What does a rodent have to do with a penguin?" <link xlink:href="http://squirrel.sourceforge.net/">Squirrel</link> is a language with a syntax not much unlike other C-like languages (C, C++, Java, ...). In the current implementation, it is integrated as elements in the SuperTux level files.</para>
+<para>One of your first questions might be, "What does a rodent have to do
+with a penguin?" <ulink url="http://squirrel.sourceforge.net/">Squirrel</ulink> is a language with a syntax not much unlike other C-like languages (C, C++, Java, ...). In the current implementation, it is integrated as elements in the SuperTux level files.</para>
</sect1>
<sect1><title>Squirrel, Scheme and SuperTux</title>
<para>I have no clue if the developers simply chose Squirrel just because the name so nicely integrates into the series of words "SuperTux" and "Scheme". Currently, the Squirrel code is integrated in string arguments of Scheme elements in SuperTux level files. (Whew.) This is an example code block inside a level:
/**
- * WARNING: This file is automatically generated from './build/i686-pc-linux-gnu/optimize/miniswig.tmp' - do not change
+ * WARNING: This file is automatically generated from:
+ * 'src/scripting/wrapper.interface.h'
+ * DO NOT CHANGE
*/
-
#include <config.h>
+
#include <new>
#include <assert.h>
#include <string>
/**
- * WARNING: This file is automatically generated from './build/i686-pc-linux-gnu/optimize/miniswig.tmp' - do not change
+ * WARNING: This file is automatically generated from:
+ * 'src/scripting/wrapper.interface.h'
+ * DO NOT CHANGE
*/
#ifndef __supertux_WRAPPER_H__
#define __supertux_WRAPPER_H__
void
WrapperCreator::create_wrapper(Namespace* ns)
{
+ std::string fromfile = original_file != "" ? original_file : inputfile;
+
// hpp file
hppout
<< "/**\n"
- << " * WARNING: This file is automatically generated from '"
- << inputfile << "' - do not change\n"
+ << " * WARNING: This file is automatically generated from:\n"
+ << " * '" << fromfile << "'\n"
+ << " * DO NOT CHANGE\n"
<< " */\n"
<< "#ifndef __" << modulename << "_WRAPPER_H__\n"
<< "#define __" << modulename << "_WRAPPER_H__\n"
// cpp header
out << "/**\n"
- << " * WARNING: This file is automatically generated from '"
- << inputfile << "' - do not change\n"
+ << " * WARNING: This file is automatically generated from:\n"
+ << " * '" << fromfile << "'\n"
+ << " * DO NOT CHANGE\n"
<< " */\n"
- << "\n"
<< "#include <config.h>\n"
+ << "\n"
<< "#include <new>\n"
<< "#include <assert.h>\n"
<< "#include <string>\n"
extern bool search_down;
extern Namespace* search_namespace;
extern Namespace* current_namespace;
+extern std::string last_docucomment;
+// the first file indicated by # 1 "..."
+// (this is what the C preprocessor outputs so that you know which was the
+// original file before preprocessing
+extern std::string original_file;
+// the filename where the current fragment came from (before it was included by
+// the preprocessor)
+extern std::string current_file;
+// get line number inside the current_file
+int getCurrentLine();
// config/output
extern std::istream* input;
%{
#include <math.h>
#include <stdlib.h>
+#include <string.h>
+#include <iostream>
#include "tree.h"
#include "parser.hpp"
#include "globals.h"
input->read(buf, max_size); \
result = input->gcount(); \
}
+
+std::string last_docucomment;
+std::string original_file;
+std::string current_file;
+int offset_lnum;
+
+int getCurrentLine()
+{
+ return yylineno - offset_lnum;
+}
%}
%%
+#[ \t]+[0-9]+[ \t]+.* {
+ int lnum;
+ char file[1024];
+ if(sscanf(yytext, "# %d \"%1023[^\"]\"", &lnum, file) == 2) {
+ offset_lnum = yylineno - lnum + 1;
+ current_file = file;
+ if(original_file == "")
+ original_file = file;
+ } else {
+ std::cerr << "Warning: Parse error in processor info directive.\n";
+ }
+}
#.* /* ignore preprocessor directives */
[[:space:]]+ /* eat spaces */
-\/\*.*\*\/ /* eat comment */
-\/\/[^\n]*\n /* eat comment */
+\/\*.*\*\/ {
+ if(yytext[2] == '*' && yytext[3] != '/') { // It's a docu comment...
+ last_docucomment = std::string(yytext+3, strlen(yytext)-5);
+ }
+}
+\/\/[^\n]*\n {
+ if(yytext[2] == '/') { // it's a docu comment...
+ last_docucomment = std::string(yytext+3, strlen(yytext)-4);
+ }
+}
class { return T_CLASS; }
struct { return T_STRUCT; }
static { return T_STATIC; }
std::cerr << "Couldn't open file '" << input << "' for reading.\n";
return 1;
}
+ current_file = inputfile;
unit = new CompilationUnit();
Namespace* std_namespace = new Namespace();
std_namespace->name = "std";
ParseError(const std::string& message) throw()
{
std::ostringstream msg;
- msg << "Parse error in line " << yylineno << ": "
+ msg << "Parse error in '" << current_file
+ << "' line " << getCurrentLine() << ": "
<< message;
this->message = msg.str();
}
current_class = new Class();
current_class->name = $2;
free($2);
+ current_class->docu_comment = last_docucomment;
+ last_docucomment = "";
current_visibility = ClassMember::PROTECTED;
}
class_body '}' ';'
{
currentFunction = new Function();
currentFunction->type = Function::CONSTRUCTOR;
+ currentFunction->docu_comment = last_docucomment;
+ last_docucomment = "";
free($1);
}
parameter_list ')' ';'
{
currentFunction = new Function();
currentFunction->type = Function::DESTRUCTOR;
+ currentFunction->docu_comment = last_docucomment;
+ last_docucomment = "";
free($3);
$$ = currentFunction;
}
delete $2;
currentFunction->name = $3;
free($3);
+ currentFunction->docu_comment = last_docucomment;
+ last_docucomment = "";
}
parameter_list ')' abstract_declaration ';'
{
DESTRUCTOR
};
FuncType type;
+ std::string docu_comment;
std::string name;
Type return_type;
std::vector<Parameter> parameters;
}
std::vector<ClassMember*> members;
+ std::string docu_comment;
};
class Namespace {