lua-users home
lua-l archive

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


Problem with 'lt' event in MAPM, Lua 4.0.
-------------------------------------------------------
MAPM - A Portable Arbitrary Precision Math Library
-------------------------------------------------------
Compare function, C wrap:
static int Bcompare(lua_State *L)
{
    M_APM a=Bget(L,1);
    M_APM b=Bget(L,2);
    lua_pushnumber(L, m_apm_compare(a,b));
    return 1;
}
-------------------------------------------------------
'lt' event definition:
local TAG=tag(Bnumber())
settagmethod( TAG,"lt", function (a,b) 
                                    local r = Bcompare(a,b) 
                                    if r== -1 then return 1 end 
                        return nil end
            )
simple test:   
-------------------------------------------------------
code                           |      output

a = Bnumber(2)          |
b = Bnumber(2)          |
print(Bcompare(a,b))  |      0
print(a,b, a<b)            |      2.0      2.0      nil -- Ok
print(a,b, a>b)            |      2.0      2.0      nil -- Ok
print(a,b, a<=b)          |      2.0      2.0      1  -- Ok
print(a,b, a>=b)          |      2.0      2.0      1  -- Ok
print(a,b, a==b)          |      2.0      2.0      nil -- Error
print(a,b, a~=b)          |      2.0      2.0      1  -- Error
-------------------------------------------------------
How I can solve this problem?

Best regards, 
      -- Alexey Yutkin.