[Scummvm-cvs-logs] scummvm master -> bf4dc80419b12bb2415d42ee413162bf56019288

fingolfin max at quendi.de
Mon Mar 21 14:48:21 CET 2011


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

Summary:
458ebbafd2 HUGO: Split Utils::Box -> new funcs Utils::yesNoBox and Utils::promptBox
dd88f39bc7 HUGO: Replace Utils::Box by Utils::notifyBox + Common::String::format
bf4dc80419 SWORD25: Reduce code duplication; formatting


Commit: 458ebbafd25d729da88eced603a88af9a05b79b3
    https://github.com/scummvm/scummvm/commit/458ebbafd25d729da88eced603a88af9a05b79b3
Author: Max Horn (max at quendi.de)
Date: 2011-03-21T04:53:50-07:00

Commit Message:
HUGO: Split Utils::Box -> new funcs Utils::yesNoBox and Utils::promptBox

This also fixes a bug in the kBoxPrompt code (it returned a pointer to
the content of a temporary string object).

Changed paths:
    engines/hugo/hugo.h
    engines/hugo/parser.cpp
    engines/hugo/parser_v1d.cpp
    engines/hugo/parser_v1w.cpp
    engines/hugo/parser_v2d.cpp
    engines/hugo/parser_v3d.cpp
    engines/hugo/schedule.cpp
    engines/hugo/util.cpp
    engines/hugo/util.h



diff --git a/engines/hugo/hugo.h b/engines/hugo/hugo.h
index a137df7..a6a939f 100644
--- a/engines/hugo/hugo.h
+++ b/engines/hugo/hugo.h
@@ -134,7 +134,7 @@ enum HugoRegistered {
 /**
  * Ways to dismiss a text/prompt box
  */
-enum box_t {kBoxAny, kBoxOk, kBoxPrompt, kBoxYesNo};
+enum box_t {kBoxAny, kBoxOk};
 
 /**
  * Inventory icon bar states
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index a0a3ee3..685cbc0 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -288,7 +288,7 @@ void Parser::keyHandler(Common::Event event) {
 			_vm->_file->restoreGame(-1);
 			break;
 		case Common::KEYCODE_n:
-			if (Utils::Box(kBoxYesNo, "%s", "Are you sure you want to start a new game?") != 0)
+			if (Utils::yesNoBox("Are you sure you want to start a new game?"))
 				_vm->_file->restoreGame(0);
 			break;
 		case Common::KEYCODE_s:
diff --git a/engines/hugo/parser_v1d.cpp b/engines/hugo/parser_v1d.cpp
index df3a73f..36b56a6 100644
--- a/engines/hugo/parser_v1d.cpp
+++ b/engines/hugo/parser_v1d.cpp
@@ -364,7 +364,7 @@ void Parser_v1d::lineHandler() {
 	}
 
 	if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) {
-		if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0)
+		if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d)))
 			_vm->endGame();
 		return;
 	}
diff --git a/engines/hugo/parser_v1w.cpp b/engines/hugo/parser_v1w.cpp
index d342427..3490c43 100644
--- a/engines/hugo/parser_v1w.cpp
+++ b/engines/hugo/parser_v1w.cpp
@@ -119,7 +119,7 @@ void Parser_v1w::lineHandler() {
 	// Special meta commands
 	// EXIT/QUIT
 	if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) {
-		if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0)
+		if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d)))
 			_vm->endGame();
 		return;
 	}
diff --git a/engines/hugo/parser_v2d.cpp b/engines/hugo/parser_v2d.cpp
index d19b8b1..50d2e5f 100644
--- a/engines/hugo/parser_v2d.cpp
+++ b/engines/hugo/parser_v2d.cpp
@@ -114,7 +114,7 @@ void Parser_v2d::lineHandler() {
 	}
 
 	if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) {
-		if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0)
+		if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d)))
 			_vm->endGame();
 		return;
 	}
diff --git a/engines/hugo/parser_v3d.cpp b/engines/hugo/parser_v3d.cpp
index fcd9378..88ff980 100644
--- a/engines/hugo/parser_v3d.cpp
+++ b/engines/hugo/parser_v3d.cpp
@@ -116,7 +116,7 @@ void Parser_v3d::lineHandler() {
 	// Special meta commands
 	// EXIT/QUIT
 	if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) {
-		if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0)
+		if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d)))
 			_vm->endGame();
 		return;
 	}
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index 1556f3a..48427c2 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -1379,7 +1379,7 @@ event_t *Scheduler::doAction(event_t *curEvent) {
 		Utils::Box(kBoxAny, TAKE_TEXT, _vm->_text->getNoun(_vm->_object->_objects[action->a42.objIndex].nounIndex, TAKE_NAME));
 		break;
 	case YESNO:                                     // act43: Prompt user for Yes or No
-		if (Utils::Box(kBoxYesNo, "%s", _vm->_file->fetchString(action->a43.promptIndex)) != 0)
+		if (Utils::yesNoBox(_vm->_file->fetchString(action->a43.promptIndex)))
 			insertActionList(action->a43.actYesIndex);
 		else
 			insertActionList(action->a43.actNoIndex);
@@ -1529,7 +1529,7 @@ void Scheduler_v1d::runScheduler() {
 }
 
 void Scheduler_v1d::promptAction(act *action) {
-	Utils::Box(kBoxPrompt, "%s", _vm->_file->fetchString(action->a3.promptIndex));
+	Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex));
 
 	warning("STUB: doAction(act3)");
 	// TODO: The answer of the player is not handled currently! Once it'll be read in the messageBox, uncomment this block
@@ -1578,7 +1578,7 @@ const char *Scheduler_v2d::getCypher() const {
 }
 
 void Scheduler_v2d::promptAction(act *action) {
-	Utils::Box(kBoxPrompt, "%s", _vm->_file->fetchString(action->a3.promptIndex));
+	Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex));
 	warning("STUB: doAction(act3), expecting answer %s", _vm->_file->fetchString(action->a3.responsePtr[0]));
 
 	// TODO: The answer of the player is not handled currently! Once it'll be read in the messageBox, uncomment this block
diff --git a/engines/hugo/util.cpp b/engines/hugo/util.cpp
index f36c431..88a3be8 100644
--- a/engines/hugo/util.cpp
+++ b/engines/hugo/util.cpp
@@ -41,10 +41,17 @@
 
 namespace Hugo {
 
+namespace Utils {
+
+enum {
+	kMaxStrLength = 1024
+};
+
+
 /**
  * Returns index (0 to 7) of first 1 in supplied byte, or 8 if not found
  */
-int Utils::firstBit(byte data) {
+int firstBit(byte data) {
 	if (!data)
 		return 8;
 
@@ -60,7 +67,7 @@ int Utils::firstBit(byte data) {
 /**
  * Returns index (0 to 7) of last 1 in supplied byte, or 8 if not found
  */
-int Utils::lastBit(byte data) {
+int lastBit(byte data) {
 	if (!data)
 		return 8;
 
@@ -76,7 +83,7 @@ int Utils::lastBit(byte data) {
 /**
  * Reverse the bit order in supplied byte
  */
-void Utils::reverseByte(byte *data) {
+void reverseByte(byte *data) {
 	byte maskIn = 0x80;
 	byte maskOut = 0x01;
 	byte result = 0;
@@ -89,18 +96,18 @@ void Utils::reverseByte(byte *data) {
 	*data = result;
 }
 
-const char *Utils::Box(box_t dismiss, const char *s, ...) {
+void Box(box_t dismiss, const char *s, ...) {
 	static char buffer[kMaxStrLength + 1];          // Format text into this
 
 	if (!s)
-		return 0;                                   // NULL strings catered for
+		return;                                   // NULL strings catered for
 
 	if (s[0] == '\0')
-		return 0;
+		return;
 
 	if (strlen(s) > kMaxStrLength - 100) {          // Test length
 		warning("String too long: '%s'", s);
-		return 0;
+		return;
 	}
 
 	va_list marker;
@@ -109,7 +116,7 @@ const char *Utils::Box(box_t dismiss, const char *s, ...) {
 	va_end(marker);
 
 	if (buffer[0] == '\0')
-		return 0;
+		return;
 
 	switch(dismiss) {
 	case kBoxAny:
@@ -118,29 +125,30 @@ const char *Utils::Box(box_t dismiss, const char *s, ...) {
 		dialog.runModal();
 		break;
 		}
-	case kBoxYesNo: {
-		GUI::MessageDialog dialog(buffer, "YES", "NO");
-		if (dialog.runModal() == GUI::kMessageOK)
-			return buffer;
-		return 0;
-		break;
-		}
-	case kBoxPrompt: {
-		EntryDialog dialog(buffer, "OK", "");
-		Common::String result = dialog.getEditString();
-
-		return result.c_str();
-
-		break;
-		}
 	default:
 		error("Unknown BOX Type %d", dismiss);
 	}
 
-	return 0;
+	return;
+}
+
+Common::String promptBox(const char *msg) {
+	if (!msg || !*msg)
+		return 0;
+
+	EntryDialog dialog(msg, "OK", "");
+	return dialog.getEditString();
 }
 
-char *Utils::strlwr(char *buffer) {
+bool yesNoBox(const char *msg) {
+	if (!msg || !*msg)
+		return 0;
+
+	GUI::MessageDialog dialog(msg, "YES", "NO");
+	return (dialog.runModal() == GUI::kMessageOK);
+}
+
+char *strlwr(char *buffer) {
 	char *result = buffer;
 
 	while (*buffer != '\0') {
@@ -152,4 +160,6 @@ char *Utils::strlwr(char *buffer) {
 	return result;
 }
 
+} // End of namespace Utils
+
 } // End of namespace Hugo
diff --git a/engines/hugo/util.h b/engines/hugo/util.h
index acead5a..12ec58f 100644
--- a/engines/hugo/util.h
+++ b/engines/hugo/util.h
@@ -40,16 +40,18 @@ enum seqTextUtil {
 };
 
 namespace Utils {
-static const int kMaxStrLength = 1024;
 
 int   firstBit(byte data);
 int   lastBit(byte data);
 
 void  reverseByte(byte *data);
 
-const char *Box(box_t, const char *, ...) GCC_PRINTF(2, 3);
+void Box(box_t, const char *, ...) GCC_PRINTF(2, 3);
+Common::String promptBox(const char *msg);
+bool yesNoBox(const char *msg);
 char *strlwr(char *buffer);
-}
+
+} // End of namespace Utils
 
 } // End of namespace Hugo
 


Commit: dd88f39bc7078f96fd06170260bf2ff332b4ca82
    https://github.com/scummvm/scummvm/commit/dd88f39bc7078f96fd06170260bf2ff332b4ca82
Author: Max Horn (max at quendi.de)
Date: 2011-03-21T05:16:35-07:00

Commit Message:
HUGO: Replace Utils::Box by Utils::notifyBox + Common::String::format

Changed paths:
    engines/hugo/display.cpp
    engines/hugo/file.cpp
    engines/hugo/file_v1d.cpp
    engines/hugo/file_v2w.cpp
    engines/hugo/hugo.cpp
    engines/hugo/hugo.h
    engines/hugo/intro.cpp
    engines/hugo/mouse.cpp
    engines/hugo/object.cpp
    engines/hugo/parser.cpp
    engines/hugo/parser_v1d.cpp
    engines/hugo/parser_v1w.cpp
    engines/hugo/parser_v2d.cpp
    engines/hugo/parser_v3d.cpp
    engines/hugo/schedule.cpp
    engines/hugo/util.cpp
    engines/hugo/util.h



diff --git a/engines/hugo/display.cpp b/engines/hugo/display.cpp
index aa4d438..333eb59 100644
--- a/engines/hugo/display.cpp
+++ b/engines/hugo/display.cpp
@@ -479,7 +479,7 @@ void Screen::shadowStr(int16 sx, const int16 sy, const char *s, const byte color
  * present in the DOS versions
  */
 void Screen::userHelp() const {
-	Utils::Box(kBoxAny , "%s",
+	Utils::notifyBox(
 	           "F1  - Press F1 again\n"
 	           "      for instructions\n"
 	           "F2  - Sound on/off\n"
diff --git a/engines/hugo/file.cpp b/engines/hugo/file.cpp
index 94e1756..f4eada4 100644
--- a/engines/hugo/file.cpp
+++ b/engines/hugo/file.cpp
@@ -550,7 +550,7 @@ void FileManager::printBootText() {
 			buf[i] ^= cypher[i % strlen(cypher)];
 
 		buf[i] = '\0';
-		Utils::Box(kBoxOk, "%s", buf);
+		Utils::notifyBox(buf);
 	}
 
 	free(buf);
diff --git a/engines/hugo/file_v1d.cpp b/engines/hugo/file_v1d.cpp
index d8b3fa4..48f274e 100644
--- a/engines/hugo/file_v1d.cpp
+++ b/engines/hugo/file_v1d.cpp
@@ -121,7 +121,7 @@ void FileManager_v1d::instructions() const {
 			f.read(wrkLine, 1);
 		} while (*wrkLine++ != '#');                // '#' is EOP
 		wrkLine[-2] = '\0';                         // Remove EOP and previous CR
-		Utils::Box(kBoxAny, "%s", line);
+		Utils::notifyBox(line);
 		wrkLine = line;
 		f.read(readBuf, 2);                         // Remove CRLF after EOP
 	}
diff --git a/engines/hugo/file_v2w.cpp b/engines/hugo/file_v2w.cpp
index b917d81..245d4d0 100644
--- a/engines/hugo/file_v2w.cpp
+++ b/engines/hugo/file_v2w.cpp
@@ -48,7 +48,7 @@ FileManager_v2w::~FileManager_v2w() {
  * Same comment than in SCI: maybe in the future we can implement this, but for now this message should suffice
  */
 void FileManager_v2w::instructions() const {
-	Utils::Box(kBoxAny, "Please use an external viewer to open the game's help file: HUGOWIN%d.HLP", _vm->_gameVariant + 1);
+	Utils::notifyBox(Common::String::format("Please use an external viewer to open the game's help file: HUGOWIN%d.HLP", _vm->_gameVariant + 1));
 }
 
 } // End of namespace Hugo
diff --git a/engines/hugo/hugo.cpp b/engines/hugo/hugo.cpp
index ec624dd..6ba9e8e 100644
--- a/engines/hugo/hugo.cpp
+++ b/engines/hugo/hugo.cpp
@@ -165,7 +165,7 @@ bool HugoEngine::isPacked() const {
  * Print options for user when dead
  */
 void HugoEngine::gameOverMsg() {
-	Utils::Box(kBoxOk, "%s", _text->getTextUtil(kGameOver));
+	Utils::notifyBox(_text->getTextUtil(kGameOver));
 }
 
 Common::Error HugoEngine::run() {
@@ -678,8 +678,8 @@ void HugoEngine::endGame() {
 	debugC(1, kDebugEngine, "endGame");
 
 	if (_boot.registered != kRegRegistered)
-		Utils::Box(kBoxAny, "%s", _text->getTextEngine(kEsAdvertise));
-	Utils::Box(kBoxAny, "%s\n%s", _episode, getCopyrightString());
+		Utils::notifyBox(_text->getTextEngine(kEsAdvertise));
+	Utils::notifyBox(Common::String::format("%s\n%s", _episode, getCopyrightString()));
 	_status.viewState = kViewExit;
 }
 
diff --git a/engines/hugo/hugo.h b/engines/hugo/hugo.h
index a6a939f..ed021f5 100644
--- a/engines/hugo/hugo.h
+++ b/engines/hugo/hugo.h
@@ -132,11 +132,6 @@ enum HugoRegistered {
 };
 
 /**
- * Ways to dismiss a text/prompt box
- */
-enum box_t {kBoxAny, kBoxOk};
-
-/**
  * Inventory icon bar states
  */
 enum istate_t {kInventoryOff, kInventoryUp, kInventoryDown, kInventoryActive};
diff --git a/engines/hugo/intro.cpp b/engines/hugo/intro.cpp
index 7551476..7cd5a0f 100644
--- a/engines/hugo/intro.cpp
+++ b/engines/hugo/intro.cpp
@@ -337,13 +337,13 @@ bool intro_v3d::introPlay() {
 		// Text boxes at various times
 		switch (introTicks) {
 		case 4:
-			Utils::Box(kBoxOk, "%s", _vm->_text->getTextIntro(kIntro1));
+			Utils::notifyBox(_vm->_text->getTextIntro(kIntro1));
 			break;
 		case 9:
-			Utils::Box(kBoxOk, "%s", _vm->_text->getTextIntro(kIntro2));
+			Utils::notifyBox(_vm->_text->getTextIntro(kIntro2));
 			break;
 		case 35:
-			Utils::Box(kBoxOk, "%s", _vm->_text->getTextIntro(kIntro3));
+			Utils::notifyBox(_vm->_text->getTextIntro(kIntro3));
 			break;
 		}
 	}
@@ -429,13 +429,13 @@ bool intro_v3w::introPlay() {
 		// Text boxes at various times
 		switch (introTicks) {
 		case 4:
-			Utils::Box(kBoxOk, "%s", _vm->_text->getTextIntro(kIntro1));
+			Utils::notifyBox(_vm->_text->getTextIntro(kIntro1));
 			break;
 		case 9:
-			Utils::Box(kBoxOk, "%s", _vm->_text->getTextIntro(kIntro2));
+			Utils::notifyBox(_vm->_text->getTextIntro(kIntro2));
 			break;
 		case 35:
-			Utils::Box(kBoxOk, "%s", _vm->_text->getTextIntro(kIntro3));
+			Utils::notifyBox(_vm->_text->getTextIntro(kIntro3));
 			break;
 		}
 	}
diff --git a/engines/hugo/mouse.cpp b/engines/hugo/mouse.cpp
index 73805dc..1b2dd58 100644
--- a/engines/hugo/mouse.cpp
+++ b/engines/hugo/mouse.cpp
@@ -187,7 +187,7 @@ void MouseHandler::processRightClick(const int16 objId, const int16 cx, const in
 				if (_vm->_hero->cycling == kCycleInvisible) // If invisible do
 					_vm->_object->useObject(objId); // immediate use
 				else
-					Utils::Box(kBoxAny, "%s", _vm->_text->getTextMouse(kMsNoWayText)); // Can't get there
+					Utils::notifyBox(_vm->_text->getTextMouse(kMsNoWayText)); // Can't get there
 			}
 			break;
 		}
@@ -241,7 +241,7 @@ void MouseHandler::processLeftClick(const int16 objId, const int16 cx, const int
 				else if (_hotspots[i].direction == Common::KEYCODE_LEFT)
 					x += kHeroMaxWidth;
 				if (!_vm->_route->startRoute(kRouteExit, i, x, y))
-					Utils::Box(kBoxAny, "%s", _vm->_text->getTextMouse(kMsNoWayText)); // Can't get there
+					Utils::notifyBox(_vm->_text->getTextMouse(kMsNoWayText)); // Can't get there
 			}
 
 			// Get rid of any attached icon
@@ -271,7 +271,7 @@ void MouseHandler::processLeftClick(const int16 objId, const int16 cx, const int
 					if (_vm->_hero->cycling == kCycleInvisible) // If invisible do
 						_vm->_object->lookObject(obj);          // immediate decription
 					else
-						Utils::Box(kBoxAny, "%s", _vm->_text->getTextMouse(kMsNoWayText));  // Can't get there
+						Utils::notifyBox(_vm->_text->getTextMouse(kMsNoWayText));  // Can't get there
 				}
 				break;
 			}
diff --git a/engines/hugo/object.cpp b/engines/hugo/object.cpp
index f82a6a5..0a52a0f 100644
--- a/engines/hugo/object.cpp
+++ b/engines/hugo/object.cpp
@@ -175,7 +175,7 @@ void ObjectHandler::useObject(int16 objId) {
 					// Deselect dragged icon if inventory not active
 					if (_vm->_inventory->getInventoryState() != kInventoryActive)
 						_vm->_screen->resetInventoryObjId();
-					Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(use->dataIndex));
+					Utils::notifyBox(_vm->_text->getTextData(use->dataIndex));
 					return;
 				}
 			}
@@ -353,7 +353,7 @@ void ObjectHandler::showTakeables() {
 		if ((obj->cycling != kCycleInvisible) &&
 		    (obj->screenIndex == *_vm->_screen_p) &&
 		    (((TAKE & obj->genericCmd) == TAKE) || obj->objValue)) {
-			Utils::Box(kBoxAny, "You can also see:\n%s.", _vm->_text->getNoun(obj->nounIndex, LOOK_NAME));
+			Utils::notifyBox(Common::String::format("You can also see:\n%s.", _vm->_text->getNoun(obj->nounIndex, LOOK_NAME)));
 		}
 	}
 }
diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp
index 685cbc0..feee4cb 100644
--- a/engines/hugo/parser.cpp
+++ b/engines/hugo/parser.cpp
@@ -485,7 +485,7 @@ void Parser::showDosInventory() const {
 	if (index & 1)
 		buffer += "\n";
 	buffer += Common::String(_vm->_text->getTextParser(kTBOutro));
-	Utils::Box(kBoxAny, "%s", buffer.c_str());
+	Utils::notifyBox(buffer.c_str());
 }
 
 } // End of namespace Hugo
diff --git a/engines/hugo/parser_v1d.cpp b/engines/hugo/parser_v1d.cpp
index 36b56a6..de18427 100644
--- a/engines/hugo/parser_v1d.cpp
+++ b/engines/hugo/parser_v1d.cpp
@@ -151,25 +151,25 @@ bool Parser_v1d::isGenericVerb_v1(const char *word, object_t *obj) {
 	// Following is equivalent to switch, but couldn't do one
 	if (word == _vm->_text->getVerb(_vm->_look, 0)) {
 		if ((LOOK & obj->genericCmd) == LOOK)
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(obj->dataIndex));
+			Utils::notifyBox(_vm->_text->getTextData(obj->dataIndex));
 		else
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBUnusual_1d));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBUnusual_1d));
 	} else if (word == _vm->_text->getVerb(_vm->_take, 0)) {
 		if (obj->carriedFl)
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBHave));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBHave));
 		else if ((TAKE & obj->genericCmd) == TAKE)
 			takeObject(obj);
 		else if (!obj->verbOnlyFl)                  // Make sure not taking object in context!
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoUse));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBNoUse));
 		else
 			return false;
 	} else if (word == _vm->_text->getVerb(_vm->_drop, 0)) {
 		if (!obj->carriedFl)
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBDontHave));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBDontHave));
 		else if ((DROP & obj->genericCmd) == DROP)
 			dropObject(obj);
 		else
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNeed));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBNeed));
 	} else {                                        // It was not a generic cmd
 		return false;
 	}
@@ -206,7 +206,7 @@ bool Parser_v1d::isObjectVerb_v1(const char *word, object_t *obj) {
 		uint16 *reqs = _arrayReqs[cmnd->reqIndex];  // ptr to list of required objects
 		for (i = 0; reqs[i]; i++) {                 // for each obj
 			if (!_vm->_object->isCarrying(reqs[i])) {
-				Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(cmnd->textDataNoCarryIndex));
+				Utils::notifyBox(_vm->_text->getTextData(cmnd->textDataNoCarryIndex));
 				return true;
 			}
 		}
@@ -214,14 +214,14 @@ bool Parser_v1d::isObjectVerb_v1(const char *word, object_t *obj) {
 
 	// Required objects are present, now check state is correct
 	if ((obj->state != cmnd->reqState) && (cmnd->reqState != kStateDontCare)){
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(cmnd->textDataWrongIndex));
+		Utils::notifyBox(_vm->_text->getTextData(cmnd->textDataWrongIndex));
 		return true;
 	}
 
 	// Everything checked.  Change the state and carry out any actions
 	if (cmnd->reqState != kStateDontCare)           // Don't change new state if required state didn't care
 		obj->state = cmnd->newState;
-	Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(cmnd->textDataDoneIndex));
+	Utils::notifyBox(_vm->_text->getTextData(cmnd->textDataDoneIndex));
 	_vm->_scheduler->insertActionList(cmnd->actIndex);
 	// Special case if verb is Take or Drop.  Assume additional generic actions
 	if ((word == _vm->_text->getVerb(_vm->_take, 0)) || (word == _vm->_text->getVerb(_vm->_drop, 0)))
@@ -241,7 +241,7 @@ bool Parser_v1d::isBackgroundWord_v1(const char *noun, const char *verb, objectL
 
 	for (int i = 0; obj[i].verbIndex; i++) {
 		if ((verb == _vm->_text->getVerb(obj[i].verbIndex, 0)) && (noun == _vm->_text->getNoun(obj[i].nounIndex, 0))) {
-			Utils::Box(kBoxAny, "%s", _vm->_file->fetchString(obj[i].commentIndex));
+			Utils::notifyBox(_vm->_file->fetchString(obj[i].commentIndex));
 			return true;
 		}
 	}
@@ -260,7 +260,7 @@ void Parser_v1d::takeObject(object_t *obj) {
 
 	_vm->adjustScore(obj->objValue);
 
-	Utils::Box(kBoxAny, TAKE_TEXT, _vm->_text->getNoun(obj->nounIndex, TAKE_NAME));
+	Utils::notifyBox(Common::String::format(TAKE_TEXT, _vm->_text->getNoun(obj->nounIndex, TAKE_NAME)));
 }
 
 /**
@@ -276,7 +276,7 @@ void Parser_v1d::dropObject(object_t *obj) {
 	obj->x = _vm->_hero->x - 1;
 	obj->y = _vm->_hero->y + _vm->_hero->currImagePtr->y2 - 1;
 	_vm->adjustScore(-obj->objValue);
-	Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBOk));
+	Utils::notifyBox(_vm->_text->getTextParser(kTBOk));
 }
 
 /**
@@ -294,7 +294,7 @@ bool Parser_v1d::isCatchallVerb_v1(bool testNounFl, const char *noun, const char
 
 	for (int i = 0; obj[i].verbIndex; i++) {
 		if ((verb == _vm->_text->getVerb(obj[i].verbIndex, 0)) && ((noun == _vm->_text->getNoun(obj[i].nounIndex, 0)) || (obj[i].nounIndex == 0))) {
-			Utils::Box(kBoxAny, "%s", _vm->_file->fetchString(obj[i].commentIndex));
+			Utils::notifyBox(_vm->_file->fetchString(obj[i].commentIndex));
 			return true;
 		}
 	}
@@ -418,11 +418,11 @@ void Parser_v1d::lineHandler() {
 	}
 	noun = findNextNoun(noun);
 	if (*farComment != '\0')                        // An object matched but not near enough
-		Utils::Box(kBoxAny, "%s", farComment);
+		Utils::notifyBox(farComment);
 	else if (!isCatchallVerb_v1(true, noun, verb, _catchallList) &&
 		     !isCatchallVerb_v1(false, noun, verb, _backgroundObjects[*_vm->_screen_p])  &&
 		     !isCatchallVerb_v1(false, noun, verb, _catchallList))
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBEh_1d));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBEh_1d));
 }
 
 void Parser_v1d::showInventory() const {
diff --git a/engines/hugo/parser_v1w.cpp b/engines/hugo/parser_v1w.cpp
index 3490c43..305fb99 100644
--- a/engines/hugo/parser_v1w.cpp
+++ b/engines/hugo/parser_v1w.cpp
@@ -182,7 +182,7 @@ void Parser_v1w::lineHandler() {
 
 	// If a not-near comment was generated, print it
 	if (*farComment != '\0') {
-		Utils::Box(kBoxAny, "%s", farComment);
+		Utils::notifyBox(farComment);
 		return;
 	}
 
@@ -190,16 +190,16 @@ void Parser_v1w::lineHandler() {
 	const char *verb = findVerb();
 	const char *noun = findNoun();
 	if (verb == _vm->_text->getVerb(_vm->_look, 0) && _vm->_maze.enabledFl) {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBMaze));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBMaze));
 		_vm->_object->showTakeables();
 	} else if (verb && noun) {                      // A combination I didn't think of
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoPoint));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBNoPoint));
 	} else if (noun) {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoun));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBNoun));
 	} else if (verb) {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBVerb));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBVerb));
 	} else {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBEh));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBEh));
 	}
 }
 
diff --git a/engines/hugo/parser_v2d.cpp b/engines/hugo/parser_v2d.cpp
index 50d2e5f..d6f2adf 100644
--- a/engines/hugo/parser_v2d.cpp
+++ b/engines/hugo/parser_v2d.cpp
@@ -175,16 +175,16 @@ void Parser_v2d::lineHandler() {
 		&& !isCatchallVerb_v1(false, noun, verb, _backgroundObjects[*_vm->_screen_p])
 		&& !isCatchallVerb_v1(false, noun, verb, _catchallList)) {
 		if (*farComment != '\0') {                  // An object matched but not near enough
-			Utils::Box(kBoxAny, "%s", farComment);
+			Utils::notifyBox(farComment);
 		} else if (_vm->_maze.enabledFl && (verb == _vm->_text->getVerb(_vm->_look, 0))) {
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBMaze));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBMaze));
 			_vm->_object->showTakeables();
 		} else if (verb && noun) {                  // A combination I didn't think of
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoUse_2d));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBNoUse_2d));
 		} else if (verb || noun) {
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoun));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBNoun));
 		} else {
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBEh_2d));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBEh_2d));
 		}
 	}
 }
diff --git a/engines/hugo/parser_v3d.cpp b/engines/hugo/parser_v3d.cpp
index 88ff980..f08d472 100644
--- a/engines/hugo/parser_v3d.cpp
+++ b/engines/hugo/parser_v3d.cpp
@@ -184,7 +184,7 @@ void Parser_v3d::lineHandler() {
 
 	// If a not-near comment was generated, print it
 	if (*farComment != '\0') {
-		Utils::Box(kBoxAny, "%s", farComment);
+		Utils::notifyBox(farComment);
 		return;
 	}
 
@@ -193,13 +193,13 @@ void Parser_v3d::lineHandler() {
 	const char *noun = findNoun();
 
 	if (verb && noun) {                             // A combination I didn't think of
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoPoint));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBNoPoint));
 	} else if (noun) {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoun));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBNoun));
 	} else if (verb) {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBVerb));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBVerb));
 	} else {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBEh));
+		Utils::notifyBox(_vm->_text->getTextParser(kTBEh));
 	}
 }
 
@@ -236,7 +236,7 @@ bool Parser_v3d::isObjectVerb_v3(object_t *obj, char *comment) {
 		uint16 *reqs = _arrayReqs[cmnd->reqIndex];  // ptr to list of required objects
 		for (i = 0; reqs[i]; i++) {                 // for each obj
 			if (!_vm->_object->isCarrying(reqs[i])) {
-				Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(cmnd->textDataNoCarryIndex));
+				Utils::notifyBox(_vm->_text->getTextData(cmnd->textDataNoCarryIndex));
 				return true;
 			}
 		}
@@ -244,14 +244,14 @@ bool Parser_v3d::isObjectVerb_v3(object_t *obj, char *comment) {
 
 	// Required objects are present, now check state is correct
 	if ((obj->state != cmnd->reqState) && (cmnd->reqState != kStateDontCare)) {
-		Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(cmnd->textDataWrongIndex));
+		Utils::notifyBox(_vm->_text->getTextData(cmnd->textDataWrongIndex));
 		return true;
 	}
 
 	// Everything checked.  Change the state and carry out any actions
 	if (cmnd->reqState != kStateDontCare)           // Don't change new state if required state didn't care
 		obj->state = cmnd->newState;
-	Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(cmnd->textDataDoneIndex));
+	Utils::notifyBox(_vm->_text->getTextData(cmnd->textDataDoneIndex));
 	_vm->_scheduler->insertActionList(cmnd->actIndex);
 
 	// See if any additional generic actions
@@ -273,35 +273,35 @@ bool Parser_v3d::isGenericVerb_v3(object_t *obj, char *comment) {
 	if (isWordPresent(_vm->_text->getVerbArray(_vm->_look)) && isNear_v3(obj, _vm->_text->getVerb(_vm->_look, 0), comment)) {
 		// Test state-dependent look before general look
 		if ((obj->genericCmd & LOOK_S) == LOOK_S) {
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(obj->stateDataIndex[obj->state]));
+			Utils::notifyBox(_vm->_text->getTextData(obj->stateDataIndex[obj->state]));
 		} else {
 			if ((LOOK & obj->genericCmd) == LOOK) {
 				if (obj->dataIndex != 0)
-					Utils::Box(kBoxAny, "%s", _vm->_text->getTextData(obj->dataIndex));
+					Utils::notifyBox(_vm->_text->getTextData(obj->dataIndex));
 				else
 					return false;
 			} else {
-				Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBUnusual));
+				Utils::notifyBox(_vm->_text->getTextParser(kTBUnusual));
 			}
 		}
 	} else if (isWordPresent(_vm->_text->getVerbArray(_vm->_take)) && isNear_v3(obj, _vm->_text->getVerb(_vm->_take, 0), comment)) {
 		if (obj->carriedFl)
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBHave));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBHave));
 		else if ((TAKE & obj->genericCmd) == TAKE)
 			takeObject(obj);
 		else if (obj->cmdIndex)                     // No comment if possible commands
 			return false;
 		else if (!obj->verbOnlyFl && (TAKE & obj->genericCmd) == TAKE)  // Make sure not taking object in context!
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNoUse));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBNoUse));
 		else
 			return false;
 	} else if (isWordPresent(_vm->_text->getVerbArray(_vm->_drop))) {
 		if (!obj->carriedFl && ((DROP & obj->genericCmd) == DROP))
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBDontHave));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBDontHave));
 		else if (obj->carriedFl && ((DROP & obj->genericCmd) == DROP))
 			dropObject(obj);
 		else if (obj->cmdIndex == 0)
-			Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBNeed));
+			Utils::notifyBox(_vm->_text->getTextParser(kTBNeed));
 		else
 			return false;
 	} else {                                        // It was not a generic cmd
@@ -383,7 +383,7 @@ void Parser_v3d::takeObject(object_t *obj) {
 
 	if (obj->seqNumb > 0)                           // If object has an image, force walk to dropped
 		obj->viewx = -1;                            // (possibly moved) object next time taken!
-	Utils::Box(kBoxAny, TAKE_TEXT, _vm->_text->getNoun(obj->nounIndex, TAKE_NAME));
+	Utils::notifyBox(Common::String::format(TAKE_TEXT, _vm->_text->getNoun(obj->nounIndex, TAKE_NAME)));
 }
 
 /**
@@ -402,7 +402,7 @@ void Parser_v3d::dropObject(object_t *obj) {
 	obj->y = _vm->_hero->y + _vm->_hero->currImagePtr->y2 - 1;
 	obj->y = (obj->y + obj->currImagePtr->y2 < kYPix) ? obj->y : kYPix - obj->currImagePtr->y2 - 10;
 	_vm->adjustScore(-obj->objValue);
-	Utils::Box(kBoxAny, "%s", _vm->_text->getTextParser(kTBOk));
+	Utils::notifyBox(_vm->_text->getTextParser(kTBOk));
 }
 
 /**
@@ -422,7 +422,7 @@ bool Parser_v3d::isCatchallVerb_v3(objectList_t obj) const {
 		   (!obj[i].matchFl || !findNoun()) &&
 		   ((obj[i].roomState == kStateDontCare) ||
 		    (obj[i].roomState == _vm->_screenStates[*_vm->_screen_p]))) {
-			Utils::Box(kBoxAny, "%s", _vm->_file->fetchString(obj[i].commentIndex));
+			Utils::notifyBox(_vm->_file->fetchString(obj[i].commentIndex));
 			_vm->_scheduler->processBonus(obj[i].bonusIndex);
 
 			// If this is LOOK (without a noun), show any takeable objects
@@ -450,7 +450,7 @@ bool Parser_v3d::isBackgroundWord_v3(objectList_t obj) const {
 		    isWordPresent(_vm->_text->getNounArray(obj[i].nounIndex)) &&
 		    ((obj[i].roomState == kStateDontCare) ||
 		     (obj[i].roomState == _vm->_screenStates[*_vm->_screen_p]))) {
-			Utils::Box(kBoxAny, "%s", _vm->_file->fetchString(obj[i].commentIndex));
+			Utils::notifyBox(_vm->_file->fetchString(obj[i].commentIndex));
 			_vm->_scheduler->processBonus(obj[i].bonusIndex);
 			return true;
 		}
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index 48427c2..45a2b77 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -1242,7 +1242,7 @@ event_t *Scheduler::doAction(event_t *curEvent) {
 			insertActionList(action->a11.actFailIndex);
 		break;
 	case TEXT:                                      // act12: Text box (CF WARN)
-		Utils::Box(kBoxAny, "%s", _vm->_file->fetchString(action->a12.stringIndex));   // Fetch string from file
+		Utils::notifyBox(_vm->_file->fetchString(action->a12.stringIndex));   // Fetch string from file
 		break;
 	case SWAP_IMAGES:                               // act13: Swap 2 object images
 		_vm->_object->swapImages(action->a13.objIndex1, action->a13.objIndex2);
@@ -1367,7 +1367,7 @@ event_t *Scheduler::doAction(event_t *curEvent) {
 		gameStatus.storyModeFl = action->a39.storyModeFl;
 		break;
 	case WARN:                                      // act40: Text box (CF TEXT)
-		Utils::Box(kBoxOk, "%s", _vm->_file->fetchString(action->a40.stringIndex));
+		Utils::notifyBox(_vm->_file->fetchString(action->a40.stringIndex));
 		break;
 	case COND_BONUS:                                // act41: Perform action if got bonus
 		if (_points[action->a41.BonusIndex].scoredFl)
@@ -1376,7 +1376,7 @@ event_t *Scheduler::doAction(event_t *curEvent) {
 			insertActionList(action->a41.actFailIndex);
 		break;
 	case TEXT_TAKE:                                 // act42: Text box with "take" message
-		Utils::Box(kBoxAny, TAKE_TEXT, _vm->_text->getNoun(_vm->_object->_objects[action->a42.objIndex].nounIndex, TAKE_NAME));
+		Utils::notifyBox(Common::String::format(TAKE_TEXT, _vm->_text->getNoun(_vm->_object->_objects[action->a42.objIndex].nounIndex, TAKE_NAME)));
 		break;
 	case YESNO:                                     // act43: Prompt user for Yes or No
 		if (Utils::yesNoBox(_vm->_file->fetchString(action->a43.promptIndex)))
diff --git a/engines/hugo/util.cpp b/engines/hugo/util.cpp
index 88a3be8..044b58e 100644
--- a/engines/hugo/util.cpp
+++ b/engines/hugo/util.cpp
@@ -43,11 +43,6 @@ namespace Hugo {
 
 namespace Utils {
 
-enum {
-	kMaxStrLength = 1024
-};
-
-
 /**
  * Returns index (0 to 7) of first 1 in supplied byte, or 8 if not found
  */
@@ -96,52 +91,24 @@ void reverseByte(byte *data) {
 	*data = result;
 }
 
-void Box(box_t dismiss, const char *s, ...) {
-	static char buffer[kMaxStrLength + 1];          // Format text into this
-
-	if (!s)
-		return;                                   // NULL strings catered for
-
-	if (s[0] == '\0')
+void notifyBox(const Common::String &msg) {
+	if (msg.empty())
 		return;
 
-	if (strlen(s) > kMaxStrLength - 100) {          // Test length
-		warning("String too long: '%s'", s);
-		return;
-	}
-
-	va_list marker;
-	va_start(marker, s);
-	vsprintf(buffer, s, marker);                    // Format string into buffer
-	va_end(marker);
-
-	if (buffer[0] == '\0')
-		return;
-
-	switch(dismiss) {
-	case kBoxAny:
-	case kBoxOk: {
-		GUI::MessageDialog dialog(buffer, "OK");
-		dialog.runModal();
-		break;
-		}
-	default:
-		error("Unknown BOX Type %d", dismiss);
-	}
-
-	return;
+	GUI::MessageDialog dialog(msg, "OK");
+	dialog.runModal();
 }
 
-Common::String promptBox(const char *msg) {
-	if (!msg || !*msg)
-		return 0;
+Common::String promptBox(const Common::String &msg) {
+	if (msg.empty())
+		return Common::String();
 
 	EntryDialog dialog(msg, "OK", "");
 	return dialog.getEditString();
 }
 
-bool yesNoBox(const char *msg) {
-	if (!msg || !*msg)
+bool yesNoBox(const Common::String &msg) {
+	if (msg.empty())
 		return 0;
 
 	GUI::MessageDialog dialog(msg, "YES", "NO");
diff --git a/engines/hugo/util.h b/engines/hugo/util.h
index 12ec58f..85fef01 100644
--- a/engines/hugo/util.h
+++ b/engines/hugo/util.h
@@ -46,9 +46,27 @@ int   lastBit(byte data);
 
 void  reverseByte(byte *data);
 
-void Box(box_t, const char *, ...) GCC_PRINTF(2, 3);
-Common::String promptBox(const char *msg);
-bool yesNoBox(const char *msg);
+/**
+ * Show a dialog notifying the user about something, with
+ * only a simple "OK" button to dismiss it.
+ */
+void notifyBox(const Common::String &msg);
+
+/**
+ * Show a dialog prompting the player to input some text.
+ */
+Common::String promptBox(const Common::String &msg);
+
+/**
+ * Show a dialog prompting the player for a "yes"/"no" choice.
+ */
+bool yesNoBox(const Common::String &msg);
+
+/**
+ * Convert a string to lower case, in place.
+ * @param buffer	string to convert to lower case
+ * @return the string which was passed in
+ */
 char *strlwr(char *buffer);
 
 } // End of namespace Utils


Commit: bf4dc80419b12bb2415d42ee413162bf56019288
    https://github.com/scummvm/scummvm/commit/bf4dc80419b12bb2415d42ee413162bf56019288
Author: Max Horn (max at quendi.de)
Date: 2011-03-21T06:36:25-07:00

Commit Message:
SWORD25: Reduce code duplication; formatting

Changed paths:
    engines/sword25/gfx/graphicengine_script.cpp
    engines/sword25/math/geometry_script.cpp
    engines/sword25/script/luabindhelper.cpp
    engines/sword25/script/luabindhelper.h



diff --git a/engines/sword25/gfx/graphicengine_script.cpp b/engines/sword25/gfx/graphicengine_script.cpp
index d67d003..d8daaab 100644
--- a/engines/sword25/gfx/graphicengine_script.cpp
+++ b/engines/sword25/gfx/graphicengine_script.cpp
@@ -81,26 +81,6 @@ static ActionCallback *actionCallbackPtr = 0;	// FIXME: should be turned into Gr
 #define ANIMATION_TEMPLATE_CLASS_NAME "Gfx.AnimationTemplate"
 static const char *GFX_LIBRARY_NAME = "Gfx";
 
-// Wie luaL_checkudata, nur ohne dass kein Fehler erzeugt wird.
-static void *my_checkudata(lua_State *L, int ud, const char *tname) {
-	int top = lua_gettop(L);
-
-	void *p = lua_touserdata(L, ud);
-	if (p != NULL) { /* value is a userdata? */
-		if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
-			// lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */
-			LuaBindhelper::getMetatable(L, tname);
-			if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
-				lua_settop(L, top);
-				return p;
-			}
-		}
-	}
-
-	lua_settop(L, top);
-	return NULL;
-}
-
 static void newUintUserData(lua_State *L, uint value) {
 	void *userData = lua_newuserdata(L, sizeof(value));
 	memcpy(userData, &value, sizeof(value));
@@ -108,8 +88,8 @@ static void newUintUserData(lua_State *L, uint value) {
 
 static AnimationTemplate *checkAnimationTemplate(lua_State *L, int idx = 1) {
 	// Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.AnimationTemplate
-	uint animationTemplateHandle;
-	if ((animationTemplateHandle = *reinterpret_cast<uint *>(my_checkudata(L, idx, ANIMATION_TEMPLATE_CLASS_NAME))) != 0) {
+	uint animationTemplateHandle = *reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, idx, ANIMATION_TEMPLATE_CLASS_NAME));
+	if (animationTemplateHandle != 0) {
 		AnimationTemplate *animationTemplatePtr = AnimationTemplateRegistry::instance().resolveHandle(animationTemplateHandle);
 		if (!animationTemplatePtr)
 			luaL_error(L, "The animation template with the handle %d does no longer exist.", animationTemplateHandle);
@@ -370,10 +350,10 @@ static const luaL_reg GFX_FUNCTIONS[] = {
 static RenderObjectPtr<RenderObject> checkRenderObject(lua_State *L, bool errorIfRemoved = true) {
 	// Der erste Parameter muss vom Typ userdata sein und die Metatable einer Klasse haben, die von Gfx.RenderObject "erbt".
 	uint *userDataPtr;
-	if ((userDataPtr = (uint *) my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0 ||
-	        (userDataPtr = (uint *) my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0 ||
-	        (userDataPtr = (uint *) my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0 ||
-	        (userDataPtr = (uint *) my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) {
+	if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0 ||
+	        (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0 ||
+	        (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0 ||
+	        (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) {
 		RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
 		if (roPtr.isValid())
 			return roPtr;
@@ -600,11 +580,11 @@ static const luaL_reg RENDEROBJECT_METHODS[] = {
 static RenderObjectPtr<Panel> checkPanel(lua_State *L) {
 	// Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Panel
 	uint *userDataPtr;
-	if ((userDataPtr = (uint *)my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0) {
+	if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0) {
 		RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
-		if (roPtr.isValid()) {
+		if (roPtr.isValid())
 			return roPtr->toPanel();
-		} else
+		else
 			luaL_error(L, "The panel with the handle %d does no longer exist.", *userDataPtr);
 	} else {
 		luaL_argcheck(L, 0, 1, "'" PANEL_CLASS_NAME "' expected");
@@ -645,11 +625,11 @@ static const luaL_reg PANEL_METHODS[] = {
 static RenderObjectPtr<Bitmap> checkBitmap(lua_State *L) {
 	// Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Bitmap
 	uint *userDataPtr;
-	if ((userDataPtr = (uint *)my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0) {
+	if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0) {
 		RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
-		if (roPtr.isValid()) {
+		if (roPtr.isValid())
 			return roPtr->toBitmap();
-		} else
+		else
 			luaL_error(L, "The bitmap with the handle %d does no longer exist.", *userDataPtr);
 	} else {
 		luaL_argcheck(L, 0, 1, "'" BITMAP_CLASS_NAME "' expected");
@@ -790,13 +770,12 @@ static const luaL_reg BITMAP_METHODS[] = {
 static RenderObjectPtr<Animation> checkAnimation(lua_State *L) {
 	// Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Animation
 	uint *userDataPtr;
-	if ((userDataPtr = (uint *)my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0) {
+	if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0) {
 		RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
 		if (roPtr.isValid())
 			return roPtr->toAnimation();
-		else {
+		else
 			luaL_error(L, "The animation with the handle %d does no longer exist.", *userDataPtr);
-		}
 	} else {
 		luaL_argcheck(L, 0, 1, "'" ANIMATION_CLASS_NAME "' expected");
 	}
@@ -1064,7 +1043,7 @@ static const luaL_reg ANIMATION_METHODS[] = {
 static RenderObjectPtr<Text> checkText(lua_State *L) {
 	// Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Text
 	uint *userDataPtr;
-	if ((userDataPtr = (uint *)my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) {
+	if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) {
 		RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
 		if (roPtr.isValid())
 			return roPtr->toText();
diff --git a/engines/sword25/math/geometry_script.cpp b/engines/sword25/math/geometry_script.cpp
index 6562a0f..4b5e055 100644
--- a/engines/sword25/math/geometry_script.cpp
+++ b/engines/sword25/math/geometry_script.cpp
@@ -51,27 +51,6 @@ namespace Sword25 {
 #define REGION_CLASS_NAME "Geo.Region"
 #define WALKREGION_CLASS_NAME "Geo.WalkRegion"
 
-// How luaL_checkudata, only without that no error is generated.
-static void *my_checkudata(lua_State *L, int ud, const char *tname) {
-	int top = lua_gettop(L);
-
-	void *p = lua_touserdata(L, ud);
-	if (p != NULL) { /* value is a userdata? */
-		if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
-			// lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */
-			LuaBindhelper::getMetatable(L, tname);
-			/* does it have the correct mt? */
-			if (lua_rawequal(L, -1, -2)) {
-				lua_settop(L, top);
-				return p;
-			}
-		}
-	}
-
-	lua_settop(L, top);
-	return NULL;
-}
-
 static void newUintUserData(lua_State *L, uint value) {
 	void *userData = lua_newuserdata(L, sizeof(value));
 	memcpy(userData, &value, sizeof(value));
@@ -276,9 +255,9 @@ static const luaL_reg GEO_FUNCTIONS[] = {
 
 static Region *checkRegion(lua_State *L) {
 	// The first parameter must be of type 'userdata', and the Metatable class Geo.Region or Geo.WalkRegion
-	uint *regionHandlePtr;
-	if ((regionHandlePtr = reinterpret_cast<uint *>(my_checkudata(L, 1, REGION_CLASS_NAME))) != 0 ||
-	        (regionHandlePtr = reinterpret_cast<uint *>(my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) {
+	uint *regionHandlePtr = reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, 1, REGION_CLASS_NAME));
+	if (regionHandlePtr != 0 ||
+	        (regionHandlePtr = reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) {
 		return RegionRegistry::instance().resolveHandle(*regionHandlePtr);
 	} else {
 		luaL_argcheck(L, 0, 1, "'" REGION_CLASS_NAME "' expected");
@@ -398,7 +377,7 @@ static const luaL_reg REGION_METHODS[] = {
 static WalkRegion *checkWalkRegion(lua_State *L) {
 	// The first parameter must be of type 'userdate', and the Metatable class Geo.WalkRegion
 	uint regionHandle;
-	if ((regionHandle = *reinterpret_cast<uint *>(my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) {
+	if ((regionHandle = *reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) {
 		return reinterpret_cast<WalkRegion *>(RegionRegistry::instance().resolveHandle(regionHandle));
 	} else {
 		luaL_argcheck(L, 0, 1, "'" WALKREGION_CLASS_NAME "' expected");
diff --git a/engines/sword25/script/luabindhelper.cpp b/engines/sword25/script/luabindhelper.cpp
index 5ff9708..03a1802 100644
--- a/engines/sword25/script/luabindhelper.cpp
+++ b/engines/sword25/script/luabindhelper.cpp
@@ -303,6 +303,27 @@ bool LuaBindhelper::getMetatable(lua_State *L, const Common::String &tableName)
 	return true;
 }
 
+// Like luaL_checkudata, only without that no error is generated.
+void *LuaBindhelper::my_checkudata(lua_State *L, int ud, const char *tname) {
+	int top = lua_gettop(L);
+
+	void *p = lua_touserdata(L, ud);
+	if (p != NULL) { /* value is a userdata? */
+		if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
+			// lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */
+			LuaBindhelper::getMetatable(L, tname);
+			if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
+				lua_settop(L, top);
+				return p;
+			}
+		}
+	}
+
+	lua_settop(L, top);
+	return NULL;
+}
+
+
 bool LuaBindhelper::createTable(lua_State *L, const Common::String &tableName) {
 	const char *partBegin = tableName.c_str();
 
diff --git a/engines/sword25/script/luabindhelper.h b/engines/sword25/script/luabindhelper.h
index dc45104..94f5274 100644
--- a/engines/sword25/script/luabindhelper.h
+++ b/engines/sword25/script/luabindhelper.h
@@ -110,6 +110,8 @@ public:
 
 	static bool getMetatable(lua_State *L, const Common::String &tableName);
 
+	static void *my_checkudata(lua_State *L, int ud, const char *tname);
+
 private:
 	static bool createTable(lua_State *L, const Common::String &tableName);
 };






More information about the Scummvm-git-logs mailing list