summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/luaharfbuzz/src/luaharfbuzz/direction.c
blob: 644b3af30a2ce0979138929703d1098ba6a57c8a (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// harfbuzz.Feature
#include "luaharfbuzz.h"

static int direction_new(lua_State *L) {
  Direction *d;
  const char *dir = luaL_checkstring(L, 1);

  d = (Direction *)lua_newuserdata(L, sizeof(*d));
  luaL_getmetatable(L, "harfbuzz.Direction");
  lua_setmetatable(L, -2);

  *d = hb_direction_from_string(dir, -1);
  return 1;
}

static int direction_to_string(lua_State *L) {
  Direction* d = (Direction *)luaL_checkudata(L, 1, "harfbuzz.Direction");

  lua_pushstring(L, hb_direction_to_string(*d));
  return 1;
}

static int direction_equals(lua_State *L) {
  Direction* lhs = (Direction *)luaL_checkudata(L, 1, "harfbuzz.Direction");
  Direction* rhs = (Direction *)luaL_checkudata(L, 2, "harfbuzz.Direction");

  lua_pushboolean(L, *lhs == *rhs);
  return 1;
}

static int direction_is_valid(lua_State *L) {
  Direction* d = (Direction *)luaL_checkudata(L, 1, "harfbuzz.Direction");

  lua_pushboolean(L, HB_DIRECTION_IS_VALID(*d));
  return 1;
}

static int direction_is_horizontal(lua_State *L) {
  Direction* d = (Direction *)luaL_checkudata(L, 1, "harfbuzz.Direction");

  lua_pushboolean(L, HB_DIRECTION_IS_HORIZONTAL(*d));
  return 1;
}

static int direction_is_vertical(lua_State *L) {
  Direction* d = (Direction *)luaL_checkudata(L, 1, "harfbuzz.Direction");

  lua_pushboolean(L, HB_DIRECTION_IS_VERTICAL(*d));
  return 1;
}

static int direction_is_forward(lua_State *L) {
  Direction* d = (Direction *)luaL_checkudata(L, 1, "harfbuzz.Direction");

  lua_pushboolean(L, HB_DIRECTION_IS_FORWARD(*d));
  return 1;
}

static int direction_is_backward(lua_State *L) {
  Direction* d = (Direction *)luaL_checkudata(L, 1, "harfbuzz.Direction");

  lua_pushboolean(L, HB_DIRECTION_IS_BACKWARD(*d));
  return 1;
}

static const struct luaL_Reg direction_methods[] = {
  { "__tostring", direction_to_string },
  { "__eq", direction_equals },
  { "is_valid", direction_is_valid },
  { "is_horizontal", direction_is_horizontal },
  { "is_vertical", direction_is_vertical },
  { "is_forward", direction_is_forward },
  { "is_backward", direction_is_backward },
  { NULL, NULL }
};

static const struct luaL_Reg direction_functions[] = {
  { "new", direction_new },
  { NULL,  NULL }
};

int register_direction(lua_State *L) {
  return register_class(L, "harfbuzz.Direction", direction_methods, direction_functions, NULL);
}