diff --git a/-Plugin-/testPlugin1.lua b/-Plugin-/testPlugin1.lua index dea12b7..5d71907 100644 --- a/-Plugin-/testPlugin1.lua +++ b/-Plugin-/testPlugin1.lua @@ -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() - 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 self.name = "" self.age = 0 diff --git a/-Plugin-/testPlugin2.lua b/-Plugin-/testPlugin2.lua index e274fff..17c6035 100644 --- a/-Plugin-/testPlugin2.lua +++ b/-Plugin-/testPlugin2.lua @@ -1,8 +1,23 @@ --- plugin.init("superPlugin") plugin.OnLoaded(function() print(PLUGIN_NAME.." has been loaded!") - local epic = plugin.getPluginRef("PluginEpic") + local epic = plugin.getPluginRef("testPlugin1") epic.newPerson("Ryan",22,"male") print(epic.getName()) 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) diff --git a/-Plugin-/testplugin2/test.dat b/-Plugin-/testplugin2/test.dat new file mode 100644 index 0000000..658df2b --- /dev/null +++ b/-Plugin-/testplugin2/test.dat @@ -0,0 +1,3 @@ +Test1 +Test2 +Test3 diff --git a/pluginManager/init.lua b/pluginManager/init.lua index 0b4f23f..c542c2a 100644 --- a/pluginManager/init.lua +++ b/pluginManager/init.lua @@ -103,8 +103,8 @@ local function _expose(tab,readonly) 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]] _expose({ - io = {io.tmpfile,io.write}, - os = {os.clock,os.date,os.difftime,os.exit,os.getenv,os.remove,os.rename,os.setlocale,os.time,os.tmpname}, + io = {tmpfile = io.tmpfile,write = io.write}, + os = {clock = os.clock,date = os.date,difftime = os.difftime,getenv = os.getenv,setlocale = os.setlocale,time = os.time,tmpname = os.tmpname}, _G = exposed },readonly) end @@ -131,6 +131,9 @@ local function file_exists(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false end end +local function _import(name,data) + __imports[name] = data +end local GLOBAL = {__PluginList={},vars = {}} local conn = multi:newConnection(true) local conn2 = multi:newConnection(true) @@ -144,6 +147,7 @@ local function cleanTab(tab) tab[i]=nil end end +local __imports = {} local function load_(path) if not file_exists(pluginLocation..package.config:sub(1,1)..path) then return end local chunk = loadfile(pluginLocation..package.config:sub(1,1)..path) @@ -151,14 +155,18 @@ local function load_(path) local temp = {} merge(temp,exposed) merge(temp,{ + import = function(name) + return __imports[name] + end, plugin = { version = version, OnLoaded = conn, OnPreload = conn3, 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 - GLOBAL[name] = {version = version} + GLOBAL[name] = {version = version or "1.0.0"} table.insert(GLOBAL.__PluginList,name) if not dirExists(pluginLocation..package.config:sub(1,1)..name) then mkDir(pluginLocation..package.config:sub(1,1)..name) @@ -205,6 +213,10 @@ local function load_(path) local t = package.config:sub(1,1) os.remove(pluginLocation..t..temp["PLUGIN_NAME"]..t..path,false) 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) GLOBAL.vars[var]=val end, @@ -216,7 +228,7 @@ local function load_(path) end, getPluginRef = function(name) local meh = {} - local link = GLOBAL[name] + local link = GLOBAL[name:lower()] setmetatable(meh,{ __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.expose =_expose plugin.load =_load +plugin.setImport = _import plugin.grant = _grant -- plugin.reloadPlugins = _reload return plugin diff --git a/test.lua b/test.lua index 5daab09..8de8f65 100644 --- a/test.lua +++ b/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 multi = require("multi") 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({ multi = multi, }) -plugin.grant("testPlugin1.lua",{ - require = require -}) -- "*" 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. -- 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 print("Done loading...") -multi:newTLoop(function() ---~ plugin.reloadPlugins() -end,1) -multi:mainloop() +