Skip to content

Commit

Permalink
feat(point): add comparison, remove to_table for Point
Browse files Browse the repository at this point in the history
  • Loading branch information
xcb-xwii committed Oct 3, 2023
1 parent b06c62d commit ee45371
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
26 changes: 22 additions & 4 deletions c/point.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,43 @@ static int LTS_point_eq(lua_State *L) {
return 1;
}

static int LTS_point_lt(lua_State *L) {
TSPoint self = LTS_check_point(L, 1);
TSPoint other = LTS_check_point(L, 2);

lua_pushboolean(L,
self.row < other.row ||
(self.row == other.row && self.column < other.column));
return 1;
}

static int LTS_point_le(lua_State *L) {
TSPoint self = LTS_check_point(L, 1);
TSPoint other = LTS_check_point(L, 2);

lua_pushboolean(L,
self.row < other.row ||
(self.row == other.row && self.column == other.column));
return 1;
}

static const luaL_Reg methods[] = {
{ "unpack", LTS_point_unpack },
{ "to_table", LTS_point_to_table },
{ "row", LTS_point_row },
{ "column", LTS_point_column },
{ NULL, NULL }
};

static const luaL_Reg metamethods[] = {
{ "__eq", LTS_point_eq },
//{ "__lt", LTS_point_lt }, TODO
//{ "__le", LTS_point_le }, TODO
{ "__lt", LTS_point_lt },
{ "__le", LTS_point_le },
{ NULL, NULL }
};

static const luaL_Reg funcs[] = {
{ "new", LTS_point_new },
{ "pack", LTS_point_new },
//{ "from_table", LTS_point_from_table }, TODO
{ NULL, NULL }
};

Expand Down
12 changes: 12 additions & 0 deletions ldoc/Point.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@ function Point:column() end
-- @tparam Point other
-- @treturn boolean
function Point:__eq(other) end

---
-- Check if a point occurs before another point.
-- @tparam Point other
-- @treturn boolean
function Point:__lt(other) end

---
-- Check if a point occurs before or is the same as another point.
-- @tparam Point other
-- @treturn boolean
function Point:__le(other) end

0 comments on commit ee45371

Please sign in to comment.