StackObjectToString() public static method

public static StackObjectToString ( IntPtr state, int index ) : string
state System.IntPtr
index int
return string
Beispiel #1
0
        private static List <string> ExecuteInternal(string query, bool withResults)
        {
            if (withResults)
            {
                query = "return " + query;
            }
            var state = LuaInterface.LuaState;
            int top   = LuaInterface.GetTop(state);

            var data   = Encoding.ASCII.GetBytes(query);
            var 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);
            }
        }
Beispiel #2
0
        private static 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);
        }