Example #1
0
 /* --------------------------------------------------------------- read --- */
 public static uint luaZ_read(ZIO z, CharPtr b, uint n)
 {
     b = new CharPtr(b);
     while (n != 0)
     {
         uint m;
         if (z.n == 0)                /* no bytes in buffer? */
         {
             if (luaZ_fill(z) == EOZ) /* try to read more */
             {
                 return(n);           /* no more input; return number of missing bytes */
             }
             else
             {
                 z.n++;     /* luaZ_fill consumed first byte; put it back */
                 z.p.dec(); //FIXME:--
             }
         }
         m = (n <= z.n) ? n : z.n;          // min. between n and z.n
         memcpy(b, z.p, m);
         z.n -= m;
         z.p += m;
         b    = b + m;
         n   -= m;
     }
     return(0);
 }
Example #2
0
        public static int lua_load(lua_State L, lua_Reader reader, object data,
                                   CharPtr chunkname, CharPtr mode)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname, mode);
            if (status == LUA_OK)                 /* no errors? */
            {
                LClosure f = clLvalue(L.top - 1); /* get newly created function */
                if (f.nupvalues == 1)             /* does it have one upvalue? */
                /* get global table from registry */
                {
                    Table            reg = hvalue(G(L).l_registry);
                    /*const*/ TValue gt  = luaH_getint(reg, LUA_RIDX_GLOBALS);
                    /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
                    setobj(L, f.upvals[0].v, gt);
                    luaC_barrier(L, f.upvals[0], gt);
                }
            }
            lua_unlock(L);
            return(status);
        }
Example #3
0
        public static int luaZ_fill(ZIO z)
        {
            uint     size;
            LuaState L = z.L;
            CharPtr  buff;

            if (z.eoz != 0)
            {
                return(EOZ);
            }
            LuaUnlock(L);
            buff = z.reader(L, z.data, out size);
            LuaLock(L);
            if (buff == null || size == 0)
            {
                z.eoz = 1;      /* avoid calling reader function next time */
                return(EOZ);
            }
            z.n = size - 1;
            z.p = new CharPtr(buff);
            int result = char2int(z.p[0]);

            z.p.inc();
            return(result);
        }
Example #4
0
 public static void luaZ_init(lua_State L, ZIO z, lua_Reader reader, object data)
 {
     z.L      = L;
     z.reader = reader;
     z.data   = data;
     z.n      = 0;
     z.p      = null;
 }
Example #5
0
 public static void luaZ_init(LinyeeState L, ZIO z, ly_Reader reader, object data)
 {
     z.L      = L;
     z.reader = reader;
     z.data   = data;
     z.n      = 0;
     z.p      = null;
     z.eoz    = 0;
 }
Example #6
0
        public static int LuaDProtectedParser(LuaState L, ZIO z, CharPtr name)
        {
            SParser p = new SParser();
            int     status;

            p.z = z; p.name = new CharPtr(name);
            luaZ_initbuffer(L, p.buff);
            status = LuaDPCall(L, FParser, p, SaveStack(L, L.top), L.errfunc);
            luaZ_freebuffer(L, p.buff);
            return(status);
        }
Example #7
0
 public static int luaZ_lookahead(ZIO z)
 {
     if (z.n == 0)
     {
         return(EOZ);
     }
     else
     {
         return((int)z.p[0]);
     }
 }
Example #8
0
 public static int zgetc(ZIO z)
 {
     if (z.n-- > 0)
     {
         int ch = (int)(z.p[0]); z.p.inc(); return(ch);
     }
     else
     {
         return(luaZ_fill(z));
     }
 }                                                                                                                                    //FIXME:(byte)->(int)
Example #9
0
		public static int zgetc(ZIO z)
		{
			if (z.n-- > 0)
			{
				int ch = char2int(z.p[0]);
				z.p.inc();
				return ch;
			}
			else
				return luaZ_fill(z);
		}
Example #10
0
 public static int zgetc(ZIO z)
 {
     if (z.n-- > 0)
     {
         int ch = char2int(z.p[0]); z.p.inc(); return(ch);
     }
     else
     {
         return(luaZ_fill(z));
     }
 }
Example #11
0
        public static int lua_load(lua_State L, string data, string chunkname)
        {
            ZIO z = new ZIO();

            if (string.IsNullOrEmpty(chunkname))
            {
                chunkname = "?";
            }
            luaZ_init(L, z, data);
            return(luaD_protectedparser(L, z, chunkname));
        }
Example #12
0
        public static int luaD_protectedparser(lua_State L, ZIO z, CharPtr name)
        {
            SParser p = new SParser();
            int     status;

            p.z = z; p.name = new CharPtr(name);
            luaZ_initbuffer(L, p.buff);
            status = luaD_pcall(L, f_parser, p, savestack(L, L.top), L.errfunc);
            luaZ_freebuffer(L, p.buff);
            return(status);
        }
Example #13
0
 public static int zgetc(ZIO z)
 {
     if (z.n-- > 0)
     {
         int ch = (int)z.p[0];
         z.p.inc();
         return(ch);
     }
     else
     {
         return(EOZ);
     }
 }
Example #14
0
 public static void luaX_setinput(lua_State L, LexState ls, ZIO z, TString source)
 {
     ls.decpoint        = '.';
     ls.L               = L;
     ls.lookahead.token = (int)RESERVED.TK_EOS;              /* no look-ahead token */
     ls.z               = z;
     ls.fs              = null;
     ls.linenumber      = 1;
     ls.lastline        = 1;
     ls.source          = source;
     luaZ_resizebuffer(ls.L, ls.buff, LUA_MINBUFFER); /* initialize buffer */
     next(ls);                                        /* read first char */
 }
Example #15
0
		public static int luaZ_fill (ZIO z) {
		  uint size;
		  LuaState L = z.L;
		  CharPtr buff;
		  lua_unlock(L);
		  buff = z.reader(L, z.data, out size);
		  lua_lock(L);
		  if (buff == null || size == 0) return EOZ;
		  z.n = size - 1;
		  z.p = new CharPtr(buff);
		  int result = char2int(z.p[0]);
		  z.p.inc();
		  return result;
		}
Example #16
0
 public static void luaX_setinput(lua_State L, LexState ls, ZIO z, TString source,
                                  int firstchar)
 {
     ls.t.token         = 0;
     ls.L               = L;
     ls.current         = firstchar;
     ls.lookahead.token = (int)RESERVED.TK_EOS;        /* no look-ahead token */
     ls.z               = z;
     ls.fs              = null;
     ls.linenumber      = 1;
     ls.lastline        = 1;
     ls.source          = source;
     ls.envn            = luaS_newliteral(L, LUA_ENV); /* get env name */
     luaZ_resizebuffer(ls.L, ls.buff, LUA_MINBUFFER);  /* initialize buffer */
 }
Example #17
0
        public static int luaD_protectedparser(lua_State L, ZIO z, CharPtr name)
        {
            SParser p = new SParser();
            int     status;

            L.nny++;                                       /* cannot yield during parsing */
            p.z           = z; p.name = new CharPtr(name); //FIXME:
            p.varl.actvar = null; p.varl.nactvar = p.varl.actvarsize = 0;
            luaZ_initbuffer(L, p.buff);
            status = luaD_pcall(L, f_parser, p, savestack(L, L.top), L.errfunc);
            luaZ_freebuffer(L, p.buff);
            luaM_freearray <vardesc>(L, p.varl.actvar /*, p.varl.actvarsize*/);
            L.nny--;
            return(status);
        }
Example #18
0
 public static int zgetc(ZIO z)
 {
     if (z.n > 0)
     {
         z.n--;
         int ch = char2int(z.p[0]);
         z.p.inc();
         return(ch);
     }
     else
     {
         z.n = (uint)(((long)z.n - 1) & 0xFFFFFFFFL);
         return(luaZ_fill(z));
     }
 }
Example #19
0
        public static int LuaLoad(LuaState L, lua_Reader reader, object data,
                                  CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            LuaLock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }
            luaZ_init(L, z, reader, data);
            status = LuaDProtectedParser(L, z, chunkname);
            LuaUnlock(L);
            return(status);
        }
Example #20
0
        public static int lua_load(lua_State L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            return(status);
        }
Example #21
0
 public static int luaZ_lookahead(ZIO z)
 {
     if (z.n == 0)
     {
         if (luaZ_fill(z) == EOZ)
         {
             return(EOZ);
         }
         else
         {
             z.n++;        /* luaZ_fill removed first byte; put back it */
             z.p.dec();
         }
     }
     return(char2int(z.p[0]));
 }
Example #22
0
        public static int luaZ_fill(ZIO z)
        {
            uint      size;
            lua_State L = z.L;
            CharPtr   buff;

            lua_unlock(L);
            buff = z.reader(L, z.data, out size);
            lua_lock(L);
            if (buff == null || size == 0)
            {
                return(EOZ);
            }
            z.n = size - 1;                                        /* discount char being returned */
            z.p = new CharPtr(buff);
            int result = (int)(z.p[0]); z.p.inc(); return(result); //FIXME:changed, (byte)->(int)
        }
Example #23
0
		public static int luaD_protectedparser (lua_State L, ZIO z, CharPtr name,
		                                        CharPtr mode) {
		  SParser p = new SParser();
		  int status;
          L.nny++;  /* cannot yield during parsing */
		  p.z = z; p.name = name; p.mode = mode; //FIXME:changed, new CharPtr //FIXME:changed, new CharPtr
          p.dyd.actvar.arr = null; p.dyd.actvar.size = 0;
		  p.dyd.gt.arr = null; p.dyd.gt.size = 0;
		  p.dyd.label.arr = null; p.dyd.label.size = 0;
		  luaZ_initbuffer(L, p.buff);
		  status = luaD_pcall(L, f_parser, p, savestack(L, L.top), L.errfunc);
		  luaZ_freebuffer(L, p.buff);
		  luaM_freearray<Vardesc>(L, p.dyd.actvar.arr/*, p.dyd.actvar.size*/);
		  luaM_freearray<Labeldesc>(L, p.dyd.gt.arr/*, p.dyd.gt.size*/);
		  luaM_freearray<Labeldesc>(L, p.dyd.label.arr/*, p.dyd.label.size*/);
		  L.nny--;
		  return status;
		}
Example #24
0
 /* --------------------------------------------------------------- read --- */
 public static uint luaZ_read(ZIO z, CharPtr b, uint n)
 {
     b = new CharPtr(b);
     while (n != 0)
     {
         uint m;
         if (luaZ_lookahead(z) == EOZ)
         {
             return(n);            // return number of missing bytes
         }
         m = (n <= z.n) ? n : z.n; // min. between n and z.n
         memcpy(b, z.p, m);
         z.n -= m;
         z.p += m;
         b    = b + m;
         n   -= m;
     }
     return(0);
 }
Example #25
0
        public static int luaZ_fill(ZIO z)
        {
            uint      size;
            lua_State L = z.L;
            CharPtr   buff;

            lua_unlock(L);
            buff = z.reader(L, z.data, out size);
            lua_lock(L);
            if (buff == null || size == 0)
            {
                return(EOZ);
            }
            z.n = size - 1;
            z.p = new CharPtr(buff);
            int result = char2int(z.p[0]);

            z.p.inc();
            return(result);
        }
        /*
        ** load precompiled chunk
        */
        public static Proto luaU_undump(lua_State L, ZIO Z, Mbuffer buff, CharPtr name)
        {
            LoadState S = new LoadState();

            if (name[0] == '@' || name[0] == '=')
            {
                S.name = name + 1;
            }
            else if (name[0] == LUA_SIGNATURE[0])
            {
                S.name = "binary string";
            }
            else
            {
                S.name = name;
            }
            S.L = L;
            S.Z = Z;
            S.b = buff;
            LoadHeader(S);
            return(LoadFunction(S, luaS_newliteral(L, "=?")));
        }
Example #27
0
 public static void zungetc(ZIO z)
 {
     z.n++; z.p.dec();
 }                                                              //FIXME: CharPtr::-- => CharPtr::dec()
Example #28
0
		public static int luaZ_fill (ZIO z) {
		  uint size;
		  LuaState L = z.L;
		  CharPtr buff;
		  if (z.eoz != 0) return EOZ;
		  LuaUnlock(L);
		  buff = z.reader(L, z.data, out size);
		  LuaLock(L);
		  if (buff == null || size == 0) {
		    z.eoz = 1;  /* avoid calling reader function next time */
		    return EOZ;
		  }
		  z.n = size - 1;
		  z.p = new CharPtr(buff);
		  int result = char2int(z.p[0]);
		  z.p.inc();
		  return result;
		}
Example #29
0
		public static void LuaXSetInput (LuaState L, LexState ls, ZIO z, TString source) {
		  ls.decpoint = '.';
		  ls.L = L;
		  ls.lookahead.token = (int)RESERVED.TK_EOS;  /* no look-ahead token */
		  ls.z = z;
		  ls.fs = null;
		  ls.linenumber = 1;
		  ls.lastline = 1;
		  ls.source = source;
		  luaZ_resizebuffer(ls.L, ls.buff, LUAMINBUFFER);  /* initialize buffer */
		  Next(ls);  /* read first char */
		}
Example #30
0
		public static uint luaZ_read (ZIO z, CharPtr b, uint n) {
		  b = new CharPtr(b);
		  while (n != 0) {
			uint m;
			if (luaZ_lookahead(z) == EOZ)
			  return n;  // return number of missing bytes
			m = (n <= z.n) ? n : z.n;  // min. between n and z.n
			memcpy(b, z.p, m);
			z.n -= m;
			z.p += m;
			b = b + m;
			n -= m;
		  }
		  return 0;
		}
Example #31
0
		public static void luaZ_init(LuaState L, ZIO z, lua_Reader reader, object data)
		{
		  z.L = L;
		  z.reader = reader;
		  z.data = data;
		  z.n = 0;
		  z.p = null;
		  z.eoz = 0;
		}
Example #32
0
		public static int luaZ_lookahead (ZIO z) {
		  if (z.n == 0) {
			if (luaZ_fill(z) == EOZ)
			  return EOZ;
			else {
			  z.n++;  /* luaZ_fill removed first byte; put back it */
			  z.p.dec();
			}
		  }
		  return char2int(z.p[0]);
		}
Example #33
0
        public static int lua_load(LuaState L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }

            #if OVERRIDE_LOAD || true
            //#if false
            if (data is LoadS)
            {
                LoadS d = data as LoadS;
                if (d.size > 0 && d.s.chars[0] != LUA_SIGNATURE[0]) // if its not binary
                {
                    Lexer l = new Lexer();
                    try
                    {
                        //Console.WriteLine(d.s);
                        TokenReader tr = l.Lex(d.s);
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        d.s    = s;
                        d.size = (lu_mem)s.Length;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    d.s.index = 0;

                    // Why isn't the size equal to the chars.Length?
                    Debug.WriteLine("Binary data: d.size=" + d.size + " d.s.chars.Length=" + d.s.chars.Length);
                    Debug.WriteLine("Equal: " + (d.size == d.s.chars.Length));
                    //Debug.Assert(d.size == d.s.chars.Length);
                    d.size = (uint)d.s.chars.Length;
                }
            }
            else if (data is LoadF)
            {
                LoadF lf = data as LoadF;

                if (lf.f.ReadByte() != LUA_SIGNATURE[0]) // if its not binary
                {
                    lf.f.Position = 0;
                    MemoryStream ms = new MemoryStream();
                    while (lf.f.Position < lf.f.Length)
                    {
                        ms.WriteByte((byte)lf.f.ReadByte());
                    }
                    ms.Position = 0;

                    // not binary file
                    ms.Position = 0;
                    StringBuilder sb = new StringBuilder();
                    while (ms.Position < ms.Length)
                    {
                        sb.Append((char)ms.ReadByte());
                    }

                    try
                    {
                        Lexer       l  = new Lexer();
                        TokenReader tr = l.Lex(sb.ToString());
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();
                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        ms = new MemoryStream();
                        // TODO: there HAS to be a better way...
                        foreach (char c2 in s)
                        {
                            ms.WriteByte((byte)c2);
                        }
                        ms.Position = 0;
                        lf.f        = ms;
                    }
                    catch (LuaSourceException ex)
                    {
                        lua_pushstring(L, ex.GenerateMessage(chunkname));
                        return(1);
                        //throw ex;
                    }
                }
                else
                {
                    lf.f.Position = 0; // reset the read character
                }
            }
            #endif
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            if (data is LoadF)
            {
                LoadF f = data as LoadF;
                if (f.f != null)
                {
                    f.f.Close();
                    f.f.Dispose();
                }
            }
            return(status);
        }
Example #34
0
        public static int lua_load(LuaState L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }

            if (data is LoadS)
            {
                LoadS d = data as LoadS;
                if (d.size > 0)
                {
                    Lexer l = new Lexer();
                    try
                    {
                        //Console.WriteLine(d.s);
                        TokenReader tr = l.Lex(d.s);
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        d.s    = s;
                        d.size = (lu_mem)s.Length;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
            }
            else if (data is LoadF)
            {
                LoadF lf = data as LoadF;

                MemoryStream ms = new MemoryStream();
                while (lf.f.Position < lf.f.Length)
                {
                    ms.WriteByte((byte)lf.f.ReadByte());
                }
                ms.Position = 0;
                if (ms.ReadByte() != 27)
                {
                    // not binary file
                    ms.Position = 0;
                    StringBuilder sb = new StringBuilder();
                    while (ms.Position < ms.Length)
                    {
                        sb.Append((char)ms.ReadByte());
                    }

                    try
                    {
                        Lexer       l  = new Lexer();
                        TokenReader tr = l.Lex(sb.ToString());
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        ms = new MemoryStream();
                        // TODO: there HAS to be a better way...
                        foreach (char c2 in s)
                        {
                            ms.WriteByte((byte)c2);
                        }
                        ms.Position = 0;
                        lf.f        = ms;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
            }

            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            return(status);
        }
Example #35
0
		public static int LuaLoad (LuaState L, lua_Reader reader, object data,
							  CharPtr chunkname) {
		  ZIO z = new ZIO();
		  int status;
		  LuaLock(L);
		  if (chunkname == null) chunkname = "?";
		  luaZ_init(L, z, reader, data);
		  status = LuaDProtectedParser(L, z, chunkname);
		  LuaUnlock(L);
		  return status;
		}
Example #36
0
		/*
		** load precompiled chunk
		*/
		public static Proto luaU_undump (LuaState L, ZIO Z, Mbuffer buff, CharPtr name)
		{
		 LoadState S = new LoadState();
		 if (name[0] == '@' || name[0] == '=')
		  S.name = name+1;
		 else if (name[0]==LUA_SIGNATURE[0])
		  S.name="binary string";
		 else
		  S.name=name;
		 S.L=L;
		 S.Z=Z;
		 S.b=buff;
		 LoadHeader(S);
		 return LoadFunction(S,luaS_newliteral(L,"=?"));
		}
Example #37
0
 public static void luaZ_init(lua_State L, ZIO z, string data)
 {
     z.L = L;
     z.n = (uint)data.Length;
     z.p = new CharPtr(data);
 }
Example #38
0
 public static int luaD_protectedparser (lua_State L, ZIO z, CharPtr name) {
     SParser p = new SParser();
     int status;
     p.z = z; p.name = new CharPtr(name);
     luaZ_initbuffer(L, p.buff);
     status = luaD_pcall(L, f_parser, p, savestack(L, L.top), L.errfunc);
     luaZ_freebuffer(L, p.buff);
     return status;
 }
Example #39
0
File: lparser.cs Project: oathx/Six
		public static Proto luaY_parser (LuaState L, ZIO z, Mbuffer buff, CharPtr name) {
		  LexState lexstate = new LexState();
		  FuncState funcstate = new FuncState();
		  lexstate.buff = buff;
		  LuaXSetInput(L, lexstate, z, luaS_new(L, name));
		  open_func(lexstate, funcstate);
		  funcstate.f.is_vararg = VARARG_ISVARARG;  /* main func. is always vararg */
		  LuaXNext(lexstate);  /* read first token */
 		  System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
		  chunk(lexstate);
		  check(lexstate, (int)RESERVED.TK_EOS);
		  close_func(lexstate);
		  LuaAssert(funcstate.prev == null);
		  LuaAssert(funcstate.f.nups == 0);
		  LuaAssert(lexstate.fs == null);
		  return funcstate.f;
		}
Example #40
0
        public static int lua_load(LuaState L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;
            lua_lock(L);
            if (chunkname == null) chunkname = "?";

            #if OVERRIDE_LOAD || true
            //#if false
            if (data is LoadS)
            {
                LoadS d = data as LoadS;
                if (d.size > 0 && d.s.chars[0] != LUA_SIGNATURE[0]) // if its not binary
                {
                    Lexer l = new Lexer();
                    try
                    {
                        //Console.WriteLine(d.s);
                        TokenReader tr = l.Lex(d.s);
                        Parser p = new Parser(tr);
                        Ast.Chunk c = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        d.s = s;
                        d.size = (lu_mem)s.Length;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    d.s.index = 0;

                    // Why isn't the size equal to the chars.Length?
                    Debug.WriteLine("Binary data: d.size=" + d.size + " d.s.chars.Length=" + d.s.chars.Length);
                    Debug.WriteLine("Equal: " + (d.size == d.s.chars.Length));
                    //Debug.Assert(d.size == d.s.chars.Length);
                    d.size = (uint)d.s.chars.Length;
                }
            }
            else if (data is LoadF)
            {
                LoadF lf = data as LoadF;

                if (lf.f.ReadByte() != LUA_SIGNATURE[0]) // if its not binary
                {
                    lf.f.Position = 0;
                    MemoryStream ms = new MemoryStream();
                    while (lf.f.Position < lf.f.Length)
                        ms.WriteByte((byte)lf.f.ReadByte());
                    ms.Position = 0;

                    // not binary file
                    ms.Position = 0;
                    StringBuilder sb = new StringBuilder();
                    while (ms.Position < ms.Length)
                        sb.Append((char)ms.ReadByte());

                    try
                    {
                        Lexer l = new Lexer();
                        TokenReader tr = l.Lex(sb.ToString());
                        Parser p = new Parser(tr);
                        Ast.Chunk c = p.Parse();
                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        ms = new MemoryStream();
                        // TODO: there HAS to be a better way...
                        foreach (char c2 in s)
                            ms.WriteByte((byte)c2);
                        ms.Position = 0;
                        lf.f = ms;
                    }
                    catch (LuaSourceException ex)
                    {
                        lua_pushstring(L, ex.GenerateMessage(chunkname));
                        return 1;
                        //throw ex;
                    }
                }
                else
                {
                    lf.f.Position = 0; // reset the read character
                }
            }
            #endif
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            if (data is LoadF)
            {
                LoadF f = data as LoadF;
                if (f.f != null)
                {
                    f.f.Close();
                    f.f.Dispose();
                }
            }
            return status;
        }
Example #41
0
 public static int LuaDProtectedParser(LuaState L, ZIO z, CharPtr name)
 {
     SParser p = new SParser();
     int status;
     p.z = z; p.name = new CharPtr(name);
     luaZ_initbuffer(L, p.buff);
     status = LuaDPCall(L, FParser, p, SaveStack(L, L.top), L.errfunc);
     luaZ_freebuffer(L, p.buff);
     return status;
 }