aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNipun Garg2019-06-06 02:56:41 +0530
committerEugene Sandulenko2019-09-03 17:16:43 +0200
commit7dd8b07cebeb76d02953c2bf40001ca65092439a (patch)
tree2325a5da2ea5eea8a8b91bf803dd8743057deaee
parentb8a4fa2902483b0262f251b78327bf85d8223f91 (diff)
downloadscummvm-rg350-7dd8b07cebeb76d02953c2bf40001ca65092439a.tar.gz
scummvm-rg350-7dd8b07cebeb76d02953c2bf40001ca65092439a.tar.bz2
scummvm-rg350-7dd8b07cebeb76d02953c2bf40001ca65092439a.zip
HDB: Modify stripComments to sanitizeScript
Lua 5.0 introduced new syntax for upvalues so the old code needs to be preprocessed first.
-rw-r--r--engines/hdb/lua-script.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp
index e98d1c4417..2feb6cd22e 100644
--- a/engines/hdb/lua-script.cpp
+++ b/engines/hdb/lua-script.cpp
@@ -647,8 +647,11 @@ bool LuaScript::executeMPC(Common::SeekableReadStream *stream, const char *name,
char *chunk = new char[length];
stream->read((void *)chunk, length);
- // Remove C-Style comments from script
- stripComments(chunk);
+ /*
+ Remove C-style comments from the script
+ and update the upvalue syntax for Lua 5.1.3
+ */
+ sanitizeScript(chunk);
if (!executeChunk(chunk, length, name)) {
delete[] chunk;
@@ -717,14 +720,17 @@ bool LuaScript::executeChunk(const char *chunk, uint chunkSize, const Common::St
return true;
}
-void LuaScript::stripComments(char *chunk) {
+void LuaScript::sanitizeScript(char *chunk) {
uint32 offset = 0;
while (chunk[offset]) {
+ // Strip C-Style comments
if (chunk[offset] == '/' && chunk[offset + 1] == '/') {
while (chunk[offset] != 0x0d) {
chunk[offset++] = ' ';
}
+ } else if (chunk[offset] == '%' && chunk[offset] != ' ') { // Update the Upvalue syntax
+ chunk[offset] = ' ';
}
offset++;
}