Pop() 공개 정적인 메소드

public static Pop ( IntPtr L, int n ) : void
L System.IntPtr
n int
리턴 void
예제 #1
0
        /// <summary>
        ///gets the list of dependencies from modinfo.tdf
        /// </summary>
        string[] GetDependenciesFromTdf(string archiveName, string fileName)
        {
            var modInfoText = Archive.ExtractTextFile(archiveName, fileName);

            Lua.lua_getglobal(L, "TDFparser");                                   // push the parser table on the stack
            Lua.lua_getfield(L, -1, "ParseText");                                // push the parse string function
            var modInfoTable = CLua.TraceCall(L, 2, new LuaString(modInfoText)); // load the tdf from string
            var modInfo      = modInfoTable[0].GetField("mod");

            // get all existing "dependN" fields
            var dependencies = new List <string>();
            var n            = 0;

            while (true)
            {
                var field = modInfo.GetField("depend" + n++);
                if (field != null)
                {
                    dependencies.Add(field.ToString());
                }
                else
                {
                    break;
                }
            }
            LuaValue.Pop(L, 1);
            return(dependencies.ToArray());
        }
예제 #2
0
        public static void CheckError(IntPtr L, int status)
        {
            if (status == 0)
            {
                return;              // no error
            }
            var message = Lua.lua_tostring(L, -1) ?? "(no error message)";

            LuaValue.Pop(L, 1);
            switch (status)
            {
            case Lua.LUA_ERRFILE:
                throw new Exception("File error: " + message);

            case Lua.LUA_ERRRUN:
                throw new Exception("Runtime error: " + message);

            case Lua.LUA_ERRSYNTAX:
                throw new Exception("Syntax error: " + message);

            case Lua.LUA_ERRMEM:
                throw new Exception("Memory error: " + message);

            case Lua.LUA_ERRERR:
                throw new Exception("Error function error: " + message);

            default:
                throw new Exception("Invalid error code");
            }
        }
예제 #3
0
        static LuaValue[] GetTdfTableFromString(IntPtr L, string fileString)
        {
            Lua.lua_getglobal(L, "TDFparser");    // push the parser table on the stack
            Lua.lua_getfield(L, -1, "ParseText"); // push the parse string function
            var ret = CLua.TraceCall(L, 2, new LuaString(fileString));

            LuaValue.Pop(L, 1);
            return(ret);
        }
예제 #4
0
        /// <summary>
        /// expects function on top
        /// runs function on top of stack, returns values returned from function, shows traceback in case of errors
        /// </summary>
        public static LuaValue[] TraceCall(IntPtr L, int resultCount, params LuaValue[] arguments)
        {
            TraceCallPushReturn(L, new ConstantResults(resultCount), arguments);
            var ret = Enumerable.Range(0, resultCount).Select(n => LuaValue.Read(L, -n - 1)).ToArray();

            Array.Reverse(ret);
            LuaValue.Pop(L, resultCount);
            return(ret);
        }
예제 #5
0
        /// <summary>
        /// /// sends arguments to output function, can be used to make print()-like functions
        /// </summary>
        public static int Print(Action <String> outputFunc, IntPtr L)
        {
            var n = Lua.lua_gettop(L); // number of arguments

            for (var i = 1; i <= n; i++)
            {
                Lua.lua_pushvalue(L, -1);       // function to be called
                Lua.lua_pushvalue(L, i);        // value to print
                Lua.lua_call(L, 1, 1);
                var s = Lua.lua_tostring(L, 1); // get result
                if (i > 1)
                {
                    outputFunc("\t");
                }
                outputFunc(s);
                LuaValue.Pop(L, 1);
            }
            outputFunc("\n");
            return(0);
        }