From cfc4ba97c3596db1105abc17692a54185cfd3a30 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 6 Jan 2014 16:00:42 -0500 Subject: [PATCH] luatz/timetable: Coercion doesn't work ==> lua relational operators only work on objects with same metatable --- luatz/timetable.lua | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/luatz/timetable.lua b/luatz/timetable.lua index e1649a0..3bb7689 100644 --- a/luatz/timetable.lua +++ b/luatz/timetable.lua @@ -143,23 +143,14 @@ function timetable_methods:rfc_3339 ( ) return strformat ( "%04u-%02u-%02uT%02u:%02u:%06.3f" , self:unpack ( ) ) end -local timetable_mt - -local function coerce_arg ( t ) - if getmetatable ( t ) == timetable_mt then - return t:timestamp ( ) - end - return t -end - -timetable_mt = { +local timetable_mt = { __index = timetable_methods ; __tostring = timetable_methods.rfc_3339 ; __eq = function ( a , b ) - return coerce_arg ( a ) == coerce_arg ( b ) + return a:timestamp ( ) == b:timestamp ( ) end ; __lt = function ( a , b ) - return coerce_arg ( a ) < coerce_arg ( b ) + return a:timestamp ( ) < b:timestamp ( ) end ; } -- 2.39.5