Various fixes to sync Lua scripting with recent updates

This just syncs various fixes that were made to the source tree while the Lua branch was outstanding that should be included in the lua tree, mostly from the python example