Maxhrk said:
Hello, sorry to animate this threat to life but i have some few questions regards, specifically, PPI.
I want to know how PPI work, so far, i have learned about ppi.load, ppi.expose that are public function(I may miss some of them, the public functions.
in any case, mind give me more examples how ppi can be used with expose, load, etc.
Thanks! :D
The actual PPI thread is over here [1], this one's for the mini-library that makes structured plugins easier to make.
Here's an example from a post I made in that thread, on page 10:
local PPI = require("ppi")
function OnRoomBrief(msg, content)
-- called by the ATCP plugin
end
-- (ID, on_success, on_failure)
PPI.OnLoad("7c08e2961c5e20e5bdbf7fc5", function(atcp)
atcp.Listen("Room.Brief", OnRoomBrief)
end, function(reason)
-- Optional callback for if it's not available.
end)
function OnPluginListChanged()
PPI.Refresh()
end
This is pretty much all you need to do on the client side. You need to call PPI.Refresh() in OnPluginListChanged() so the library can track installed plugin. To tell PPI that you want to communicate with a specific plugin, you pass it that plugin's ID in OnLoad, as well as two functions. One function is called when the interface is successfully set up, and it receives the interface itself. The other is optional, called when the interface wasn't loaded and receiving the reason as a string.
Your OnLoad callbacks are called whenever the target plugin is reloaded, too. You primarily just want to use it to initialize. In this case, I'm telling my ATCP plugin what messages I'm listening for. You can also store the interface somewhere else so you can access it later; I don't expect you to do -everything- you need in the initialization callback.
Also, notice that I'm passing a function to the other plugin! This isn't normally possible between plugins, and in fact this involves a little trickery to do. This is important though, because that function will be called when that ATCP message is received. I don't have to do anything else, because PPI and the ATCP plugin do the rest.
On the "service" side (i.e. the ATCP plugin here), you need to use PPI.Expose to register functions that clients can call.
local PPI = require("ppi")
local PPI = require("libraries.ppi")
PPI.Expose("Listen",
function(message, callback)
-- stuff here
end
)
PPI handles passing the parameters and return values back and forth, so you can pretty much treat it as a normal function.
Beyond this extra scaffolding, you write the rest of your plugin pretty normally.
Maxhrk said: EDIT: my goal with this PPi is that i want to listen to any plugins that might want to tell my GMCP plugin like, "hello! i am mapper, i want to hear from you regards room.list and whatever the info it may have, bahbah. bah. THANKS! bye!" so I can register the mapper in list and when i got the GMCP message and if it contains room.info, so I can look up in the table to see which plugin want this kind of information. Then, to give that information to the plugin subscriber(s)
That what i want to know how to use PPI with that I has in mind. Thanks again!
Take a look at my ATCP plugin and how it uses PPI. You'll probably have to very similar things for GMCP. (The main script file is in ATCP.plugin/scripts/main.lua)
I wrote PPI specifically for this kind of thing. ;)
[1] http://www.gammon.com.au/forum/?id=9970&page=999 (the PPI thread) |