Commit graph

1 commit

Author SHA1 Message Date
Vadim Peretokin
87fe7fa080
fix: replacing a temp item's script no longer keeps running the old function callback (#9496)
#### Brief overview of PR changes/additions
- `setScript()` on a temp trigger/timer/alias/key that was created with
a function callback (`tempTrigger`/`tempTimer`/`tempAlias`/`tempKey`
with a function argument) now releases that callback: it clears the
registered-function flag and removes the function from the Lua registry
before switching to the new script string.
- Without this, such an item would keep executing the stale callback so
the new script never runs (triggers/aliases/keys), and the old function
would never be freed from the Lua registry (all four types).
- Adds a functional test (`SetScriptCallbackTest`) covering all four
types, plus the empty-script and non-callback (no-op) cases.

#### Motivation for adding to Mudlet
Keeps a temp item's execution state and cleanup consistent when its
script is replaced. No current scripting API or editor path replaces a
temp item's script, so this closes the gap before anything can reach it.

#### Other info (issues closed, discussion etc)
A temp item's function callback is stored in the Lua registry keyed by
the item pointer; `setScript()` previously left both that entry and the
`mRegisteredAnonymousLuaFunction` flag untouched. Because each
destructor picks its cleanup branch from `mScript.isEmpty()`, once a
non-empty script was set the pointer-keyed entry was orphaned. `TAction`
(buttons) has no function-callback path and is unaffected. Behaviour of
every existing caller is unchanged, covered by the no-op guard case.

**Test case:**
```
run: flock /tmp/mudlet-functional-tests.lock ctest --output-on-failure -R SetScriptCallbackTest
```
All 6 sub-tests pass with the fix; 5 of 6 fail against the pre-fix
baseline (the non-callback no-op case passes by design, guarding that
existing behaviour is unchanged). Related suites
`EnableDisableByNameTest` and `TFeedTriggersRecursionTest` still pass.

Assisted-by: Claude:claude-opus-4-8
2026-07-30 08:35:03 +02:00