Exemple #1
0
		//#define Sizeof(x)	((int)sizeof(x))
		//#define VOID(p)		((const void*)(p))

		public static void PrintString(TString ts)
		{
		 CharPtr s=GetStr(ts);
		 uint i,n=ts.tsv.len;
		 putchar('"');
		 for (i=0; i<n; i++)
		 {
		  int c=s[i];
		  switch (c)
		  {
		   case '"': printf("\\\""); break;
		   case '\\': printf("\\\\"); break;
		   case '\a': printf("\\a"); break;
		   case '\b': printf("\\b"); break;
		   case '\f': printf("\\f"); break;
		   case '\n': printf("\\n"); break;
		   case '\r': printf("\\r"); break;
		   case '\t': printf("\\t"); break;
		   case '\v': printf("\\v"); break;
		   default:	if (isprint((byte)c))
   					putchar(c);
				else
					printf("\\%03u",(byte)c);
				break;
		  }
		 }
		 putchar('"');
		}
Exemple #2
0
		public static TString newlstr (lua_State L, CharPtr str, uint l,
											   uint h) {
		  TString ts;
		  stringtable tb;
		  if (l+1 > MAX_SIZET /GetUnmanagedSize(typeof(char)))
		    luaM_toobig(L);
		  ts = new TString(new char[l+1]);
		  AddTotalBytes(L, (int)(l + 1) * GetUnmanagedSize(typeof(char)) + GetUnmanagedSize(typeof(TString)));
		  ts.tsv.len = l;
		  ts.tsv.hash = h;
		  ts.tsv.marked = luaC_white(G(L));
		  ts.tsv.tt = LUA_TSTRING;
		  ts.tsv.reserved = 0;
		  //memcpy(ts+1, str, l*GetUnmanagedSize(typeof(char)));
		  memcpy(ts.str.chars, str.chars, str.index, (int)l);
		  ts.str[l] = '\0';  /* ending 0 */
		  tb = G(L).strt;
		  h = (uint)lmod(h, tb.size);
		  ts.tsv.next = tb.hash[h];  /* chain new entry */
		  tb.hash[h] = obj2gco(ts);
		  tb.nuse++;
		  if ((tb.nuse > (int)tb.size) && (tb.size <= MAX_INT/2))
		    luaS_resize(L, tb.size*2);  /* too crowded */
		  return ts;
		}
Exemple #3
0
		/*
		** function to be used with macro "fasttm": optimized for absence of
		** tag methods
		*/
		public static TValue luaT_gettm (Table events, TMS event_, TString ename) {
		  /*const*/ TValue tm = luaH_getstr(events, ename);
		  LuaAssert(event_ <= TMS.TM_EQ);
		  if (TTIsNil(tm)) {  /* no tag method? */
			events.flags |= (byte)(1<<(int)event_);  /* cache this fact */
			return null;
		  }
		  else return tm;
		}
Exemple #4
0
 public static void StringMark(TString s)
 {
     Reset2Bits(ref s.tsv.marked, WHITE0BIT, WHITE1BIT);
 }
Exemple #5
0
 private static expkind singlevaraux(FuncState fs, TString n, expdesc var, int base_)
 {
     if (fs == null) {  /* no more levels? */
     init_exp(var, expkind.VGLOBAL, NO_REG);  /* default is global variable */
     return expkind.VGLOBAL;
       }
       else {
     int v = searchvar(fs, n);  /* look up at current level */
     if (v >= 0) {
       init_exp(var, expkind.VLOCAL, v);
       if (base_==0)
         markupval(fs, v);  /* local will be used as an upval */
       return expkind.VLOCAL;
     }
     else {  /* not found at current level; try upper one */
       if (singlevaraux(fs.prev, n, var, 0) == expkind.VGLOBAL)
           return expkind.VGLOBAL;
       var.u.s.info = indexupvalue(fs, n, var);  /* else was LOCAL or UPVAL */
       var.k = expkind.VUPVAL;  /* upvalue in this level */
       return expkind.VUPVAL;
     }
       }
 }
Exemple #6
0
 private static Proto LoadFunction(LoadState S, TString p)
 {
     Proto f;
      if (++S.L.nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
      f=luaF_newproto(S.L);
      setptvalue2s(S.L,S.L.top,f); incr_top(S.L);
      f.source=LoadString(S); if (f.source==null) f.source=p;
      f.linedefined=LoadInt(S);
      f.lastlinedefined=LoadInt(S);
      f.nups=LoadByte(S);
      f.numparams=LoadByte(S);
      f.is_vararg=LoadByte(S);
      f.maxstacksize=LoadByte(S);
      LoadCode(S,f);
      LoadConstants(S,f);
      LoadDebug(S,f);
      IF (luaG_checkcode(f)==0 ? 1 : 0, "bad code");
      StkId.dec(ref S.L.top);
      S.L.nCcalls--;
      return f;
 }
Exemple #7
0
		public static void luaS_fix(TString s)
		{
			lu_byte marked = s.tsv.marked;	// can't pass properties in as ref
			l_setbit(ref marked, FIXEDBIT);
			s.tsv.marked = marked;
		}
Exemple #8
0
 private static void new_localvar(LexState ls, TString name, int n)
 {
     FuncState fs = ls.fs;
       luaY_checklimit(fs, fs.nactvar+n+1, LUAI_MAXVARS, "local variables");
       fs.actvar[fs.nactvar+n] = (ushort)registerlocalvar(ls, name);
 }
Exemple #9
0
 public static CharPtr GetStr(TString ts)
 {
     return ts.str;
 }
Exemple #10
0
 //#define setsvalue2s	setsvalue
 internal static void setsvalue2s(lua_State L, TValue obj, TString x)
 {
     setsvalue(L, obj, x);
 }
Exemple #11
0
 private static void fornum(LexState ls, TString varname, int line)
 {
     /* fornum . NAME = exp1,exp1[,exp1] forbody */
       FuncState fs = ls.fs;
       int base_ = fs.freereg;
       new_localvarliteral(ls, "(for index)", 0);
       new_localvarliteral(ls, "(for limit)", 1);
       new_localvarliteral(ls, "(for step)", 2);
       new_localvar(ls, varname, 3);
       checknext(ls, '=');
       exp1(ls);  /* initial value */
       checknext(ls, ',');
       exp1(ls);  /* limit */
       if (testnext(ls, ',') != 0)
     exp1(ls);  /* optional step */
       else {  /* default step = 1 */
     LuaKCodeABx(fs, OpCode.OP_LOADK, fs.freereg, LuaKNumberK(fs, 1));
     LuaKReserveRegs(fs, 1);
       }
       forbody(ls, base_, line, 1, 1);
 }
Exemple #12
0
 public static Node hashstr(Table t, TString str)
 {
     return hashpow2(t, str.tsv.hash);
 }
Exemple #13
0
 public static void stringmark(TString s)
 {
     reset2bits(ref s.tsv.marked, WHITE0BIT, WHITE1BIT);
 }
Exemple #14
0
 public static TValue luaH_setstr(lua_State L, Table t, TString key)
 {
     TValue p = luaH_getstr(t, key);
       if (p != luaO_nilobject)
     return (TValue)p;
       else {
     TValue k = new TValue();
     setsvalue(L, k, key);
     return newkey(L, t, k);
       }
 }
Exemple #15
0
 /*
 ** search function for strings
 */
 public static TValue luaH_getstr(Table t, TString key)
 {
     Node n = hashstr(t, key);
       do {  /* check whether `key' is somewhere in the chain */
     if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
       return gval(n);  /* that's it */
     else n = gnext(n);
       } while (n != null);
       return luaO_nilobject;
 }
Exemple #16
0
 private static int l_strcmp(TString ls, TString rs)
 {
     CharPtr l = getstr(ls);
       uint ll = ls.tsv.len;
       CharPtr r = getstr(rs);
       uint lr = rs.tsv.len;
       for (;;) {
     //int temp = strcoll(l, r);
       int temp = String.Compare(l.ToString(), r.ToString());
     if (temp != 0) return temp;
     else {  /* strings are equal up to a `\0' */
       uint len = (uint)l.ToString().Length;  /* index of first `\0' in both strings */
       if (len == lr)  /* r is finished? */
         return (len == ll) ? 0 : 1;
       else if (len == ll)  /* l is finished? */
         return -1;  /* l is smaller than r (because r is not finished) */
       /* both strings longer than `len'; go on comparing (after the `\0') */
       len++;
       l += len; ll -= len; r += len; lr -= len;
     }
       }
 }
Exemple #17
0
 private static void codestring(LexState ls, expdesc e, TString s)
 {
     init_exp(e, expkind.VK, LuaKStringK(ls.fs, s));
 }
Exemple #18
0
 private static void DumpFunction(Proto f, TString p, DumpState D)
 {
     DumpString( ((f.source==p) || (D.strip!=0)) ? null : f.source, D);
      DumpInt(f.linedefined,D);
      DumpInt(f.lastlinedefined,D);
      DumpChar(f.nups,D);
      DumpChar(f.numparams,D);
      DumpChar(f.is_vararg,D);
      DumpChar(f.maxstacksize,D);
      DumpCode(f,D);
      DumpConstants(f,D);
      DumpDebug(f,D);
 }
Exemple #19
0
 private static void forlist(LexState ls, TString indexname)
 {
     /* forlist . NAME {,NAME} IN explist1 forbody */
       FuncState fs = ls.fs;
       expdesc e = new expdesc();
       int nvars = 0;
       int line;
       int base_ = fs.freereg;
       /* create control variables */
       new_localvarliteral(ls, "(for generator)", nvars++);
       new_localvarliteral(ls, "(for state)", nvars++);
       new_localvarliteral(ls, "(for control)", nvars++);
       /* create declared variables */
       new_localvar(ls, indexname, nvars++);
       while (testnext(ls, ',') != 0)
     new_localvar(ls, str_checkname(ls), nvars++);
       checknext(ls, (int)RESERVED.TK_IN);
       line = ls.linenumber;
       adjust_assign(ls, 3, explist1(ls, e), e);
       LuaKCheckStack(fs, 3);  /* extra space to call generator */
       forbody(ls, base_, line, nvars - 3, 0);
 }
Exemple #20
0
 private static void DumpString(TString s, DumpState D)
 {
     if (s==null || GetStr(s)==null)
      {
       uint size=0;
       DumpVar(size,D);
      }
      else
      {
       uint size=s.tsv.len+1;		/* include trailing '\0' */
       DumpVar(size,D);
       DumpBlock(GetStr(s),size,D);
      }
 }
Exemple #21
0
 private static int indexupvalue(FuncState fs, TString name, expdesc v)
 {
     int i;
       Proto f = fs.f;
       int oldsize = f.sizeupvalues;
       for (i=0; i<f.nups; i++) {
     if ((int)fs.upvalues[i].k == (int)v.k && fs.upvalues[i].info == v.u.s.info) {
       LuaAssert(f.upvalues[i] == name);
       return i;
     }
       }
       /* new one */
       luaY_checklimit(fs, f.nups + 1, LUAI_MAXUPVALUES, "upvalues");
       LuaMGrowVector(fs.L, ref f.upvalues, f.nups, ref f.sizeupvalues, MAXINT, "");
       while (oldsize < f.sizeupvalues) f.upvalues[oldsize++] = null;
       f.upvalues[f.nups] = name;
       LuaCObjBarrier(fs.L, f, name);
       LuaAssert(v.k == expkind.VLOCAL || v.k == expkind.VUPVAL);
       fs.upvalues[f.nups].k = CastByte(v.k);
       fs.upvalues[f.nups].info = CastByte(v.u.s.info);
       return f.nups++;
 }
Exemple #22
0
		//#define setsvalue2n	setsvalue
		internal static void SetSValue2N(LuaState L, Lua.LuaTypeValue obj, TString x) { SetSValue(L, obj, x); }
Exemple #23
0
 //#define setsvalue2s	setsvalue
 internal static void SetSValue2S(LuaState L, TValue obj, TString x)
 {
     SetSValue(L, obj, x);
 }
Exemple #24
0
		public static int luaK_stringK (FuncState fs, TString s) {
		  TValue o = new TValue();
		  setsvalue(fs.L, o, s);
		  return addk(fs, o, o);
		}
Exemple #25
0
		public static int LuaKStringK (FuncState fs, TString s) {
		  TValue o = new LuaTypeValue();
		  SetSValue(fs.L, o, s);
		  return AddK(fs, o, o);
		}
 protected virtual Node_String parseString(TString node)
 {
     return new Node_String(
     node.Text,
     getSource(node));
 }
Exemple #27
0
		public static int sizestring(TString s) {return ((int)s.len + 1) * GetUnmanagedSize(typeof(char)); }
Exemple #28
0
 private static int searchvar(FuncState fs, TString n)
 {
     int i;
       for (i=fs.nactvar-1; i >= 0; i--) {
     if (n == getlocvar(fs, i).varname)
       return i;
       }
       return -1;  /* not found */
 }
Exemple #29
0
 private static int registerlocalvar(LexState ls, TString varname)
 {
     FuncState fs = ls.fs;
       Proto f = fs.f;
       int oldsize = f.sizelocvars;
       LuaMGrowVector(ls.L, ref f.locvars, fs.nlocvars, ref f.sizelocvars,
                   (int)SHRT_MAX, "too many local variables");
       while (oldsize < f.sizelocvars) f.locvars[oldsize++].varname = null;
       f.locvars[fs.nlocvars].varname = varname;
       LuaCObjBarrier(ls.L, f, varname);
       return fs.nlocvars++;
 }
Exemple #30
0
		public static TValue luaH_setstr (LuaState L, Table t, TString key) {
		  TValue p = luaH_getstr(t, key);
		  if (p != LuaONilObject)
			return (TValue)p;
		  else {
			TValue k = new LuaTypeValue();
			SetSValue(L, k, key);
			return newkey(L, t, k);
		  }
		}