Lua review

first batch of lua patch.

I probably have one more patch for core, but it's currently tangled in lua commits so I can't easily extract it.