fixed int vs size_t mismatches, add checks to lua args before sending to c