- out << ind << ns_prefix << _class->name << "* _this;\n";
- out << ind << "sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0);\n";
+ out << ind << "SQUserPointer data;\n";
+ out << ind << "if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) {\n";
+ out << ind << ind << "sq_throwerror(vm, _SC(\"'" << function->name << "' called without instance\"));\n";
+ out << ind << ind << "return SQ_ERROR;\n";
+ out << ind << "}\n";
+ out << ind << ns_prefix << _class->name << "* _this = reinterpret_cast<" << ns_prefix << _class->name << "*> (data);\n";
+ }
+
+ // custom function?
+ if(function->custom) {
+ 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 '" + function->name + "' has to return SQInteger");
+ if(function->parameters.size() != 1)
+ throw std::runtime_error(
+ "custom function '" + function->name + "' must have 1 HSQUIRRELVM parameter");
+
+ out << ind << "return ";
+ if(_class != 0)
+ out << "_this->";
+ else
+ out << ns_prefix;
+ out << function->name << "(vm);\n";
+ out << "}\n";
+ out << "\n";
+ return;