lua-users home
lua-l archive

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


Hi.
Is it possible to change strings __eq metamethod? I'd like to change it so I can do caseless comparisons. I know that in order to do that, I need to do it from C, so I expected this to work.

   // get string metatable
       lua_pushstring(eval, "");
       lua_getmetatable(eval, -1);

   // define a lua function (dostring just evaluates the code)
       eval.dostring("test = function(k,v) print(k,v); return true; end");
       lua_pushstring(eval, "__eq");   // push the key
       lua_getglobal(eval, "test");      // push the value (my function)

       lua_rawset(eval, -3);   // set the metamethod
       eval.dostring("return \"abc\" == \"ABc\"");
       bool b = lua_toboolean(eval, -1);

That's not working. What am I doing wrong? I also tried to set __eq from Lua, using the debug library, to no avail.

Thanks in advance,
Ignacio Burgueño