Pretty plugins' functions calling - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: Pretty plugins' functions calling (/thread-3159.html) |
Pretty plugins' functions calling - TC1061 - 01-13-2018 This code will help to call functions of other plugins, like they're just libraries: PF={} local function hasPlugin(name) return cPluginManager:DoWithPlugin(name,function(Plugin) if Plugin:IsLoaded() then return true end return false end) end setmetatable(PF,{ __index=function(s,i) if not hasPlugin(i) then return nil end local pluginName=i return setmetatable({},{ __index=function(s,i) return function(...) cPluginManager:CallPlugin(pluginName,i,...) end end }) end })After adding this file in start of main file, all you need to call functions from other plugins is to call PF.PluginName.FunctionName(...), for example if you need to call a function named "CoolFunction" from plugin named "CoolPlugin", you can do this: Code: PF.CoolPlugin.CoolFunction(...) RE: Pretty plugins' functions calling - xoft - 01-14-2018 That is a nice hack, however I fear the performance will be terrible. RE: Pretty plugins' functions calling - TC1061 - 01-15-2018 I think perfomance will not be terrible. RE: Pretty plugins' functions calling - xoft - 01-15-2018 Compared to calling within a single plugin, it will be much worse. It's not about the Lua plumbing that you put together, it's about the actual inter-plugin call, which is pretty expensive - everything needs to get serialized, wrapped to C++, lock up a mutex for the other Lua state, find the function there, deserialize, call it, and then back the same way for the return values. Wth the mutex locking, it could even potentially create a deadlock. RE: Pretty plugins' functions calling - TC1061 - 01-15-2018 (01-15-2018, 01:19 PM)xoft Wrote: Compared to calling within a single plugin, it will be much worse. It's not about the Lua plumbing that you put together, it's about the actual inter-plugin call, which is pretty expensive - everything needs to get serialized, wrapped to C++, lock up a mutex for the other Lua state, find the function there, deserialize, call it, and then back the same way for the return values. Wth the mutex locking, it could even potentially create a deadlock. Ok, I know. But it will not much worse than just calling cPluginManager:CallPlugin, I think. This hack is just pretty plugins' function calling, not perfomance hack. |