Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        int SpawnFunc(ILua lua)
        {
            try
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "ents");
                lua.GetField(-1, "Create");
                lua.PushString("prop_physics");
                lua.MCall(1, 1);

                if (lua.GetType(-1) != (int)TYPES.ENTITY)
                {
                    throw new SpawnEntityException("ents.Create returned a value which type is not Entity");
                }

                lua.GetField(-1, "SetModel");
                lua.Push(-2);
                lua.PushString("models/props_c17/oildrum001.mdl");
                lua.MCall(2, 0);

                lua.GetField(-1, "SetPos");
                lua.Push(-2);
                lua.PushVector(new System.Numerics.Vector3(0));
                lua.MCall(2, 0);

                lua.GetField(-1, "Spawn");
                lua.Push(-2);
                lua.MCall(1, 0);

                lua.GetField(-1, "IsValid");
                lua.Push(-2);
                lua.MCall(1, 1);
                if (!lua.GetBool(-1))
                {
                    throw new SpawnEntityException("Entity is not valid");
                }

                lua.Pop(lua.Top());

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

            return(0);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        void SetPlayerList(ILua lua)
        {
            if (!getPlayersTasks.IsEmpty)
            {
                List <string> players            = new List <string>();
                Exception     executionException = null;

                try
                {
                    lua.PushGlobalTable();
                    lua.GetField(-1, "player");
                    lua.GetField(-1, "GetAll");
                    lua.MCall(0, 1);
                    lua.PushNil();
                    while (lua.Next(-2) != 0)
                    {
                        lua.GetField(-1, "Nick");
                        lua.Push(-2);
                        lua.MCall(1, 1);
                        players.Add(lua.GetString(-1));
                        lua.Pop(2);
                    }
                    lua.Pop(lua.Top());
                }
                catch (Exception e)
                {
                    executionException = e;
                }

                TaskCompletionSource <List <string> > task;
                while (getPlayersTasks.TryDequeue(out task))
                {
                    if (executionException == null)
                    {
                        task.SetResult(players);
                    }
                    else
                    {
                        task.SetException(executionException);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                string first_string  = Guid.NewGuid().ToString();
                string second_string = Guid.NewGuid().ToString();

                int number_of_items_on_stack = lua.Top();

                lua.PushString(first_string);
                lua.PushString(second_string);
                lua.Push(-2);

                string received_string         = lua.GetString(-1);
                string another_received_string = lua.GetString(-2);

                lua.Pop(3);

                if (received_string != first_string || another_received_string != second_string)
                {
                    throw new PushTestException("Received strings are invalid");
                }

                if (lua.Top() != number_of_items_on_stack)
                {
                    throw new PushTestException("Not all strings were poped from the stack");
                }

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

            return(taskCompletion.Task);
        }
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                this.lua_extructor = lua_extructor;

                this.NewTypeId = lua.CreateMetaTable("TestType1");

                lua.PushManagedFunction(this.ToStringImpl);

                lua.SetField(-2, "__tostring");

                lua.Pop(1);


                //Create new table to test newly created metatable

                lua.CreateTable();

                lua.PushMetaTable(this.NewTypeId);

                lua.SetMetaTable(-2);

                /*
                 * if(!lua.IsType(-1, this.NewTypeId))
                 * {
                 *  throw new Exception("Received type id is invalid");
                 * }
                 *
                 * string received_type_name = lua.GetTypeName(lua.GetType(-1));
                 *
                 * if(received_type_name != "TestType1")
                 * {
                 *  throw new Exception("Received type name is invalid");
                 * }
                 */

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);

                lua.GetField(-1, "tostring");

                lua.Push(-3);

                lua.MCall(1, 1);

                if (lua.GetString(-1) != this.RandomString)
                {
                    throw new Exception("Metatable method __tostring returned incorrect string");
                }

                lua.Pop(3);

                lua.PushMetaTable(NewTypeId);

                lua.PushNil();

                lua.SetField(-2, "__tostring");

                lua.Pop(1);

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

            return(taskCompletion.Task);
        }