-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowGlobalVariables.lua
409 lines (348 loc) · 15.2 KB
/
ShowGlobalVariables.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
-- Module
--[[
Module ShowGlobalVariables.lua
Bei der Entwicklung von Modulen passiert es leicht, dass Variablen oder Funktionen global definiert werden obwohl sie lokal sein sollten.
Zumeist funktioniert das Skript dann trotzdem wie erwartet, so dass dieser Fehler nur schlecht auffällt.
Das Modul ShowGlobalVariables zeigt globale Variablen und globale Funktionen.
Die bekannten Namen aus EEP bzw. von Lua können unterdrückt werden, so dass man nur die selbst definierten Namen erhält.
Verwendung (auch mehrfach):
require('ShowGlobalVariables')() -- nur eigene Variablen und Funktionen
require('ShowGlobalVariables')(true) -- auch Variablen und Funktionen von EEP
Frank Buchholz, 2019-2022
]]
local _VERSION = 'v2023-06-30'
-- bekannte Namen, die nicht gezeigt werden sollen
local NamesTable = {
-- EEP variables
'EEPTime', -- EEP 10.2 plug-in 2
'EEPTimeH', -- EEP 10.2 plug-in 2
'EEPTimeM', -- EEP 10.2 plug-in 2
'EEPTimeS', -- EEP 10.2 plug-in 2
'EEPVer', -- EEP 10.2 plug-in 2
'EEPLng', -- EEP 17
'EEPGrowingTime', -- EEP 17.1 (?)
-- EEP 10.2 functions
'clearlog', -- EEP 10.2 plug-in 2
'EEPMain', -- EEP 10.2 plug-in 2
'EEPGetSignal', -- EEP 10.2 plug-in 2
'EEPGetSwitch', -- EEP 10.2 plug-in 2
'EEPOnSignal_1', -- EEP 10.2 plug-in 2
'EEPOnSwitch_1', -- EEP 10.2 plug-in 2
'EEPRegisterSignal', -- EEP 10.2 plug-in 2
'EEPRegisterSwitch', -- EEP 10.2 plug-in 2
'EEPSetSignal', -- EEP 10.2 plug-in 2
'EEPSetSwitch', -- EEP 10.2 plug-in 2
-- EEP 11.0 functions
'EEPGetTrainSpeed', -- EEP 11.0
'EEPLoadData', -- EEP 11.0
'EEPRollingstockGetAxis', -- EEP 11.0
'EEPRollingstockGetCouplingFront', -- EEP 11.0
'EEPRollingstockGetCouplingRear', -- EEP 11.0
'EEPRollingstockSetAxis', -- EEP 11.0
'EEPRollingstockSetCouplingFront', -- EEP 11.0
'EEPRollingstockSetCouplingRear', -- EEP 11.0
'EEPRollingstockSetSlot', -- EEP 11.0
'EEPSaveData', -- EEP 11.0
'EEPSetTrainSpeed', -- EEP 11.0
-- EEP 11.1 functions
'EEPStructureAnimateAxis', -- EEP 11.1 Plug-in 1
'EEPStructureGetAxis', -- EEP 11.1 Plug-in 1
'EEPStructureGetFire', -- EEP 11.1 Plug-in 1
'EEPStructureGetLight', -- EEP 11.1 Plug-in 1
'EEPStructureGetRotation', -- EEP 11.1 Plug-in 1
'EEPStructureGetSmoke', -- EEP 11.1 Plug-in 1
'EEPStructureSetAxis', -- EEP 11.1 Plug-in 1
'EEPStructureSetFire', -- EEP 11.1 Plug-in 1
'EEPStructureSetLight', -- EEP 11.1 Plug-in 1
'EEPStructureSetPosition', -- EEP 11.1 Plug-in 1
'EEPStructureSetRotation', -- EEP 11.1 Plug-in 1
'EEPStructureSetSmoke', -- EEP 11.1 Plug-in 1
-- EEP 11.2 functions
'EEPGetTrainRoute', -- EEP 11.2 Plug-in 2
'EEPSetTrainAxis', -- EEP 11.2 Plug-in 2
'EEPSetTrainCouplingFront', -- EEP 11.2 Plug-in 2
'EEPSetTrainCouplingRear', -- EEP 11.2 Plug-in 2
'EEPSetTrainHook', -- EEP 11.2 Plug-in 2
'EEPSetTrainHorn', -- EEP 11.2 Plug-in 2
'EEPSetTrainLight', -- EEP 11.2 Plug-in 2, EEP 14.2 Plug-In 2
'EEPSetTrainRoute', -- EEP 11.2 Plug-in 2
'EEPSetTrainSmoke', -- EEP 11.2 Plug-in 2
'EEPTrainLooseCoupling', -- EEP 11.2 Plug-in 2
-- EEP 11.3 functions
'EEPGetTrainFromTrainyard', -- EEP 11.3 plug-in 2, EEP 14.2 plug-In 2
'EEPIsAuxiliaryTrackReserved', -- EEP 11.3 Plug-in 3
'EEPIsControlTrackReserved', -- EEP 11.3 Plug-in 3
'EEPIsRailTrackReserved', -- EEP 11.3 Plug-in 3
'EEPIsRoadTrackReserved', -- EEP 11.3 Plug-in 3
'EEPIsTramTrackReserved', -- EEP 11.3 Plug-in 3
'EEPLoadProject', -- EEP 11.3 Plug-in 3
'EEPRegisterAuxiliaryTrack', -- EEP 11.3 Plug-in 3
'EEPRegisterControlTrack', -- EEP 11.3 Plug-in 3
'EEPRegisterRailTrack', -- EEP 11.3 Plug-in 3
'EEPRegisterRoadTrack', -- EEP 11.3 Plug-in 3
'EEPRegisterTramTrack', -- EEP 11.3 Plug-in 3
'EEPSetCamera', -- EEP 11.3 Plug-in 3
'EEPSetPerspectiveCamera', -- EEP 11.3 Plug-in 3, EEP 14.2 Plug-In 2
-- EEP 13 functions
'EEPChangeInfoSignal', -- EEP 13
'EEPChangeInfoStructure', -- EEP 13
'EEPChangeInfoSwitch', -- EEP 13
'EEPShowInfoSignal', -- EEP 13
'EEPShowInfoStructure', -- EEP 13
'EEPShowInfoSwitch', -- EEP 13
-- EEP 13.1 functions
'EEPHideInfoTextBottom', -- EEP 13 plug-In 1
'EEPHideInfoTextTop', -- EEP 13 plug-In 1
'EEPPlaySound', -- EEP 13 plug-In 1
'EEPShowInfoTextBottom', -- EEP 13 plug-In 1
'EEPShowInfoTextTop', -- EEP 13 plug-In 1
'EEPShowScrollInfoTextBottom', -- EEP 13 plug-In 1
'EEPShowScrollInfoTextTop', -- EEP 13 plug-In 1
'EEPStructurePlaySound', -- EEP 13 plug-In 1
-- EEP 13.2 functions
'EEPGetRollingstockItemName', -- EEP 13.2 plug-in 2
'EEPGetRollingstockItemsCount', -- EEP 13.2 plug-in 2
'EEPGetSignalTrainName', -- EEP 13.2 plug-in 2
'EEPGetSignalTrainsCount', -- EEP 13.2 plug-in 2
'EEPGetTrainyardItemName', -- EEP 13.2 plug-in 2
'EEPGetTrainyardItemStatus', -- EEP 13.2 plug-in 2
'EEPGetTrainyardItemsCount', -- EEP 13.2 plug-in 2
-- EEP 14.1 functions
'EEPOnTrainCoupling', -- EEP 14 Plug-In 1
'EEPOnTrainExitTrainyard', -- EEP 14 Plug-In 1
'EEPOnTrainLooseCoupling', -- EEP 14 Plug-In 1
'EEPPause', -- EEP 14 plug-in 1
'EEPSetTrainName', -- EEP 14 Plug-In 1
-- EEP 14.2 functions
'EEPGoodsGetModelType', -- EEP 14.2 Plug-In 2
'EEPGoodsGetPosition', -- EEP 14.2 Plug-In 2
'EEPGoodsSetPosition', -- EEP 14.2 Plug-In 2
'EEPGoodsSetRotation', -- EEP 14.2 Plug-In 2
'EEPRollingstockGetLength', -- EEP 14.2 Plug-In 2
'EEPRollingstockGetModelType', -- EEP 14.2 Plug-In 2
'EEPRollingstockGetMotor', -- EEP 14.2 Plug-In 2
'EEPRollingstockGetTagText', -- EEP 14.2 Plug-In 2
'EEPRollingstockGetTrack', -- EEP 14.2 Plug-In 2
'EEPRollingstockGetTrainName', -- EEP 14.2 Plug-In 2
'EEPRollingstockSetTagText', -- EEP 14.2 Plug-In 2
'EEPSetTime', -- EEP 14.2 Plug-In 2
'EEPSetTrainHookGlue', -- EEP 14.2 Plug-In 2
'EEPStructureGetModelType', -- EEP 14.2 Plug-In 2
'EEPStructureGetPosition', -- EEP 14.2 Plug-In 2
'EEPStructureGetTagText', -- EEP 14.2 Plug-In 2
'EEPStructureIsAxisAnimate', -- EEP 14.2 Plug-In 2
'EEPStructureSetTagText', -- EEP 14.2 Plug-In 2
-- EEP 15 functions
'EEPAuxiliaryTrackSetTextureText', -- EEP 15
'EEPGoodsSetTextureText', -- EEP 15
'EEPRailTrackSetTextureText', -- EEP 15
'EEPRoadTrackSetTextureText', -- EEP 15
'EEPRollingstockSetTextureText', -- EEP 15
'EEPSignalSetTextureText', -- EEP 15
'EEPStructureSetTextureText', -- EEP 15
'EEPTramTrackSetTextureText', -- EEP 15
-- EEP 15.1 functions
'EEPGetTrainActive', -- EEP 15.1 Plug-in 1
'EEPGetTrainLength', -- EEP 15.1 Plug-in 1
'EEPRollingstockGetActive', -- EEP 15.1 Plug-in 1
'EEPRollingstockGetOrientation', -- EEP 15.1 Plug-in 1
'EEPRollingstockSetActive', -- EEP 15.1 Plug-in 1
'EEPSetTrainActive', -- EEP 15.1 Plug-in 1
-- EEP 16.1 functions
'EEPActivateCtrlDesk', -- EEP 16.1 Plug-in 1
'EEPGetCameraPosition', -- EEP 16.1 Plug-in 1
'EEPGetCameraRotation', -- EEP 16.1 Plug-in 1
'EEPGetCloudsIntensity', -- EEP 16.1 Plug-in 1
'EEPGetFogIntensity', -- EEP 16.1 Plug-in 1
'EEPGetHailIntensity', -- EEP 16.1 Plug-in 1
'EEPGetRainIntensity', -- EEP 16.1 Plug-in 1
'EEPGetSnowIntensity', -- EEP 16.1 Plug-in 1
'EEPGetWindIntensity', -- EEP 16.1 Plug-in 1
'EEPGoodsGetRotation', -- EEP 16.1 Plug-in 1
'EEPOnSaveAnl', -- EEP 16.1 Plug-in 1
'EEPRollingstockGetHook', -- EEP 16.1 Plug-in 1
'EEPRollingstockGetHookGlue', -- EEP 16.1 Plug-in 1
'EEPRollingstockGetMileage', -- EEP 16.1 Plug-in 1
'EEPRollingstockGetPosition', -- EEP 16.1 Plug-in 1
'EEPRollingstockGetSmoke', -- EEP 16.1 Plug-in 1
'EEPRollingstockSetHook', -- EEP 16.1 Plug-in 1
'EEPRollingstockSetHookGlue', -- EEP 16.1 Plug-in 1
'EEPRollingstockSetHorn', -- EEP 16.1 Plug-in 1
'EEPRollingstockSetSmoke', -- EEP 16.1 Plug-in 1
'EEPRollingstockSetUserCamera', -- EEP 16.1 Plug-in 1
'EEPSetCameraPosition', -- EEP 16.1 Plug-in 1
'EEPSetCameraRotation', -- EEP 16.1 Plug-in 1
'EEPSetCloudsIntensity', -- EEP 16.1 Plug-in 1
'EEPSetDarkCloudsIntensity', -- EEP 16.1 Plug-in 1
'EEPSetFogIntensity', -- EEP 16.1 Plug-in 1
'EEPSetHailIntensity', -- EEP 16.1 Plug-in 1
'EEPSetRainIntensity', -- EEP 16.1 Plug-in 1
'EEPSetSnowIntensity', -- EEP 16.1 Plug-in 1
'EEPSetWindIntensity', -- EEP 16.1 Plug-in 1
-- EEP 16.2 functions
-- EEP 16.3 functions
'EEPRollingstockGetTextureText', -- EEP 16.3 Plug-in 3
-- EEP 16.4 functions
-- EEP 17 variables and functions
'EEPOnBeforeSaveAnl', -- EEP 17
'EEPGetAnlVer', -- EEP 17
'EEPGetAnlLng', -- EEP 17
'EEPRollingstockGetUserCamera', -- EEP 17
-- EEP 17 Plugin 1
'EEPSetZoneWindIntensity', -- EEP 17 Plug-in 1
'EEPSetZoneRainIntensity', -- EEP 17 Plug-in 1
'EEPSetZoneSnowIntensity', -- EEP 17 Plug-in 1
'EEPSetZoneHailIntensity', -- EEP 17 Plug-in 1
'EEPSetZoneFogIntensity', -- EEP 17 Plug-in 1
'EEPSetZoneClouds', -- EEP 17 Plug-in 1
'EEPSetZonePos', -- EEP 17 Plug-in 1
'EEPGetZoneWindIntensity', -- EEP 17 Plug-in 1
'EEPGetZoneRainIntensity', -- EEP 17 Plug-in 1
'EEPGetZoneSnowIntensity', -- EEP 17 Plug-in 1
'EEPGetZoneHailIntensity', -- EEP 17 Plug-in 1
'EEPGetZoneFogIntensity', -- EEP 17 Plug-in 1
'EEPGetZoneClouds', -- EEP 17 Plug-in 1
'EEPGetZonePos', -- EEP 17 Plug-in 1
'EEPGetAnlName', -- EEP 17 Plug-in 1
'EEPSignalSetTagText', -- EEP 17 Plug-in 1
'EEPSignalGetTagText', -- EEP 17 Plug-in 1
-- NICHT enthalten:
-- EEPSetZoneDarkClouds
-- EEPGetZoneDarkClouds
-- EEP 17.2 Plug-in 2
'EEPStructureGetTextureText', -- EEP 17.2 Plug-in 2
'EEPSignalGetTextureText', -- EEP 17.2 Plug-in 2
'EEPGoodsGetTextureText', -- EEP 17.2 Plug-in 2
'EEPRailTrackGetTextureText', -- EEP 17.2 Plug-in 2
'EEPRoadTrackGetTextureText', -- EEP 17.2 Plug-in 2
'EEPTramTrackGetTextureText', -- EEP 17.2 Plug-in 2
'EEPAuxiliaryTrackGetTextureText', -- EEP 17.2 Plug-in 2
'EEPGetSeason', -- EEP 17.2 Plug-in 2
'EEPGetFramesPerSecond', -- EEP 17.2 Plug-in 2
'EEPGetCurrentFrame ', -- EEP 17.2 Plug-in 2
'EEPGetCurrentRenderFrame ', -- EEP 17.2 Plug-in 2
'EEPGetTimeLapse', -- EEP 17.2 Plug-in 2
-- Lua standard variables
'_G',
'_VERSION',
'bit32',
'coroutine',
'debug',
'io',
'math',
'os',
'package',
'string',
'table',
'utf8',
-- Lua standard functions
'assert',
'collectgarbage',
'dofile',
'error',
'getmetatable',
'ipairs',
'load',
'loadfile',
'next',
'pairs',
'pcall',
'print',
'rawequal',
'rawget',
'rawlen',
'rawset',
'require',
'select',
'setmetatable',
'tonumber',
'tostring',
'type',
'xpcall',
}
-- Tabelle (mit impliziten numerischen Schlüssel) in Tabelle mit explizites Schlüsseln übertragen
local NamesSet = {}
for key, name in pairs(NamesTable) do
NamesSet[name] = true
end
-- Utility functions to access a table in sorted order
local sort = function (a, b)
if type(a) == "number" and type(b) == "number" then
-- sort numbers
return a < b
else
-- sort anything else
return string.lower(tostring(a)) < string.lower(tostring(b))
end
end
local function pairsByKeys (t, f)
local f = f or sort
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
local function showVariable(key, value)
if type(value) == "table" then
local size = 0
for k,v in pairs(value) do size = size + 1 end
print(key, " [", type(value), "] ", size, " entries")
else -- if type(value) == "string" or type(value) == "number" then
print(key, " [", type(value), "] = ", value)
end
end
local function ShowGlobalVariables(all)
print("\nGlobal Variables:")
-- Show EEP global variables
for key, value in pairsByKeys(_G) do
if all == true or not NamesSet[key] then
if type(value) ~= "function" and string.sub(key, 1, 3) == "EEP" then
showVariable(key, value)
end
end
end
print("")
-- Show other global variables
for key, value in pairsByKeys(_G) do
if all == true or not NamesSet[key] then
if type(value) ~= "function" and string.sub(key, 1, 3) ~= "EEP" then
showVariable(key, value)
end
end
end
print("\nGlobal Functions:")
-- Show EEP functions
for key, value in pairsByKeys(_G) do
if all == true or not NamesSet[key] then
if type(value) == "function" and string.sub(key, 1, 3) == "EEP" then
print(key)
end
end
end
print("")
-- Show other functions
for key, value in pairsByKeys(_G) do
if all == true or not NamesSet[key] then
if type(value) == "function" and string.sub(key, 1, 3) ~= "EEP" then
print(key)
end
end
end
print("")
-- Return self to allow a construction like this:
--[[
ShowGlobalVariables = require("ShowGlobalVariables")() -- show it during initialization
function EEPMain()
ShowGlobalVariables() -- show it regularly
end
--]]
return ShowGlobalVariables --
end
return ShowGlobalVariables