From 2a018cfa49e0a85d2984f6daf6ee3c3372bdafda Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 21 Jan 2014 22:59:08 +0100 Subject: Implemented cPluginManager:CallPlugin() API. This function supersedes cPlugin:Call(), is safer to use in regards to multithreading and once again removes the need for the cPlugin class being exported at all. --- MCServer/Plugins/Debuggers/Debuggers.lua | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'MCServer/Plugins/Debuggers/Debuggers.lua') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 2d2d2736d..624261cbf 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -64,7 +64,8 @@ function Initialize(Plugin) -- TestBlockAreas(); -- TestSQLiteBindings(); -- TestExpatBindings(); - + TestPluginCalls(); + return true end; @@ -72,6 +73,38 @@ end; +function TestPluginCalls() + -- In order to test the inter-plugin communication, we're going to call Core's ReturnColorFromChar() function + -- It is a rather simple function that doesn't need any tables as its params and returns a value, too + -- Note the signature: function ReturnColorFromChar( Split, char ) ... return cChatColog.Gray ... end + -- The Split parameter should be a table, but it is not used in that function anyway, + -- so we can get away with passing nil to it. + + -- Use the old, deprecated and unsafe method: + local Core = cPluginManager:Get():GetPlugin("Core") + if (Core ~= nil) then + LOGINFO("Calling Core::ReturnColorFromChar() the old-fashioned way...") + local Gray = Core:Call("ReturnColorFromChar", nil, "8") + if (Gray ~= cChatColor.Gray) then + LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "")) + else + LOGINFO("Call succeeded") + end + end + + -- Use the new method: + LOGINFO("Calling Core::ReturnColorFromChar() the recommended way...") + local Gray = cPluginManager:CallPlugin("Core", "ReturnColorFromChar", nil, "8") + if (Gray ~= cChatColor.Gray) then + LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "")) + else + LOGINFO("Call succeeded") + end +end + + + + function TestBlockAreas() LOG("Testing block areas..."); -- cgit v1.2.3