Sorry, Nick, I missed this post on accident!
Nick Gammon said:
Fadedparadox said:
I'm not sure if this is what you mean, but this is a function I'd make accessible to additional plugins. ...
I think the whole idea of the PPI script is to make functions available to additional plugins. However what I think David and Twisol are arguing about is *passing* functions to plugins, as arguments to another function. Maybe I'm wrong about that.
I think it's more about passing functions in general; the pass-by-name suggestion David had unfortunately leaves out local functions, table functions, and closures. (Remember, all of these are represented by the same exact thing on the client side, it's the service that actually deals with the function call.)
Nick Gammon said: However as I mentioned a few pages back, which seems to have been ignored, another way of doing that is simply to have the battle plugin do a BroadcastPlugin call to tell *all* plugins (whether or not they are interested) that a battle has stopped or started.
I did give my reasons for why I thought this way was better. One is that it allows you to map incoming messages directly to functions, which does away with the if-else ladders to check ID and message. Another is, of course, the inherent rich type-passing that PPI implements.
Nick Gammon said:Or, using the notify paradigm, you can pass the *names* of callbacks, like this:
function OnStartBattle ()
DrawBorder "red"
end
function OnStopBattle ()
DrawBorder "black"
end
-- call other plugin
ppi.Expose ("OnStartBattle")
ppi.Expose ("OnStopBattle")
battle_plugin.NotifyMeOfBattles ("OnStartBattle", "OnStopBattle")
This second technique first exposes the callback functions as ones available to be called back into this function, and then calls them by name (effectively, passing a string rather than a function). This is much more language-neutral.
I don't agree with that, to be honest. As I mentioned, passing by name requires that the function be available through _G, which locks out locals, closures, and table entries. Passing identifiers, or messages if you prefer to call them that, is in fact no different than BroadcastPlugin. As BroadcastPlugin and OnPluginBroadcast can do it in any language, it should be quite possible to implement in any language. Again, they aren't functions precisely, they are operations or messages.
Nick Gammon said: For that matter, BroadcastPlugin is language-neutral too.
Indeed - my PPI is quite similar except for the points I mentioned earlier in the post. |