fix some lua errors & style:
1. replace lua_isnil with lua_isnoneornil in a lot places
2. replace a lot lua_gettop() .. lua_isxyz(idx) with luaL_checkxyz
3. use luaL_optxyz()