Click here to Skip to main content
15,881,172 members
Articles / Containers / Virtual Machine

Conscript: An embeddable, compiled scripting language for .NET

Rate me:
Please Sign up or sign in to vote.
4.97/5 (58 votes)
5 Sep 2008CPOL15 min read 157.7K   1.4K   141  
An API for enhancing any .NET application with a scripting language
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

using Conscript.Compiler;
using Conscript.Runtime;

namespace Conscript.Compiler
{
    /// <summary>
    /// Represents a compiled function within a script. The function defines
    /// the number of parameters accepted by the function and the associated
    /// entry point into the executable.
    /// </summary>
    public class ScriptFunction
    {
        #region Private Variables

        private ScriptExecutable m_scriptExecutable;
        private String m_strName;
        private List<String> m_listParameters;
        private ScriptInstruction m_scriptInstructionEntryPoint;

        #endregion

        #region Public Methods

        /// <summary>
        /// Constructs a script function for the given
        /// <see cref="ScriptExecutable"/>, with the given name, parameter
        /// count and entry point into the executable.
        /// </summary>
        /// <param name="scriptExecutable">Executable form of the
        /// <see cref="Script"/>.</param>
        /// <param name="strName">Script function name.</param>
        /// <param name="listParameters">List of parameter names.</param>
        /// <param name="scriptInstructionEntryPoint">Entry point
        /// <see cref="ScriptInstruction"/> in the executable.</param>
        public ScriptFunction(ScriptExecutable scriptExecutable,
            String strName, List<String> listParameters,
            ScriptInstruction scriptInstructionEntryPoint)
        {
            m_scriptExecutable = scriptExecutable;
            m_strName = strName;
            m_listParameters = new List<string>(listParameters);
            m_scriptInstructionEntryPoint = scriptInstructionEntryPoint;
        }

        /// <summary>
        /// Returns a string representation of the function.
        /// </summary>
        /// <returns>String representation of the function.</returns>
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append(m_strName);
            stringBuilder.Append("(");
            for (int iIndex = 0; iIndex < m_listParameters.Count; iIndex++)
            {
                if (iIndex > 0) stringBuilder.Append(", ");
                stringBuilder.Append(m_listParameters[iIndex]);
            }
            stringBuilder.Append(") [");
            stringBuilder.Append(ParameterCount.ToString("00000000"));
            stringBuilder.Append("]");
            return stringBuilder.ToString();
        }

        /// <summary>
        /// The <see cref="ScriptExecutable"/> associated with the
        /// <see cref="Script"/> that contains the function.
        /// </summary>
        public ScriptExecutable Executable
        {
            get { return m_scriptExecutable; }
        }

        /// <summary>
        /// Name of the function.
        /// </summary>
        public String Name
        {
            get { return m_strName; }
        }

        /// <summary>
        /// Number of parameters accepted by the function.
        /// </summary>
        public uint ParameterCount
        {
            get { return (uint) m_listParameters.Count; }
        }

        /// <summary>
        /// List of parameter names.
        /// </summary>
        public ReadOnlyCollection<String> Parameters
        {
            get { return m_listParameters.AsReadOnly(); }
        }

        /// <summary>
        /// Entry point into the <see cref="ScriptExecutable"/> in
        /// <see cref="ScriptInstruction"/> form.
        /// </summary>
        public ScriptInstruction EntryPoint
        {
            get { return m_scriptInstructionEntryPoint; }
            set { m_scriptInstructionEntryPoint = value; }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Malta Malta
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions