When borrowing this code for my own purposes, I ran into a bug that checkudata can leave extra items on the stack if the call to lua_rawequal() fails then the metatable and field are left on the stack. That if statement should have an else case to pop those two off the sack.
I apologize for not having an exact way to make it fail so you can test it, but I know how hard Lua stack issues can be to debug so figured I'd drop this note here.
Fix committed as [f83d67].
Related
Commit: [f83d67]