Esempio n. 1
0
File: Lua.cs Progetto: bmk10/NLua
        /*
         * Indexer for global variables from the LuaInterpreter
         * Supports navigation of tables by using . operator
         */
        public object this [string fullPath] {
            get {
                object   returnValue = null;
                int      oldTop      = LuaLib.LuaGetTop(luaState);
                string[] path        = fullPath.Split(new char[] { '.' });
                LuaLib.LuaGetGlobal(luaState, path [0]);
                returnValue = translator.GetObject(luaState, -1);
                LuaBase dispose = null;

                if (path.Length > 1)
                {
                    dispose = returnValue as LuaBase;
                    string[] remainingPath = new string[path.Length - 1];
                    Array.Copy(path, 1, remainingPath, 0, path.Length - 1);
                    returnValue = GetObject(remainingPath);
                    if (dispose != null)
                    {
                        dispose.Dispose();
                    }
                }

                LuaLib.LuaSetTop(luaState, oldTop);
                return(returnValue);
            }
            set {
                int      oldTop = LuaLib.LuaGetTop(luaState);
                string[] path   = fullPath.Split(new char[] { '.' });

                if (path.Length == 1)
                {
                    translator.Push(luaState, value);
                    LuaLib.LuaSetGlobal(luaState, fullPath);
                }
                else
                {
                    LuaLib.LuaGetGlobal(luaState, path [0]);
                    string[] remainingPath = new string[path.Length - 1];
                    Array.Copy(path, 1, remainingPath, 0, path.Length - 1);
                    SetObject(remainingPath, value);
                }

                LuaLib.LuaSetTop(luaState, oldTop);

                // Globals auto-complete
                if (value == null)
                {
                    // Remove now obsolete entries
                    globals.Remove(fullPath);
                }
                else
                {
                    // Add new entries
                    if (!globals.Contains(fullPath))
                    {
                        RegisterGlobal(fullPath, value.GetType(), 0);
                    }
                }
            }
        }
Esempio n. 2
0
 public override bool Equals(object o)
 {
     if (o is LuaBase)
     {
         LuaBase l = (LuaBase)o;
         return(_Interpreter.compareRef(l._Reference, _Reference));
     }
     else
     {
         return(false);
     }
 }