mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-16 22:58:09 +00:00
HDB: Add ScriptPatches for upvalues and setglobal
Moved the upvalue-syntax modification from sanitizeComments to the scriptPatches
This commit is contained in:
parent
95234eef3b
commit
341759cf0d
@ -35,8 +35,9 @@ struct ScriptPatch {
|
||||
const char* replace;
|
||||
} scriptPatches[] = {
|
||||
{"GLOBAL_LUA", "for i,npc in npcs do", "for i,npc in pairs(npcs) do"},
|
||||
{"GLOBAL_LUA", "setglobal( npcdef.codename..\"_init\", function() return NPC_Init( npcdef ) end )", "npcdef.codename..\"_init\" = function() return NPC_Init( npcdef ) end"},
|
||||
{"GLOBAL_LUA", "setglobal( npcdef.codename..\"_use\", function(x, y, v1, v2) return NPC_Use( npcdef, x, y, v1, v2 ) end )", "npcdef.codename..\"_use\" = function(x, y, v1, v2) return NPC_Use( npcdef, x, y, v1, v2 ) end"},
|
||||
{"GLOBAL_LUA", "setglobal( npcdef.codename..\"_init\", function() return NPC_Init( %npcdef ) end )", "_G[npcdef.codename .. \"_init\"] = function() return NPC_Init( npcdef ) end"},
|
||||
{"GLOBAL_LUA", "setglobal( npcdef.codename..\"_use\", function(x, y, v1, v2) return NPC_Use( %npcdef, x, y, v1, v2 ) end )", "_G[npcdef.codename .. \"_use\"] = function(x, y, v1, v2) return NPC_Use( npcdef, x, y, v1, v2 ) end"},
|
||||
{"MAP00_DEMO_LUA", "tempfunc = function() emptybed_use( %x, %y, %v1, %v2 ) end", "tempfunc = function() emptybed_use(x, y, v1, v2) end"},
|
||||
{NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
@ -63,7 +64,6 @@ bool LuaScript::init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Called from Lua, this will pop into the menu
|
||||
*/
|
||||
@ -722,7 +722,7 @@ bool LuaScript::executeMPC(Common::SeekableReadStream *stream, const char *name,
|
||||
char *chunk = new char[length];
|
||||
stream->read((void *)chunk, length);
|
||||
|
||||
sanitizeScript(chunk);
|
||||
stripComments(chunk);
|
||||
|
||||
/*
|
||||
Remove C-style comments from the script
|
||||
@ -759,7 +759,7 @@ bool LuaScript::executeFile(const Common::String &filename) {
|
||||
char *fileData = new char[fileSize];
|
||||
file->read((void *)fileData, fileSize);
|
||||
|
||||
sanitizeScript(fileData);
|
||||
stripComments(fileData);
|
||||
|
||||
Common::String fileDataString(fileData);
|
||||
|
||||
@ -807,7 +807,7 @@ bool LuaScript::executeChunk(Common::String &chunk, uint chunkSize, const Common
|
||||
return true;
|
||||
}
|
||||
|
||||
void LuaScript::sanitizeScript(char *chunk) {
|
||||
void LuaScript::stripComments(char *chunk) {
|
||||
uint32 offset = 0;
|
||||
|
||||
while (chunk[offset]) {
|
||||
@ -817,9 +817,6 @@ void LuaScript::sanitizeScript(char *chunk) {
|
||||
chunk[offset++] = ' ';
|
||||
}
|
||||
}
|
||||
else if (chunk[offset] == '%' && chunk[offset] != ' ') { // Update the Upvalue syntax
|
||||
chunk[offset] = ' ';
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ private:
|
||||
|
||||
bool registerExtensions();
|
||||
bool executeChunk(Common::String &chunk, uint chunkSize, const Common::String &chunkName) const;
|
||||
void sanitizeScript(char *chunk);
|
||||
void stripComments(char *chunk);
|
||||
void addPatches(Common::String &chunk, const char *scriptName);
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user