示例#1
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;
 }
示例#2
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]);
 }
示例#3
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;
 }
示例#4
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;
 }
示例#5
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;
 }
示例#6
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);
 }
示例#7
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;
 }
示例#8
0
 /*
 ** 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,"=?"));
 }
示例#9
0
 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;
 }
示例#10
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;
 }
示例#11
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 */
 }