lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Not looked too deeply into this but there is a Python AST tool. You could presumably write a tool to rewrite the AST into Lua. However there are some features in Python, such as the try: ... except: ... else: ... finally: blocks that might be difficult to translate into Lua. Also the behaviour of the basic data collections in Python is different to Lua (or even Ruby in my experience). You would find yourself having to implement all sorts of Python features in Lua, making it a lot less Lua and more Python in another syntax. For example referencing a non-existent key in a dictionary in Python will throw an exception but Lua will return a nil. So if this is used in the Python source then you will have to implement that in Lua tables too (that is you will need to implement an exception handling mechanism that works the same was as the one in Python)

Of course this depends on which features of Python are used in the source. You only need to implement what you actually use. You also might have the option to rewrite problematic parts on the Python source into something easier to translate

Python is, sort of, OO and it is likely to be used in most codebases of significant size so you will need to implement that too. Remember it will not be enough to simply implement OO in Lua (which can easily be done) but to implement Python OO in Lua

Even if you got that all to work the resulting code would be an abomination and very difficult to support or extend

Unless it is a really trivial Python source it is unlikely to be a "hands off" automatic translation

Like someone said, you will be wanting some tests. Lots of tests