Пример #1
0
        private void RunScript(string script)
        {
            try
            {
                ExecutionStart?.Invoke(this, EventArgs.Empty);
                lock (_script)
                {
                    _script.DoString(script, codeFriendlyName: "script");
                }

                ExecutionComplete?.Invoke(this, ExitCondition.ProgramEnd);
            }
            catch (InterpreterException e)
            {
                LuaError?.Invoke(this, e);
                ExecutionComplete?.Invoke(this, ExitCondition.ScriptError);
            }
            catch (ThreadAbortException)
            {
                // Ignore
            }
            catch (Exception e)
            {
                CsError?.Invoke(this, e);
                ExecutionComplete?.Invoke(this, ExitCondition.CsError);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TFunc">方法代理类型</typeparam>
        /// <typeparam name="T">方法返回类型</typeparam>
        /// <param name="funcName"></param>
        /// <param name="args"></param>
        /// <param name="result"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public bool TryCall <TFunc, T>(string funcName, out T result, out LuaError error, params object[] args)
        {
            result = default(T);
            error  = LuaError.Unknown;
            dynamic func;

            if (!TryGetFunc <TFunc>(funcName, out func))
            {
                error = LuaError.FuncNotFound;
                return(false);
            }
            result = (T)func.DynamicInvoke(args);
            return(true);
        }
Пример #3
0
        private void ErrorCodeToException(LuaError returnCode)
        {
            switch (returnCode)
            {
            case LuaError.FileNotFound:
                throw new LuaProcessFileException(ConvertToString(-1));

            case LuaError.GCMetaMethod:
            case LuaError.Runtime:
            case LuaError.Unknown:
                throw new LuaException($"Something went wrong, LuaError returns {returnCode}");

            case LuaError.Memory:
                throw new LuaOutOfMemoryException("Memory is over");

            case LuaError.Syntax:
                throw new LuaSyntaxException(ConvertToString(-1));
            }
        }
Пример #4
0
 public InvocationException(LuaError error, string function)
     : base(string.Format("{0} error when calling function \"{1}\"", error, function))
 {
 }
Пример #5
0
        /// <summary>
        /// Checks a return value from a LUA function for an error
        /// </summary>
        /// <param name="ret"></param>
        private void CheckError( LuaError ret )
        {
            if (ret != LuaError.NoError)
            { // Error
                switch (ret)
                {
                    case LuaError.ErrorRuntime:
                        {
                            throw new LuaException("Runtime error in LUA script.");
                        }

                    case LuaError.ErrorFile:
                        {
                            throw new LuaException("I/O error in LUA subsystem.");
                        }

                    case LuaError.ErrorSyntax:
                        { // Error in syntax
                            string syntax = null;
                            if (Stack.TypeOf(Stack.TopIndex) == LuaType.String)
                            {
                                // Retrieve the value from the string
                                syntax = (string)Stack.TopValue;
                                // Pop it
                                Stack.Pop();
                            }
                            throw new LuaSyntaxException(syntax);
                        }

                    case LuaError.ErrorMemory:
                        { // Error in memory
                            throw new LuaException("LUA caused an error in memory allocation.");
                        }

                    default:
                        { // Unknown
                            throw new LuaException("Unknown exception from LUA.");
                        }
                }
            }
        }