Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ World/Plugin communication(and other assorted questions)

World/Plugin communication(and other assorted questions)

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Ircria   (24 posts)  Bio
Date Tue 28 Sep 2010 05:34 AM (UTC)
Message
Hello.

First of all, I'm sorry if this is in the wrong section.

Now, I've come across a few problems over the last couple days. Most of them, as the title may suggest, deal with communication between the plugins and the world, vice versa, and plugins with other plugins.

Do scripts(functions specifically) have the ability to be global so the content inside of them may be used by the plugins if in the world or another plugin, or vice versa when referring to the world?

Is it possible to get the client-stored variables(the ones returned by GetVariable) in plugins from the world, vice versa, and between different plugins?

Is there any way for plugins to advertise their existence to other plugins and send data to them?

For a couple non-plugin related questions...

Is it possible to save lua variables/tables in a format where they could be executed with dofile()?

Does anybody have anybody else have issues getting anything done through loadstring() to execute?


Thank you all for any help, and I'm sorry if this was a bit wordy.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Tue 28 Sep 2010 05:48 AM (UTC)
Message
Ircria said:
Do scripts(functions specifically) have the ability to be global so the content inside of them may be used by the plugins if in the world or another plugin, or vice versa when referring to the world?

You can use CallPlugin() to call a global function in another script's space. Since you can also call API functions it has access to, like SetVariable, this can be pretty useful in a lot of ways.

Ircria said:
Is it possible to get the client-stored variables(the ones returned by GetVariable) in plugins from the world, vice versa, and between different plugins?

Sadly, no. CallPlugin can't access the world space. You can hack around it by using aliases and Execute(), but it's not foolproof.

Ircria said:
Is there any way for plugins to advertise their existence to other plugins and send data to them?

I wrote a PPI module that makes this very easy. Nick created his own version which comes bundled with MUSHclient; I don't have any experience working with that version, but give it a try first. If it doesn't meet your expectations, mine might.

Ircria said:
Is it possible to save lua variables/tables in a format where they could be executed with dofile()?

Serialize to a string using serialize.save_simple in the serialize.lua module, then... uh, save to a file with a "return " prepended to the content. Then you can dofile() it and get the result back. But I'd rather save to a string and put it in a MUSHclient variable, which MUSHclient can save automatically if you have save_state="y" in the <plugin> tag, and then read it back in with loadstring("return " .. GetVariable("stuff"))().

Ircria said:
Does anybody have anybody else have issues getting anything done through loadstring() to execute?

Example? Make sure you call the result of loadstring() though; it returns a function containing the code you passed to it, instead of executing it right away.

Ircria said:
Thank you all for any help

Not a problem!

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 28 Sep 2010 06:17 AM (UTC)
Message
Ircria said:

Is it possible to get the client-stored variables(the ones returned by GetVariable) in plugins from the world, vice versa, and between different plugins?


I think Twisol misunderstood your question.

Yes, any client variables (the GetVariable ones) are readily accessible to all plugins.

Template:function=GetPluginVariable GetPluginVariable

The documentation for the GetPluginVariable script function is available online. It is also in the MUSHclient help file.



You can read any plugin's variable by knowing its plugin ID, and the main script space variables by using a plugin ID of an empty string.

Ircria said:

Is there any way for plugins to advertise their existence to other plugins and send data to them?


You can advertise your existence with BroadcastPlugin. You can also send data to them the same way. Also using CallPlugin you can send data to a particular plugin.

Template:function=BroadcastPlugin BroadcastPlugin

The documentation for the BroadcastPlugin script function is available online. It is also in the MUSHclient help file.



Template:function=CallPlugin CallPlugin

The documentation for the CallPlugin script function is available online. It is also in the MUSHclient help file.



Ircria said:

Is it possible to save lua variables/tables in a format where they could be executed with dofile()?

Does anybody have anybody else have issues getting anything done through loadstring() to execute?


As Twisol said, serializing is a popular and useful way of doing it. This is described here:

Template:post=4960 Please see the forum thread: http://gammon.com.au/forum/?id=4960.


There should be no issues with loadstring, providing you remember to execute the returned function. If nothing happens you need to put () at the end of the returned value.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Tue 28 Sep 2010 06:18 AM (UTC)
Message
Hmm, yeah, I think I did misunderstand your question. Sorry!

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Tue 28 Sep 2010 06:22 AM (UTC)
Message
For advertising, a useful callback function is OnPluginListChanged. This is documented here:

http://www.gammon.com.au/scripts/doc.php?general=plugin_callbacks

It's useful because you get called when the list of plugins changes (for example, one is added). Thus that is a useful time to advertise your existence.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


17,284 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.