lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have been programming Lua for nearly two years, and it still
took me several minutes to find the bug.

----
MyClass = {}

function MyClass.init(class,myclass)
    setmetatable(myclass,class)
    return myclass
end

function MyClass.__gt(x,y) return x:cmp(y)>0 end

function MyClass.cmp(x,y) -- details unimportant, it is defined
end

setmetatable(MyClass,{__call=MyClass.init})
MyClass.__index=MyClass
----

> print (MyClass{1,2}>MyClass{1,3})
stdin:1: attempt to compare two table values
stack traceback:
	stdin:1: in main chunk
	[C]: in ?