X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=tools%2Fminiswig%2Fcreate_wrapper.cpp;h=826a9aba88138a079fb8d92ce8a2f43aaa28283e;hb=2b318b2284a78ae34a6752a807c4eb7b5632299c;hp=29f35b2a18b1f0543e77f8dab0647fd18d57a193;hpb=4eff38d2a777e7a889428eadbef0d1eae7d35db0;p=supertux.git diff --git a/tools/miniswig/create_wrapper.cpp b/tools/miniswig/create_wrapper.cpp index 29f35b2a1..826a9aba8 100644 --- a/tools/miniswig/create_wrapper.cpp +++ b/tools/miniswig/create_wrapper.cpp @@ -1,11 +1,13 @@ #include #include "tree.hpp" +#include "create_wrapper.hpp" +#include "globals.hpp" + #include #include #include -#include "create_wrapper.hpp" -#include "globals.hpp" +#include void WrapperCreator::create_wrapper(Namespace* ns) @@ -24,14 +26,10 @@ WrapperCreator::create_wrapper(Namespace* ns) << " * '" << fromfile << "'\n" << " * DO NOT CHANGE\n" << " */\n" - << "#ifndef __" << modulename << "_WRAPPER_H__\n" - << "#define __" << modulename << "_WRAPPER_H__\n" + << "#ifndef HEADER_SUPERTUX_SCRIPTING_WRAPPER_HPP\n" //TODO avoid hardcoding + << "#define HEADER_SUPERTUX_SCRIPTING_WRAPPER_HPP\n" << "\n" - << "#include \n" - << "#include \"wrapper.interface.hpp\"\n" - << "\n" - << "namespace Scripting\n" - << "{\n" + << "namespace Scripting {\n" << "\n"; hppout << "void register_" << modulename << "_wrapper(HSQUIRRELVM v);\n" @@ -44,6 +42,7 @@ WrapperCreator::create_wrapper(Namespace* ns) if(_class == 0) continue; + hppout << "class " << _class->name << ";\n"; hppout << "void create_squirrel_instance(HSQUIRRELVM v, " << ns_prefix << _class->name << "* object, bool setup_releasehook = false);\n"; @@ -51,7 +50,9 @@ WrapperCreator::create_wrapper(Namespace* ns) hppout <<"\n" << "}\n" << "\n" - << "#endif\n"; + << "#endif\n" + << "\n" + << "/* EOF */\n"; // cpp header out << "/**\n" @@ -59,20 +60,14 @@ WrapperCreator::create_wrapper(Namespace* ns) << " * '" << fromfile << "'\n" << " * DO NOT CHANGE\n" << " */\n" - << "#include \n" << "\n" - << "#include \n" - << "#include \n" - << "#include \n" << "#include \n" - << "#include \n" - << "#include \"squirrel_error.hpp\"\n" - << "#include \"wrapper.interface.hpp\"\n" << "\n" - << "namespace Scripting\n" - << "{\n" - << "namespace Wrapper\n" - << "{\n" + << "#include \"scripting/squirrel_error.hpp\"\n" + << "#include \"scripting/wrapper.interface.hpp\"\n" + << "\n" + << "namespace Scripting {\n" + << "namespace Wrapper {\n" << "\n"; for(std::vector::iterator i = ns->types.begin(); @@ -108,7 +103,9 @@ WrapperCreator::create_wrapper(Namespace* ns) out << "}\n" << "\n" - << "} // end of namespace Scripting\n"; + << "} // end of namespace Scripting\n" + << "\n" + << "/* EOF */\n"; } void @@ -122,10 +119,12 @@ WrapperCreator::create_register_function_code(Function* function, Class* _class) << (_class != 0 ? _class->name + "_" : "") << function->name << "_wrapper, 0);\n"; - if(!function->custom) { + if(function->custom) { + out << ind << "sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, " << function->parameter_spec << ");\n"; + } else { out << ind << "sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, \""; - out << "x|t "; + out << "x|t"; if(!function->parameters.empty()) { @@ -133,20 +132,23 @@ WrapperCreator::create_register_function_code(Function* function, Class* _class) // Skip the first parameter since its a HSQUIRRELVM that is // handled internally - if (function->suspend) + if (function->suspend) { ++p; - + } else if (p->type.atomic_type == HSQUIRRELVMType::instance()) { + ++p; + } + for(; p != function->parameters.end(); ++p) { if(p->type.atomic_type == &BasicType::INT) { - out << "i "; + out << "i"; } else if(p->type.atomic_type == &BasicType::FLOAT) { - out << "f|i "; + out << "n"; } else if(p->type.atomic_type == &BasicType::BOOL) { - out << "b "; + out << "b"; } else if(p->type.atomic_type == StringType::instance()) { - out << "s "; + out << "s"; } else { - out << ". "; + out << "."; } } } @@ -313,14 +315,14 @@ WrapperCreator::create_function_wrapper(Class* _class, Function* function) // custom function? if(function->custom) { - if(function->type != Function::FUNCTION) + if(function->type != Function::FUNCTION) throw std::runtime_error( "custom not allow constructor+destructor yet"); if(function->return_type.atomic_type != SQIntegerType::instance()) - throw std::runtime_error("custom function has to return SQInteger"); + throw std::runtime_error("custom function '" + function->name + "' has to return SQInteger"); if(function->parameters.size() != 1) throw std::runtime_error( - "custom function must have 1 HSQUIRRELVM parameter"); + "custom function '" + function->name + "' must have 1 HSQUIRRELVM parameter"); out << ind << "return "; if(_class != 0)