Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions faf/tools/fa/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 10 additions & 6 deletions faf/tools/lua/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
try:
import lupa


def from_lua(lua_code):
"""
Use Lupa as a parser by actually running the code
Expand All @@ -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())
Expand Down