forked from VoxeLibre/VoxeLibre
document script
This commit is contained in:
parent
45201481c1
commit
81ee51b0c2
|
@ -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
|
||||
|
|
|
@ -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<nomtableau>[^ \t\]]+)[ ]*=[ ]*\{')
|
||||
pattern = re.compile(r'^(?P<nomtableau>[A-Za-z_0-9]+)[ ]*=[ ]*\{')
|
||||
pattern_local = re.compile(r'local (?P<nomvar>[A-Za-z_0-9]+)')
|
||||
|
||||
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]+)')
|
||||
|
||||
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]))
|
||||
|
|
Loading…
Reference in New Issue