Beispiel #1
0
        private void pushObject(Object o)
        {
            GCHandle gch = GCHandle.Alloc(o);

            // Store the GCHandle so that it won't get garbage collected.
            mLuaReferences.Add(gch);

            // Push a userdata onto the stack (we don't care about the returned address)
            // This is needed because we cannot create a metatable for a lightuserdata.
            // So we make the light userdata a member of it's metatable.
            IntPtr p = LuaDll.lua_newuserdata(L, 8);

            // Write the IntPtr of the object handle to the userdata.
            Marshal.WriteIntPtr(p, GCHandle.ToIntPtr(gch));

            // Pushes the metatable of the given class onto the stack
            pushMetatable(o.GetType());

            // We should have a metatable of this object's class on the top of the stack.
            // Now register the object, which is below that (-2)
            // o.__metatable = mt
            LuaDll.lua_setmetatable(L, -2);

            // The exported object should now be on the top of the stack.
        }