private void registerClass(Type t) { string className = t.FullName; if (LuaDll.luaL_newmetatable(L, className) == 1) { int top = LuaDll.lua_gettop(L); Console.WriteLine("Registering class " + className); foreach (System.Reflection.MethodInfo mi in t.GetMethods()) { if (mi.IsPublic) { // Check that this method has been declared as bindable? if (isBindable(mi)) { // If the name is set, then bind using that name. string bindName = getBindableName(mi, mi.Name); // Push the method pushFunction(mi, bindName); // Set the pushed closure as a member of our table. // The method should be at the top of the stack (-1), and the table below that (-2) // mt[mi.Name] = method; LuaDll.lua_setfield(L, -2, bindName); } } } // Register some luaisms // __gc LuaDll.lua_pushcfunction(L, mgcAdapterDelegate); LuaDll.lua_setfield(L, -2, "__gc"); // __tostring LuaDll.lua_pushcfunction(L, mtostringAdapterDelegate); LuaDll.lua_setfield(L, -2, "__tostring"); // __eq // Comparison operator LuaDll.lua_pushcfunction(L, meqAdapterDelegate); LuaDll.lua_setfield(L, -2, "__eq"); LuaDll.lua_pushstring(L, "__index"); // Push "__index" LuaDll.lua_pushvalue(L, -2); // Copy the metatable to the top of the stack LuaDll.lua_settable(L, -3); // mt["__index"] = mt // metatable should be at top of stack. Debug.Assert(top == LuaDll.lua_gettop(L), "Top is wrong"); } }