summaryrefslogtreecommitdiff
path: root/common.h
blob: e21c7a5ff78d8b8d42bd799d0de27943a31c6bbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef NERV_COMMON_H
#define NERV_COMMON_H
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "luaT/luaT.h"
#include <stdio.h>
#include <stdlib.h>

typedef struct HashNode {
    const char *key;
    void *val;
    struct HashNode *next;
} HashNode;

typedef int (*HashMapCmp_t)(const char *a, const char *b);
typedef size_t (*HashKey_t)(const char *key);

typedef struct HashMap {
    HashNode **bucket;
    HashMapCmp_t cmp;
    HashKey_t hfunc;
    size_t size;
} HashMap;

HashMap *hashmap_create(size_t size, HashKey_t hfunc, HashMapCmp_t cmp);
void *hashmap_getval(HashMap *h, const char *key);
void hashmap_setval(HashMap *h, const char *key, void *val);
void hashmap_clear(HashMap *h);

size_t bkdr_hash(const char *key);

int nerv_error(lua_State *L, const char *err_mesg_fmt, ...); 
int nerv_error_method_not_implemented(lua_State *L);
void luaN_append_methods(lua_State *L, const luaL_Reg *mlist);
#endif