summaryrefslogtreecommitdiffstats
path: root/Server/Plugins
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-05-31 01:01:55 +0200
committerworktycho <work.tycho@gmail.com>2016-05-31 01:01:55 +0200
commit5618e453e60219c10ac4d811dc44926ecee7c370 (patch)
tree3d618336ec689295e950a4177b32d8e8cba8445e /Server/Plugins
parentMerge pull request #3078 from cuberite/AddTerrainGenDocs (diff)
downloadcuberite-5618e453e60219c10ac4d811dc44926ecee7c370.tar
cuberite-5618e453e60219c10ac4d811dc44926ecee7c370.tar.gz
cuberite-5618e453e60219c10ac4d811dc44926ecee7c370.tar.bz2
cuberite-5618e453e60219c10ac4d811dc44926ecee7c370.tar.lz
cuberite-5618e453e60219c10ac4d811dc44926ecee7c370.tar.xz
cuberite-5618e453e60219c10ac4d811dc44926ecee7c370.tar.zst
cuberite-5618e453e60219c10ac4d811dc44926ecee7c370.zip
Diffstat (limited to 'Server/Plugins')
-rw-r--r--Server/Plugins/APIDump/Classes/Plugins.lua2
-rw-r--r--Server/Plugins/Debuggers/Debuggers.lua57
-rw-r--r--Server/Plugins/Debuggers/Info.lua6
3 files changed, 64 insertions, 1 deletions
diff --git a/Server/Plugins/APIDump/Classes/Plugins.lua b/Server/Plugins/APIDump/Classes/Plugins.lua
index e053c57e2..d5ac5fdbd 100644
--- a/Server/Plugins/APIDump/Classes/Plugins.lua
+++ b/Server/Plugins/APIDump/Classes/Plugins.lua
@@ -65,7 +65,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
{ Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "(STATIC) Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error. The callback uses the following signature: <pre class=\"prettyprint lang-lua\">function(Split)</pre> The Split parameter contains an array-table of the words that the admin has typed. If the callback returns true, the command is assumed to have executed successfully; in all other cases the server issues a warning to the console that the command is unknown (this is so that subcommands can be implemented)." },
{ Params = "Command, Callback, HelpString", Return = "[bool]", Notes = "Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command. Returns true if successful, logs to console and returns no value on error. The callback uses the following signature: <pre class=\"prettyprint lang-lua\">function(Split)</pre> The Split parameter contains an array-table of the words that the admin has typed. If the callback returns true, the command is assumed to have executed successfully; in all other cases the server issues a warning to the console that the command is unknown (this is so that subcommands can be implemented)." },
},
- CallPlugin = { Params = "PluginName, FunctionName, [FunctionArgs...]", Return = "[FunctionRets]", Notes = "(STATIC) Calls the specified function in the specified plugin, passing all the given arguments to it. If it succeeds, it returns all the values returned by that function. If it fails, returns no value at all. Note that only strings, numbers, bools, nils and classes can be used for parameters and return values; tables and functions cannot be copied across plugins." },
+ CallPlugin = { Params = "PluginName, FunctionName, [FunctionArgs...]", Return = "[FunctionRets]", Notes = "(STATIC) Calls the specified function in the specified plugin, passing all the given arguments to it. If it succeeds, it returns all the values returned by that function. If it fails, returns no value at all. Note that only strings, numbers, bools, nils, API classes and simple tables can be used for parameters and return values; functions cannot be copied across plugins." },
DoWithPlugin = { Params = "PluginName, CallbackFn", Return = "bool", Notes = "(STATIC) Calls the CallbackFn for the specified plugin, if found. A plugin can be found even if it is currently unloaded, disabled or errored, the callback should check the plugin status. If the plugin is not found, this function returns false, otherwise it returns the bool value that the callback has returned. The CallbackFn has the following signature: <pre class=\"prettyprint lang-lua\">function ({{cPlugin|Plugin}})</pre>" },
ExecuteCommand = { Params = "{{cPlayer|Player}}, CommandStr", Return = "{{cPluginManager#CommandResult|CommandResult}}", Notes = "Executes the command as if given by the specified Player. Checks permissions." },
ExecuteConsoleCommand = { Params = "CommandStr", Return = "bool, string", Notes = "Executes the console command as if given by the admin on the console. If the command is successfully executed, returns true and the text that would be output to the console normally. On error it returns false and an error message." },
diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua
index ae06b4fc9..aa2205368 100644
--- a/Server/Plugins/Debuggers/Debuggers.lua
+++ b/Server/Plugins/Debuggers/Debuggers.lua
@@ -1921,6 +1921,63 @@ end
+function HandleConsoleTestCall(a_Split, a_EntireCmd)
+ LOG("Testing inter-plugin calls")
+ LOG("Note: These will fail if the Core plugin is not enabled")
+
+ -- Test calling the HandleConsoleWeather handler:
+ local pm = cPluginManager
+ LOG("Calling Core's HandleConsoleWeather")
+ local isSuccess = pm:CallPlugin("Core", "HandleConsoleWeather",
+ {
+ "/weather",
+ "rain",
+ }
+ )
+ if (type(isSuccess) == "boolean") then
+ LOG("Success")
+ else
+ LOG("FAILED")
+ end
+
+ -- Test injecting some code:
+ LOG("Injecting code into the Core plugin")
+ isSuccess = pm:CallPlugin("Core", "dofile", pm:GetCurrentPlugin():GetLocalFolder() .. "/Inject.lua")
+ if (type(isSuccess) == "boolean") then
+ LOG("Success")
+ else
+ LOG("FAILED")
+ end
+
+ -- Test the full capabilities of the table-passing API, using the injected function:
+ LOG("Calling injected code")
+ isSuccess = pm:CallPlugin("Core", "injectedPrintParams",
+ {
+ "test",
+ nil,
+ {
+ "test",
+ "test"
+ },
+ [10] = "test",
+ ["test"] = "test",
+ [{"test"}] = "test",
+ [true] = "test",
+ }
+ )
+ if (type(isSuccess) == "boolean") then
+ LOG("Success")
+ else
+ LOG("FAILED")
+ end
+
+ return true
+end
+
+
+
+
+
function HandleConsoleTestJson(a_Split, a_EntireCmd)
LOG("Testing Json parsing...")
local t1 = cJson:Parse([[{"a": 1, "b": "2", "c": [3, "4", 5] }]])
diff --git a/Server/Plugins/Debuggers/Info.lua b/Server/Plugins/Debuggers/Info.lua
index fa85f0532..af3461342 100644
--- a/Server/Plugins/Debuggers/Info.lua
+++ b/Server/Plugins/Debuggers/Info.lua
@@ -254,6 +254,12 @@ g_PluginInfo =
HelpString = "Tests the world scheduling",
},
+ ["testcall"] =
+ {
+ Handler = HandleConsoleTestCall,
+ HelpString = "Tests inter-plugin calls with various values"
+ },
+
["testjson"] =
{
Handler = HandleConsoleTestJson,