@@ -5,6 +5,7 @@ for i = 65, 90 do table.insert(Charset, string.char(i)) end
5
5
for i = 97 , 122 do table.insert (Charset , string.char (i )) end
6
6
7
7
MSK .GetRandomString = function (length )
8
+ assert (length , ' Parameter "length" is nil on function MSK.GetRandomString' )
8
9
math.randomseed (GetGameTimer ())
9
10
10
11
return length > 0 and MSK .GetRandomString (length - 1 ) .. Charset [math.random (1 , # Charset )] or ' '
18
19
exports (' GetConfig' , MSK .GetConfig )
19
20
exports (' getConfig' , MSK .GetConfig ) -- Support for old Versions
20
21
22
+ MSK .StartsWith = function (str , startStr )
23
+ assert (str and type (str ) == ' string' , ' Parameter "str" has to be a string on function MSK.StartsWith' )
24
+ assert (startStr and type (startStr ) == ' string' , ' Parameter "startStr" has to be a string on function MSK.StartsWith' )
25
+ return str :sub (1 , # startStr ) == startStr
26
+ end
27
+ exports (' StartsWith' , MSK .StartsWith )
28
+
21
29
MSK .Round = function (num , decimal )
30
+ assert (num and tonumber (num ), ' Parameter "num" has to be a number on function MSK.Round' )
31
+ assert (not decimal or decimal and tonumber (decimal ), ' Parameter "decimal" has to be a number on function MSK.Round' )
22
32
return tonumber (string.format (" %." .. (decimal or 0 ) .. " f" , num ))
23
33
end
24
34
exports (' Round' , MSK .Round )
25
35
26
36
MSK .Trim = function (str , bool )
27
- if bool then return (str :gsub (" ^%s*(.-)%s*$" , " %1" )) end
28
- return (str :gsub (" %s+" , " " ))
37
+ assert (str and tostring (str ), ' Parameter "str" has to be a string on function MSK.Trim' )
38
+ str = tostring (str )
39
+ if bool then return str :gsub (" ^%s*(.-)%s*$" , " %1" ) end
40
+ return str :gsub (" %s+" , " " )
29
41
end
30
42
exports (' Trim' , MSK .Trim )
31
43
32
44
MSK .Split = function (str , delimiter )
45
+ assert (str and type (str ) == ' string' , ' Parameter "str" has to be a string on function MSK.Split' )
46
+ assert (delimiter and type (delimiter ) == ' string' , ' Parameter "delimiter" has to be a string on function MSK.Split' )
33
47
local result = {}
34
48
35
- for match in (s .. delimiter ):gmatch (" (.-)" .. delimiter ) do
49
+ for match in (str .. delimiter ):gmatch (" (.-)" .. delimiter ) do
36
50
table.insert (result , match )
37
51
end
38
52
41
55
exports (' Split' , MSK .Split )
42
56
43
57
MSK .TableContains = function (tbl , val )
44
- if not tbl then return end
45
- if not val then return end
58
+ assert ( tbl and type ( tbl ) == ' table ' , ' Parameter "tbl" has to be a table on function MSK.TableContains ' )
59
+ assert ( val , ' Parameter " val" is nil on function MSK.TableContains ' )
46
60
47
61
if type (val ) == ' table' then
48
62
for k , v in pairs (tbl ) do
@@ -65,6 +79,8 @@ MSK.Table_Contains = MSK.TableContains -- Support for old Versions
65
79
exports (' TableContains' , MSK .TableContains )
66
80
67
81
MSK .Comma = function (int , tag )
82
+ assert (int and tonumber (int ), ' Parameter "int" has to be a number on function MSK.Comma' )
83
+ assert (not tag or tag and type (tag ) == ' string' and not tonumber (tag ), ' Parameter "tag" has to be a string on function MSK.Comma' )
68
84
if not tag then tag = ' .' end
69
85
local newInt = int
70
86
@@ -82,6 +98,7 @@ exports('Comma', MSK.Comma)
82
98
83
99
local Timeout = 0
84
100
MSK .SetTimeout = function (ms , cb )
101
+ assert (ms and tonumber (ms ), ' Parameter "ms" has to be a number on function MSK.SetTimeout' )
85
102
local requestId = Timeout + 1
86
103
87
104
SetTimeout (ms , function ()
@@ -100,7 +117,7 @@ MSK.AddTimeout = MSK.SetTimeout -- Support for old Versions
100
117
exports (' SetTimeout' , MSK .SetTimeout )
101
118
102
119
MSK .ClearTimeout = function (requestId )
103
- if not requestId then return end
120
+ assert ( requestId , ' Parameter " requestId" is nil on function MSK.ClearTimeout ' )
104
121
Timeouts [requestId ] = true
105
122
end
106
123
MSK .DelTimeout = MSK .ClearTimeout -- Support for old Versions
@@ -134,15 +151,17 @@ MSK.Logging = function(code, ...)
134
151
local args = {... }
135
152
table.remove (args , 1 )
136
153
137
- print (script , Config .LoggingTypes [action ], ... )
154
+ print (( ' %s %s ' ): format ( script , Config .LoggingTypes [action ]) , ... )
138
155
else
139
- print (script , Config .LoggingTypes [code ], ... )
156
+ assert (code and type (code ) == ' string' , ' Parameter "code" has to be a string on function MSK.Logging' )
157
+ print ((' %s %s' ):format (script , Config .LoggingTypes [code ]), ... )
140
158
end
141
159
end
142
160
MSK .logging = MSK .Logging -- Support for old Versions
143
161
exports (' Logging' , MSK .Logging )
144
162
145
163
logging = function (code , ...)
146
164
if not Config .Debug then return end
147
- print (Config .LoggingTypes [code ], ... )
165
+ local script = " [^2" .. GetCurrentResourceName ().. " ^0]"
166
+ print ((' %s %s' ):format (script , Config .LoggingTypes [code ]), ... )
148
167
end
0 commit comments