Example #1
0
        public void inspectClass(Object o)
        {
            int top = LuaDll.lua_gettop(L);

            // check if this class is registered and inspect the metatable
            LuaDll.luaL_getmetatable(L, o.GetType().FullName);
            if (LuaDll.lua_isnil(L, -1))
            {
                Console.WriteLine("inspectClass - metatable not found for class [{0}]", o.GetType().FullName);
                return;
            }

            Console.WriteLine("Inspecting {0}", o.GetType().FullName);

            /* table is in the stack at index 't' */
            int t = LuaDll.lua_gettop(L);

            LuaDll.lua_pushnil(L);  /* first key */
            while (LuaDll.lua_next(L, t) != 0)
            {
                // Use built-in "print" function to print the two values on the stack.
                LuaDll.lua_getglobal(L, "print");
                LuaDll.lua_pushstring(L, "\t");
                LuaDll.lua_pushvalue(L, -4);
                LuaDll.lua_pushvalue(L, -4);
                LuaDll.lua_call(L, 3, 0);

                /* removes 'value'; keeps 'key' for next iteration */
                LuaDll.lua_pop(L, 1);
            }

            // Pop the metatable
            LuaDll.lua_pop(L, 1);

            Debug.Assert(top == LuaDll.lua_gettop(L), "Error in stack");
        }