diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp index 7fdd667b97b..14b0468cbc5 100644 --- a/engines/director/lingo/lingo-builtins.cpp +++ b/engines/director/lingo/lingo-builtins.cpp @@ -502,13 +502,50 @@ void LB::b_charToNum(int nargs) { } void LB::b_delete(int nargs) { - Datum d = g_lingo->pop(); + Datum d = g_lingo->pop(false); - Datum res(d.asInt()); + Datum field; + int start, end; + if (d.type == FIELDREF || d.type == VAR) { + field = d; + start = 0; + end = -1; + } else if (d.type == CHUNKREF) { + TYPECHECK2(d.u.cref->source, FIELDREF, VAR); + field = d.u.cref->source; + start = d.u.cref->start; + end = d.u.cref->end; + } else { + warning("b_delete: bad field type: %s", d.type2str()); + return; + } - warning("STUB: b_delete"); + if (start < 0) + return; - g_lingo->push(res); + Common::String text = g_lingo->varFetch(field).asString(); + if (d.type == CHUNKREF) { + switch (d.u.cref->type) { + case kChunkChar: + break; + case kChunkWord: + while (end < (int)text.size() && Common::isSpace(text[end])) + end++; + break; + case kChunkItem: + case kChunkLine: + // last char of the first portion is the delimiter. skip it. + if (start > 0) + start--; + break; + } + } + + Common::String res = text.substr(0, start) + text.substr(end); + Datum s; + s.u.s = new Common::String(res); + s.type = STRING; + g_lingo->varAssign(field, s); } void LB::b_hilite(int nargs) { diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp index db32e786e46..a926583a39b 100644 --- a/engines/director/lingo/lingo-bytecode.cpp +++ b/engines/director/lingo/lingo-bytecode.cpp @@ -372,9 +372,12 @@ void LC::cb_unk2() { } void LC::cb_delete() { - g_lingo->readInt(); - g_lingo->printSTUBWithArglist("cb_delete", 9); - g_lingo->dropStack(9); + int varType = g_lingo->readInt(); + Datum varID = g_lingo->pop(); + Datum var = g_lingo->findVarV4(varType, varID); + Datum chunkRef = readChunkRef(var); + g_lingo->push(chunkRef); + LB::b_delete(1); } void LC::cb_field() {