Beispiel #1
0
    public static void Main(string[] args)
    {
        Table  env = new Table();
        Symbol k;
        object v;

        k      = Lua.Symbol.Intern("print");
        v      = new Print();
        env[k] = v;

        k      = Lua.Symbol.Intern("setmetatable");
        v      = new SetMetatable();
        env[k] = v;

        k      = Lua.Symbol.Intern("pairs");
        v      = new Pairs();
        env[k] = v;

        Lua.Symbol s = Lua.Symbol.Intern("tonumber");
        k      = s;
        v      = new ToNumber();
        env[k] = v;

        k = Lua.Symbol.Intern("os");
        Table os = new Table();

        v      = os;
        env[k] = v;
        k      = Lua.Symbol.Intern("clock");
        v      = new Clock();
        os[k]  = v;

        k = Lua.Symbol.Intern("io");
        Table io = new Table();

        v      = io;
        env[k] = v;
        k      = Lua.Symbol.Intern("write");
        v      = new Write();
        io[k]  = v;

        k = Lua.Symbol.Intern("math");
        Table math = new Table();

        v       = math;
        env[k]  = v;
        k       = Lua.Symbol.Intern("floor");
        v       = new Floor();
        math[k] = v;

        function1 f = new function1();

        f.Env = env;
        f.InvokeS();
        for (int i = 0; i <= System.GC.MaxGeneration; i++)
        {
            Console.WriteLine(System.GC.CollectionCount(i));
        }
    }
Beispiel #2
0
    public static Symbol Intern(string s) {
      Symbol sym;
      interned.TryGetValue(s, out sym);
      if(sym == null) {
	sym = new Symbol(s);
	interned[s] = sym;
      }
      return sym;
    }
Beispiel #3
0
    public static void Main(string[] args)
    {
        Table  env = new Table();
        Symbol k;
        object v;

        k      = Lua.Symbol.Intern("print");
        v      = new Print();
        env[k] = v;

        k      = Lua.Symbol.Intern("setmetatable");
        v      = new SetMetatable();
        env[k] = v;

        k      = Lua.Symbol.Intern("pairs");
        v      = new Pairs();
        env[k] = v;

        Lua.Symbol s = Lua.Symbol.Intern("tonumber");
        k      = s;
        v      = new ToNumber();
        env[k] = v;

        k = Lua.Symbol.Intern("os");
        Table os = new Table();

        v      = os;
        env[k] = v;
        k      = Lua.Symbol.Intern("clock");
        v      = new Clock();
        os[k]  = v;

        k = Lua.Symbol.Intern("io");
        Table io = new Table();

        v      = io;
        env[k] = v;
        k      = Lua.Symbol.Intern("write");
        v      = new Write();
        io[k]  = v;

        k = Lua.Symbol.Intern("math");
        Table math = new Table();

        v       = math;
        env[k]  = v;
        k       = Lua.Symbol.Intern("floor");
        v       = new Floor();
        math[k] = v;

        function1 f = new function1();

        f.Env = env;
        f.InvokeS();
    }
 public virtual object this[Symbol key] { get { return this[(object)key]; } set { this[(object)key] = value; } }
Beispiel #5
0
    public static void Main(string[] args)
    {
        Table  env = new Table();
        Symbol k;
        object v;

        k      = Lua.Symbol.Intern("print");
        v      = new Print();
        env[k] = v;

        k      = Lua.Symbol.Intern("setmetatable");
        v      = new SetMetatable();
        env[k] = v;

        k      = Lua.Symbol.Intern("pairs");
        v      = new Pairs();
        env[k] = v;

        Lua.Symbol s = Lua.Symbol.Intern("tonumber");
        k      = s;
        v      = new ToNumber();
        env[k] = v;

        k = Lua.Symbol.Intern("os");
        Table os = new Table();

        v      = os;
        env[k] = v;
        k      = Lua.Symbol.Intern("clock");
        v      = new Clock();
        os[k]  = v;

        k = Lua.Symbol.Intern("io");
        Table io = new Table();

        v      = io;
        env[k] = v;
        k      = Lua.Symbol.Intern("write");
        v      = new Write();
        io[k]  = v;

        k = Lua.Symbol.Intern("math");
        Table math = new Table();

        v       = math;
        env[k]  = v;
        k       = Lua.Symbol.Intern("floor");
        v       = new Floor();
        math[k] = v;

        Closure c = (Closure)Assembly.LoadFrom(args[0] + ".dll").
                    GetType(args[0] + ".function1").GetConstructor(new Type[0]).
                    Invoke(new object[0]);

        c.Env = env;
        c.InvokeS();
        for (int i = 0; i <= System.GC.MaxGeneration; i++)
        {
            Console.WriteLine(System.GC.CollectionCount(i));
        }
    }
Beispiel #6
0
    public override object this[Symbol key] 
    {
      get 
      {
	object value = Nil.Instance;
	object idx_meta;
	Node n = this.node[key.hash % ((this.node.Length - 1) | 1)];
	do {  /* check whether `key' is somewhere in the chain */
	  if (key == n.key) {
	    value = n.val;  /* that's it */
	    break;
	  } else n = n.next;
	} while (n != null);
	if(value == Nil.Instance && this._meta != null && ((idx_meta = this._meta.GetSymbol(Reference.__index).val) != Nil.Instance)) {
	  if(idx_meta is Closure)
	    value = ((Reference)idx_meta).InvokeS(this, key);
	  else
	    value = ((Table)idx_meta)[key];
	}
	return value;
      }
      set
	{
	  Node n = this.node[key.hash % ((this.node.Length - 1) | 1)];
	  do {  /* check whether `key' is somewhere in the chain */
	    if (key == n.key) {
	      n.val = value;
	      return;  /* that's it */
	    } else n = n.next;
	  } while (n != null);
	  if(n==null && value != Nil.Instance) {
	    n = NewKey(key);
	    n.val = value;
	  }
	}
    }
Beispiel #7
0
 int Hash(Symbol s) {
   return (int)(s.hash % ((this.node.Length - 1) | 1));
 }
Beispiel #8
0
 Node MainPosition(Symbol key) 
 {
   int hash = Hash(key);
   return this.node[hash];
 }
Beispiel #9
0
    Node GetSymbol(Symbol key) 
    {
      Node n = this.node[key.hash % ((this.node.Length - 1) | 1)];
      do {  /* check whether `key' is somewhere in the chain */
	if (key == n.key)
	  return n;  /* that's it */
	else n = n.next;
      } while (n != null);
      return Node.NilNode;
    }