aboutsummaryrefslogtreecommitdiff
path: root/src/api/cp_replace.c
blob: a0fb3ac8a1b81bdb2059a5ddc9b6d35532e4ae6c (plain)
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
37
38
39
40
41
42
#include "api.h"
#include "renderer.h"


static int f_new(lua_State *L) {
  CPReplaceTable *rep_table = lua_newuserdata(L, sizeof(CPReplaceTable));
  luaL_setmetatable(L, API_TYPE_REPLACE);
  ren_cp_replace_init(rep_table);
  return 1;
}


static int f_gc(lua_State *L) {
  CPReplaceTable *rep_table = luaL_checkudata(L, 1, API_TYPE_REPLACE);
  ren_cp_replace_free(rep_table);
  return 0;
}


static int f_add(lua_State *L) {
  CPReplaceTable *rep_table = luaL_checkudata(L, 1, API_TYPE_REPLACE);
  const char *src = luaL_checkstring(L, 2);
  const char *dst = luaL_checkstring(L, 3);
  ren_cp_replace_add(rep_table, src, dst);
  return 0;
}


static const luaL_Reg lib[] = {
  { "__gc",               f_gc     },
  { "new",                f_new    },
  { "add",                f_add    },
  { NULL, NULL }
};

int luaopen_renderer_replacements(lua_State *L) {
  luaL_newmetatable(L, API_TYPE_REPLACE);
  luaL_setfuncs(L, lib, 0);
  lua_pushvalue(L, -1);
  lua_setfield(L, -2, "__index");
  return 1;
}