コード例 #1
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                string key   = Guid.NewGuid().ToString();
                string value = Guid.NewGuid().ToString();

                lua.CreateTable();
                lua.PushString(value);
                lua.SetField(-2, key);

                lua.PushNil();
                lua.Next(-2);

                string received_key   = lua.GetString(-2);
                string received_value = lua.GetString(-1);
                lua.Pop(3);

                if (received_key != key || received_value != value)
                {
                    throw new NextTestException("Received key value pair is invalid");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #2
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushManagedFunction((lua) =>
                {
                    throw new Exception(random_string);
                });
                lua.MCall(0, 0);

                throw new Exception("The managed exception was not caught by MCall.");
            }
            catch (Exception e)
            {
                if (e is GmodLuaException && e.Message.Contains(random_string))
                {
                    taskCompletion.TrySetResult(true);
                }
                else
                {
                    taskCompletion.TrySetException(new Exception[] { e });
                }
            }

            return(taskCompletion.Task);
        }
コード例 #3
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushManagedClosure(lua =>
                {
                    throw new Exception(error_message);
                }, 0);

                lua.MCall(0, 0);

                throw new Exception("MCall hasn't caught an exception");
            }
            catch (Exception e)
            {
                if (e is GmodLuaException && e.ToString().Contains(error_message))
                {
                    taskCompletion.TrySetResult(true);
                }
                else
                {
                    taskCompletion.TrySetException(new Exception[] { e });
                }
            }

            return(taskCompletion.Task);
        }
コード例 #4
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushAngle(new System.Numerics.Vector3(0));
                if (!lua.GetMetaTable(-1))
                {
                    throw new GetMetaTableTestException("GetMetaTable returned false");
                }
                lua.GetField(-1, "IsZero");
                lua.Push(-3);
                lua.MCall(1, 1);
                bool received_bool = lua.GetBool(-1);
                lua.Pop(3);
                if (!received_bool)
                {
                    throw new GetMetaTableTestException("Meta function returned False but must return True");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #5
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            this.lua_extructor = lua_extructor;

            try
            {
                lua.CreateTable();
                lua.CreateTable();
                lua.PushManagedFunction(MetaToStringDelegate);
                lua.SetField(-2, "__tostring");
                lua.SetMetaTable(-2);

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "tostring");
                lua.Push(-3);
                lua.MCall(1, 1);

                string get_val = lua.GetString(-1);

                lua.Pop(2);

                if (get_val != to_str_msg)
                {
                    throw new CreateMetaTableException("Recieved string is incorrect");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #6
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                string random_key1 = Guid.NewGuid().ToString();
                string random_key2 = Guid.NewGuid().ToString();
                string random_key3 = Guid.NewGuid().ToString();

                string random1 = Guid.NewGuid().ToString();
                string random2 = Guid.NewGuid().ToString();
                string random3 = Guid.NewGuid().ToString();

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.PushString(random1);
                lua.SetField(-2, random_key1);

                lua.PushString(random2);
                lua.SetField(-2, random_key2);

                lua.PushString(random3);
                lua.SetField(-2, random_key3);

                lua.Pop(lua.Top());

                lua.PushGlobalTable();

                lua.GetField(-1, random_key1);
                if (lua.GetString(-1) != random1)
                {
                    throw new Exception("First random string is invalid");
                }
                lua.Pop(1);

                lua.GetField(-1, random_key2);
                if (lua.GetString(-1) != random2)
                {
                    throw new Exception("Second random string is invalid");
                }
                lua.Pop(1);

                lua.GetField(-1, random_key3);
                if (lua.GetString(-1) != random3)
                {
                    throw new Exception("Third random string is invalid");
                }
                lua.Pop(1);

                lua.Pop(1);

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #7
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                IntPtr func_int_ptr;

                unsafe
                {
                    func_int_ptr = (IntPtr)(delegate * unmanaged[Cdecl] < IntPtr, int >) & TestFunc;
                }

                lua.PushCFunction(func_int_ptr);

                lua.MCall(0, 1);

                string ret_string = lua.GetString(-1);

                lua.Pop(1);

                if (ret_string != random)
                {
                    throw new Exception("Return string is incorrect");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #8
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                try
                {
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        LoadLibraryA("Kernel32");
                    }
                    else
                    {
                        dlopen("libdl", 0);
                    }
                }
                catch (DllNotFoundException)
                {
                    taskCompletion.TrySetResult(true);
                }
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #9
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushManagedFunction((lua) =>
                {
                    lua.PushString(random_string);
                    return(1);
                });
                lua.MCall(0, 1);
                string ret_string = lua.GetString(-1);
                lua.Pop(1);

                if (ret_string != random_string)
                {
                    throw new Exception("Return string is invalid");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #10
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushManagedClosure(lua =>
                {
                    if (lua.Top() != 3)
                    {
                        throw new Exception("Closure execution stack has incorect number of items.");
                    }

                    string one   = lua.GetString(1);
                    string two   = lua.GetString(2);
                    double three = lua.GetNumber(3);

                    lua.Pop(3);

                    lua.PushString(one + three);
                    lua.PushString(three + two);

                    if (lua.Top() != 2)
                    {
                        throw new Exception("Closure execution stack has incorrect number of items after executtion.");
                    }

                    return(2);
                }, 0);

                lua.PushString(random1);
                lua.PushString(random2);
                lua.PushNumber(random3);

                lua.MCall(3, 2);

                string ret_1 = lua.GetString(-2);
                string ret_2 = lua.GetString(-1);

                lua.Pop(2);

                if (ret_1 != random1 + random3)
                {
                    throw new Exception("First return string is incorrect.");
                }

                if (ret_2 != random3 + random2)
                {
                    throw new Exception("Second return string is incorrect.");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #11
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                if (lua.GetTypeName(TYPES.NIL) != "nil")
                {
                    throw new Exception("GetTypeName returned incorrect name for the type NIL");
                }

                if (lua.GetTypeName(TYPES.STRING) != "string")
                {
                    throw new Exception("GetTypeName returned incorrect name for the type STRING");
                }

                if (lua.GetTypeName(TYPES.NUMBER) != "number")
                {
                    throw new Exception("GetTypeName returned incorrect name for the type NUMBER");
                }

                if (lua.GetTypeName(TYPES.BOOL) != "bool")
                {
                    throw new Exception("GetTypeName returned incorrect name for the type BOOL");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #12
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            this.lua_extructor = lua_extructor;

            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                string closure_upvalue = Guid.NewGuid().ToString();

                lua.PushString(closure_upvalue);

                lua.PushCClosure(closure_ptr, 1);

                lua.MCall(0, 1);

                string received_string = lua.GetString(-1);

                lua.Pop(1);

                if (received_string != (closure_upvalue + string_to_add))
                {
                    throw new PushCClosureTestException("Received string is invalid");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #13
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushManagedClosure(l =>
                {
                    if (l.Top() != 0)
                    {
                        throw new Exception("Closure execution stack is non-empty.");
                    }
                    l.PushString(random);
                    return(1);
                }, 0);
                lua.MCall(0, 1);
                string ret_string = lua.GetString(-1);
                lua.Pop(1);

                if (ret_string != random)
                {
                    throw new Exception("Return string is incorrect.");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #14
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                Random rand = new Random();

                int random_number = rand.Next(1, 500);

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "tonumber");
                lua.PushString(random_number.ToString());
                try
                {
                    lua.MCall(1, 1);
                }
                catch (GmodLuaException)
                {
                    throw new MCallTestException("Exception was thrown by MCall, but it is not expected.");
                }
                int received_number = (int)lua.GetNumber(-1);
                if (received_number != random_number)
                {
                    throw new MCallTestException("Numbers mismatch.");
                }
                lua.Pop(2);

                string random_error_message = Guid.NewGuid().ToString();

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "assert");
                lua.PushBool(false);
                lua.PushString(random_error_message);
                try
                {
                    lua.MCall(2, 0);
                }
                catch (GmodLuaException e)
                {
                    if (e.Message != random_error_message)
                    {
                        throw new MCallTestException("Error message is invalid");
                    }

                    taskCompletion.TrySetResult(true);
                }
                catch (Exception)
                {
                    throw new MCallTestException("Wrong exception type was thrown");
                }
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #15
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                /*
                 * //Test PushUserData
                 * lua.PushUserData((IntPtr)this.RandomInt);
                 *
                 * if(lua.GetUserType(-1, (int)TYPES.USERDATA) != (IntPtr)this.RandomInt)
                 * {
                 *  throw new Exception("GetUserType returned incorrect pointer after PushUserData");
                 * }
                 *
                 * lua.Pop(1);
                 */

                //Test PushUserType
                this.Type_Id = lua.CreateMetaTable("UserDataTestType");
                lua.Pop(1);

                lua.PushUserType((IntPtr)RandomInt2, this.Type_Id);

                if (lua.GetUserType(-1, this.Type_Id) != (IntPtr)this.RandomInt2)
                {
                    throw new Exception("GetUserType returned incorrect pointer after PushUserType");
                }

                //Test SetUserType
                lua.SetUserType(-1, (IntPtr)this.RandomInt3);
                if (lua.GetUserType(-1, this.Type_Id) != (IntPtr)this.RandomInt3)
                {
                    throw new Exception("GetUserType returned incorrect pointer after SetUserType");
                }

                //Additional test for GetType and IsType
                if (lua.GetType(-1) != this.Type_Id)
                {
                    throw new Exception("GetType returned incorrect type id on usertype");
                }

                if (!lua.IsType(-1, this.Type_Id))
                {
                    throw new Exception("IsType returned false on usertype");
                }

                lua.Pop(1);

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #16
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                assembly_context.SetCustomNativeLibraryResolver((context, lib_name) =>
                {
                    if (lib_name == "SomeRandomLibraryName")
                    {
                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                        {
                            return(NativeLibrary.Load("Kernel32"));
                        }
                        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                        {
                            return(NativeLibrary.Load("libdl.so"));
                        }
                        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                        {
                            return(NativeLibrary.Load("libdl.dylib"));
                        }
                        else
                        {
                            return(IntPtr.Zero);
                        }
                    }
                    else
                    {
                        return(IntPtr.Zero);
                    }
                });

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    LoadLibraryA("Kernel32");
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    dlopen("libdl", 0);
                }
                else
                {
                    throw new PlatformNotSupportedException("The current OS platform is not supported by GmodNET.Tests");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            assembly_context.SetCustomNativeLibraryResolver(null);

            return(taskCompletion.Task);
        }
コード例 #17
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                int type1 = lua.CreateMetaTable(Guid.NewGuid().ToString());
                int type2 = lua.CreateMetaTable(Guid.NewGuid().ToString());
                lua.Pop(2);

                lua.PushUserType((IntPtr)1, type1);

                if (lua.GetUserType(-1, type2) != IntPtr.Zero)
                {
                    throw new Exception("GetUserType returned non-zero pointer in the first test.");
                }

                if (lua.GetUserType(-1, type1) != (IntPtr)1)
                {
                    throw new Exception("GetUserType returned invalid pointer in the second test.");
                }

                lua.Pop(1);

                lua.PushUserType((IntPtr)2, type2);

                if (lua.GetUserType(-1, type1) != IntPtr.Zero)
                {
                    throw new Exception("GetUserType returned non-zero pointer in the third test.");
                }

                if (lua.GetUserType(-1, type2) != (IntPtr)2)
                {
                    throw new Exception("GetUserType returned invalid pointer in the fourth test.");
                }

                lua.Pop(1);

                lua.PushString(Guid.NewGuid().ToString());

                if (lua.GetUserType(-1, type1) != IntPtr.Zero)
                {
                    throw new Exception("GetUserType returned invalid pointer in the fifth test.");
                }

                lua.Pop(1);

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #18
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            task_completion = new TaskCompletionSource <bool>();

            Random rand = new Random();

            int[] random_numbers = new int[1000];
            for (int i = 0; i < 1000; i++)
            {
                random_numbers[i] = rand.Next(2);
            }

            bool[] random_bools = new bool[1000];
            for (int i = 0; i < 1000; i++)
            {
                if (random_numbers[i] == 0)
                {
                    random_bools[i] = false;
                }
                else
                {
                    random_bools[i] = true;
                }
            }


            try
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                for (int i = 0; i < 1000; i++)
                {
                    lua.PushBool(random_bools[i]);
                    lua.SetField(-2, this.uuid + "Bool" + i.ToString());
                }
                for (int i = 0; i < 1000; i++)
                {
                    lua.GetField(-1, this.uuid + "Bool" + i.ToString());
                    bool tmp = lua.GetBool(-1);
                    lua.Pop(1);

                    if (tmp != random_bools[i])
                    {
                        throw new PushBoolException(i, random_bools[i], tmp);
                    }
                }
                lua.Pop(1);

                task_completion.TrySetResult(true);
            }
            catch (Exception e)
            {
                task_completion.TrySetException(new Exception[] { e });
            }

            return(task_completion.Task);
        }
コード例 #19
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushManagedFunction((lua) =>
                {
                    int stack_items = lua.Top();
                    if (stack_items != 3)
                    {
                        throw new Exception("The number of items on the execution stack is incorrect");
                    }

                    string first  = lua.GetString(1);
                    string second = lua.GetString(2);
                    double third  = lua.GetNumber(3);

                    lua.Pop(3);

                    lua.PushString(first + third);
                    lua.PushString(third + second);

                    return(2);
                });

                lua.PushString(random_string_1);
                lua.PushString(random_string_2);
                lua.PushNumber(random_number);

                lua.MCall(3, 2);

                string ret_1 = lua.GetString(-2);
                string ret_2 = lua.GetString(-1);

                lua.Pop(2);

                if (ret_1 != random_string_1 + random_number)
                {
                    throw new Exception("First return string is incorrect");
                }

                if (ret_2 != random_number + random_string_2)
                {
                    throw new Exception("Second return string is incorrect");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #20
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                int stack_state = lua.Top();

                lua.PushString(random1);
                lua.PushString(random2);
                lua.PushManagedClosure(lua =>
                {
                    if (lua.Top() != 1)
                    {
                        throw new Exception("Managed closure execution stack has incorrect number of items");
                    }

                    double num = lua.GetNumber(1);

                    lua.Pop(1);

                    string first  = lua.GetString(GmodInterop.GetUpvalueIndex(1));
                    string second = lua.GetString(GmodInterop.GetUpvalueIndex(2));

                    lua.PushString(first + num + second);

                    return(1);
                }, 2);

                if (lua.Top() != stack_state + 1)
                {
                    throw new Exception("Wrong number of items left on the stack");
                }

                lua.PushNumber(random3);

                lua.MCall(1, 1);

                string ret = lua.GetString(-1);
                lua.Pop(1);

                if (ret != random1 + random3 + random2)
                {
                    throw new Exception("Return string is incorrect");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #21
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            this.lua_extructor = lua_extructor;

            try
            {
                // Create metatable
                lua.CreateTable();
                lua.PushManagedFunction(this.eq_func);
                lua.SetField(-2, "__eq");

                // Create first table to compare
                lua.CreateTable();
                lua.PushNumber(1);
                lua.SetField(-2, "A");
                lua.Push(-2);
                lua.SetMetaTable(-2);

                // Create second table to compare
                lua.CreateTable();
                lua.PushNumber(2);
                lua.SetField(-2, "A");
                lua.Push(-3);
                lua.SetMetaTable(-2);

                // Get compare results
                bool equal_result     = lua.Equal(-1, -2);
                bool raw_equal_result = lua.RawEqual(-1, -2);

                lua.Pop(3);

                if (!equal_result)
                {
                    throw new EqualityTestException("ILua.Equal returned false but must return true");
                }

                if (raw_equal_result)
                {
                    throw new EqualityTestException("ILua.RawEqual returned true but must return false");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #22
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            try
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "hook");
                lua.GetField(-1, "Add");
                lua.PushString("Tick");
                lua.PushString(hook_id);
                lua.PushManagedFunction(l =>
                {
                    try
                    {
                        if (counter < 33)
                        {
                            counter++;
                        }
                        else
                        {
                            l.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                            l.GetField(-1, "hook");
                            l.GetField(-1, "Remove");
                            l.PushString("Tick");
                            l.PushString(hook_id);
                            l.MCall(2, 0);
                            l.Pop(2);

                            if (counter == 33)
                            {
                                taskCompletion.TrySetResult(true);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        taskCompletion.TrySetException(new Exception[] { e });
                    }

                    return(0);
                });
                lua.MCall(3, 0);
                lua.Pop(2);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #23
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                int stack_state = lua.Top();

                custom_type_id = lua.CreateMetaTable(Guid.NewGuid().ToString());
                lua.PushManagedFunction(lua =>
                {
                    long value = (long)lua.GetUserType(1, custom_type_id);
                    lua.Pop(1);
                    lua.PushString((value * 2).ToString());
                    return(1);
                });
                lua.SetField(-2, "__call");
                lua.Pop(1);

                lua.PushUserType((IntPtr)random_integer, custom_type_id);
                lua.MCall(0, 1);
                string ret_string = lua.GetString(-1);
                lua.Pop(1);

                lua.PushMetaTable(custom_type_id);
                lua.PushNil();
                lua.SetField(-2, "__call");
                lua.Pop(1);

                if ((stack_state - lua.Top()) != 0)
                {
                    throw new Exception("Lua stack has some values left");
                }

                if (ret_string != (random_integer * 2).ToString())
                {
                    throw new Exception("Return string is incorrect");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #24
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            try
            {
                Random rand = new Random();

                int random_number = rand.Next(1, 500);

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "tonumber");
                lua.PushString(random_number.ToString());
                if (lua.PCall(1, 1, 0) != 0)
                {
                    throw new PCallTest_NoError_Exception("PCall returned nonzero error code");
                }
                double recieved_num = lua.GetNumber(-1);
                if (recieved_num != (double)random_number)
                {
                    throw new PCallTest_NoError_Exception("Recieved value is invalid");
                }
                lua.Pop(2);

                string random_error_msg = Guid.NewGuid().ToString();

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "assert");
                lua.PushBool(false);
                lua.PushString(random_error_msg);
                if (lua.PCall(2, 0, 0) == 0)
                {
                    throw new PCallTest_Exception("assert(false, ...) didn't throw an error");
                }
                string res_err_msg = lua.GetString(-1);
                if (res_err_msg != random_error_msg)
                {
                    throw new PCallTest_Exception("Received error message is invalid");
                }
                lua.Pop(2);

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #25
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            this.lua_extructor = lua_extructor;

            try
            {
                lua.PushManagedFunction(this.spawn_func);
                lua.MCall(0, 0);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #26
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext assembly_context)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                int lua_state = lua.Top();

                lua.PushString(random);
                lua.PushManagedClosure(lua =>
                {
                    if (lua.Top() != 0)
                    {
                        throw new Exception("Managed closure execution stack is non-empty");
                    }

                    string upvalue = lua.GetString(GmodInterop.GetUpvalueIndex(1));

                    lua.PushString(upvalue + upvalue);

                    return(1);
                }, 1);

                if (lua.Top() != lua_state + 1)
                {
                    throw new Exception("There is incorrect number of items on the Lua stack");
                }

                lua.MCall(0, 1);

                string ret = lua.GetString(-1);
                lua.Pop(1);

                if (ret != random + random)
                {
                    throw new Exception("Return string is incorrect");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #27
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                int initial_number_of_values = lua.Top();

                Random rand = new Random();

                int count = rand.Next(5, 16);

                for (int i = 0; i < count; i++)
                {
                    lua.PushNumber(1);
                }

                int first_get = lua.Top();

                lua.Pop(1);

                int second_get = lua.Top();

                if (first_get != initial_number_of_values + count || second_get != initial_number_of_values + count - 1)
                {
                    throw new PopTopException("Test failed");
                }

                lua.Pop(second_get - initial_number_of_values);

                int last_get = lua.Top();

                if (last_get != initial_number_of_values)
                {
                    throw new PopTopException("Test failed on last check");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #28
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            taskSource = new TaskCompletionSource <bool>();

            try
            {
                string LuaNumId = Guid.NewGuid().ToString();

                double[] Random_numbers = new double[10];

                Random rand = new Random();

                for (int i = 0; i < 10; i++)
                {
                    Random_numbers[i] = rand.NextDouble();
                }

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);

                for (int i = 0; i < 10; i++)
                {
                    lua.PushNumber(Random_numbers[i]);
                    lua.SetField(-2, LuaNumId + "Num" + i.ToString());
                }

                for (int i = 0; i < 10; i++)
                {
                    lua.GetField(-1, LuaNumId + "Num" + i.ToString());
                    double tmp = lua.GetNumber(-1);
                    lua.Pop(1);

                    if (tmp != Random_numbers[i])
                    {
                        throw new PushNumberException(i, Random_numbers[i], tmp);
                    }
                }

                taskSource.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskSource.TrySetException(new Exception[] { e });
            }

            return(taskSource.Task);
        }
コード例 #29
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                lua.PushNumber(1);

                lua.PushString("Dima is the best boy.");

                lua.PushBool(true);

                lua.PushNil();

                if (!lua.IsType(-4, TYPES.NUMBER))
                {
                    throw new Exception("IsType returned false on NUMBER type");
                }

                if (!lua.IsType(-3, TYPES.STRING))
                {
                    throw new Exception("IsType returned false on STRING type");
                }

                if (!lua.IsType(-2, TYPES.BOOL))
                {
                    throw new Exception("IsType returned false on BOOL type");
                }

                if (!lua.IsType(-1, TYPES.NIL))
                {
                    throw new Exception("IsType returned false on NIL type");
                }

                lua.Pop(4);

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
コード例 #30
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                string random_string = Guid.NewGuid().ToString();

                lua.PushString(random_string);

                int reference = lua.ReferenceCreate();

                if (lua.GetType(-1) == (int)TYPES.STRING && lua.GetString(-1) == random_string)
                {
                    throw new ReferenceTestException("String wasn't poped from the stack");
                }

                lua.ReferencePush(reference);

                if (lua.GetType(-1) == (int)TYPES.STRING && lua.GetString(-1) != random_string)
                {
                    throw new ReferenceTestException("Reference wasn't pushed to the stack");
                }

                lua.Pop(1);

                lua.ReferenceFree(reference);

                lua.ReferencePush(reference);

                if (lua.GetType(-1) == (int)TYPES.STRING && lua.GetString(-1) == random_string)
                {
                    throw new ReferenceTestException("Reference wasn't freed");
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }