lua-users home
lua-l archive

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


Hi, all!

I'm doing weird experiments with Lua, and need weird functionality for them :)

1. I need table, which can be compared with any other type (if
possible, including other tables with other meta-tables), using
meta-method of this table. I am ready to hack Lua sources to achieve
such behavior if changes would be local enough. Possible performance
hits are not the problem in this specific case. However, Lua behavior
should remain unchanged in other parts as much as possible.

I apologize for bad knowledge of Lua internals. But by quick glance
I've found few

   if (ttype(l) != ttype(r))

checks in lvm.c code. Would change like this be enough and safe?

 int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
   int res;
   if (ttisnumber(l) && ttisnumber(l))
     return luai_numlt(nvalue(l), nvalue(r));
   else if (ttisstring(l) && ttisstring(l))
     return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
   else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
     return res;
   return luaG_ordererror(L, l, r);
 }

2. Something really weird: I also need something (an __eq
meta-method?) which would catch implicit comparison with nil (or
false) like this:

  if t then
     print "t is not nil"
  else
     print "t is nil"
  end

I need to be able to simulate nil (or false) value here when t is a
meta-tabled table.

Thanks in advance,
Alexander.