/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


		#include "viewer_base/viewer_base_vmhook.h"
		#include "viewer_base/viewer_base.h"

		using namespace GS;
		using namespace GS::Script;


//------------------------------------------------------------------------------
void			ViewerEventHookTable::OnStep(char type, const char *source, int line, const char *funcname)
{}
void			ViewerEventHookTable::Kill(const char *reason)
{	viewer->DisplayUserMessage(ViewerBase::MessageWarning, String::Format("The script VM was killed:\n\n%s", reason));	}
void			ViewerEventHookTable::OnCompilerError(const char *error, const char *source, int line)
{	viewer->DisplayUserMessage(ViewerBase::MessageNormal, String::Format("Script compiler error.\n\nSource: %s\nLine: %d\n\n%s", source, line, error));	}
void			ViewerEventHookTable::OnRuntimeException(const char *error)
{
	String msg = String::Format("Script runtime exception:\n\n%s", error);

	AutoList <IVM::CallStackEntry *> callstack;
	viewer->project->vm->GetCallStack(callstack);

	msg += "\n\nCallstack:\n\n";
	ListForeachPtr(IVM::CallStackEntry *, cs, callstack)
		msg += String::Format("    - %s() (line %d) in \"%s\"\n", cs->function.c_str(), cs->line, cs->source.c_str());
	
	__LOG_E__ << "Squirrel Compiler Error: '" << msg << "'\n";

	viewer->DisplayUserMessage(ViewerBase::MessageNormal, msg);
}
//------------------------------------------------------------------------------
