LuaInterface.ObjectTranslator.throwError C# (CSharp) Method

throwError() private method

private throwError ( IntPtr luaState, object e ) : void
luaState IntPtr
e object
return void
        internal void throwError(IntPtr luaState, object e)
        {
            // We use this to remove anything pushed by luaL_where
            int oldTop = LuaDLL.lua_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
            LuaDLL.luaL_where(luaState, 1);
            object[] curlev = popValues(luaState, oldTop);

            // Determine the position in the script where the exception was triggered
            string errLocation = "";
            if (curlev.Length > 0)
                errLocation = curlev[0].ToString();

            string message = e as string;
            if (message != null)
            {
                // Wrap Lua error (just a string) and store the error location
                e = new LuaScriptException(message, errLocation);
            }
            else
            {
                Exception ex = e as Exception;
                if (ex != null)
                {
                    // Wrap generic .NET exception as an InnerException and store the error location
                    e = new LuaScriptException(ex, errLocation);
                }
            }

            push(luaState, e);
            LuaDLL.lua_error(luaState);
        }

Usage Example

        public static int getConstructorSignature(IntPtr luaState)
        {
            ObjectTranslator objectTranslator = ObjectTranslator.FromState(luaState);
            IReflect         reflect          = null;
            int num = LuaDLL.luanet_checkudata(luaState, 1, "luaNet_class");

            if (num != -1)
            {
                reflect = (IReflect)objectTranslator.objects[num];
            }
            if (reflect == null)
            {
                objectTranslator.throwError(luaState, "get_constructor_bysig: first arg is invalid type reference");
            }
            Type[] array = new Type[LuaDLL.lua_gettop(luaState) - 1];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = objectTranslator.FindType(LuaDLL.lua_tostring(luaState, i + 2));
            }
            try
            {
                ConstructorInfo constructor = reflect.UnderlyingSystemType.GetConstructor(array);
                objectTranslator.pushFunction(luaState, new LuaCSFunction(new LuaMethodWrapper(objectTranslator, null, reflect, constructor).call));
            }
            catch (Exception ex)
            {
                objectTranslator.throwError(luaState, ex.Message);
                LuaDLL.lua_pushnil(luaState);
            }
            return(1);
        }
All Usage Examples Of LuaInterface.ObjectTranslator::throwError