diff --git a/lua/gpm/commands.lua b/lua/gpm/commands.lua index 22fb704b..3f4cc2ea 100644 --- a/lua/gpm/commands.lua +++ b/lua/gpm/commands.lua @@ -73,6 +73,13 @@ function gpm.Reload( ... ) return end + if SERVER then + net.Start( "GPM.Networking" ) + net.WriteUInt( 2, 3 ) + net.WriteTable( arguments ) + net.Broadcast() + end + local packages, count = {}, 0 for _, searchable in ipairs( arguments ) do if #searchable == 0 then continue end @@ -90,7 +97,7 @@ function gpm.Reload( ... ) logger:Info( "Found %d candidates to reload, reloading...", count ) for pkg in pairs( packages ) do - pkg:Reload() + pkg:Reload( true ) end end diff --git a/lua/gpm/fs.lua b/lua/gpm/fs.lua index ecda8341..b9711d8f 100644 --- a/lua/gpm/fs.lua +++ b/lua/gpm/fs.lua @@ -1,18 +1,17 @@ -local logger = gpm.Logger local SERVER = SERVER local util = util -- https://github.com/Pika-Software/gm_asyncio -- https://github.com/WilliamVenner/gm_async_write if util.IsBinaryModuleInstalled( "asyncio" ) and pcall( require, "asyncio" ) then - logger:Info( "A third-party file system API 'asyncio' has been initialized." ) + gpm.Logger:Info( "A third-party file system API 'asyncio' has been initialized." ) elseif SERVER and util.IsBinaryModuleInstalled( "async_write" ) and pcall( require, "async_write" ) then - logger:Info( "A third-party file system API 'async_write' has been initialized." ) + gpm.Logger:Info( "A third-party file system API 'async_write' has been initialized." ) end -- https://github.com/Pika-Software/gm_efsw if util.IsBinaryModuleInstalled( "efsw" ) and pcall( require, "efsw" ) then - logger:Info( "gm_efsw is initialized, package auto-reload are available." ) + gpm.Logger:Info( "gm_efsw is initialized, package auto-reload are available." ) end -- Libraries @@ -34,14 +33,22 @@ local assert = assert local type = type if efsw ~= nil then - hook.Add( "FileWatchEvent", "GPM.AutoReload", function( actionID, _, filePath ) - local importPath = string.match( filePath, ".*/lua/(packages/.*)/" ) + hook.Add( "FileWatchEvent", "GPM.EFSW", function( action, _, filePath ) + if action <= 0 then return end + + local importPath = string.match( string.sub( filePath, 5 ), "packages/[^/]+" ) if not importPath then return end local pkg = gpm.Packages[ importPath ] if not pkg then return end - pkg:Reload() + local timerName = "GPM.EFSW." .. importPath + timer.Create( timerName, 0.5, 1, function() + timer.Remove( timerName ) + if pkg:IsInstalled() then + pkg:Reload() + end + end ) end ) end diff --git a/lua/gpm/http.lua b/lua/gpm/http.lua index afb5e9e8..05c94560 100644 --- a/lua/gpm/http.lua +++ b/lua/gpm/http.lua @@ -1,4 +1,3 @@ -local logger = gpm.Logger local promise = promise local ipairs = ipairs local util = util @@ -7,12 +6,10 @@ local type = type -- https://github.com/WilliamVenner/gmsv_reqwest -- https://github.com/timschumi/gmod-chttp if SERVER then - if util.IsBinaryModuleInstalled( "reqwest" ) then - logger:Info( "A third-party http client 'reqwest' has been initialized." ) - require( "reqwest" ) - elseif util.IsBinaryModuleInstalled( "chttp" ) then - logger:Info( "A third-party http client 'chttp' has been initialized." ) - require( "chttp" ) + if util.IsBinaryModuleInstalled( "reqwest" ) and pcall( require, "reqwest" ) then + gpm.Logger:Info( "A third-party http client 'reqwest' has been initialized." ) + elseif util.IsBinaryModuleInstalled( "chttp" ) and pcall( require, "chttp" ) then + gpm.Logger:Info( "A third-party http client 'chttp' has been initialized." ) end end diff --git a/lua/gpm/init.lua b/lua/gpm/init.lua index f42fcb42..e760bbdf 100644 --- a/lua/gpm/init.lua +++ b/lua/gpm/init.lua @@ -24,7 +24,7 @@ MsgN( [[ module( "gpm", package.seeall ) -_VERSION = 013403 +_VERSION = 013500 if not Colors then Realm = "unknown" diff --git a/lua/gpm/package.lua b/lua/gpm/package.lua index c6f58381..930b5a8b 100644 --- a/lua/gpm/package.lua +++ b/lua/gpm/package.lua @@ -171,7 +171,7 @@ do source.send = nil end - -- Isolation features + -- Libs autonames feature local autonames = source.autonames if type( autonames ) == "table" then autonames.properties = autonames.properties ~= false and source.environment @@ -189,6 +189,21 @@ do } end + local defaults = source.defaults + if type( defaults ) == "table" then + defaults.typeid = autonames.typeid ~= false and source.environment + defaults.http = autonames.http ~= false and source.environment + defaults.type = autonames.type ~= false and source.environment + defaults.file = autonames.file ~= false and source.environment + else + source.defaults = { + ["typeid"] = source.environment, + ["http"] = source.environment, + ["type"] = source.environment, + ["file"] = source.environment + } + end + return source elseif type( source ) == "function" then local metadata = {} @@ -360,14 +375,23 @@ do if type( env ) ~= "table" then env = environment.Create( _G ) self.Environment = env + env._PKG = self env.AddCSLuaFile = addCSLuaFile env.ArgAssert = gpm.ArgAssert - env.TypeID = gpm.TypeID - env.http = gpm.http - env.type = gpm.type - env._PKG = self - env.file = fs + end + + env.TypeID = nil + env.http = nil + env.type = nil + env.file = nil + + local defaults = metadata.defaults + if defaults then + if defaults.typeid then env.TypeID = gpm.TypeID end + if defaults.http then env.http = gpm.http end + if defaults.type then env.type = gpm.type end + if defaults.file then env.file = fs end end env._VERSION = metadata.version @@ -864,7 +888,9 @@ do self:ClearCallbacks() end - gpm.Packages[ self:GetImportPath() ] = nil + local importPath = self:GetImportPath() + gpm.ImportTasks[ importPath ] = nil + gpm.Packages[ importPath ] = nil self.Installed = nil logger:Info( "Package '%s' was successfully uninstalled, took %.4f seconds.", self:GetIdentifier(), SysTime() - stopwatch )