From 72e53a82d7cbf01137a3bb462c49d8a9908070dd Mon Sep 17 00:00:00 2001 From: AFCMS Date: Mon, 26 Apr 2021 19:16:27 +0200 Subject: [PATCH 1/4] Basic not working script --- tools/create_luacheck.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) mode change 100644 => 100755 tools/create_luacheck.py diff --git a/tools/create_luacheck.py b/tools/create_luacheck.py old mode 100644 new mode 100755 index e69de29bb..31046a575 --- a/tools/create_luacheck.py +++ b/tools/create_luacheck.py @@ -0,0 +1,22 @@ +import os +import re +from pathlib import Path + +path = "../mods/" +pattern = re.compile(r'[a-z]') + +pathlist = Path(path).rglob('*.lua') +for path in pathlist: + path_in_str = str(path) + print(path_in_str) + with open(path_in_str) as f: + for line in f: + if pattern.search(line): + print(line) + +for subdir, dirs, files in os.walk(path): + for file in files: + print(os.path.join(subdir, file)) + filepath = subdir + os.sep + file + if filepath.endswith(".lua"): + print(filepath) \ No newline at end of file From 0a2fcdc4e8901f847aab1b5299140a91f1ae8dad Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 27 Apr 2021 19:16:08 +0200 Subject: [PATCH 2/4] fixes --- tools/create_luacheck.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/create_luacheck.py b/tools/create_luacheck.py index 31046a575..1c38c33f4 100755 --- a/tools/create_luacheck.py +++ b/tools/create_luacheck.py @@ -2,17 +2,25 @@ import os import re from pathlib import Path -path = "../mods/" -pattern = re.compile(r'[a-z]') +path = "./mods/" +# pattern = re.compile(r'^(?P[^ \t\]]+)[ ]*=[ ]*\{') +pattern = re.compile(r'^(?P[^ \t\]]+)[ ]*=[ ]*\{') + pathlist = Path(path).rglob('*.lua') for path in pathlist: path_in_str = str(path) - print(path_in_str) + # print(path_in_str) + trouve = False with open(path_in_str) as f: - for line in f: - if pattern.search(line): - print(line) + for i, line in enumerate(f.readlines()): + m = pattern.match(line) + if m: + print(path_in_str, ":", i+1, ":", m.group('nomtableau').strip()) + trouve = True + break + if not trouve: + print(path_in_str, ": -") for subdir, dirs, files in os.walk(path): for file in files: From cbb014ed3867418d373dadbfc05e5d7dc90a8b4c Mon Sep 17 00:00:00 2001 From: AFCMS Date: Mon, 3 May 2021 22:11:49 +0200 Subject: [PATCH 3/4] basic working script --- mods/MAPGEN/mcl_villages/const.lua | 2 +- tools/create_luacheck.py | 31 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/mods/MAPGEN/mcl_villages/const.lua b/mods/MAPGEN/mcl_villages/const.lua index 6621dbf3a..e5cbc9b39 100644 --- a/mods/MAPGEN/mcl_villages/const.lua +++ b/mods/MAPGEN/mcl_villages/const.lua @@ -7,7 +7,7 @@ end --[[ Manually set in 'buildings.lua' -- material to replace cobblestone with -wallmaterial = { +local wallmaterial = { "mcl_core:junglewood", "mcl_core:sprucewood", "mcl_core:wood", diff --git a/tools/create_luacheck.py b/tools/create_luacheck.py index 1c38c33f4..a9caad38e 100755 --- a/tools/create_luacheck.py +++ b/tools/create_luacheck.py @@ -4,8 +4,10 @@ from pathlib import Path path = "./mods/" # pattern = re.compile(r'^(?P[^ \t\]]+)[ ]*=[ ]*\{') -pattern = re.compile(r'^(?P[^ \t\]]+)[ ]*=[ ]*\{') +pattern = re.compile(r'^(?P[A-Za-z_0-9]+)[ ]*=[ ]*\{') +pattern_local = re.compile(r'local (?P[A-Za-z_0-9]+)') +global_vars = [] pathlist = Path(path).rglob('*.lua') for path in pathlist: @@ -13,18 +15,31 @@ for path in pathlist: # print(path_in_str) trouve = False with open(path_in_str) as f: + variables_locales = [] for i, line in enumerate(f.readlines()): m = pattern.match(line) if m: - print(path_in_str, ":", i+1, ":", m.group('nomtableau').strip()) - trouve = True - break - if not trouve: - print(path_in_str, ": -") + nomtableau = m.group('nomtableau') + if nomtableau not in variables_locales: + print(path_in_str, ":", i+1, ":", m.group('nomtableau').strip()) + global_vars.append(m.group('nomtableau').strip()) + trouve = True + break -for subdir, dirs, files in os.walk(path): + else: + n = pattern_local.match(line) + if n: + variables_locales.append(n.group('nomvar')) + + if not trouve: + nb_varloc = len(variables_locales) + #print(path_in_str, ": -", "({} variables locales)".format(nb_varloc) if nb_varloc > 0 else '') + +""" for subdir, dirs, files in os.walk(path): for file in files: print(os.path.join(subdir, file)) filepath = subdir + os.sep + file if filepath.endswith(".lua"): - print(filepath) \ No newline at end of file + print(filepath) """ + +print(', '.join(['"{}"'.format(v) for v in global_vars])) From 81ee51b0c2663db964f6801a1c1e163941be0281 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Mon, 10 May 2021 09:58:26 +0200 Subject: [PATCH 4/4] document script --- tools/README.md | 14 ++++++++++++++ tools/create_luacheck.py | 35 +++++++++++++++++------------------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/tools/README.md b/tools/README.md index abcc73ae3..4dc378bc1 100644 --- a/tools/README.md +++ b/tools/README.md @@ -27,3 +27,17 @@ Usage: - Convert the textures - Put the new texture directory in the Minetest texture pack directory, just like any other Minetest texture pack + +## Luacheck Globals Generators +This is a Python script which list every single global tables in mineclone2 source code. +It outputs a list to be used in luacheck conf files. + +Modes of operation: +- List global tables + +Requirements: +- Know how to use the console +- Python 3 + +Usage: +- In the console, run `python3 ./tools/create_luacheck.py` in the MineClone2 directory diff --git a/tools/create_luacheck.py b/tools/create_luacheck.py index a9caad38e..8b55c1376 100755 --- a/tools/create_luacheck.py +++ b/tools/create_luacheck.py @@ -2,44 +2,43 @@ import os import re from pathlib import Path +# Just run this script from mineclone2 directory to get a list of every global vars to use in luacheck configuration files + path = "./mods/" -# pattern = re.compile(r'^(?P[^ \t\]]+)[ ]*=[ ]*\{') -pattern = re.compile(r'^(?P[A-Za-z_0-9]+)[ ]*=[ ]*\{') -pattern_local = re.compile(r'local (?P[A-Za-z_0-9]+)') + +pattern = re.compile(r'^(?P[A-Za-z_0-9]+)[ ]*=[ ]*\{') +pattern_local = re.compile(r'local (?P[A-Za-z_0-9]+)') global_vars = [] + +print("---Copy/Paste output in your luacheck conf file---\n") + + pathlist = Path(path).rglob('*.lua') for path in pathlist: path_in_str = str(path) # print(path_in_str) trouve = False with open(path_in_str) as f: - variables_locales = [] + local_vars = [] for i, line in enumerate(f.readlines()): m = pattern.match(line) if m: - nomtableau = m.group('nomtableau') - if nomtableau not in variables_locales: - print(path_in_str, ":", i+1, ":", m.group('nomtableau').strip()) - global_vars.append(m.group('nomtableau').strip()) - trouve = True + 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 break else: n = pattern_local.match(line) if n: - variables_locales.append(n.group('nomvar')) + local_vars.append(n.group('local_var')) - if not trouve: + if not found: nb_varloc = len(variables_locales) #print(path_in_str, ": -", "({} variables locales)".format(nb_varloc) if nb_varloc > 0 else '') -""" for subdir, dirs, files in os.walk(path): - for file in files: - print(os.path.join(subdir, file)) - filepath = subdir + os.sep + file - if filepath.endswith(".lua"): - print(filepath) """ - print(', '.join(['"{}"'.format(v) for v in global_vars]))