Exemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="LuaThread"/> that will run the given <see cref="LuaFunction"/>.
        /// </summary>
        /// <param name="function">The <see cref="LuaFunction"/>.</param>
        /// <returns>The resulting <see cref="LuaThread"/>.</returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="function"/> is tied to a different <see cref="Lua"/> environment.
        /// </exception>
        /// <exception cref="ArgumentNullException"><paramref name="function"/> is <c>null</c>.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="Lua"/> environment is disposed.</exception>
        public LuaThread CreateThread(LuaFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException(nameof(function));
            }
            ThrowIfDisposed();

            var threadState = LuaApi.NewThread(MainState);

            function.PushOnto(threadState);
            var result = (LuaThread)ToObject(-1, LuaType.Thread);

            LuaApi.Pop(MainState, 1);
            return(result);
        }