Example #1
0
 private static CharPtr PushNextTemplate(LuaState L, CharPtr path)
 {
     CharPtr l;
     while (path[0] == LUA_PATHSEP[0]) path = path.next();  /* skip separators */
     if (path[0] == '\0') return null;  /* no more templates */
     l = strchr(path, LUA_PATHSEP[0]);  /* find next separator */
     if (l == null) l = path + strlen(path);
     LuaPushLString(L, path, (uint)(l - path));  /* template */
     return l;
 }
Example #2
0
 public static void LuaOChunkID(CharPtr out_, CharPtr source, uint bufflen)
 {
     //out_ = "";
       if (source[0] == '=') {
     strncpy(out_, source+1, (int)bufflen);  /* remove first char */
     out_[bufflen-1] = '\0';  /* ensures null termination */
       }
       else {  /* out = "source", or "...source" */
     if (source[0] == '@') {
       uint l;
       source = source.next();  /* skip the `@' */
       bufflen -= (uint)(" '...' ".Length + 1);
       l = (uint)strlen(source);
       strcpy(out_, "");
       if (l > bufflen) {
         source += (l-bufflen);  /* get last part of file name */
         strcat(out_, "...");
       }
       strcat(out_, source);
     }
     else {  /* out = [string "string"] */
       uint len = strcspn(source, "\n\r");  /* stop at first newline */
       bufflen -= (uint)(" [string \"...\"] ".Length + 1);
       if (len > bufflen) len = bufflen;
       strcpy(out_, "[string \"");
       if (source[len] != '\0') {  /* must truncate? */
         strncat(out_, source, (int)len);
         strcat(out_, "...");
       }
       else
         strcat(out_, source);
       strcat(out_, "\"]");
     }
       }
 }
Example #3
0
        private static CharPtr min_expand(MatchState ms, CharPtr s,
										 CharPtr p, CharPtr ep)
        {
            for (;;) {
            CharPtr res = match(ms, s, ep+1);
            if (res != null)
              return res;
              else if ( (s < ms.src_end) && (singlematch((byte)(s[0]), p, ep) != 0) )
              s = s.next();  /* try with one more repetition */
            else return null;
              }
        }
Example #4
0
 private static CharPtr scanformat(lua_State L, CharPtr strfrmt, CharPtr form)
 {
     CharPtr p = strfrmt;
       while (p[0] != '\0' && strchr(FLAGS, p[0]) != null) p = p.next();  /* skip flags */
       if ((uint)(p - strfrmt) >= (FLAGS.Length+1))
     luaL_error(L, "invalid format (repeated flags)");
       if (isdigit((byte)(p[0]))) p = p.next();  /* skip width */
       if (isdigit((byte)(p[0]))) p = p.next();  /* (2 digits at most) */
       if (p[0] == '.') {
     p = p.next();
     if (isdigit((byte)(p[0]))) p = p.next();  /* skip precision */
     if (isdigit((byte)(p[0]))) p = p.next();  /* (2 digits at most) */
       }
       if (isdigit((byte)(p[0])))
     luaL_error(L, "invalid format (width or precision too long)");
       form[0] = '%';
       form = form.next();
       strncpy(form, strfrmt, p - strfrmt + 1);
       form += p - strfrmt + 1;
       form[0] = '\0';
       return p;
 }
Example #5
0
        private static CharPtr matchbalance(MatchState ms, CharPtr s,
										   CharPtr p)
        {
            if ((p[0] == 0) || (p[1] == 0))
            luaL_error(ms.L, "unbalanced pattern");
              if (s[0] != p[0]) return null;
              else {
            int b = p[0];
            int e = p[1];
            int cont = 1;
            while ((s=s.next()) < ms.src_end) {
              if (s[0] == e) {
                if (--cont == 0) return s+1;
              }
              else if (s[0] == b) cont++;
            }
              }
              return null;  /* string ends out of balance */
        }
Example #6
0
 private static int matchbracketclass(int c, CharPtr p, CharPtr ec)
 {
     int sig = 1;
       if (p[1] == '^') {
     sig = 0;
     p = p.next();  /* skip the `^' */
       }
       while ((p=p.next()) < ec) {
     if (p == L_ESC) {
       p = p.next();
       if (match_class(c, (byte)(p[0])) != 0)
         return sig;
     }
     else if ((p[1] == '-') && (p + 2 < ec)) {
       p+=2;
       if ((byte)((p[-2])) <= c && (c <= (byte)p[0]))
         return sig;
     }
     else if ((byte)(p[0]) == c) return sig;
       }
       return (sig == 0) ? 1 : 0;
 }
Example #7
0
 private static CharPtr classend(MatchState ms, CharPtr p)
 {
     p = new CharPtr(p);
       char c = p[0];
       p = p.next();
       switch (c) {
     case L_ESC: {
       if (p[0] == '\0')
         luaL_error(ms.L, "malformed pattern (ends with " + LUA_QL("%%") + ")");
       return p+1;
     }
     case '[': {
       if (p[0] == '^') p = p.next();
       do {  /* look for a `]' */
         if (p[0] == '\0')
           luaL_error(ms.L, "malformed pattern (missing " + LUA_QL("]") + ")");
         c = p[0];
         p = p.next();
         if (c == L_ESC && p[0] != '\0')
           p = p.next();  /* skip escapes (e.g. `%]') */
       } while (p[0] != ']');
       return p+1;
     }
     default: {
       return p;
     }
       }
 }
Example #8
0
 private static CharPtr match(MatchState ms, CharPtr s, CharPtr p)
 {
     s = new CharPtr(s);
       p = new CharPtr(p);
       init: /* using goto's to optimize tail recursion */
       switch (p[0]) {
     case '(': {  /* start capture */
       if (p[1] == ')')  /* position capture? */
         return start_capture(ms, s, p+2, CAP_POSITION);
       else
         return start_capture(ms, s, p+1, CAP_UNFINISHED);
     }
     case ')': {  /* end capture */
       return end_capture(ms, s, p+1);
     }
     case L_ESC: {
       switch (p[1]) {
         case 'b': {  /* balanced string? */
           s = matchbalance(ms, s, p+2);
           if (s == null) return null;
           p+=4; goto init;  /* else return match(ms, s, p+4); */
         }
         case 'f': {  /* frontier? */
           CharPtr ep; char previous;
           p += 2;
           if (p[0] != '[')
             luaL_error(ms.L, "missing " + LUA_QL("[") + " after " +
                                LUA_QL("%%f") + " in pattern");
           ep = classend(ms, p);  /* points to what is next */
           previous = (s == ms.src_init) ? '\0' : s[-1];
           if ((matchbracketclass((byte)(previous), p, ep-1)!=0) ||
              (matchbracketclass((byte)(s[0]), p, ep-1)==0)) return null;
           p=ep; goto init;  /* else return match(ms, s, ep); */
         }
         default: {
           if (isdigit((byte)(p[1]))) {  /* capture results (%0-%9)? */
             s = match_capture(ms, s, (byte)(p[1]));
             if (s == null) return null;
             p+=2; goto init;  /* else return match(ms, s, p+2) */
           }
           goto dflt;  /* case default */
         }
       }
     }
     case '\0': {  /* end of pattern */
       return s;  /* match succeeded */
     }
     case '$': {
       if (p[1] == '\0')  /* is the `$' the last char in pattern? */
         return (s == ms.src_end) ? s : null;  /* check end of string */
       else goto dflt;
     }
     default: dflt: {  /* it is a pattern item */
       CharPtr ep = classend(ms, p);  /* points to what is next */
       int m = (s<ms.src_end) && (singlematch((byte)(s[0]), p, ep)!=0) ? 1 : 0;
       switch (ep[0]) {
         case '?': {  /* optional */
           CharPtr res;
           if ((m!=0) && ((res=match(ms, s+1, ep+1)) != null))
             return res;
           p=ep+1; goto init;  /* else return match(ms, s, ep+1); */
         }
         case '*': {  /* 0 or more repetitions */
           return max_expand(ms, s, p, ep);
         }
         case '+': {  /* 1 or more repetitions */
           return ((m!=0) ? max_expand(ms, s+1, p, ep) : null);
         }
         case '-': {  /* 0 or more repetitions (minimum) */
           return min_expand(ms, s, p, ep);
         }
         default: {
           if (m==0) return null;
           s = s.next(); p=ep; goto init;  /* else return match(ms, s+1, ep); */
         }
       }
     }
       }
 }
Example #9
0
		public static int LuaGetInfo (LuaState L, CharPtr what, ref LuaDebug ar) {
		  int status;
		  Closure f = null;
		  CallInfo ci = null;
		  LuaLock(L);
		  if (what == '>') {
			StkId func = L.top - 1;
			luai_apicheck(L, TTIsFunction(func));
			what = what.next();  /* skip the '>' */
			f = CLValue(func);
			StkId.Dec(ref L.top);  /* pop function */
		  }
		  else if (ar.i_ci != 0) {  /* no tail call? */
			ci = L.base_ci[ar.i_ci];
			LuaAssert(TTIsFunction(ci.func));
			f = CLValue(ci.func);
		  }
		  status = AuxGetInfo(L, what, ar, f, ci);
		  if (strchr(what, 'f') != null) {
			if (f == null) SetNilValue(L.top);
			else SetCLValue(L, L.top, f);
			IncrTop(L);
		  }
		  if (strchr(what, 'L') != null)
			CollectValidLines(L, f);
		  LuaUnlock(L);
		  return status;
		}
Example #10
0
        private static CharPtr match(MatchState ms, CharPtr s, CharPtr p)
        {
            s = new CharPtr(s);
              p = new CharPtr(p);
              bool runDflt = false;
              bool runInit = true;
              if (ms.matchdepth-- == 0)
            LuaLError(ms.L, "pattern too complex");
              //init:
              while (runInit) { // Replaces "init:" in order to be compatible with Mono.
              runInit = false; // No "goto init" until further notice.
              if (p != '\0') { /* end of pattern? */
                switch (p[0]) {
                  case '(': {  /* start capture */
                      if (p[1] == ')') {  /* position capture? */
                        s = start_capture(ms, s, p + 2, CAP_POSITION);
                      }
                      else {
                        s = start_capture(ms, s, p + 1, CAP_UNFINISHED);
                      }
                      break;
                    }
                  case ')': {  /* end capture */
                      s = end_capture(ms, s, p + 1);
                      break;
                    }
                  case '$': {
                      if (p[1] != '\0') {  /* is the `$' the last char in pattern? */
                        runDflt = true; //goto dflt; /* no; go to default */
                      }
                      s = (s == ms.src_end) ? s : null;  /* check end of string */
                      break;
                    }
                  case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
                      switch (p[1]) {
                        case 'b': {  /* balanced string? */
                            s = matchbalance(ms, s, p + 2);
                            if (s != null) {
                              p += 4;
                              runInit = true; //goto init;  /* return match(ms, s, p+4); */
                            }
                            /* else fail (s == NULL) */
                            break;
                          }
                        case 'f': {  /* frontier? */
                            CharPtr ep; char previous;
                            p += 2;
                            if (p[0] != '[') {
                              LuaLError(ms.L, "missing " + LUA_QL("[") + " after " +
                                          LUA_QL("%%f") + " in pattern");
                            }
                            ep = classend(ms, p);  /* points to what is next */
                            previous = (s == ms.src_init) ? '\0' : s[-1];
                            if ((matchbracketclass((byte)(previous), p, ep - 1) == 0) ||
                              (matchbracketclass((byte)(s[0]), p, ep - 1) != 0)) {
                              p = ep;
                              runInit = true; //goto init; /* else return match(ms, s, ep); */
                            }
                            s = null;  /* match failed */
                            break;
                          }
                        default: {
                            if (isdigit((byte)(p[1]))) {  /* capture results (%0-%9)? */
                              s = match_capture(ms, s, (byte)(p[1]));
                              if (s != null) {
                                p += 2;
                                runInit = true; //goto init;  /* else return match(ms, s, p+2) */
                              }
                              break;
                            }
                            runDflt = true; //goto dflt;
                            break;
                          }
                      }
                      break;
                    }
                  default: {
                      runDflt = true; // goto dflt
                      break;
                    }
                }
              }

              //dflt:
              if (runDflt) // Replaces "dflt:" in order to be compatible with Mono.
              {  /* pattern class plus optional suffix */
                  runDflt = false; // no more "goto dflt" until further notice.
                  CharPtr ep = classend(ms, p);  /* points to optional suffix */
                  /* does not match at least once? */
                  if ((s >= ms.src_end) || (singlematch((byte)(s[0]), p, ep) == 0)) {
                    if (ep == '*' || ep == '?' || ep == '-') { /* accept empty? */
                      p = ep + 1;
                      runInit = true; //goto init; /* return match(ms, s, ep + 1); */
                    }
                    else  /* '+' or no suffix */
                      s = null; /* fail */
                  }
                  else { /* matched once */
                    switch (ep[0]) {
                      case '?': {  /* optional */
                          CharPtr res;
                          if ((res = match(ms, s + 1, ep + 1)) != null) {
                            s = res;
                          }
                          else {
                            p = ep + 1;
                            runInit = true; //goto init;  /* else return match(ms, s, ep+1); */
                          }
                          break;
                        }
                      case '+': {  /* 1 or more repetitions */
                          s = s.next(); /* 1 match already done */
                          s = max_expand(ms, s, p, ep); // cannot fall through, repeating '*' instruction instead.
                          break;
                        }
                      case '*': {  /* 0 or more repetitions */
                          s = max_expand(ms, s, p, ep);
                          break;
                        }
                      case '-': {  /* 0 or more repetitions (minimum) */
                          s = min_expand(ms, s, p, ep);
                          break;
                        }
                      default: { /* no suffix */
                          s = s.next();
                          p = ep;
                          runInit = true; //goto init;  /* return match(ms, s+1, ep); */
                          break;
                        }
                    }
                  }
              }
              }

              ms.matchdepth++;
              return s;
        }
Example #11
0
		private static int AuxGetInfo (LuaState L, CharPtr what, LuaDebug ar,
							Closure f, CallInfo ci) {
		  int status = 1;
		  if (f == null) {
			InfoTailCall(ar);
			return status;
		  }
		  for (; what[0] != 0; what = what.next()) {
			switch (what[0]) {
			  case 'S': {
				FuncInfo(ar, f);
				break;
			  }
			  case 'l': {
				ar.currentline = (ci != null) ? CurrentLine(L, ci) : -1;
				break;
			  }
			  case 'u': {
				ar.nups = f.c.nupvalues;
				break;
			  }
			  case 'n': {
				ar.namewhat = (ci!=null) ? GetFuncName(L, ci, ref ar.name) : null;
				if (ar.namewhat == null) {
				  ar.namewhat = "";  /* not found */
				  ar.name = null;
				}
				break;
			  }
			  case 'L':
			  case 'f':  /* handled by lua_getinfo */
				break;
			  default: status = 0;  break;/* invalid option */
			}
		  }
		  return status;
		}
Example #12
0
        private static CharPtr StrFTimeAdd(CharPtr str, CharPtr pt, CharPtr ptlim)
        {
            pt[0] = str[0];
            str = str.next();

            while (pt < ptlim && pt[0] != 0)
            {
                pt.inc();

                pt[0] = str[0];
                str = str.next();
            }
            return pt;
        }
Example #13
0
File: lauxlib.cs Project: oathx/Six
		public static void LuaLAddLString (LuaLBuffer B, CharPtr s, uint l) {
			while (l-- != 0)
			{
				char c = s[0];
				s = s.next();
				LuaLAddChar(B, c);
			}
		}
Example #14
0
 public static int lua_getinfo(lua_State L, CharPtr what, lua_Debug ar)
 {
     int status;
       Closure f = null;
       CallInfo ci = null;
       lua_lock(L);
       if (what == '>') {
     StkId func = L.top - 1;
     luai_apicheck(L, ttisfunction(func));
     what = what.next();  /* skip the '>' */
     f = clvalue(func);
     StkId.dec(ref L.top);  /* pop function */
       }
       else if (ar.i_ci != 0) {  /* no tail call? */
     ci = L.base_ci[ar.i_ci];
     lua_assert(ttisfunction(ci.func));
     f = clvalue(ci.func);
       }
       status = auxgetinfo(L, what, ar, f, ci);
       if (strchr(what, 'f') != null) {
     if (f == null) setnilvalue(L.top);
     else setclvalue(L, L.top, f);
     incr_top(L);
       }
       if (strchr(what, 'L') != null)
     collectvalidlines(L, f);
       lua_unlock(L);
       return status;
 }
Example #15
0
		public static void luaL_addlstring (luaL_Buffer B, CharPtr s, uint l) {
			while (l-- != 0)
			{
				char c = s[0];
				s = s.next();
				luaL_addchar(B, c);
			}
		}