Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C#

Script.NET a language for embedding scripting functionality into CLR Applications

Rate me:
Please Sign up or sign in to vote.
4.90/5 (50 votes)
16 Dec 2008CPOL6 min read 224.2K   2.8K   196  
Scripting language for .NET Framework 2.0. Supports native .NET Types, Dynamic casting, Meta programming.
using System.Collections;

internal class  ObjectList
{
	class Link {
		internal object it;
		internal Link next;
		internal Link(object o, Link x) { it=o;next=x; }
	}		
	void Add0(Link a) {
		if (head==null)
			head = last = a;
		else
			last = last.next = a;
	}
	object Get0(Link a,int x) { 
		if (a==null || x<0)  // safety
			return null;
		if (x==0)
			return a.it;
		return Get0(a.next,x-1);
	}
	private Link head = null, last=null;
	private int count = 0;
	public ObjectList() {}
	public void Add(object o) { Add0(new Link(o,null)); count++; }
	public void Push(object o) { head = new Link(o,head); count++; }
	public object Pop() { object r=head.it; head=head.next; count--; return r; }
	public object Top { get { return head.it; }}
	public int Count { get { return count; }}
	public object this[int ix] { get { return Get0(head,ix); } }
	internal class  OListEnumerator : IEnumerator
	{
		ObjectList list;
		Link cur = null;
		public object Current { get { return cur.it; }}
		public OListEnumerator(ObjectList o)
		{
			list = o;
		}
		public bool MoveNext()
		{
			if (cur==null)
				cur = list.head;
			else
				cur = cur.next;
			return cur!=null;
		}
		public void Reset()
		{
			cur = null;
		}
	}
	public IEnumerator GetEnumerator()
	{
		return new OListEnumerator(this);
	}
}

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
Architect
Netherlands Netherlands
Please visit my website for more articles

I'm software developer & Ph.D. student

Comments and Discussions