I’m new to Lua and I was wondering if there are some compact way to define a list, a metatable in Lua as we do in Python:
lis = [i for i in set if i>0]
Any example would be greatly appreciated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Lua has no native list
However as @joachim pointed out, the are some hacks you can use to achieve it.
It would yield:
Notice that
comprehensiondoesn’t work in plain 5.2.x Lua. It requires Penlight Lua Libraries: http://stevedonovan.github.com/Penlight/api/index.htmlYou can also use MetaLua or LuaMacros