diff --git a/c/point.c b/c/point.c index c5848e6..d1318fb 100644 --- a/c/point.c +++ b/c/point.c @@ -68,9 +68,28 @@ 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 } @@ -78,15 +97,14 @@ static const luaL_Reg methods[] = { 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 } }; diff --git a/ldoc/Point.lua b/ldoc/Point.lua index 27ee3bb..a5942ab 100644 --- a/ldoc/Point.lua +++ b/ldoc/Point.lua @@ -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