tpt++: lots of random fixes to the legacy lua api 21854df9f334