Add old function back to lua_dump.py
This commit is contained in:
parent
af262da9de
commit
a4d5dc23d3
15
lua_dump.py
15
lua_dump.py
@ -90,6 +90,14 @@ def dump(obj):
|
|||||||
# Clean tracebacks
|
# Clean tracebacks
|
||||||
raise TypeError(msg)
|
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):
|
def _walk(obj, seen):
|
||||||
yield obj
|
yield obj
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
@ -124,10 +132,11 @@ def _replace_values(obj):
|
|||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
obj[k] = tuple(v)
|
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
|
Serializes an object into a Lua table with the assumption that the
|
||||||
object cannot be serialized into lua.
|
resulting table will never be modified. This allows any duplicate lists and
|
||||||
|
tuples to be reused.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Count all tuples
|
# Count all tuples
|
||||||
|
@ -287,7 +287,7 @@ def main():
|
|||||||
print('Writing to ' + filename + '...')
|
print('Writing to ' + filename + '...')
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
f.write(_comment.lstrip())
|
f.write(_comment.lstrip())
|
||||||
f.write(lua_dump.serialize(data))
|
f.write(lua_dump.serialize_readonly(data))
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
print('Done.')
|
print('Done.')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user