Skip to content

Conversation

@Kipstz
Copy link
Contributor

@Kipstz Kipstz commented Dec 24, 2025

Adds a new 'onInitFinal' event that triggers after ALL Lua states have completed their 'onInit' handlers. This provides a reliable synchronization point for inter-state communication.

Use case: When multiple Lua states need to communicate (e.g., a centralized settings manager), they can now safely interact in onInitFinal knowing all states are fully initialized.

Closes #434

Adds a new 'onInitFinal' event that triggers after ALL Lua states
have completed their 'onInit' handlers. This provides a reliable
synchronization point for inter-state communication.

Use case: When multiple Lua states need to communicate (e.g., a
centralized settings manager), they can now safely interact in
onInitFinal knowing all states are fully initialized.

Closes BeamMP#434
auto DataPtr = std::make_unique<StateThreadData>(Name, StateId, *this);
mLuaStates[StateId] = std::move(DataPtr);
RegisterEvent("onInit", StateId, "onInit");
RegisterEvent("onInitFinal", StateId, "onInitFinal");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this line added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, to create the event?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is something up to the scripter so that the server doesn't implicitly call functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So why do it for “onInit”?

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 not entirely sure but it might be left over from the old scripting engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I know I just followed what had already been done at the time. I think the implementation is fine. If in the future we have to redo the entire basis of the system, I would do it again, but I find it a bit strange to do things halfway. We might as well redo everything properly in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the best solution would be to remove both of those calls and see if anything breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] onInitFinal - A event called when all lua states have been initialized

2 participants