Added ExecuteChecked method for ScriptContextHandle

This commit is contained in:
yvt 2013-09-13 16:03:10 +09:00
parent 0e55445931
commit beec305bd9
2 changed files with 23 additions and 0 deletions

View File

@ -218,6 +218,26 @@ namespace spades {
return GetContext();
}
void ScriptContextHandle::ExecuteChecked() {
SPADES_MARK_FUNCTION();
asIScriptContext * ctx = GetContext();
int r = ctx->Execute();
manager->CheckError(r);
if(r == asEXECUTION_ABORTED) {
SPRaise("Script execution aborted.");
}else if(r == asEXECUTION_SUSPENDED) {
SPRaise("Script execution suspended."); // TODO: shouldn't raise error?
}else if(r == asEXECUTION_EXCEPTION) {
const char *secName = NULL;
int line = 0, column = 0;
asIScriptFunction *func = ctx->GetExceptionFunction();
// TODO: backtrace generation
line = ctx->GetExceptionLineNumber(&column, &secName);
SPRaise("%s @ [%s:%d,%d] %s", ctx->GetExceptionString(),
secName?secName:"(stub)", line, column,
func->GetDeclaration(true, true));
}
}
static std::map<std::string, ScriptObjectRegistrar *> * registrars = NULL;

View File

@ -75,6 +75,9 @@ namespace spades {
void operator =(const ScriptContextHandle&);
asIScriptContext *GetContext() const;
asIScriptContext *operator ->() const;
ScriptManager *GetManager() const { return manager; }
void ExecuteChecked();
};
class ScriptObjectRegistrar {