Add old function back to lua_dump.py

This commit is contained in:
luk3yx 2021-03-22 08:11:59 +13:00
parent af262da9de
commit a4d5dc23d3
2 changed files with 13 additions and 4 deletions

View File

@ -90,6 +90,14 @@ def dump(obj):
# Clean tracebacks
raise TypeError(msg)
def serialize(obj):
"""
Serialize an object into valid Lua code. This will raise a TypeError if the
object cannot be serialized into lua.
"""
return 'return ' + dump(obj)
def _walk(obj, seen):
yield obj
if isinstance(obj, dict):
@ -124,10 +132,11 @@ def _replace_values(obj):
if isinstance(v, list):
obj[k] = tuple(v)
def serialize(obj):
def serialize_readonly(obj):
"""
Serialize an object into valid Lua code. This will raise a TypeError if the
object cannot be serialized into lua.
Serializes an object into a Lua table with the assumption that the
resulting table will never be modified. This allows any duplicate lists and
tuples to be reused.
"""
# Count all tuples

View File

@ -287,7 +287,7 @@ def main():
print('Writing to ' + filename + '...')
with open(filename, 'w') as f:
f.write(_comment.lstrip())
f.write(lua_dump.serialize(data))
f.write(lua_dump.serialize_readonly(data))
f.write('\n')
print('Done.')