static int bcrc_optimal(lua_State* L) { Crc** ud = newudata(L); *ud = new CrcOptimal<Optimal>(); luaL_argcheck(L, *ud, 1, "out of memory"); return 1; }
void *kp_newuserdata(ktap_State *ks, size_t size) { Udata *u; u = newudata(ks, size); return u + 1; }
/*- - crc = bcrc.new(bits, poly[, initial, xor, reflect_input, reflect_remainder]) Mandatory args: - bits=n, where n is 8, 16, 24, 32 - poly=n, where n is the polynomial Optional args: - initial=n, where n is the initial value for the crc, defaults to 0 - xor=n, where n is the value to xor with the final value, defaults to 0 - reflect_input=bool, defaults to false - reflect_remainder=bool, defaults to false Returns a crc object. */ static int bcrc_new(lua_State *L) { int bits = luaL_checkint(L, 1); int poly = luaL_checkint(L, 2); int initial = luaL_optint(L, 3, 0); int xor_ = luaL_optint(L, 4, 0); int reflect_input = lua_toboolean(L, 5); int reflect_remainder = lua_toboolean(L, 6); Crc** ud = newudata(L); switch(bits) { case 8: *ud = new CrcBasic< 8>(poly, initial, xor_, reflect_input, reflect_remainder); break; case 16: *ud = new CrcBasic<16>(poly, initial, xor_, reflect_input, reflect_remainder); break; case 24: *ud = new CrcBasic<24>(poly, initial, xor_, reflect_input, reflect_remainder); break; case 32: *ud = new CrcBasic<32>(poly, initial, xor_, reflect_input, reflect_remainder); break; default: return luaL_argerror(L, 2, "unsupported crc bit width"); } luaL_argcheck(L, *ud, 1, "out of memory"); return 1; }