コード例 #1
0
        internal void ThrowError(ScriptState luaState, object e)
        {
            if (Disposed)
            {
                return;
            }
            // We use this to remove anything pushed by luaL_where
            int oldTop = LuaCore.GetTop(luaState);

            // Stack frame #1 is our C# wrapper, so not very interesting to the user
            // Stack frame #2 must be the lua code that called us, so that's what we want to use
            LuaCore.Where(luaState, 1);
            var curlev = ObjectMgr.PopResults(luaState, oldTop);

            // Determine the position in the script where the exception was triggered
            string errLocation = string.Empty;

            if (curlev.Count > 0)
            {
                errLocation = curlev[0].ToString();
            }

            var message = e as string;

            if (message != null)
            {
                e = new LuaSourcetException(message, errLocation);
            }
            else
            {
                var ex = e as Exception;
                if (ex != null)
                {
                    e = new LuaSourcetException(ex, errLocation);
                }
            }
            ObjectMgr.PushObject(luaState, e);
            LuaCore.Error(luaState);
        }
コード例 #2
0
        public IList <object> RunScript(string script)
        {
            if (Disposed)
            {
                return(null);
            }
            Script = script;
            var luaState = State;
            int oldTop   = LuaCore.GetTop(luaState);

            if (LuaCore.LoadBuffer(luaState, script, 0, ChunkName) == 0)
            {
                if (LuaCore.Call(luaState, 0, -1, 0) == 0)
                {
                    return(ObjectMgr.PopResults(luaState, oldTop));
                }
                ThrowExceptionFromError(luaState, oldTop);
            }
            else
            {
                ThrowExceptionFromError(luaState, oldTop);
            }
            return(null);
        }