2021-04-26 20:16:27 +03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
2024-05-19 03:33:21 +03:00
|
|
|
# Just run this script from voxelibre directory to get a list of every global vars to use in luacheck configuration files
|
2021-05-10 10:58:26 +03:00
|
|
|
|
2021-04-27 20:16:08 +03:00
|
|
|
path = "./mods/"
|
2021-05-10 10:58:26 +03:00
|
|
|
|
|
|
|
pattern = re.compile(r'^(?P<global_var>[A-Za-z_0-9]+)[ ]*=[ ]*\{')
|
|
|
|
pattern_local = re.compile(r'local (?P<local_var>[A-Za-z_0-9]+)')
|
2021-04-27 20:16:08 +03:00
|
|
|
|
2021-05-03 23:11:49 +03:00
|
|
|
global_vars = []
|
2021-04-26 20:16:27 +03:00
|
|
|
|
2021-05-10 10:58:26 +03:00
|
|
|
|
|
|
|
print("---Copy/Paste output in your luacheck conf file---\n")
|
|
|
|
|
|
|
|
|
2021-04-26 20:16:27 +03:00
|
|
|
pathlist = Path(path).rglob('*.lua')
|
|
|
|
for path in pathlist:
|
|
|
|
path_in_str = str(path)
|
2021-04-27 20:16:08 +03:00
|
|
|
# print(path_in_str)
|
2022-07-15 22:24:45 +03:00
|
|
|
found = False
|
2021-04-26 20:16:27 +03:00
|
|
|
with open(path_in_str) as f:
|
2021-05-10 10:58:26 +03:00
|
|
|
local_vars = []
|
2021-04-27 20:16:08 +03:00
|
|
|
for i, line in enumerate(f.readlines()):
|
|
|
|
m = pattern.match(line)
|
|
|
|
if m:
|
2021-05-10 10:58:26 +03:00
|
|
|
global_name = m.group('global_var')
|
|
|
|
if global_name not in local_vars:
|
|
|
|
#print(path_in_str, ":", i+1, ":", m.group('global_var').strip())
|
|
|
|
global_vars.append(m.group('global_var').strip())
|
|
|
|
found = True
|
2021-05-03 23:11:49 +03:00
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
n = pattern_local.match(line)
|
|
|
|
if n:
|
2021-05-10 10:58:26 +03:00
|
|
|
local_vars.append(n.group('local_var'))
|
2021-05-03 23:11:49 +03:00
|
|
|
|
2021-05-10 10:58:26 +03:00
|
|
|
if not found:
|
2022-07-15 22:24:45 +03:00
|
|
|
nb_varloc = len(local_vars)
|
2021-05-03 23:11:49 +03:00
|
|
|
#print(path_in_str, ": -", "({} variables locales)".format(nb_varloc) if nb_varloc > 0 else '')
|
2021-04-26 20:16:27 +03:00
|
|
|
|
2021-05-03 23:11:49 +03:00
|
|
|
print(', '.join(['"{}"'.format(v) for v in global_vars]))
|