better parameter checking for both the lua and C APIs