예제 #1
0
        void AssertFile(string path)
        {
            string error = string.Empty;

            int result = Lua.luaL_loadfile(state, path);

            if (result != 0)
            {
                Lua.CharPtr pstring = Lua.lua_tostring(state, 1);
                if (pstring != null)
                {
                    error = pstring.ToString();
                }
            }

            Assert.True(result == 0, "Fail loading file: " + path + "ERROR:" + error);

            result = Lua.lua_pcall(state, 0, -1, 0);

            if (result != 0)
            {
                Lua.CharPtr pstring = Lua.lua_tostring(state, 1);
                if (pstring != null)
                {
                    error = pstring.ToString();
                }
            }


            Assert.True(result == 0, "Fail calling file: " + path + " ERROR: " + error);
        }
예제 #2
0
        static int loadline(Lua.lua_State L)
        {
            int status;

            Lua.lua_settop(L, 0);
            if (pushline(L, 1) == 0)
            {
                return(-1);                 /* no input */
            }
            for (; ;)
            {              /* repeat until gets a complete line */
                Lua.CharPtr line = Lua.lua_tostring(L, 1);
                Lua.WriteLog(line.ToString());
                status = Lua.luaL_loadbuffer(L, Lua.lua_tostring(L, 1), Lua.lua_strlen(L, 1), "=stdin");
                if (incomplete(L, status) == 0)
                {
                    break;                              /* cannot try to add lines? */
                }
                if (pushline(L, 0) == 0)                /* no more input? */
                {
                    return(-1);
                }
                Lua.lua_pushliteral(L, "\n");          /* add a new line... */
                Lua.lua_insert(L, -2);                 /* ...between the two lines */
                Lua.lua_concat(L, 3);                  /* join them */
            }
            Lua.lua_saveline(L, 1);
            Lua.lua_remove(L, 1);              /* remove line */
            return(status);
        }
예제 #3
0
        public Lua.CharPtr Connect(Lua.CharPtr address, int port, pTimeout tm)
        {
            if (tcpSocket != null)
            {
                try
                {
                    int timeout = (int)tm.block * 1000;
                    if (timeout < 0)
                    {
                        timeout = 0;
                    }
#if !NETFX_CORE
                    tcpSocket.Connect(new DnsEndPoint(address.ToString(), port), timeout);
#else
                    //TODO:
#endif
                }
                catch (Exception e)
                {
                    return(address);
                }
            }

            /*else if(tcpSocketChannel != null)
             * {
             *      try
             *      {
             *              int timeout = (int) tm.block * 1000;
             *              if(timeout < 0)
             *                      timeout = 0;
             *              tcpSocketChannel.configureBlocking(true);
             *              boolean connected = tcpSocketChannel.connect(new InetSocketAddress(InetAddress.getByName(address.toString()), port));
             *              while(!tcpSocketChannel.finishConnect())
             *              {
             *                      Thread.sleep(50);
             *              }
             *              tcpSocketChannel.socket().setSoTimeout(timeout);
             *              tcpSocketChannel.socket().setKeepAlive(true);
             *              tcpSocketChannel.socket().setTcpNoDelay(true);
             *              //tcpSocketWriter = new BufferedWriter(new OutputStreamWriter(tcpSocketChannel.socket().getOutputStream()));
             *              if(cantSetNonBlocking)
             *              {
             *                      SetNonBlocking(cantSetNonBlockingValue);
             *                      cantSetNonBlocking = false;
             *              }
             *      }
             *      catch (Exception e)
             *      {
             *              return address;
             *      }
             * }*/
            return(null);
        }
예제 #4
0
        public Lua.CharPtr Bind(Lua.CharPtr address, int port)
        {
            if (tcpSocket != null)
            {
                try
                {
#if !NETFX_CORE
                    tcpSocket.Bind(new DnsEndPoint(address.ToString(), port));
#else
                    //TODO:
#endif
                }
                catch (Exception e)
                {
                    return(address);
                }
            }
            return(null);
        }
예제 #5
0
        //#define	IS(s)	(strcmp(argv[i],s)==0)

        static int doargs(int argc, string[] argv)
        {
            int i;
            int version = 0;

            if ((argv.Length > 0) && (argv[0] != ""))
            {
                progname = argv[0];
            }
            for (i = 1; i < argc; i++)
            {
                if (argv[i][0] != '-')                  /* end of options; keep it */
                {
                    break;
                }
                else if (Lua.strcmp(argv[i], "--") == 0)                        /* end of options; skip it */
                {
                    ++i;
                    if (version != 0)
                    {
                        ++version;
                    }
                    break;
                }
                else if (Lua.strcmp(argv[i], "-") == 0)                 /* end of options; use stdin */
                {
                    break;
                }
                else if (Lua.strcmp(argv[i], "-l") == 0)                        /* list */
                {
                    ++listing;
                }
                else if (Lua.strcmp(argv[i], "-o") == 0)                        /* output file */
                {
                    output = argv[++i];
                    if (output == null || (output[0] == 0))
                    {
                        usage(Lua.LUA_QL("-o") + " needs argument");
                    }
                    if (Lua.strcmp(argv[i], "-") == 0)
                    {
                        output = null;
                    }
                }
                else if (Lua.strcmp(argv[i], "-p") == 0)                        /* parse only */
                {
                    dumping = 0;
                }
                else if (Lua.strcmp(argv[i], "-s") == 0)                        /* strip debug information */
                {
                    stripping = 1;
                }
                else if (Lua.strcmp(argv[i], "-v") == 0)                        /* show version */
                {
                    ++version;
                }
                else                                    /* unknown option */
                {
                    usage(argv[i]);
                }
            }
            if (i == argc && ((listing != 0) || (dumping == 0)))
            {
                dumping   = 0;
                argv[--i] = Output.ToString();
            }
            if (version != 0)
            {
                Lua.printf("%s  %s\n", Lua.LUA_RELEASE, Lua.LUA_COPYRIGHT);
                if (version == argc - 1)
                {
                    Environment.Exit(Lua.EXIT_SUCCESS);
                }
            }
            return(i);
        }
예제 #6
0
        public static string dolua_(string message)
        {
            if (DEBUG_)
            {
                Lua.fprintf(Lua.stdout, "%s\n", "==============>" + message);
            }
            if (L_ == null)
            {
                L_ = Lua.luaL_newstate();
                Lua.luaL_openlibs(L_);
            }

            if (DEBUG_)
            {
                Lua.fprintf(Lua.stdout, "%s\n", "==============>2");
            }

            string errorMessage = null;
            bool   printResult  = true;
            int    status       = Lua.luaL_loadbuffer(L_, message, (uint)Lua.strlen(message), "=stdin");

            if (status == 0)
            {
                if (DEBUG_)
                {
                    Lua.fprintf(Lua.stdout, "%s\n", "==============>3");
                }
                status = docall_(L_, 0, printResult ? Lua.LUA_MULTRET : 0);
            }
            if ((status != 0) && !Lua.lua_isnil(L_, -1))
            {
                if (DEBUG_)
                {
                    Lua.fprintf(Lua.stdout, "%s\n", "==============>4");
                }
                Lua.CharPtr msg = Lua.lua_tostring(L_, -1);
                if (msg == null)
                {
                    msg = "(error object is not a string)";
                }
                errorMessage = msg.ToString();
                Lua.lua_pop(L_, 1);
                /* force a complete garbage collection in case of errors */
                Lua.lua_gc(L_, Lua.LUA_GCCOLLECT, 0);
            }
            if (printResult)
            {
                //see Lua.LUA_MULTRET
                if (status == 0 && Lua.lua_gettop(L_) > 0)                    /* any result to print? */
                {
                    Lua.luaL_checkstack(L_, Lua.LUA_MINSTACK, "too many results to print");
                    Lua.lua_getglobal(L_, "print");
                    Lua.lua_insert(L_, 1);
                    if (Lua.lua_pcall(L_, Lua.lua_gettop(L_) - 1, 0, 0) != 0)
                    {
                        l_message_(progname, Lua.lua_pushfstring(L_,
                                                                 "error calling " + Lua.LUA_QL("print").ToString() + " (%s)",
                                                                 Lua.lua_tostring(L_, -1)));
                    }
                }
            }
            return(errorMessage);
        }