Lua tutorial help for Python programmer?

Skip Montanaro skip.montanaro at gmail.com
Mon Nov 7 14:27:48 EST 2016


I just got Lua scripting dumped in my lap as a way to do some server
side scripting in Redis. The very most basic stuff isn't too hard (i =
1, a = {"x"=4, ...}, for i = 1,10,2 do ... end), but as soon as I get
beyond that, I find it difficult to formulate questions which coax
Google into useful suggestions. Is there an equivalent to the
python-tutor, python-help, or even this (python-list/comp.lang.python)
for people to ask Lua questions from the perspective of a Python
programmer? Maybe an idiom translation table?

A couple questions to show what sort of (terribly basic) stuff I'm after.

1. print(tbl) where tbl is a Lua table prints something useless like

table: 0x3c73310

How can I print a table in one go so I see all its keys and values?

2. The redis-py package helpfully converts the result of HGETALL to a
Python dictionary. On the server, The Lua code just sees an
interleaved list (array?) of the key/value pairs, e.g., "a" "1" "b"
"2" "c" "hello". I'd dictify that in Python easily enough:

dict(zip(result[::2], result[1::2]))

and get {"a": "1", "b": "2", "c": "hello"}

Skimming the Lua reference manual, I didn't see anything like dict()
and zip(). I suspect I'm thinking like a Python programmer when I
shouldn't be. Is there a Lua idiom which tackles this problem in a
straightforward manner, short of a numeric for loop?

As you can see, this is pretty trivial stuff, mostly representing
things which are just above the level of the simplest tutorial.

Thanks,

Skip



More information about the Python-list mailing list