![]() |
|
HOWTO: Inter-plugin communication - 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: HOWTO: Inter-plugin communication (/thread-579.html) |
RE: HOWTO: Inter-plugin communication - NiLSPACE - 10-22-2013 (10-22-2013, 09:39 PM)bearbin Wrote: Easiest thing to do is probably concat the table and resurrect it on the other side, asumming it's full of strings or ints. It's full of functions
RE: HOWTO: Inter-plugin communication - bearbin - 10-22-2013 Oh, can't do that. Maybe store then as strings instead that can be called through IPC? RE: HOWTO: Inter-plugin communication - NiLSPACE - 10-22-2013 Well as you could maybe see in my Login plugin I can't do that. The functions in that table are specific for that table and can't be used outside it. You can compare it with a World or Player object. RE: HOWTO: Inter-plugin communication - FakeTruth - 10-22-2013 You cannot pass functions as it is right now RE: HOWTO: Inter-plugin communication - NiLSPACE - 10-22-2013 Yea I know, but you can pass userdata. And with my 'Login' plugin I have a table with functions in it where I keep my passwords. So I was wondering if I could somehow convert the table to userdata so it could be passable. This is the code: function LoadPasswords(Path)
local File = io.open(Path)
local Table = {}
if File then
for I in File:lines() do
local Split = StringSplit(I, ";")
Table[Split[1]] = Split[2]
end
File:close()
else
local File = io.open(Path, "w")
File:write()
File:close()
end
local Object = {}
function Object:GetPassFromPlayer(PlayerName)
if Table[PlayerName] ~= nil then
return true, Table[PlayerName]
end
return false
end
function Object:AddPass(PlayerName, Password)
if Table[PlayerName] == nil then
Table[PlayerName] = md5(Password)
return true
end
return false
end
function Object:RemovePlayer(PlayerName)
if Table[PlayerName] ~= nil then
Table[PlayerName] = nil
return true
end
return false
end
function Object:ChangePass(PlayerName, NewPassword)
if Table[PlayerName] ~= nil then
Table[PlayerName] = md5(NewPassword)
return true
end
return false
end
function Object:PlayerExists(PlayerName)
if Table[PlayerName] ~= nil then
return true
end
return false
end
function Object:ReturnTable()
return Table
end
function Object:Save()
local File = io.open(Path, "w")
for I, k in pairs(Table) do
File:write(I .. ";" .. k .. "\n")
end
File:close()
end
return Object
end
RE: HOWTO: Inter-plugin communication - FakeTruth - 10-23-2013 Yeah that's not gonna work ![]() You will have to make those Object functions global so other plugins can access them. Use some kind of key to identify the Objects, this could be the player name and pass that key to the functions. You will need to keep track of the Objects in your plugin yourself. I suppose you would like to call LoadPasswords() from another plugin? And then the other plugin will receive this Object containing functions. To still have the same functionality without passing tables around you need to restructure some things.
local AllLoadedStuff = {}
function LoadPasswords(path)
-- ... do stuff
-- Create a unique key
AllLoadedStuff[Key] = WhateverYouLoaded
return Key
end
-- Former Object:GetPassFromPlayer
function GetPassFromPlayer(Key, PlayerName)
local Object = AllLoadedStuff[Key];
-- Still use Object functions
return Object:GetPassFromPlayer(PlayerName)
-- Or copy everything in here
if Table[PlayerName] ~= nil then
return true, Table[PlayerName]
end
return false
end
Not sure if it's clear what I mean?
RE: HOWTO: Inter-plugin communication - NiLSPACE - 10-23-2013 Yes I think I know what you mean, but isn't there a way to create a userdata object? just like the cPlayer or cWorld object since that can be passed. RE: HOWTO: Inter-plugin communication - FakeTruth - 10-23-2013 In C++, yes. But that userdata is always shared data and therefore not thread safe. Not to mention that you still cannot store Lua functions in them, you would still have the same limitations as when you would simply send your table as a string like bearbin suggests. RE: HOWTO: Inter-plugin communication - xoft - 10-23-2013 Anyway, why would you want to make so much communication? It's inherently slow, so you can't be doing much through it. RE: HOWTO: Inter-plugin communication - bearbin - 10-23-2013 I thought it wasn't _that_ slow. I thought we benchmarked it to do 10000 things per tick on debug and it was fine? |