{
std::string fromfile = original_file != "" ? original_file : inputfile;
+ if(selected_namespace != "") {
+ ns_prefix = selected_namespace;
+ ns_prefix += "::";
+ }
+
// hpp file
hppout
<< "/**\n"
<< "#define __" << modulename << "_WRAPPER_H__\n"
<< "\n"
<< "#include <squirrel.h>\n"
+ << "#include \"wrapper.interface.hpp\"\n"
+ << "\n"
+ << "namespace SquirrelWrapper\n"
+ << "{\n"
<< "\n";
- if(selected_namespace != "") {
- hppout << "namespace " << selected_namespace << "\n"
- << "{\n";
- }
- for(std::vector<AtomicType*>::iterator i = ns->types.begin();
- i != ns->types.end(); ++i) {
- AtomicType* type = *i;
- Class* _class = dynamic_cast<Class*> (type);
- if(_class == 0)
- continue;
- hppout << "class " << _class->name << ";\n";
- }
-
- if(selected_namespace != "") {
- hppout << "}\n";
- }
-
- hppout << "\n"
- << "namespace SquirrelWrapper\n"
- << "{\n"
- << "\n";
-
- if(selected_namespace != "") {
- hppout << "using namespace " << selected_namespace << ";\n"
- << "\n";
- }
-
hppout << "void register_" << modulename << "_wrapper(HSQUIRRELVM v);\n"
<< "\n";
continue;
hppout << "void create_squirrel_instance(HSQUIRRELVM v, "
- << _class->name
+ << ns_prefix << _class->name
<< "* object, bool setup_releasehook = false);\n";
}
hppout <<"\n"
<< "{\n"
<< "\n";
- if(selected_namespace != "") {
- out << "using namespace " << selected_namespace << ";\n";
- out << "\n";
- }
-
for(std::vector<AtomicType*>::iterator i = ns->types.begin();
i != ns->types.end(); ++i) {
AtomicType* type = *i;
}
out << ind << "\n";
// push return value back on stack and return
- if(function->return_type.is_void()) {
- if(function->docu_comment.find("@SUSPEND@") != std::string::npos) {
- out << ind << "return sq_suspendvm(v);\n";
- } else {
- out << ind << "return 0;\n";
+ if(function->suspend) {
+ if(!function->return_type.is_void()) {
+ std::stringstream msg;
+ msg << "Function '" << function->name << "' declared as suspend"
+ << " but has a return value.";
+ throw std::runtime_error(msg.str());
}
+ out << ind << "return sq_suspendvm(v);\n";
+ } else if(function->return_type.is_void()) {
+ out << ind << "return 0;\n";
} else {
push_to_stack(function->return_type, "return_value");
out << ind << "return 1;\n";
WrapperCreator::create_squirrel_instance(Class* _class)
{
out << "void create_squirrel_instance(HSQUIRRELVM v, "
- << _class->name
+ << ns_prefix << _class->name
<< "* object, bool setup_releasehook)\n"
<< "{\n"
<< ind << "sq_pushstring(v, \"" << _class->name << "\", -1);\n"
<< "object of type '" << _class->name << "'\";\n"
<< ind << ind << "throw SquirrelError(v, msg.str());\n"
<< ind << "}\n"
+ << ind << "sq_remove(v, -2);\n"
<< "\n"
<< ind << "if(setup_releasehook) {\n"
<< ind << ind << "sq_setreleasehook(v, -1, "
{
out << "static int " << _class->name << "_release_hook(SQUserPointer ptr, int )\n"
<< "{\n"
- << ind << _class->name
- << "* _this = reinterpret_cast<" << _class->name << "*> (ptr);\n"
+ << ind << ns_prefix << _class->name
+ << "* _this = reinterpret_cast<" << ns_prefix << _class->name
+ << "*> (ptr);\n"
<< ind << "delete _this;\n"
<< ind << "return 0;\n"
<< "}\n"