another try
[supertux.git] / tools / miniswig / create_wrapper.cpp
index e072b6f..53e5b28 100644 (file)
@@ -1,3 +1,5 @@
+#include <config.h>
+
 #include "tree.hpp"
 #include <iostream>
 #include <sstream>
@@ -257,7 +259,7 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function)
     if(function->type == Function::CONSTRUCTOR)
         function->name = "constructor";
 
-    out << "static int ";
+    out << "static SQInteger ";
     if(_class != 0) {
         out << _class->name << "_";
     }
@@ -284,8 +286,8 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function)
         if(function->type != Function::FUNCTION)
             throw std::runtime_error(
                     "custom not allow constructor+destructor yet");
-        if(function->return_type.atomic_type != &BasicType::INT)
-            throw std::runtime_error("custom function has to return int");
+        if(function->return_type.atomic_type != SQIntegerType::instance())
+            throw std::runtime_error("custom function has to return SQInteger");
         if(function->parameters.size() != 1)
             throw std::runtime_error(
                     "custom function must have 1 HSQUIRRELVM parameter");
@@ -342,7 +344,19 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function)
     for(size_t i = 0; i < function->parameters.size(); ++i) {
         if(i != 0)
             out << ", ";
-        out << "arg" << i;
+        const Parameter param = function->parameters[i];
+        if(param.type.ref == 0 && param.type.pointer == 0) {
+            if(param.type.atomic_type == &BasicType::INT)
+                out << "static_cast<int> (arg" << i << ")";
+            else if(param.type.atomic_type == &BasicType::FLOAT)
+                out << "static_cast<float> (arg" << i << ")";
+            else if(param.type.atomic_type == &BasicType::BOOL)
+                out << "arg" << i << " == SQTrue";
+            else
+                out << "arg" << i;
+        } else {
+            out << "arg" << i;
+        }
     }
     out << ");\n";
     if(function->type == Function::CONSTRUCTOR) {
@@ -393,13 +407,13 @@ WrapperCreator::prepare_argument(const Type& type, size_t index,
     if(type.pointer > 0)
         throw std::runtime_error("Pointers not handled yet");
     if(type.atomic_type == &BasicType::INT) {
-        out << ind << "int " << var << ";\n";
+        out << ind << "SQInteger " << var << ";\n";
         out << ind << "if(SQ_FAILED(sq_getinteger(vm, " << index << ", &" << var << "))) {\n";
         out << ind << ind << "sq_throwerror(vm, _SC(\"Argument " << (index-1) << " not an integer\"));\n";
         out << ind << ind << "return SQ_ERROR;\n";
         out << ind << "}\n";
     } else if(type.atomic_type == &BasicType::FLOAT) {
-        out << ind << "float " << var << ";\n";
+        out << ind << "SQFloat " << var << ";\n";
         out << ind << "if(SQ_FAILED(sq_getfloat(vm, " << index << ", &" << var << "))) {\n";
         out << ind << ind << "sq_throwerror(vm, _SC(\"Argument " << (index-1) << " not a float\"));\n";
         out << ind << ind << "return SQ_ERROR;\n";
@@ -411,7 +425,7 @@ WrapperCreator::prepare_argument(const Type& type, size_t index,
         out << ind << ind << "return SQ_ERROR;\n";
         out << ind << "}\n";
     } else if(type.atomic_type == StringType::instance()) {
-        out << ind << "const char* " << var << ";\n";
+        out << ind << "const SQChar* " << var << ";\n";
         out << ind << "if(SQ_FAILED(sq_getstring(vm, " << index << ", &" << var << "))) {\n";
         out << ind << ind << "sq_throwerror(vm, _SC(\"Argument " << (index-1) << " not a string\"));\n";
         out << ind << ind << "return SQ_ERROR;\n";
@@ -506,7 +520,7 @@ WrapperCreator::create_squirrel_instance(Class* _class)
 void
 WrapperCreator::create_class_release_hook(Class* _class)
 {
-    out << "static int " << _class->name << "_release_hook(SQUserPointer ptr, int )\n"
+    out << "static SQInteger " << _class->name << "_release_hook(SQUserPointer ptr, int )\n"
         << "{\n"
         << ind << ns_prefix << _class->name 
         << "* _this = reinterpret_cast<" << ns_prefix << _class->name