DIRECTOR: LINGO: Add guardrail for implicit factory calls

It is possible to have a script which looks like a factory,
but has normal functions in it also. Calling those normal functions
should not apply the bodge which injects the me object as argument 1.
This commit is contained in:
Scott Percival 2024-05-02 22:42:03 +08:00 committed by Eugene Sandulenko
parent 64cc8adb3c
commit 10ac6b61d8

View File

@ -1554,10 +1554,13 @@ void LC::call(const Common::String &name, int nargs, bool allowRetVal) {
if (g_lingo->_state->me.type == OBJECT) {
AbstractObject *target = g_lingo->_state->me.u.obj;
funcSym = target->getMethod(name);
if (funcSym.type != VOIDSYM) {
if (name.hasPrefixIgnoreCase("m") && funcSym.type != VOIDSYM) {
if (nargs == 0) {
debugC(3, kDebugLingoExec, "Factory method call detected with missing first arg");
g_lingo->_stack.push_back(Datum());
nargs = 1;
} else {
debugC(3, kDebugLingoExec, "Factory method call detected with invalid first arg: <%s>", g_lingo->_stack[g_lingo->_stack.size() - nargs].asString(true).c_str());
}
g_lingo->_stack[g_lingo->_stack.size() - nargs] = funcSym.target; // Set first arg to target
call(funcSym, nargs, allowRetVal);