Debian Codegraph @

texk/web2c/luatexdir/luaharfbuzz/src/luaharfbuzzsubset/luaharfbuzzsubset.c

raw
1 #include "luaharfbuzzsubset.h"
2
3 static int subset(lua_State *L) {
4 // arguments: face and input
5 Face *face = (Face *)luaL_checkudata(L, 1, "harfbuzz.Face");
6 SubsetInput *input = (SubsetInput*)luaL_checkudata(L, 2, "harfbuzz.SubsetInput");
7
8 // perform the subset
9 hb_face_t* subset_face = hb_subset_or_fail(*face, *input);
10 if (subset_face == NULL) {
11 lua_pushnil(L);
12 return 0;
13 }
14 // create a new userdata for the subset face
15 hb_face_t **ud = (hb_face_t **)lua_newuserdata(L, sizeof(hb_face_t *));
16 *ud = subset_face;
17 luaL_getmetatable(L, "harfbuzz.Face");
18 lua_setmetatable(L, -2);
19 return 1;
20 }
21
22 static int version (lua_State *L) {
23 lua_pushstring(L, hb_version_string());
24 return 1;
25 }
26
27 static const struct luaL_Reg lib_table [] = {
28 {"subset", subset},
29 {"version", version},
30 {NULL, NULL}
31 };
32
33 int luaopen_luaharfbuzzsubset (lua_State *L) {
34 lua_newtable(L);
35
36 register_subset_input(L);
37 lua_setfield(L, -2, "SubsetInput");
38
39 luaL_setfuncs(L, lib_table, 0);
40
41 return 1;
42 }
43