Finally working on this again
This commit is contained in:
parent
bfd0821776
commit
ee5df92dbc
@ -1,7 +1,4 @@
|
|||||||
plugin.init("PluginEpic") -- creates a folder that the plug in can use for saving data, and sets up certain data so some plug-in functions can work
|
|
||||||
plugin.OnPreload(function()
|
plugin.OnPreload(function()
|
||||||
canRun = plugin.request("require",true)
|
|
||||||
if not canRun then return nil,"Missing features that are required for this plugin to work!" end
|
|
||||||
local self = plugin.expose() -- exposes this plugins namespace that is public between all plugins
|
local self = plugin.expose() -- exposes this plugins namespace that is public between all plugins
|
||||||
self.name = ""
|
self.name = ""
|
||||||
self.age = 0
|
self.age = 0
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
-- plugin.init("superPlugin")
|
|
||||||
plugin.OnLoaded(function()
|
plugin.OnLoaded(function()
|
||||||
print(PLUGIN_NAME.." has been loaded!")
|
print(PLUGIN_NAME.." has been loaded!")
|
||||||
local epic = plugin.getPluginRef("PluginEpic")
|
local epic = plugin.getPluginRef("testPlugin1")
|
||||||
epic.newPerson("Ryan",22,"male")
|
epic.newPerson("Ryan",22,"male")
|
||||||
print(epic.getName())
|
print(epic.getName())
|
||||||
local list = plugin.getPluginList()
|
local list = plugin.getPluginList()
|
||||||
|
for i,v in pairs(list) do
|
||||||
|
print(i,v)
|
||||||
|
end
|
||||||
|
if plugin.fileExists("test.dat") then
|
||||||
|
print("File contents Start:")
|
||||||
|
local file = plugin.openFile("test.dat")
|
||||||
|
io.write(file:getData())
|
||||||
|
io.write("File contents End\n")
|
||||||
|
else
|
||||||
|
print("no has")
|
||||||
|
local file = plugin.openFreshFile("test.dat")
|
||||||
|
file:tackE("Test1\n")
|
||||||
|
file:tackE("Test2\n")
|
||||||
|
file:tackE("Test3\n")
|
||||||
|
file:tofile()
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
3
-Plugin-/testplugin2/test.dat
Normal file
3
-Plugin-/testplugin2/test.dat
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test1
|
||||||
|
Test2
|
||||||
|
Test3
|
||||||
@ -103,8 +103,8 @@ local function _expose(tab,readonly)
|
|||||||
elseif tab=="std" then
|
elseif tab=="std" then
|
||||||
tab = [[_VERSION,assert,collectgarbage,error,getfenv,getmetatable,ipairs,loadstring,module,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,math,coroutine,string,table]]
|
tab = [[_VERSION,assert,collectgarbage,error,getfenv,getmetatable,ipairs,loadstring,module,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,math,coroutine,string,table]]
|
||||||
_expose({
|
_expose({
|
||||||
io = {io.tmpfile,io.write},
|
io = {tmpfile = io.tmpfile,write = io.write},
|
||||||
os = {os.clock,os.date,os.difftime,os.exit,os.getenv,os.remove,os.rename,os.setlocale,os.time,os.tmpname},
|
os = {clock = os.clock,date = os.date,difftime = os.difftime,getenv = os.getenv,setlocale = os.setlocale,time = os.time,tmpname = os.tmpname},
|
||||||
_G = exposed
|
_G = exposed
|
||||||
},readonly)
|
},readonly)
|
||||||
end
|
end
|
||||||
@ -131,6 +131,9 @@ local function file_exists(name)
|
|||||||
local f=io.open(name,"r")
|
local f=io.open(name,"r")
|
||||||
if f~=nil then io.close(f) return true else return false end
|
if f~=nil then io.close(f) return true else return false end
|
||||||
end
|
end
|
||||||
|
local function _import(name,data)
|
||||||
|
__imports[name] = data
|
||||||
|
end
|
||||||
local GLOBAL = {__PluginList={},vars = {}}
|
local GLOBAL = {__PluginList={},vars = {}}
|
||||||
local conn = multi:newConnection(true)
|
local conn = multi:newConnection(true)
|
||||||
local conn2 = multi:newConnection(true)
|
local conn2 = multi:newConnection(true)
|
||||||
@ -144,6 +147,7 @@ local function cleanTab(tab)
|
|||||||
tab[i]=nil
|
tab[i]=nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local __imports = {}
|
||||||
local function load_(path)
|
local function load_(path)
|
||||||
if not file_exists(pluginLocation..package.config:sub(1,1)..path) then return end
|
if not file_exists(pluginLocation..package.config:sub(1,1)..path) then return end
|
||||||
local chunk = loadfile(pluginLocation..package.config:sub(1,1)..path)
|
local chunk = loadfile(pluginLocation..package.config:sub(1,1)..path)
|
||||||
@ -151,14 +155,18 @@ local function load_(path)
|
|||||||
local temp = {}
|
local temp = {}
|
||||||
merge(temp,exposed)
|
merge(temp,exposed)
|
||||||
merge(temp,{
|
merge(temp,{
|
||||||
|
import = function(name)
|
||||||
|
return __imports[name]
|
||||||
|
end,
|
||||||
plugin = {
|
plugin = {
|
||||||
version = version,
|
version = version,
|
||||||
OnLoaded = conn,
|
OnLoaded = conn,
|
||||||
OnPreload = conn3,
|
OnPreload = conn3,
|
||||||
OnReboot = conn4,
|
OnReboot = conn4,
|
||||||
init = function(name,version)
|
init = function(version)
|
||||||
|
local name = path:sub(1,-5):lower() -- Plugin name is equal to filename
|
||||||
temp["PLUGIN_NAME"]=name
|
temp["PLUGIN_NAME"]=name
|
||||||
GLOBAL[name] = {version = version}
|
GLOBAL[name] = {version = version or "1.0.0"}
|
||||||
table.insert(GLOBAL.__PluginList,name)
|
table.insert(GLOBAL.__PluginList,name)
|
||||||
if not dirExists(pluginLocation..package.config:sub(1,1)..name) then
|
if not dirExists(pluginLocation..package.config:sub(1,1)..name) then
|
||||||
mkDir(pluginLocation..package.config:sub(1,1)..name)
|
mkDir(pluginLocation..package.config:sub(1,1)..name)
|
||||||
@ -205,6 +213,10 @@ local function load_(path)
|
|||||||
local t = package.config:sub(1,1)
|
local t = package.config:sub(1,1)
|
||||||
os.remove(pluginLocation..t..temp["PLUGIN_NAME"]..t..path,false)
|
os.remove(pluginLocation..t..temp["PLUGIN_NAME"]..t..path,false)
|
||||||
end,
|
end,
|
||||||
|
fileExists = function(path)
|
||||||
|
local t = package.config:sub(1,1)
|
||||||
|
return file_exists(pluginLocation..t..temp["PLUGIN_NAME"]..t..path)
|
||||||
|
end,
|
||||||
setGlobal = function(var,val)
|
setGlobal = function(var,val)
|
||||||
GLOBAL.vars[var]=val
|
GLOBAL.vars[var]=val
|
||||||
end,
|
end,
|
||||||
@ -216,7 +228,7 @@ local function load_(path)
|
|||||||
end,
|
end,
|
||||||
getPluginRef = function(name)
|
getPluginRef = function(name)
|
||||||
local meh = {}
|
local meh = {}
|
||||||
local link = GLOBAL[name]
|
local link = GLOBAL[name:lower()]
|
||||||
setmetatable(meh,{
|
setmetatable(meh,{
|
||||||
__index = link -- Cannot alter a plugin's created domain but can read from it
|
__index = link -- Cannot alter a plugin's created domain but can read from it
|
||||||
})
|
})
|
||||||
@ -285,6 +297,7 @@ plugin.setPluginFolder = _setPluginFolder
|
|||||||
plugin.setProtection =_setProtection
|
plugin.setProtection =_setProtection
|
||||||
plugin.expose =_expose
|
plugin.expose =_expose
|
||||||
plugin.load =_load
|
plugin.load =_load
|
||||||
|
plugin.setImport = _import
|
||||||
plugin.grant = _grant
|
plugin.grant = _grant
|
||||||
-- plugin.reloadPlugins = _reload
|
-- plugin.reloadPlugins = _reload
|
||||||
return plugin
|
return plugin
|
||||||
|
|||||||
10
test.lua
10
test.lua
@ -1,4 +1,4 @@
|
|||||||
package.path = "./?/init.lua;"..package.path
|
package.path = "./?/init.lua;../multiworkspace/?/init.lua;"..package.path
|
||||||
local plugin = require("pluginManager")
|
local plugin = require("pluginManager")
|
||||||
local multi = require("multi")
|
local multi = require("multi")
|
||||||
plugin.setPluginFolder("-Plugin-") -- Creates if does not exist and sets the plugin folder where plugins will be loaded
|
plugin.setPluginFolder("-Plugin-") -- Creates if does not exist and sets the plugin folder where plugins will be loaded
|
||||||
@ -7,9 +7,6 @@ plugin.expose("std") -- string or table, std allows all non dangerious features
|
|||||||
plugin.expose({
|
plugin.expose({
|
||||||
multi = multi,
|
multi = multi,
|
||||||
})
|
})
|
||||||
plugin.grant("testPlugin1.lua",{
|
|
||||||
require = require
|
|
||||||
})
|
|
||||||
-- "*" allows you to use _G as the enviroment
|
-- "*" allows you to use _G as the enviroment
|
||||||
-- setting readonly, the second argument to true makes plugins able to read from global, but not write to it.
|
-- setting readonly, the second argument to true makes plugins able to read from global, but not write to it.
|
||||||
-- you can use a table instead of a string and put the name spaces directly that you want
|
-- you can use a table instead of a string and put the name spaces directly that you want
|
||||||
@ -21,7 +18,4 @@ plugin.grant("testPlugin1.lua",{
|
|||||||
]]
|
]]
|
||||||
plugin.load() -- loads plugins
|
plugin.load() -- loads plugins
|
||||||
print("Done loading...")
|
print("Done loading...")
|
||||||
multi:newTLoop(function()
|
|
||||||
--~ plugin.reloadPlugins()
|
|
||||||
end,1)
|
|
||||||
multi:mainloop()
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user