Skip to content

Commit

Permalink
Merge 6687cab into e7c3d6c
Browse files Browse the repository at this point in the history
  • Loading branch information
duk3luk3 committed Aug 31, 2017
2 parents e7c3d6c + 6687cab commit 2b04e2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit 2b04e2e

Please sign in to comment.