Skip to content

Commit

Permalink
Added UnloadPlugin script function
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed May 8, 2011
1 parent f33af34 commit 5072cd1
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc.cpp
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions doc.h
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions mushclient.cnt
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions mushclient.odl
Expand Up @@ -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);
Expand Down Expand Up @@ -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

};
Expand Down
1 change: 1 addition & 0 deletions scripting/functionlist.cpp
Expand Up @@ -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 )" } ,
Expand Down
15 changes: 15 additions & 0 deletions scripting/lua_methods.cpp
Expand Up @@ -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
//----------------------------------------
Expand Down Expand Up @@ -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},
Expand Down
42 changes: 42 additions & 0 deletions scripting/methods/methods_plugins.cpp
Expand Up @@ -31,6 +31,7 @@
// LoadPlugin
// PluginSupports
// ReloadPlugin
// UnloadPlugin
// SaveState

// gets our own plugin id
Expand Down Expand Up @@ -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.