FAForever / fa

Lua code for FAF
221 stars 228 forks source link

commandmode.lua callback refactor #6200

Closed clyfordv closed 3 weeks ago

clyfordv commented 1 month ago

Issues:

Changes:

Notes:

Garanas commented 1 month ago

Great initiative 👍

Would it be interesting to add the remaining callbacks, but have them be empty? If anything else it would serve as documentation.

clyfordv commented 1 month ago

Yes that sounds like a splendid idea.

Garanas commented 1 month ago

One interesting problem is that you can no longer hook these functions 'the usual way'. You'd also need to overwrite the definition in OnCommandIssuedCallback in order for the hook it to work.

One solution to that is to put them in a separate file. What are your thoughts on this?

clyfordv commented 1 month ago

The hook would need to (with the current setup) look something like:

oldOnGuardIssued = OnGuardIssued

OnCommandIssuedCallback.OnGuardIssued = function(command)
    $NEW_LOGIC
    oldOnGuardIssued(command)
end

?

To me it isn't terribly different from hooking a class. I'm on the fence about putting it in a separate file for readability reasons, but the above doesn't seem so bad to me. We could also add a comment to the callback table indicating the proper hook format.

Garanas commented 1 month ago

You're right; maybe I am a bit too anxious about it. Could you add a bit of documentation on how to hook these functions? Then we can merge this in.