Exemplo n.º 1
0
        /// <summary>
        /// Loads a string containing a Lua/MoonSharp function.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="globalTable">The global table to bind to this chunk.</param>
        /// <param name="funcFriendlyName">Name of the function used to report errors, etc.</param>
        /// <returns>
        /// A DynValue containing a function which will execute the loaded code.
        /// </returns>
        public DynValue LoadFunction(string code, Table globalTable = null, string funcFriendlyName = null)
        {
            string chunkName = string.Format("libfunc_{0}", funcFriendlyName ?? m_Sources.Count.ToString());

            SourceCode source = new SourceCode(chunkName, code, m_Sources.Count, this);

            m_Sources.Add(source);

            int address = Loader_Fast.LoadFunction(this, source, m_ByteCode, globalTable ?? m_GlobalTable);

            SignalSourceCodeChange(source);
            SignalByteCodeChange();

            return(MakeClosure(address));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a string containing a Lua/MoonSharp function.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="globalTable">The global table to bind to this chunk.</param>
        /// <param name="funcFriendlyName">Name of the function used to report errors, etc.</param>
        /// <returns>
        /// A DynValue containing a function which will execute the loaded code.
        /// </returns>
        public DynValue LoadFunction(string code, Table globalTable = null, string funcFriendlyName = null)
        {
            if (!m_isAlive)
            {
                throw new InvalidOperationException("Attempting to loadfunction on a dead Script");
            }
            this.CheckScriptOwnership(globalTable);

            string chunkName = string.Format("libfunc_{0}", funcFriendlyName ?? m_Sources.Count.ToString());

            SourceCode source = new SourceCode(chunkName, code, m_Sources.Count, this);

            m_Sources.Add(source);

            int address = Loader_Fast.LoadFunction(this, source, m_ByteCode, globalTable != null || m_GlobalTable != null);

            SignalSourceCodeChange(source);
            SignalByteCodeChange();

            return(MakeClosure(address, globalTable ?? m_GlobalTable));
        }