Lua indentation code in Lua [closed]

淺唱寂寞╮ 提交于 2019-11-29 01:36:28

I have written a Lua beautifier and applied it to my project with a large group of Lua files (about 8k lines in total). The beautifier is in Perl (and yes, I saw that the question is about it being in Lua), but (1) it is only 55 lines and it should be easily translatable to Lua (I just haven't got time to do that yet), and (2) you can format your files somewhere else and transfer back to your environment (unless you need this re-formatting to be done on a regular basis).

This beautifier is based on another Lua-based one (udead link as of 3/11/2013; web archive copy), but the original one didn't handle all the cases that I was interested in, so I ended up re-writing it. It may still work for you though.

The beautifier doesn't change the line structure (it was one of the requirements), which makes it easy to check, but changes the indentation and formatting (and handles complex cases of embedded anonymous functions and other similar things). The link includes some examples of what it does. You can also review the long commit I did for our project with most of the converted files: https://github.com/pkulchenko/ZeroBraneStudio/commit/85be27559058ce085e95cef47de2c11185f9211a.

If you are looking only for an easy way to indent your files (rather than to integrate the indentation logic into your application), then you can use ZeroBrane Studio IDE (Edit | Source | Correct Indentation or Ctrl-I).

I tried a number of these but with no real success. Then I hit on the solution: the Eclipse based Lua Development tools.

http://eclipse.org/koneki/ldt/

Download what you need for your version (if you have a 64 bit windows, the 32 bit version doesn't work). Run the .exe (no install required!), then do ctrl+shift+f, and your code is all pretty printed!

Try this code formatter written in Lua, it has a few options and you can always edit it if you want to customize it beyond the options:

http://lua-users.org/wiki/SourceCodeFormatter

Sounds like Serpent might be what you are looking for; pretty-prints Lua source code with indentation.

Also https://github.com/LuaDist/luapretty

Although it is Lua-based, it requires some libraries. See the README.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!