New lua kernel i

This is the first part of PR #280 , I merge it because it will be helpful to simplify the code for lua random map generation, also because I think I want to refactor the second part, although the first part is good, and will get most of the conflicts out of the way.