[Scummvm-git-logs] scummvm master -> bf099a6ae76c6eade09367238d97c72728abe4ac

grisenti noreply at scummvm.org
Mon Jan 9 20:58:17 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
bf099a6ae7 HPL1: replace logging for script engine


Commit: bf099a6ae76c6eade09367238d97c72728abe4ac
    https://github.com/scummvm/scummvm/commit/bf099a6ae76c6eade09367238d97c72728abe4ac
Author: grisenti (emanuele at grisenti.net)
Date: 2023-01-09T21:58:05+01:00

Commit Message:
HPL1: replace logging for script engine

Changed paths:
    engines/hpl1/engine/impl/SqScript.cpp
    engines/hpl1/engine/impl/SqScript.h
    engines/hpl1/engine/system/low_level_system.cpp
    engines/hpl1/engine/system/low_level_system.h


diff --git a/engines/hpl1/engine/impl/SqScript.cpp b/engines/hpl1/engine/impl/SqScript.cpp
index 15b33b7cb23..488826202a4 100644
--- a/engines/hpl1/engine/impl/SqScript.cpp
+++ b/engines/hpl1/engine/impl/SqScript.cpp
@@ -42,11 +42,9 @@ namespace hpl {
 
 //-----------------------------------------------------------------------
 
-cSqScript::cSqScript(const tString &asName, asIScriptEngine *apScriptEngine,
-					 cScriptOutput *apScriptOutput, int alHandle)
+cSqScript::cSqScript(const tString &asName, asIScriptEngine *apScriptEngine, int alHandle)
 	: iScript(asName) {
 	mpScriptEngine = apScriptEngine;
-	mpScriptOutput = apScriptOutput;
 	mlHandle = alHandle;
 
 	mpContext = mpScriptEngine->CreateContext();
@@ -85,16 +83,10 @@ bool cSqScript::CreateFromFile(const tString &asFileName) {
 	}
 
 	if (_module->Build() < 0) {
-		Error("Couldn't build script '%s'!\n", asFileName.c_str());
-		Log("------- SCRIPT OUTPUT BEGIN --------------------------\n");
-		mpScriptOutput->Display();
-		mpScriptOutput->Clear();
-		Log("------- SCRIPT OUTPUT END ----------------------------\n");
-
+		Hpl1::logError(Hpl1::kDebugSaves, "Couldn't build script '%s'!\n", asFileName.c_str());
 		hplDeleteArray(pCharBuffer);
 		return false;
 	}
-	mpScriptOutput->Clear();
 
 	hplDeleteArray(pCharBuffer);
 	return true;
@@ -152,45 +144,4 @@ char *cSqScript::LoadCharBuffer(const tString &asFileName, int &alLength) {
 	return pBuffer;
 }
 
-//-----------------------------------------------------------------------
-
-//////////////////////////////////////////////////////////////////////////
-// STATIC PRIVATE METHODS
-//////////////////////////////////////////////////////////////////////////
-
-//-----------------------------------------------------------------------
-
-//-----------------------------------------------------------------------
-
-void cScriptOutput::AddMessage(const asSMessageInfo *msg) {
-	char sMess[1024];
-
-	tString type = "ERR ";
-	if (msg->type == asMSGTYPE_WARNING)
-		type = "WARN";
-	else if (msg->type == asMSGTYPE_INFORMATION)
-		type = "INFO";
-
-	snprintf(sMess, 1024, "%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type.c_str(), msg->message);
-
-	msMessage += sMess;
-}
-
-void cScriptOutput::Display() {
-	if (msMessage.size() > 500) {
-		while (msMessage.size() > 500) {
-			tString sSub = msMessage.substr(0, 500);
-			msMessage = msMessage.substr(500);
-			Log(sSub.c_str());
-		}
-		Log(msMessage.c_str());
-	} else {
-		Log(msMessage.c_str());
-	}
-}
-
-void cScriptOutput::Clear() {
-	msMessage = "";
-}
-
 } // namespace hpl
diff --git a/engines/hpl1/engine/impl/SqScript.h b/engines/hpl1/engine/impl/SqScript.h
index fcffdfb5100..5608a43dcea 100644
--- a/engines/hpl1/engine/impl/SqScript.h
+++ b/engines/hpl1/engine/impl/SqScript.h
@@ -33,24 +33,9 @@
 
 namespace hpl {
 
-class cScriptOutput // : public  asIOutputStream
-{
-public:
-	cScriptOutput() : msMessage("") {}
-	~cScriptOutput() {}
-
-	void AddMessage(const asSMessageInfo *msg);
-	void Display();
-	void Clear();
-
-private:
-	tString msMessage;
-};
-
 class cSqScript : public iScript {
 public:
-	cSqScript(const tString &asName, asIScriptEngine *apScriptEngine,
-			  cScriptOutput *apScriptOutput, int alHandle);
+	cSqScript(const tString &asName, asIScriptEngine *apScriptEngine, int alHandle);
 	~cSqScript();
 
 	bool CreateFromFile(const tString &asFileName);
@@ -64,7 +49,6 @@ public:
 private:
 	asIScriptEngine *mpScriptEngine;
 	asIScriptModule *_module;
-	cScriptOutput *mpScriptOutput;
 
 	asIScriptContext *mpContext;
 
diff --git a/engines/hpl1/engine/system/low_level_system.cpp b/engines/hpl1/engine/system/low_level_system.cpp
index 2d8cc61bd8c..fa1300ecedb 100644
--- a/engines/hpl1/engine/system/low_level_system.cpp
+++ b/engines/hpl1/engine/system/low_level_system.cpp
@@ -32,11 +32,23 @@
 
 namespace hpl {
 
+static void scriptEngineLog(const asSMessageInfo *msg) {
+	switch (msg->type) {
+		case asMSGTYPE_ERROR:
+			Hpl1::logError(Hpl1::kDebugScripts, "%s (%d, %d) : %s\n", msg->section, msg->row, msg->col, msg->message);
+			break;
+		case asMSGTYPE_WARNING:
+			Hpl1::logWarning(Hpl1::kDebugScripts, "%s (%d, %d) : %s\n", msg->section, msg->row, msg->col, msg->message);
+			break;
+		case asMSGTYPE_INFORMATION:
+			Hpl1::logInfo(Hpl1::kDebugScripts, "%s (%d, %d) : %s\n", msg->section, msg->row, msg->col, msg->message);
+	}
+}
+
 LowLevelSystem::LowLevelSystem() {
 	_scriptEngine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
 	RegisterScriptArray(_scriptEngine, true);
-	_scriptOutput = hplNew(cScriptOutput, ());
-	_scriptEngine->SetMessageCallback(asMETHOD(cScriptOutput, AddMessage), _scriptOutput, asCALL_THISCALL);
+	_scriptEngine->SetMessageCallback(asFunctionPtr(scriptEngineLog), nullptr, asCALL_CDECL);
 	RegisterStdString(_scriptEngine);
 	_handleCount = 0;
 }
@@ -44,10 +56,7 @@ LowLevelSystem::LowLevelSystem() {
 LowLevelSystem::~LowLevelSystem() {
 	/*Release all runnings contexts */
 	cleanupRegisteredString();
-	_scriptOutput->Display();
 	_scriptEngine->Release();
-	hplDelete(_scriptOutput);
-
 	// perhaps not the best thing to skip :)
 	// if(gpLogWriter)	hplDelete(gpLogWriter);
 	// gpLogWriter = NULL;
@@ -372,14 +381,13 @@ cDate LowLevelSystem::getDate() {
 }
 
 iScript *LowLevelSystem::createScript(const tString &name) {
-	return hplNew(cSqScript, (name, _scriptEngine, _scriptOutput, _handleCount++));
+	return hplNew(cSqScript, (name, _scriptEngine, _handleCount++));
 }
 
 bool LowLevelSystem::addScriptFunc(const tString &funcDecl, asGENFUNC_t pFunc, int callConv) {
 	if (_scriptEngine->RegisterGlobalFunction(funcDecl.c_str(),
 											  asFUNCTION(pFunc), callConv) < 0) {
-		Error("Couldn't add func '%s'\n", funcDecl.c_str());
-		_scriptOutput->Display();
+		Hpl1::logError(Hpl1::kDebugScripts, "Couldn't add script function '%s'\n", funcDecl.c_str());
 		return false;
 	}
 
diff --git a/engines/hpl1/engine/system/low_level_system.h b/engines/hpl1/engine/system/low_level_system.h
index 52d37b05a36..afcad39aed3 100644
--- a/engines/hpl1/engine/system/low_level_system.h
+++ b/engines/hpl1/engine/system/low_level_system.h
@@ -92,8 +92,6 @@ extern void SetWindowCaption(const tString &name);
 
 extern unsigned long GetApplicationTime();
 
-class cScriptOutput;
-
 class LowLevelSystem {
 public:
 	LowLevelSystem();
@@ -139,7 +137,6 @@ public:
 	void sleep(const unsigned int millisecs);
 private:
 	asIScriptEngine *_scriptEngine;
-	cScriptOutput *_scriptOutput;
 	int _handleCount;
 };
 




More information about the Scummvm-git-logs mailing list