Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script termination option to 'Lua Scripts' floater #1152

Merged
merged 4 commits into from
Apr 12, 2024

Conversation

maxim-productengine
Copy link
Contributor

Add the way to terminate selected script in 'Lua Scripts' floater: call lluau::error when it's needed (but if the script is blocked in getNext(), close the queue first).

@nat-goodspeed
Copy link
Collaborator

Maxim, thanks, I'm looking, but it will probably be tomorrow before I can respond.

Copy link
Collaborator

@nat-goodspeed nat-goodspeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're still working on this, so maybe my comments have become moot. But there are a couple things in this PR as it now stands that I'd like to see changed.

@@ -429,6 +429,7 @@ void LLApp::setStatus(EAppStatus status)
statsd = LLSD::Integer(status);
}
LLEventPumps::instance().obtain("LLApp").post(llsd::map("status", statsd));
LLEventPumps::instance().obtain("LLLua").post(llsd::map("status", "close_all"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting to look at this made me realize that I want to write a mechanism to request termination of an arbitrary C++ coroutine, not just one running Lua.

Quick sketch: I want to add a new data structure indicating a terminate request to LLCoros, plus an LLEventStream. The LLCoros constructor will cause its "LLCoros" LLEventPump to listen on "LLApp" so that events posted to "LLApp" will be passed along on "LLCoros".

I'll make LLCoros::checkStop() check for a termination request for this specific coroutine, in addition to checking for general viewer shutdown.

There are a few different places where a coroutine listens on "LLApp" for viewer shutdown events. I'll change those to listen on "LLCoros" instead.

The point of the distinction is that then I can resurrect the commented-out LLCoros::kill() method to set a termination request for the subject coroutine. But in case the subject coroutine is waiting for an event, kill() will also post a heads-up event on "LLCoros" to cause each waiting coroutine to check for a termination request. I'd rather not post that event on the more generic "LLApp" event pump.

So what I think I'd like to do is to accept this PR (once you're done; I realize you're still refining it) and then recast it to use the termination mechanism described above. I'll probably remove this second post() call at that time.

Copy link
Contributor Author

@maxim-productengine maxim-productengine Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I missed the ability to terminate coroutine once or twice in the past when working on maint bugs. So, I'm for it.

I'm not planning any more changes for now for this PR. (there will be some changes related to script termination as you know, but I'll create separate pr)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry to say I overlooked an important point. I can indeed introduce a flag for the next time a given coroutine wakes up and calls LLCoros::checkStop(), but I can't cause that coroutine to wake up and check it. An LLEventStream listener runs on the coroutine calling post(). An exception thrown by such a listener will propagate through the post() call.

The Boost.Fiber library we use does not provide a way to force an exception onto a suspended fiber -- although tantalizingly, the Boost.Context library on which it's based provides a mechanism that could support that. At present, the best we can do is to wait for the subject coroutine to call checkStop().

indra/llcommon/lualistener.cpp Outdated Show resolved Hide resolved
indra/newview/llfloaterluascripts.cpp Outdated Show resolved Hide resolved
indra/newview/llluamanager.cpp Show resolved Hide resolved
indra/newview/llluamanager.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@nat-goodspeed nat-goodspeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Maxim!

@nat-goodspeed nat-goodspeed merged commit 3a1a3bb into release/luau-scripting Apr 12, 2024
11 checks passed
@nat-goodspeed nat-goodspeed deleted the lua-terminate-script branch April 12, 2024 20:40
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants