Example #1
0
        /// <summary>
        /// Executes a Lua chnk and returns all the chunk's return values in an array.
        /// </summary>
        /// <param name = "chunk">Chunk to execute</param>
        /// <param name = "chunkName">Name to associate with the chunk</param>
        /// <returns></returns>
        public object[] DoString(string chunk, string chunkName)
        {
            int oldTop = LuaLib.lua_gettop(luaState);

            executing = true;

            if (LuaLib.luaL_loadbuffer(luaState, chunk, chunkName) == 0)
            {
                try
                {
                    if (LuaLib.lua_pcall(luaState, 0, -1, 0) == 0)
                    {
                        return(translator.popValues(luaState, oldTop));
                    }
                    else
                    {
                        ThrowExceptionFromError(oldTop);
                    }
                }
                finally
                {
                    executing = false;
                }
            }
            else
            {
                ThrowExceptionFromError(oldTop);
            }

            return(null);                               // Never reached - keeps compiler happy
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name = "chunk"></param>
        /// <param name = "name"></param>
        /// <returns></returns>
        public LuaFunction LoadString(string chunk, string name)
        {
            int oldTop = LuaLib.lua_gettop(luaState);

            executing = true;

            try
            {
                if (LuaLib.luaL_loadbuffer(luaState, chunk, name) != 0)
                {
                    ThrowExceptionFromError(oldTop);
                }
            }
            finally
            {
                executing = false;
            }

            var result = translator.getFunction(luaState, -1);

            translator.popValues(luaState, oldTop);
            return(result);
        }