Пример #1
0
        private static int DeleteSelf(IntPtr L)
        {
            IntPtr ppMyClass    = XLLRTWarper.luaL_checkudata(L, 1, "HelloBolt.MyClass");
            IntPtr myclassIndex = new IntPtr(Marshal.ReadInt32(ppMyClass));

            allLuaMyClassObj[myclassIndex.ToInt32()] = null;
            return(0);
        }
Пример #2
0
        private static int AttachResultListener(IntPtr L)
        {
            IntPtr  ppMyClass    = XLLRTWarper.luaL_checkudata(L, 1, "HelloBolt.MyClass");
            IntPtr  myclassIndex = new IntPtr(Marshal.ReadInt32(ppMyClass));
            MyClass theObj       = allLuaMyClassObj[myclassIndex.ToInt32()];

            if (XLLRTWarper.lua_type(L, 2) == (int)LuaTypes.LUA_TFUNCTION)
            {
                int             functionRef = XLLRTWarper.luaL_ref(L, (int)LuaInnerIndex.LUA_REGISTRYINDEX);
                LuaMyClassAddOb theOb       = new LuaMyClassAddOb(L, functionRef);
                theObj.OnAddFinish += theOb.OnAddFinish;
            }
            return(0);
        }
Пример #3
0
        private static int Add(IntPtr L)
        {
            //考虑到unsafe代码里传递对象指针生命周期管理非常麻烦,这里配合s_currentIndex,allLuaMyClassObj
            //牺牲了一点性能实现了一个简单的方案.
            //每个封装函数的开始就是得到对象的C# object instance
            IntPtr  ppMyClass    = XLLRTWarper.luaL_checkudata(L, 1, "HelloBolt.MyClass");
            IntPtr  myclassIndex = new IntPtr(Marshal.ReadInt32(ppMyClass));
            MyClass theObj       = allLuaMyClassObj[myclassIndex.ToInt32()];

            int lhs    = XLLRTWarper.lua_tointeger(L, 2);
            int rhs    = XLLRTWarper.lua_tointeger(L, 3);
            int result = theObj.Add(lhs, rhs);

            XLLRTWarper.lua_pushinteger(L, result);
            return(1);
        }