supports suspending functions
[supertux.git] / tools / miniswig / create_wrapper.cpp
index 2233f83..7adce5d 100644 (file)
@@ -1,23 +1,26 @@
-#include "tree.h"
+#include "tree.hpp"
 #include <iostream>
 #include <sstream>
 #include <stdexcept>
-#include "create_wrapper.h"
-#include "globals.h"
+#include "create_wrapper.hpp"
+#include "globals.hpp"
 
 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"
         << "\n"
-        << "#include \"wrapper_util.h\"\n"
+        << "#include \"wrapper_util.hpp\"\n"
         << "\n"
         << "extern WrappedFunction " << modulename << "_global_functions[];\n"
         << "extern WrappedClass " << modulename << "_classes[];\n"
@@ -27,17 +30,18 @@ WrapperCreator::create_wrapper(Namespace* ns)
     
     // 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"
         << "#include <squirrel.h>\n"
-        << "#include \"wrapper_util.h\"\n"
-        << "#include \"wrapper.interface.h\"\n"
+        << "#include \"wrapper_util.hpp\"\n"
+        << "#include \"wrapper.interface.hpp\"\n"
         << "\n";
     if(selected_namespace != "") {
         out << "using namespace " << selected_namespace << ";\n";
@@ -144,7 +148,7 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function)
             p != function->parameters.end(); ++p) {
         if(i == 0 && p->type.atomic_type == HSQUIRRELVMType::instance()) {
             out << ind << "HSQUIRRELVM arg0 = v;\n";
-            arg_offset++;
+            arg_offset--;
         } else {
             char argname[64];
             snprintf(argname, sizeof(argname), "arg%d", i);
@@ -188,7 +192,11 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function)
     out << ind << "\n";
     // push return value back on stack and return
     if(function->return_type.is_void()) {
-        out << ind << "return 0;\n";
+        if(function->docu_comment.find("@SUSPEND@") != std::string::npos) {
+          out << ind << "sq_suspendvm(v);\n";
+        } else {
+          out << ind << "return 0;\n";
+        }
     } else {
         push_to_stack(function->return_type, "return_value");
         out << ind << "return 1;\n";