From: Ingo Ruhnke Date: Fri, 6 Mar 2009 00:03:39 +0000 (+0000) Subject: Added function argument type and count checking for functions exported to Squirrel X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7baf00e0fa05776566327eeb9628f8a2869e8479;p=supertux.git Added function argument type and count checking for functions exported to Squirrel SVN-Revision: 5844 --- diff --git a/tools/miniswig/create_wrapper.cpp b/tools/miniswig/create_wrapper.cpp index d574ea5f3..a31663166 100644 --- a/tools/miniswig/create_wrapper.cpp +++ b/tools/miniswig/create_wrapper.cpp @@ -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::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"; }