Plugin Communication

Posted by Sikai on Mon 12 Oct 2009 05:09 AM — 6 posts, 19,958 views.

#0
Basically here's the problem:
I need a plugin to get_a_world, draw a miniwindow and add a hotspot in the new window.

I can get the plugin to open the window and draw a miniwindow in it, however the hotspot callbacks are never called.


	local mapget = get_a_world("MapGet", "Aardwolf")
	if mapget then
		win = GetPluginID()
		local w_width = mapget.GetInfo(264)
		local w_height = mapget.GetInfo(263)
		Note(w_width)
		Note(w_height)
		mapget:WindowCreate(win, 0, 0, w_width, w_height, 0, 0, ColourNameToRGB("white"))
		mapget:WindowLoadImage(win, "im", location)
		mapget:WindowDrawImage(win, "im", 0,0,w_width,w_height, 2,0,0,0,0)
		mapget:WindowAddHotspot(win, "hs1", 0, 0, w_width,w_height, "", "", "", "", "mouseup",
								"Zoom", 10, 0)
		mapget:WindowShow(win, True)
   


I tried installing a helper plugin in the new world window which would handle the drawing and adding a hotspot, the idea being perhaps the hotspot callback function was out of scope. But doing it that way, I can't get the main plugin in the main window to communicate with the helper plugin in the other world.

What to do????
Australia Forum Administrator #1
Personally I am moving away from multiple, dummy, worlds in favour of doing everything in the main world (which can be a large window) rather than having to carefully position multiple world windows and handle the focus and related problems.

Hotspot callbacks will need to be added in the plugin that implements the callback. Thus, if you have a helper plugin, that helper plugin needs to be the one that installs the hotspot.
USA #2
Interesting problem. How were your plugins communicating initially? I imagine a combination of GetPluginVariable() and CallPlugin(). I can't tell entirely from this code snippet, but have you tried using GetWorldById(<other world ID>), and using the returned world to CallPlugin() across? Like:


w = GetPluginById("4a6110b2c72e8b8101abb263")
w.CallPlugin("775d4e95358a9244aa4fbebe", "function_to_call", "string parameter")



EDIT: In light of Nick's post, you might want to try sending a string-dumped Lua function through to the other plugin. Something like this:


hotspot_callback = function()
  Note("Called!")
end

local dumped_func = utils.base64encode(string.dump(hotspot_callback))

w = GetPluginById("4a6110b2c72e8b8101abb263")
w.CallPlugin("775d4e95358a9244aa4fbebe", "function_to_call", dumped_func)


On the other side, you'd use this to unserialize the function:


hotspot_callback = loadstring(utils.base65decode(param))()


That way, if it's the other plugin that's creating the hotspot, it'll also have the function, even though it came from another plugin. (Still think function serialization isn't useful, Nick? ;) )
Amended on Mon 12 Oct 2009 06:43 AM by Twisol
Australia Forum Administrator #3
Can't you just send the function source?
USA #4
Now you mention it, yes, you could; that's how my LoadPPI file worked. It sort of depends on what you want, I guess.
#5
I ended up taking the easy way out and had the initial plugin Execute a command on the client window, then in the client window an alias captures the command and sends it to the helper plugin