Skip to content

Commit d923fc1

Browse files
authored
Merge pull request #29 from Pika-Software/dev
1.36.0
2 parents e7d882d + 4132ee7 commit d923fc1

16 files changed

Lines changed: 1066 additions & 902 deletions

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,46 @@ Also, you can run an existing addon via gpm, just add the code below to `package
2727
```lua
2828
-- lua/packages/example-package/package.lua
2929
name = "example-package"
30-
main = "init.lua"
31-
version = 1
30+
version = 000100
3231

33-
-- allowed sides to run package, if client is false then the server will not send anything
34-
client = true
35-
server = true
32+
-- Files to be used as an entry point into the package, supports relative paths and global relative to "lua/"
33+
init = {
34+
["client"] = "cl_init.lua",
35+
["server"] = "init.lua",
36+
["menu"] = "init.lua"
37+
}
3638

37-
-- if there is no autorun, the package will wait for import from another package
39+
-- If there is no autorun, the package will wait for import from another package
3840
autorun = true
3941

40-
-- don't touch it if you don't know what you're doing
42+
-- Don't touch it if you don't know what you're doing
4143
environment = true
4244

43-
-- client files
45+
-- Client files ( supports relative paths and global paths by "lua/" )
4446
send = {
45-
"my/client/file.lua",
46-
"my/client/file2.lua"
47+
"file.lua",
48+
"my_addon/file2.lua"
4749
}
4850

49-
-- if false, the logger will not be created by default
51+
-- If false, the logger will not be created by default and logs color
5052
logger = false
5153
color = Color( 255, 255, 0 )
5254

53-
-- if nil, all gamemodes are allowed
55+
-- Allowed gamemodes list, if nil then all gamemodes are allowed
5456
gamemodes = {
5557
"sandbox",
5658
"darkrp"
5759
}
5860

59-
-- if nil, all maps are allowed
61+
-- Allowed maps list, if nil then all maps are allowed
6062
maps = {
6163
"gm_construct"
6264
}
6365

64-
-- if true, then the package is allowed to run only in a singleplayer game
66+
-- If true, then the package is allowed to run only in a singleplayer game
6567
singleplayer = false
6668

69+
-- Enables automatic naming for listed libraries, e.g. all hooks with hook = true will have a package identifier in the hook name, if the hook name is a string of course...
6770
autonames = {
6871
["properties"] = true,
6972
["timer"] = true,
@@ -81,14 +84,16 @@ autonames = {
8184
- ### Package version (`version`) (def. `nil`)
8285
By default, the version is a number whose format is { 00 } { 00 } { 00 } = 0.0.0, you can also use your own version format, just put your version here as a string.
8386

84-
- ### Package entry point (`main`) (def. `init.lua`)
85-
The `main` in this case is the entry point to the package (where the code execution will start from), you can use either the full `lua/` path, for example 'lua/packages/example-package/init.lua' or a local path relative to your package folder.
86-
87-
- ### Package client entry point (`cl_main`) ( def. `nil`)
88-
An optional parameter that substitutes `main` with another file for the client, helps to easily separate the client and server sides.
87+
- ### Package init (`init`)
88+
This is a universal parameter, which can be either a string or a table, in case it is a string, the package will run on both server and client and menu using the same initialization point, but if it is a table, it must contain parameters like ["realm"] = "path/to/init. lua", if any side is not specified then it won't be launched/sent, i.e. if we specify this value to {["server"] = "init.lua"} the package will only run on server and won't be sent to clients and also will not support menu realm.
8989

90-
- ### Client and server (`client`, `server`, `menu`) (def. `true`, `true`, `false`)
91-
You can change the permissions to run a package, for example if you set `client` to `false` the client will not be able to run it, moreover it will not even know that such a package exists and therefore will not see its files. `menu` is works only in menu realm.
90+
#### Example
91+
```lua
92+
init = {
93+
["server"] = "init.lua",
94+
["client"] = "cl_init.lua"
95+
}
96+
```
9297

9398
- ### Package autorun (`autorun`) (def. `false`)
9499
The default setting is `false`, if this parameter is set to `true` and the package is in a valid `lua/` directory, the package will automatically start and will not wait to be run externally.
@@ -100,7 +105,7 @@ autonames = {
100105
The list of files to send to the client, can be useful if the package runs exclusively on the client and has more than one file. (must be a table with indexes from 1 to infinity)
101106

102107
- ### Package logger (`logger`) (def. `false`)
103-
If set to `true` then a personal logger object will be created in the package environment, to easily send logs to the console. If necessary, you can create a logger object yourself, just call `gpm.logger.Create( name, color )` (`name` is `string`, `color` is `Color`).
108+
If set to `true` then a personal logger object will be created in the package environment, to easily send logs to the console. If necessary, you can create a logger object yourself, just call `gpm.CreateLogger( name, color )` (`name` is `string`, `color` is `Color`).
104109

105110
#### Example usage
106111
```lua

lua/gpm/commands.lua

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local logger = gpm.Logger
22
local SERVER = SERVER
33
local ipairs = ipairs
4+
local table = table
45
local gpm = gpm
56
local net = net
67

@@ -51,12 +52,25 @@ do
5152
local colors = gpm.Colors
5253
local pairs = pairs
5354
local MsgC = MsgC
55+
local type = type
5456

5557
function gpm.PrintPackageList( packages )
5658
MsgC( colors.Realm, gpm.Realm, colors.PrimaryText, " packages:\n" )
5759

60+
if type( packages ) ~= "table" then
61+
packages = {}
62+
63+
for _, pkg in pairs( gpm.Packages ) do
64+
packages[ #packages + 1 ] = pkg
65+
end
66+
end
67+
68+
table.sort( packages, function( a, b )
69+
return a:GetIdentifier() < b:GetIdentifier()
70+
end )
71+
5872
local total = 0
59-
for _, pkg in pairs( packages or gpm.Packages ) do
73+
for _, pkg in pairs( packages ) do
6074
MsgC( colors.Realm, "\t* ", colors.PrimaryText, pkg:GetIdentifier() .. "\n" )
6175
total = total + 1
6276
end
@@ -66,6 +80,10 @@ do
6680

6781
end
6882

83+
local function catch( message )
84+
logger:Error( message )
85+
end
86+
6987
function gpm.Reload( ... )
7088
local arguments = { ... }
7189
if #arguments == 0 then
@@ -83,7 +101,7 @@ function gpm.Reload( ... )
83101
local packages, count = {}, 0
84102
for _, searchable in ipairs( arguments ) do
85103
if #searchable == 0 then continue end
86-
for _, pkg in ipairs( gpm.package.Find( searchable, false, false ) ) do
104+
for _, pkg in ipairs( gpm.Find( searchable, false, false ) ) do
87105
packages[ pkg ] = true
88106
count = count + 1
89107
end
@@ -97,7 +115,7 @@ function gpm.Reload( ... )
97115
logger:Info( "Found %d candidates to reload, reloading...", count )
98116

99117
for pkg in pairs( packages ) do
100-
pkg:Reload( true )
118+
pkg:Reload( true ):Catch( catch )
101119
end
102120
end
103121

@@ -111,7 +129,7 @@ function gpm.Uninstall( force, ... )
111129
local packages, count = {}, 0
112130
for _, searchable in ipairs( arguments ) do
113131
if #searchable == 0 then continue end
114-
for _, pkg in ipairs( gpm.package.Find( searchable, false, false ) ) do
132+
for _, pkg in ipairs( gpm.Find( searchable, false, false ) ) do
115133
packages[ pkg ] = true
116134
count = count + 1
117135
end
@@ -245,7 +263,8 @@ if CLIENT then
245263

246264
local pkg = gpm.Packages[ importPath ]
247265
if not pkg then return end
248-
pkg:Reload()
266+
267+
pkg:Reload():Catch( catch )
249268
end
250269
}
251270

lua/gpm/environment.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local debug = debug
55
-- Variables
66
local setmetatable = setmetatable
77
local rawget = rawget
8-
local ipairs = ipairs
98
local type = type
109

1110
module( "gpm.environment" )
@@ -45,13 +44,7 @@ do
4544

4645
function UnLink( environment1, environment2 )
4746
local links = GetLinks( environment1 )
48-
for index, environment in ipairs( links ) do
49-
if environment == environment2 then
50-
table.remove( links, index )
51-
break
52-
end
53-
end
54-
47+
table.RemoveByIValue( links, environment2 )
5548
return environment1
5649
end
5750

0 commit comments

Comments
 (0)