Skip to content

Commit

Permalink
Merge pull request #28 from Pika-Software/dev
Browse files Browse the repository at this point in the history
1.35.0
  • Loading branch information
unknown-gd authored Jun 14, 2023
2 parents 4c09ce2 + dd04e55 commit e7d882d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 23 deletions.
9 changes: 8 additions & 1 deletion lua/gpm/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
21 changes: 14 additions & 7 deletions lua/gpm/fs.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
11 changes: 4 additions & 7 deletions lua/gpm/http.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local logger = gpm.Logger
local promise = promise
local ipairs = ipairs
local util = util
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lua/gpm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MsgN( [[

module( "gpm", package.seeall )

_VERSION = 013403
_VERSION = 013500

if not Colors then
Realm = "unknown"
Expand Down
40 changes: 33 additions & 7 deletions lua/gpm/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit e7d882d

Please sign in to comment.