- // part1 of registration of the instance in the root table
- sq_pushroottable(v);
- sq_pushstring(v, name, -1);
-
- // resolve class name
- sq_pushroottable(v);
- sq_pushstring(v, type, -1);
- print_stack(v);
- if(sq_get(v, -2) < 0) {
- std::ostringstream msg;
- msg << "Couldn't resolve squirrel type '" << type << "'.";
- throw std::runtime_error(msg.str());
- }
- sq_remove(v, -2); // remove roottable
- print_stack(v);
-
- // create an instance and set pointer to c++ object
- print_stack(v);
- check(sq_createinstance(v, -1));
- printf("after creatinstance\n");
- print_stack(v);
- check(sq_setinstanceup(v, -1, object));
- printf("after setinstanceup\n");
- print_stack(v);
+ std::ostringstream msg;
+ msg << "SQuirrel error: " << message << " (";
+ const char* lasterr;
+ sq_getlasterror(v);
+ sq_getstring(v, -1, &lasterr);
+ sq_pop(v, 1);
+ msg << lasterr << ")";
+ this->message = msg.str();
+}