예제 #1
0
        /*
         * Pushes the entire array into the Lua stack and returns the number
         * of elements pushed.
         */
        internal int returnValues(LuaCore.lua_State luaState, object[] returnValues)
        {
            if (LuaLib.lua_checkstack(luaState, returnValues.Length + 5))
            {
                for (int i = 0; i < returnValues.Length; i++)
                {
                    push(luaState, returnValues[i]);
                }

                return(returnValues.Length);
            }
            else
            {
                return(0);
            }
        }
예제 #2
0
        /*
         * Calls the object as a function with the provided arguments and
         * casting returned values to the types in returnTypes before returning
         * them in an array
         */
        internal object[] callFunction(object function, object[] args, Type[] returnTypes)
        {
            int nArgs  = 0;
            int oldTop = LuaLib.lua_gettop(luaState);

            if (!LuaLib.lua_checkstack(luaState, args.Length + 6))
            {
                throw new LuaException("Lua stack overflow");
            }

            translator.push(luaState, function);

            if (!args.IsNull())
            {
                nArgs = args.Length;

                for (int i = 0; i < args.Length; i++)
                {
                    translator.push(luaState, args[i]);
                }
            }

            executing = true;

            try
            {
                int error = LuaLib.lua_pcall(luaState, nArgs, -1, 0);
                if (error != 0)
                {
                    ThrowExceptionFromError(oldTop);
                }
            }
            finally
            {
                executing = false;
            }

            return(!returnTypes.IsNull() ? translator.popValues(luaState, oldTop, returnTypes) : translator.popValues(luaState, oldTop));
        }