예제 #1
0
        private static string PopError(IntPtr state)
        {
            IntPtr p = LuaInterface.ToLString(state, 1, 0);

            if (p == IntPtr.Zero)
            {
                return("Unknown Error");
            }
            LuaInterface.Pop(state, 1);
            return(Marshal.PtrToStringAnsi(p));
        }
예제 #2
0
        private static List <string> ExecuteInternal(string query, bool withResults)
        {
            if (withResults)
            {
                query = "return " + query;
            }
            IntPtr state = LuaInterface.LuaState;
            int    top   = LuaInterface.GetTop(state);

            byte[] data   = Encoding.UTF8.GetBytes(query);
            IntPtr memory = Marshal.AllocHGlobal(data.Length + 1);

            try
            {
                Marshal.Copy(data, 0, memory, data.Length);
                Marshal.WriteByte(memory + data.Length, 0);

                if (LuaInterface.LoadBuffer(state, memory, data.Length, "cleanCore") > 0)
                {
                    return new List <string> {
                               PopError(state)
                    }
                }
                ;

                if (LuaInterface.PCall(state, 0, withResults ? (int)LuaInterface.LuaConstant.MultRet : 0, 0) > 0)
                {
                    return new List <string> {
                               PopError(state)
                    }
                }
                ;

                int returnValueCount = LuaInterface.GetTop(state) - top;
                var ret = new List <string>(returnValueCount);
                for (int i = 1; i <= returnValueCount; i++)
                {
                    ret.Add(LuaInterface.StackObjectToString(state, i));
                }
                LuaInterface.Pop(state, returnValueCount);
                return(ret);
            }
            finally
            {
                Marshal.FreeHGlobal(memory);
            }
        }
예제 #3
0
        private int HandleVictimCall(IntPtr luaState)
        {
            int top = LuaInterface.GetTop(luaState);

            if (top > 0)
            {
                var args = new List <string>(top);
                for (int i = 1; i <= top; i++)
                {
                    args.Add(LuaInterface.StackObjectToString(luaState, i));
                }
                LuaInterface.Pop(luaState, top);
                HandleEvent(args);
            }
            else
            {
                // legal call
                return((int)_eventDetour.CallOriginal(luaState));
            }

            return(0);
        }