Added function argument type and count checking for functions exported to Squirrel
authorIngo Ruhnke <grumbel@gmx.de>
Fri, 6 Mar 2009 00:03:39 +0000 (00:03 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Fri, 6 Mar 2009 00:03:39 +0000 (00:03 +0000)
SVN-Revision: 5844

tools/miniswig/create_wrapper.cpp

index d574ea5..a316631 100644 (file)
@@ -121,6 +121,38 @@ WrapperCreator::create_register_function_code(Function* function, Class* _class)
     out << ind << "sq_newclosure(v, &"
         << (_class != 0 ? _class->name + "_" : "") << function->name
         << "_wrapper, 0);\n";
+
+    if(!function->custom) {
+      out << ind << "sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, \"";
+
+      out << "x|t ";
+
+      if(!function->parameters.empty())
+        {
+          std::vector<Parameter>::iterator p = function->parameters.begin();
+          
+          // Skip the first parameter since its a HSQUIRRELVM that is
+          // handled internally
+          if (function->suspend)
+            ++p;
+          
+          for(; p != function->parameters.end(); ++p) {
+            if(p->type.atomic_type == &BasicType::INT) {
+              out << "i ";
+            } else if(p->type.atomic_type == &BasicType::FLOAT) {
+              out << "f|i ";
+            } else if(p->type.atomic_type == &BasicType::BOOL) {
+              out << "b ";
+            } else if(p->type.atomic_type == StringType::instance()) {
+              out << "s ";
+            } else {
+              out << ". ";
+            }
+          }
+      }
+      out << "\");\n";
+    }
+
     create_register_slot_code("function", function->name);
     out << "\n";
 }