DIRECTOR: LINGO: Properly compile scripts with mixed immediate code and definitions

This commit is contained in:
Eugene Sandulenko 2019-12-01 14:02:26 +01:00
parent c489e87bf3
commit c3dde9220c
3 changed files with 9 additions and 3 deletions

View File

@ -1002,7 +1002,7 @@ void Lingo::c_whencode() {
int entity = g_lingo->_currentEntityId;
g_lingo->_currentEntityId = 0;
Symbol *sym = g_lingo->define(eventname, start, 0, NULL, end);
Symbol *sym = g_lingo->define(eventname, start, 0, NULL, end, false); // Redefine, but not remove code
g_lingo->_currentEntityId = entity;

View File

@ -212,7 +212,7 @@ void Lingo::cleanLocalVars() {
g_lingo->_localvars = 0;
}
Symbol *Lingo::define(Common::String &name, int start, int nargs, Common::String *prefix, int end) {
Symbol *Lingo::define(Common::String &name, int start, int nargs, Common::String *prefix, int end, bool removeCode) {
if (prefix)
name = *prefix + "-" + name;
@ -244,6 +244,12 @@ Symbol *Lingo::define(Common::String &name, int start, int nargs, Common::String
sym->nargs = nargs;
sym->maxArgs = nargs;
// Now remove all defined code from the _currentScript
if (removeCode)
for (int i = end - 1; i >= start; i--) {
_currentScript->remove_at(i);
}
return sym;
}

View File

@ -214,7 +214,7 @@ public:
void popContext();
Symbol *lookupVar(const char *name, bool create = true, bool putInGlobalList = false);
void cleanLocalVars();
Symbol *define(Common::String &s, int start, int nargs, Common::String *prefix = NULL, int end = -1);
Symbol *define(Common::String &s, int start, int nargs, Common::String *prefix = NULL, int end = -1, bool removeCode = true);
void processIf(int elselabel, int endlabel);
int alignTypes(Datum &d1, Datum &d2);