diff --git a/faf/tools/fa/mods.py b/faf/tools/fa/mods.py index 3ae0457..706ea9a 100644 --- a/faf/tools/fa/mods.py +++ b/faf/tools/fa/mods.py @@ -47,6 +47,8 @@ def parse_mod_info(zip_file_or_folder): else: raise ValueError("Not a directory nor a file: " + str(zip_file_or_folder)) + lua_data = {k: v for k, v in lua_data.items() if v is not None and v is not ""} + data, errors = ModInfoSchema().load(dict(lua_data)) if errors: raise ValueError(errors) diff --git a/faf/tools/lua/parse.py b/faf/tools/lua/parse.py index 3508f9d..f7b04a9 100644 --- a/faf/tools/lua/parse.py +++ b/faf/tools/lua/parse.py @@ -3,7 +3,6 @@ try: import lupa - def from_lua(lua_code): """ Use Lupa as a parser by actually running the code @@ -14,18 +13,23 @@ def from_lua(lua_code): fa_functions_path = pkg_resources.resource_filename('static', 'lua/fa_functions.lua') lua = lupa.LuaRuntime() + # we don't care about all of the "internal" globals + # especially not the ones that contain binary stuff + # resulting in UnicodeDecodeError when we try to unfold them + default_globals = dict(lua.globals()).keys() with open(fa_functions_path, 'r') as fp: lua.execute(fp.read()) lua.execute(lua_code) - def unfold_table(t, seen=None): + def unfold_table(t): result = {} for k, v in t.items(): - if not lupa.lua_type(v): # Already a python type - result[k] = v - elif lupa.lua_type(v) == 'table': - result[k] = dict(v) + if k not in default_globals: + if not lupa.lua_type(v): # Already a python type + result[k] = v + elif lupa.lua_type(v) == 'table': + result[k] = dict(v) return result return unfold_table(lua.globals())