Пример #1
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);
        }