cPlugin_NewLua: why is it Lua-exported?
#12
Quote:The old plugins are ones that are set in the settings.ini by Plugin=<name>, rather than NewPlugin=<name>. They have a completely different architecture, from what I can gather.
O, RLY?)

Take a look at the Area plugin. It's an old-style plugin:
Code:
-- create new unique global
AreaPlugin = {}
AreaPlugin.__index = AreaPlugin

-- some configurations
AreaPlugin.PLUGIN_NAME = "Area Plugin"
AreaPlugin.PLUGIN_VERSION = 3
AreaPlugin.PLUGIN_MSG_PREFIX = cChatColor.LightBlue .. "* "

-- some plugin locals
AreaPlugin.Players = {}
AreaPlugin.PlayerIdx = 0
..... BLAH-BLAH-BLAH ....
Get rid of that part:
Code:
function AreaPlugin:new()
    local t = {}
    setmetatable(t, AreaPlugin)
    local w = Lua__cPlugin:new()
    tolua.setpeer(w, t)
    w:tolua__set_instance(w)
    return w
end
Fix prefixes:
Code:
function AreaPlugin:OnDisable()
  -- write back file
  AreaPlugin.IniFile:WriteFile()
  
  Log( self:GetName() .. " v." .. self:GetVersion() .. " is shutting down..." )
end
One should also replace "self" with custom table variable that has Plugin as it's value (look at Core, PLUGIN variable)
Code:
function OnDisable()
  -- write back file
  AreaPlugin.IniFile:WriteFile()
  
  Log( PLUGIN:GetName() .. " v." .. PLUGIN:GetVersion() .. " is shutting down..." )
end
Remove that part too, as it will be done automatically:
Code:
-- create new instance of plugin
cRoot:Get():GetPluginManager():AddPlugin( AreaPlugin:new() )
Change GetWorld() (if it has no parameters) to GetDefaultWorld() and...
TADA! Now you have new-styled Area plugin.

Quote:I don't even think all the new hooks work in them.
Fair point. But when old-style plugins were written those hooks didn't even exist.

Of course, if plugin is REALLY old and don't have command bindings (it parses chat messages manually) you might want to update it to use commands (so commands would be visible with /help core plugin command!). But that's not requied for plugin to work.
Reply
Thanks given by:


Messages In This Thread
cPlugin_NewLua: why is it Lua-exported? - by xoft - 06-06-2012, 12:14 AM
RE: cPlugin_NewLua: why is it Lua-exported? - by Taugeshtu - 06-14-2012, 01:50 AM



Users browsing this thread: 2 Guest(s)