27 lines
712 B
C
27 lines
712 B
C
#include <lauxlib.h>
|
|
#include <lua.h>
|
|
#include <stdint.h>
|
|
|
|
uint32_t lookup3(const void *key, size_t length, uint32_t initval);
|
|
|
|
// Lua wrapper
|
|
static int l_lookup3(lua_State *L) {
|
|
size_t len;
|
|
const char *str = luaL_checklstring(L, 1, &len); // get string + length
|
|
uint32_t initval = (uint32_t)luaL_checkinteger(L, 2); // get initval
|
|
|
|
uint32_t hash = lookup3(str, len, initval);
|
|
|
|
lua_pushinteger(L, hash); // return the hash
|
|
return 1; // number of return values
|
|
}
|
|
|
|
// Module open function
|
|
int luaopen_lookup3(lua_State *L) {
|
|
lua_newtable(L);
|
|
|
|
lua_pushcfunction(L, l_lookup3);
|
|
lua_setfield(L, -2, "lookup3");
|
|
|
|
return 1; // return the table
|
|
}
|