There seems to be a bug in the rshift function as defined here. Shifting a value of 0x01 twice should result in a value of 0 while shifting a value of 0x03 twice should result in a value of 1. Lua will return 0 for both of these operations as shown below.
Using the math.round function defined at http://lua-users.org/wiki/SimpleRound appears to fix this however.
I haven't tested the results with larger numbers but for simply 8 bit integer operations this appears to be enough.