Exemplo n.º 1
0
 /// <summary>
 /// Pops the amount of values from the stack of the source, and pushes onto the destinations
 /// threads stack. This method can be used to transfer values between threads.
 /// </summary>
 /// <param name="source">Source thread.</param>
 /// <param name="destination">Destination thread.</param>
 /// <param name="count">Number of arguments to copy.</param>
 public static void Move(LuaThread source, LuaThread destination, int count)
 {
     if (source != null || destination != null)
     { // One of those is null.
         throw new ArgumentNullException("source or destination");
     }
     NativeLua.lua_xmove(source.Handle, destination.Handle, count);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a given item from the stack.
        /// </summary>
        /// <param name="index">Index of the item to be retrieved</param>
        /// <returns>Value of the item</returns>
        public object this[int index]
        {
            get
            {
                LuaType type = TypeOf(index);
                object value = null;

                if (type == LuaType.None)
                { // Invalid type
                    throw new IndexOutOfRangeException("Index does not exist or has type LUA_NONE");
                }
                switch (type)
                {
                    case LuaType.Boolean:
                        { // A boolean
                            value = (bool)(NativeLua.lua_toboolean(lua, index) != 0);
                        }
                        break;

                    case LuaType.Nil:
                        { // Nil this means, null
                            value = null;
                        }
                        break;

                    case LuaType.Number:
                        { // A ordinary number :)
                            value = (NativeLua.lua_tonumber(lua, index));
                        }
                        break;

                    case LuaType.String:
                        { // A string
                            value = (NativeLua.lua_tostring(lua, index));
                        }
                        break;

                    case LuaType.Function:
                        { // A function
                            value = (NativeLua.lua_tocfunction(lua, index));
                        }
                        break;

                    case LuaType.UserData:
                        { // User data
                            value = (NativeLua.lua_touserdata(lua, index));
                        }
                        break;

                    case LuaType.Thread:
                        {
                            value = new LuaThread(NativeLua.lua_tothread(lua, index));
                        }
                        break;

                    case LuaType.Table:
                        {
                            value = (object)new LuaTable(new Lua(lua), index);
                        }
                        break;

                    case LuaType.LightUserData:
                        { // But for now we even take the table into the pointers
                            value = (NativeLua.lua_topointer(lua, index));
                        }
                        break;

                    default:
                        { // Error... Unknown object
                            throw new LuaException("Unknown object");
                        }
                }
                return value;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new Lua coroutine (thread) from the context of the current object.
        /// </summary>
        /// <returns>An object representing the new Lua thread.</returns>
        public LuaThread CreateThread()
        {
            LuaThread thread = new LuaThread(this);

            return thread;
        }