diff --git a/elements.lua b/elements.lua index 64a4097..64cbab7 100644 --- a/elements.lua +++ b/elements.lua @@ -3,4 +3,58 @@ -- by make_elements.py. -- -return {["formspec_version"] = {{{"version", "number"}}}, ["size"] = {{{{"w", "number"}, {"h", "number"}}}, {{{"w", "number"}, {"h", "number"}, {"fixed_size", "boolean"}}}}, ["position"] = {{{{"x", "number"}, {"y", "number"}}}}, ["anchor"] = {{{{"x", "number"}, {"y", "number"}}}}, ["no_prepend"] = {{}}, ["real_coordinates"] = {{{"bool", "boolean"}}}, ["container"] = {{{{"x", "number"}, {"y", "number"}}}}, ["container_end"] = {{}}, ["scroll_container"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"scrollbar_name", "string"}, {"orientation", "string"}, {"scroll_factor", "number"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"scrollbar_name", "string"}, {"orientation", "string"}}}, ["scroll_container_end"] = {{}}, ["list"] = {{{"inventory_location", "string"}, {"list_name", "string"}, {{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"", "null"}}, {{"inventory_location", "string"}, {"list_name", "string"}, {{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"starting_item_index", "number"}}}, ["listring"] = {{{"inventory_location", "string"}, {"list_name", "string"}}, {}}, ["listcolors"] = {{{"slot_bg_normal", "string"}, {"slot_bg_hover", "string"}, {"slot_border", "string"}, {"tooltip_bgcolor", "string"}, {"tooltip_fontcolor", "string"}}, {{"slot_bg_normal", "string"}, {"slot_bg_hover", "string"}, {"slot_border", "string"}}, {{"slot_bg_normal", "string"}, {"slot_bg_hover", "string"}}}, ["tooltip"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"tooltip_text", "string"}, {"bgcolor", "string"}, {"fontcolor", "string"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"tooltip_text", "string"}, {"bgcolor", "string"}}, {{"gui_element_name", "string"}, {"tooltip_text", "string"}, {"bgcolor", "string"}, {"fontcolor", "string"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"tooltip_text", "string"}}, {{"gui_element_name", "string"}, {"tooltip_text", "string"}, {"bgcolor", "string"}}, {{"gui_element_name", "string"}, {"tooltip_text", "string"}}}, ["image"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}}}, ["animated_image"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"texture_name", "string"}, {"frame_count", "number"}, {"frame_duration", "number"}, {"frame_start", "number"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"texture_name", "string"}, {"frame_count", "number"}, {"frame_duration", "number"}}}, ["model"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"mesh", "string"}, {{{"textures", "string"}, "..."}}, {{"rotation_x", "number"}, {"rotation_y", "number"}}, {"continuous", "boolean"}, {"mouse_control", "boolean"}, {{"frame_loop_begin", "number"}, {"frame_loop_end", "number"}}, {"animation_speed", "number"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"mesh", "string"}, {{{"textures", "string"}, "..."}}, {{"rotation_x", "number"}, {"rotation_y", "number"}}, {"continuous", "boolean"}, {"mouse_control", "boolean"}, {{"frame_loop_begin", "number"}, {"frame_loop_end", "number"}}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"mesh", "string"}, {{{"textures", "string"}, "..."}}, {{"rotation_x", "number"}, {"rotation_y", "number"}}, {"continuous", "boolean"}, {"mouse_control", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"mesh", "string"}, {{{"textures", "string"}, "..."}}, {{"rotation_x", "number"}, {"rotation_y", "number"}}, {"continuous", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"mesh", "string"}, {{{"textures", "string"}, "..."}}, {{"rotation_x", "number"}, {"rotation_y", "number"}}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"mesh", "string"}, {{{"textures", "string"}, "..."}}}}, ["item_image"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"item_name", "string"}}}, ["bgcolor"] = {{{"bgcolor", "string"}, {"fullscreen", "fullscreen"}, {"fbgcolor", "string"}}, {{"bgcolor", "string"}, {"fullscreen", "fullscreen"}}, {{"bgcolor", "string"}}}, ["background"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}, {"auto_clip", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}}}, ["background9"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}, {"auto_clip", "boolean"}, {{"middle_x", "number"}, {"middle_y", "number"}, {"middle_x2", "number"}, {"middle_y2", "number"}}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}, {"auto_clip", "boolean"}, {{"middle_x", "number"}, {"middle_y", "number"}}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}, {"auto_clip", "boolean"}, {{"middle_x", "number"}}}}, ["pwdfield"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"label", "string"}}}, ["field"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"label", "string"}, {"default", "string"}}, {{"name", "string"}, {"label", "string"}, {"default", "string"}}}, ["field_close_on_enter"] = {{{"name", "string"}, {"close_on_enter", "boolean"}}}, ["textarea"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"label", "string"}, {"default", "string"}}}, ["label"] = {{{{"x", "number"}, {"y", "number"}}, {"label", "string"}}}, ["hypertext"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"text", "string"}}}, ["vertlabel"] = {{{{"x", "number"}, {"y", "number"}}, {"label", "string"}}}, ["button"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"label", "string"}}}, ["image_button"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}, {"name", "string"}, {"label", "string"}, {"noclip", "boolean"}, {"drawborder", "boolean"}, {"pressed_texture_name", "string"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}, {"name", "string"}, {"label", "string"}}}, ["item_image_button"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"item_name", "string"}, {"name", "string"}, {"label", "string"}}}, ["button_exit"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {"label", "string"}}}, ["image_button_exit"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"texture_name", "string"}, {"name", "string"}, {"label", "string"}}}, ["textlist"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"listelem", "string"}, "..."}}, {"selected_idx", "number"}, {"transparent", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"listelem", "string"}, "..."}}, {"selected_idx", "number"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"listelem", "string"}, "..."}}}}, ["tabheader"] = {{{{"x", "number"}, {"y", "number"}}, {"h", "number"}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}, {"transparent", "boolean"}, {"draw_border", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}, {"transparent", "boolean"}, {"draw_border", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}, {"transparent", "boolean"}, {"draw_border", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {"h", "number"}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}, {"transparent", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}, {"transparent", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}, {"transparent", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {"h", "number"}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}}, {{{"x", "number"}, {"y", "number"}}, {"name", "string"}, {{{"caption", "string"}, "..."}}, {"current_tab", "string"}}}, ["box"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"color", "string"}}}, ["dropdown"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"item", "string"}, "..."}}, {"selected_idx", "number"}, {"index_event", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {"w", "number"}, {"name", "string"}, {{{"item", "string"}, "..."}}, {"selected_idx", "number"}, {"index_event", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"item", "string"}, "..."}}, {"selected_idx", "number"}}, {{{"x", "number"}, {"y", "number"}}, {"w", "number"}, {"name", "string"}, {{{"item", "string"}, "..."}}, {"selected_idx", "number"}}}, ["checkbox"] = {{{{"x", "number"}, {"y", "number"}}, {"name", "string"}, {"label", "string"}, {"selected", "boolean"}}, {{{"x", "number"}, {"y", "number"}}, {"name", "string"}, {"label", "string"}}}, ["scrollbar"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"orientation", "string"}, {"name", "string"}, {"value", "string"}}}, ["scrollbaroptions"] = {{{{"opt", "table"}, "..."}}}, ["table"] = {{{{"x", "number"}, {"y", "number"}}, {{"w", "number"}, {"h", "number"}}, {"name", "string"}, {{{"cells", "string"}, "..."}}, {"selected_idx", "number"}}}, ["tableoptions"] = {{{{"opt", "table"}, "..."}}}, ["tablecolumns"] = {{{{{"type", "string"}, {{"opt", "table"}, "..."}}, "..."}}}, ["style"] = {{{{{"selectors", "string"}, "..."}}, {{"prop", "table"}, "..."}}, {{{"name", "string"}}, {{"prop", "table"}, "..."}}}, ["style_type"] = {{{{{"selectors", "string"}, "..."}}, {{"prop", "table"}, "..."}}, {{{"name", "string"}}, {{"prop", "table"}, "..."}}}, ["set_focus"] = {{{"name", "string"}, {"force", "boolean"}}, {{"name", "string"}}}} \ No newline at end of file +local a = {} +a[1] = {"w", "number"} +a[2] = {"h", "number"} +a[3] = {a[1], a[2]} +a[4] = {{"x", "number"}, {"y", "number"}} +a[5] = {{a[4]}} +a[6] = {} +a[7] = {a[6]} +a[8] = {"scrollbar_name", "string"} +a[9] = {"orientation", "string"} +a[10] = {"inventory_location", "string"} +a[11] = {"list_name", "string"} +a[12] = {"slot_bg_normal", "string"} +a[13] = {"slot_bg_hover", "string"} +a[14] = {"slot_border", "string"} +a[15] = {"tooltip_text", "string"} +a[16] = {"bgcolor", "string"} +a[17] = {"fontcolor", "string"} +a[18] = {"gui_element_name", "string"} +a[19] = {"texture_name", "string"} +a[20] = {a[4], a[3], a[19]} +a[21] = {"name", "string"} +a[22] = {"frame_count", "number"} +a[23] = {"frame_duration", "number"} +a[24] = {"mesh", "string"} +a[25] = {{{"textures", "string"}, "..."}} +a[26] = {{"rotation_x", "number"}, {"rotation_y", "number"}} +a[27] = {"continuous", "boolean"} +a[28] = {"mouse_control", "boolean"} +a[29] = {{"frame_loop_begin", "number"}, {"frame_loop_end", "number"}} +a[30] = {"item_name", "string"} +a[31] = {"fullscreen", "fullscreen"} +a[32] = {"auto_clip", "boolean"} +a[33] = {"middle_x", "number"} +a[34] = {"middle_y", "number"} +a[35] = {"label", "string"} +a[36] = {{a[4], a[3], a[21], a[35]}} +a[37] = {"default", "string"} +a[38] = {a[4], a[3], a[21], a[35], a[37]} +a[39] = {{a[4], a[35]}} +a[40] = {a[4], a[3], a[19], a[21], a[35]} +a[41] = {{{"listelem", "string"}, "..."}} +a[42] = {"selected_idx", "number"} +a[43] = {"transparent", "boolean"} +a[44] = {{{"caption", "string"}, "..."}} +a[45] = {"current_tab", "string"} +a[46] = {"draw_border", "boolean"} +a[47] = {{{"item", "string"}, "..."}} +a[48] = {"index_event", "boolean"} +a[49] = {{"opt", "table"}, "..."} +a[50] = {{a[49]}} +a[51] = {{"prop", "table"}, "..."} +a[52] = {a[21]} +a[53] = {{{{{"selectors", "string"}, "..."}}, a[51]}, {a[52], a[51]}} +return {["formspec_version"] = {{{"version", "number"}}}, ["size"] = {{a[3]}, {{a[1], a[2], {"fixed_size", "boolean"}}}}, ["position"] = a[5], ["anchor"] = a[5], ["no_prepend"] = a[7], ["real_coordinates"] = {{{"bool", "boolean"}}}, ["container"] = a[5], ["container_end"] = a[7], ["scroll_container"] = {{a[4], a[3], a[8], a[9], {"scroll_factor", "number"}}, {a[4], a[3], a[8], a[9]}}, ["scroll_container_end"] = a[7], ["list"] = {{a[10], a[11], a[4], a[3], {"", "null"}}, {a[10], a[11], a[4], a[3], {"starting_item_index", "number"}}}, ["listring"] = {{a[10], a[11]}, a[6]}, ["listcolors"] = {{a[12], a[13], a[14], {"tooltip_bgcolor", "string"}, {"tooltip_fontcolor", "string"}}, {a[12], a[13], a[14]}, {a[12], a[13]}}, ["tooltip"] = {{a[4], a[3], a[15], a[16], a[17]}, {a[4], a[3], a[15], a[16]}, {a[18], a[15], a[16], a[17]}, {a[4], a[3], a[15]}, {a[18], a[15], a[16]}, {a[18], a[15]}}, ["image"] = {a[20]}, ["animated_image"] = {{a[4], a[3], a[21], a[19], a[22], a[23], {"frame_start", "number"}}, {a[4], a[3], a[21], a[19], a[22], a[23]}}, ["model"] = {{a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29], {"animation_speed", "number"}}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28], a[29]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27], a[28]}, {a[4], a[3], a[21], a[24], a[25], a[26], a[27]}, {a[4], a[3], a[21], a[24], a[25], a[26]}, {a[4], a[3], a[21], a[24], a[25]}}, ["item_image"] = {{a[4], a[3], a[30]}}, ["bgcolor"] = {{a[16], a[31], {"fbgcolor", "string"}}, {a[16], a[31]}, {a[16]}}, ["background"] = {{a[4], a[3], a[19], a[32]}, a[20]}, ["background9"] = {{a[4], a[3], a[19], a[32], {a[33], a[34], {"middle_x2", "number"}, {"middle_y2", "number"}}}, {a[4], a[3], a[19], a[32], {a[33], a[34]}}, {a[4], a[3], a[19], a[32], {a[33]}}}, ["pwdfield"] = a[36], ["field"] = {a[38], {a[21], a[35], a[37]}}, ["field_close_on_enter"] = {{a[21], {"close_on_enter", "boolean"}}}, ["textarea"] = {a[38]}, ["label"] = a[39], ["hypertext"] = {{a[4], a[3], a[21], {"text", "string"}}}, ["vertlabel"] = a[39], ["button"] = a[36], ["image_button"] = {{a[4], a[3], a[19], a[21], a[35], {"noclip", "boolean"}, {"drawborder", "boolean"}, {"pressed_texture_name", "string"}}, a[40]}, ["item_image_button"] = {{a[4], a[3], a[30], a[21], a[35]}}, ["button_exit"] = a[36], ["image_button_exit"] = {a[40]}, ["textlist"] = {{a[4], a[3], a[21], a[41], a[42], a[43]}, {a[4], a[3], a[21], a[41], a[42]}, {a[4], a[3], a[21], a[41]}}, ["tabheader"] = {{a[4], a[2], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[3], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[21], a[44], a[45], a[43], a[46]}, {a[4], a[2], a[21], a[44], a[45], a[43]}, {a[4], a[3], a[21], a[44], a[45], a[43]}, {a[4], a[21], a[44], a[45], a[43]}, {a[4], a[2], a[21], a[44], a[45]}, {a[4], a[3], a[21], a[44], a[45]}, {a[4], a[21], a[44], a[45]}}, ["box"] = {{a[4], a[3], {"color", "string"}}}, ["dropdown"] = {{a[4], a[3], a[21], a[47], a[42], a[48]}, {a[4], a[1], a[21], a[47], a[42], a[48]}, {a[4], a[3], a[21], a[47], a[42]}, {a[4], a[1], a[21], a[47], a[42]}}, ["checkbox"] = {{a[4], a[21], a[35], {"selected", "boolean"}}, {a[4], a[21], a[35]}}, ["scrollbar"] = {{a[4], a[3], a[9], a[21], {"value", "string"}}}, ["scrollbaroptions"] = a[50], ["table"] = {{a[4], a[3], a[21], {{{"cells", "string"}, "..."}}, a[42]}}, ["tableoptions"] = a[50], ["tablecolumns"] = {{{{{"type", "string"}, a[49]}, "..."}}}, ["style"] = a[53], ["style_type"] = a[53], ["set_focus"] = {{a[21], {"force", "boolean"}}, a[52]}} diff --git a/lua_dump.py b/lua_dump.py index 530e3c3..35e735a 100644 --- a/lua_dump.py +++ b/lua_dump.py @@ -26,6 +26,7 @@ # IN THE SOFTWARE. # +import collections, copy from decimal import Decimal def _escape_string(x): @@ -46,18 +47,18 @@ class _PartialTypeError(TypeError): return 'Object of type ' + repr(type(self.args[0]).__name__) + \ ' is not Lua serializable.' -def _dump(obj): - if isinstance(obj, set): +def _dump(obj, dump_func): + if isinstance(obj, (set, frozenset)): obj = dict.fromkeys(obj, True) if isinstance(obj, dict): res = [] for k, v in obj.items(): - res.append('[' + _dump(k) + '] = ' + _dump(v)) + res.append('[' + dump_func(k) + '] = ' + dump_func(v)) return '{' + ', '.join(res) + '}' if isinstance(obj, (tuple, list)): - return '{' + ', '.join(map(_dump, obj)) + '}' + return '{' + ', '.join(map(dump_func, obj)) + '}' if isinstance(obj, bool): return 'true' if obj else 'false' @@ -82,21 +83,88 @@ def dump(obj): """ try: - return _dump(obj) + return _dump(obj, _dump) except _PartialTypeError as e: msg = str(e) # Clean tracebacks raise TypeError(msg) +def _walk(obj, seen): + yield obj + if isinstance(obj, dict): + for k, v in obj.items(): + # yield from _walk(k, seen) + yield from _walk(v, seen) + elif isinstance(obj, (tuple, list, set, frozenset)): + try: + if obj in seen: + return + seen.add(obj) + except TypeError: + pass + for v in obj: + yield from _walk(v, seen) + +def _replace_values(obj): + if isinstance(obj, dict): + it = obj.items() + elif isinstance(obj, list): + it = enumerate(obj) + else: + return + + for k, v in it: + if isinstance(v, tuple): + new_obj = list(v) + _replace_values(new_obj) + obj[k] = tuple(new_obj) + continue + _replace_values(v) + if isinstance(v, list): + obj[k] = tuple(v) + def serialize(obj): """ Serialize an object into valid Lua code. This will raise a TypeError if the object cannot be serialized into lua. """ + # Count all tuples + ref_count = collections.Counter() + + obj = copy.deepcopy(obj) + _replace_values(obj) + + for item in _walk(obj, set()): + if isinstance(item, (tuple, frozenset)): + try: + ref_count[item] += 1 + except TypeError: + pass + + # This code is heavily inspired by MT's builtin/common/serialize.lua + dumped = {} + res = [] + def dump_or_ref(obj2): + try: + count = ref_count[obj2] + except TypeError: + count = 0 + if count >= 2: + if obj2 not in dumped: + code = _dump(obj2, dump_or_ref) + idx = len(res) + 1 + res.append('a[{}] = {}'.format(idx, code)) + dumped[obj2] = idx + return 'a[{}]'.format(dumped[obj2]) + return _dump(obj2, dump_or_ref) + try: - return 'return ' + _dump(obj) + res.append('return ' + _dump(obj, dump_or_ref)) + if len(res) > 1: + res.insert(0, 'local a = {}') + return '\n'.join(res) except _PartialTypeError as e: msg = str(e) diff --git a/make_elements.py b/make_elements.py index ae1adfb..eb6afc9 100755 --- a/make_elements.py +++ b/make_elements.py @@ -288,12 +288,7 @@ def main(): with open(filename, 'w') as f: f.write(_comment.lstrip()) f.write(lua_dump.serialize(data)) - # elems = fetch_and_parse() - # for elem in sorted(elems): - # for def_ in elems[elem]: - # f.write('formspec_ast.register_element({}, {})\n'.format( - # lua_dump.dump(elem), lua_dump.dump(def_) - # )) + f.write('\n') print('Done.') if __name__ == '__main__':