Permalink
Browse files

Added UnloadPlugin script function

  • Loading branch information...
1 parent f33af34 commit 5072cd1e2643677d863a2fb54932a168c4fe1813 @nickgammon committed May 8, 2011
Showing with 70 additions and 8 deletions.
  1. +1 −0 doc.cpp
  2. +1 −0 doc.h
  3. +1 −0 mushclient.cnt
  4. +9 −8 mushclient.odl
  5. +1 −0 scripting/functionlist.cpp
  6. +15 −0 scripting/lua_methods.cpp
  7. +42 −0 scripting/methods/methods_plugins.cpp
View
@@ -609,6 +609,7 @@ BEGIN_DISPATCH_MAP(CMUSHclientDoc, CDocument)
DISP_FUNCTION(CMUSHclientDoc, "Menu", Menu, VT_BSTR, VTS_BSTR VTS_BSTR)
DISP_FUNCTION(CMUSHclientDoc, "DatabaseGetField", DatabaseGetField, VT_VARIANT, VTS_BSTR VTS_BSTR)
DISP_FUNCTION(CMUSHclientDoc, "WindowSetZOrder", WindowSetZOrder, VT_I4, VTS_BSTR VTS_I4)
+ DISP_FUNCTION(CMUSHclientDoc, "UnloadPlugin", UnloadPlugin, VT_I4, VTS_BSTR)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "NormalColour", GetNormalColour, SetNormalColour, VT_I4, VTS_I2)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "BoldColour", GetBoldColour, SetBoldColour, VT_I4, VTS_I2)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "CustomColourText", GetCustomColourText, SetCustomColourText, VT_I4, VTS_I2)
View
@@ -2736,6 +2736,7 @@ class CMUSHclientDoc : public CDocument
afx_msg BSTR Menu(LPCTSTR Items, LPCTSTR Default);
afx_msg VARIANT DatabaseGetField(LPCTSTR Name, LPCTSTR Sql);
afx_msg long WindowSetZOrder(LPCTSTR Name, long Order);
+ afx_msg long UnloadPlugin(LPCTSTR PluginID);
afx_msg long GetNormalColour(short WhichColour);
afx_msg void SetNormalColour(short WhichColour, long nNewValue);
afx_msg long GetBoldColour(short WhichColour);
View
@@ -517,6 +517,7 @@
3 UdpListen=FNC_UdpListen
3 UdpPortList=FNC_UdpPortList
3 UdpSend=FNC_UdpSend
+3 UnloadPlugin=FNC_UnloadPlugin
3 Version=FNC_Version
3 WindowAddHotspot=FNC_WindowAddHotspot
3 WindowArc=FNC_WindowArc
View
@@ -70,14 +70,14 @@ library MUSHclient
[id(44)] long SetCommand(BSTR Message);
[id(45)] BSTR GetNotes();
[id(46)] void SetNotes(BSTR Message);
- [id(407), propget] long NormalColour(short WhichColour);
- [id(407), propput] void NormalColour(short WhichColour, long nNewValue);
- [id(408), propget] long BoldColour(short WhichColour);
- [id(408), propput] void BoldColour(short WhichColour, long nNewValue);
- [id(409), propget] long CustomColourText(short WhichColour);
- [id(409), propput] void CustomColourText(short WhichColour, long nNewValue);
- [id(410), propget] long CustomColourBackground(short WhichColour);
- [id(410), propput] void CustomColourBackground(short WhichColour, long nNewValue);
+ [id(408), propget] long NormalColour(short WhichColour);
+ [id(408), propput] void NormalColour(short WhichColour, long nNewValue);
+ [id(409), propget] long BoldColour(short WhichColour);
+ [id(409), propput] void BoldColour(short WhichColour, long nNewValue);
+ [id(410), propget] long CustomColourText(short WhichColour);
+ [id(410), propput] void CustomColourText(short WhichColour, long nNewValue);
+ [id(411), propget] long CustomColourBackground(short WhichColour);
+ [id(411), propput] void CustomColourBackground(short WhichColour, long nNewValue);
[id(47)] void Redraw();
[id(48)] long ResetTimer(BSTR TimerName);
[id(49)] void SetOutputFont(BSTR FontName, short PointSize);
@@ -438,6 +438,7 @@ library MUSHclient
[id(404)] BSTR Menu(BSTR Items, BSTR Default);
[id(405)] VARIANT DatabaseGetField(BSTR Name, BSTR Sql);
[id(406)] long WindowSetZOrder(BSTR Name, long Order);
+ [id(407)] long UnloadPlugin(BSTR PluginID);
//}}AFX_ODL_METHOD
};
@@ -376,6 +376,7 @@ tInternalFunctionsTable InternalFunctionsTable [] = {
{ "UdpListen" , "( IP , Port , Script )" } ,
{ "UdpPortList" , "( )" } ,
{ "UdpSend" , "( IP , Port , Text )" } ,
+{ "UnloadPlugin" , "( PluginID )" },
{ "Version" , "( )" } ,
{ "WindowAddHotspot" , "( WindowName , HotspotId , Left , Top , Right , Bottom , MouseOver , CancelMouseOver , MouseDown , CancelMouseDown , MouseUp , TooltipText , Cursor , Flags )" } ,
{ "WindowArc" , "( WindowName , Left , Top , Right , Bottom , x1 , y1 , x2 , y2 , PenColour , PenStyle , PenWidth )" } ,
@@ -5736,6 +5736,20 @@ static int L_UdpSend (lua_State *L)
return 1; // number of result fields
} // end of L_UdpSend
+
+//----------------------------------------
+// world.UnloadPlugin
+//----------------------------------------
+static int L_UnloadPlugin (lua_State *L)
+ {
+ CMUSHclientDoc *pDoc = doc (L);
+ lua_pushnumber (L, pDoc->UnloadPlugin (
+ my_checkstring (L, 1) // Plugin ID
+ ));
+ return 1; // number of result fields
+ } // end of L_UnloadPlugin
+
+
//----------------------------------------
// world.Version
//----------------------------------------
@@ -6974,6 +6988,7 @@ static const struct luaL_Reg worldlib [] =
{"UdpListen", L_UdpListen},
{"UdpPortList", L_UdpPortList},
{"UdpSend", L_UdpSend},
+ {"UnloadPlugin", L_UnloadPlugin},
{"Version", L_Version},
{"WindowAddHotspot", L_WindowAddHotspot},
{"WindowArc", L_WindowArc},
@@ -31,6 +31,7 @@
// LoadPlugin
// PluginSupports
// ReloadPlugin
+// UnloadPlugin
// SaveState
// gets our own plugin id
@@ -610,3 +611,44 @@ long CMUSHclientDoc::BroadcastPlugin(long Message, LPCTSTR Text)
return iCount;
} // end of CMUSHclientDoc::BroadcastPlugin
+
+
+long CMUSHclientDoc::UnloadPlugin(LPCTSTR PluginID)
+{
+// first, find plugin by ID
+CPlugin * pPlugin = GetPlugin (PluginID);
+
+ // if not found, try to find by name
+ if (pPlugin == NULL && strlen (PluginID) > 0)
+ {
+ PluginListIterator pit = find_if (m_PluginList.begin (),
+ m_PluginList.end (),
+ bind2nd (compare_plugin_name (), PluginID));
+ if (pit != m_PluginList.end ())
+ pPlugin = *pit;
+
+ }
+
+ if (pPlugin == NULL)
+ return eNoSuchPlugin;
+
+ // cannot delete ourselves
+ if (pPlugin == m_CurrentPlugin)
+ return eBadParameter;
+
+ PluginListIterator pit = find (m_PluginList.begin (),
+ m_PluginList.end (),
+ pPlugin);
+
+ if (pit == m_PluginList.end () )
+ return eNoSuchPlugin;
+
+ m_PluginList.erase (pit); // remove from list
+ delete pPlugin; // delete the plugin
+
+ PluginListChanged ();
+ SetModifiedFlag (TRUE); // document has now changed
+
+ return eOK;
+
+ }

0 comments on commit 5072cd1

Please sign in to comment.