summaryrefslogtreecommitdiffstats
path: root/version.php
diff options
context:
space:
mode:
authorFrank Karlitschek <frank@owncloud.org>2015-04-15 22:16:26 +0200
committerFrank Karlitschek <frank@owncloud.org>2015-04-15 22:16:26 +0200
commitf50798a674bf223e1c8015b9a27287b2ac6c9f1a (patch)
treead14033b81766b10fd8f59537d4ed0414969684d /version.php
parent8653da6c16597959c7bd0f0b202747ff96204575 (diff)
downloadnextcloud-server-f50798a674bf223e1c8015b9a27287b2ac6c9f1a.tar.gz
nextcloud-server-f50798a674bf223e1c8015b9a27287b2ac6c9f1a.zip
8.1 alpha 1v8.1.0alpha1
Diffstat (limited to 'version.php')
-rw-r--r--version.php4
1 files changed, 2 insertions, 2 deletions
diff --git a/version.php b/version.php
index 0872d7c61f2..f5ede61afd9 100644
--- a/version.php
+++ b/version.php
@@ -23,10 +23,10 @@
// We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number.
-$OC_Version=array(8, 1, 0, 1);
+$OC_Version=array(8, 1, 0, 2);
// The human readable string
-$OC_VersionString='8.1 pre alpha';
+$OC_VersionString='8.1 alpha 1';
// The ownCloud channel
$OC_Channel='git';
pan class="mi">1, &s1); TTree *tree2 = getpatt(L, 2, &s2); TTree *tree = newtree(L, 1 + s1 + s2); /* create new tree */ tree->tag = tag; tree->u.ps = 1 + s1; memcpy(sib1(tree), tree1, s1 * sizeof(TTree)); memcpy(sib2(tree), tree2, s2 * sizeof(TTree)); joinktables(L, 1, sib2(tree), 2); return tree; } static int lp_P (lua_State *L) { luaL_checkany(L, 1); getpatt(L, 1, NULL); lua_settop(L, 1); return 1; } /* ** sequence operator; optimizations: ** false x => false, x true => x, true x => x ** (cannot do x . false => false because x may have runtime captures) */ static int lp_seq (lua_State *L) { TTree *tree1 = getpatt(L, 1, NULL); TTree *tree2 = getpatt(L, 2, NULL); if (tree1->tag == TFalse || tree2->tag == TTrue) lua_pushvalue(L, 1); /* false . x == false, x . true = x */ else if (tree1->tag == TTrue) lua_pushvalue(L, 2); /* true . x = x */ else newroot2sib(L, TSeq); return 1; } /* ** choice operator; optimizations: ** charset / charset => charset ** true / x => true, x / false => x, false / x => x ** (x / true is not equivalent to true) */ static int lp_choice (lua_State *L) { Charset st1, st2; TTree *t1 = getpatt(L, 1, NULL); TTree *t2 = getpatt(L, 2, NULL); if (tocharset(t1, &st1) && tocharset(t2, &st2)) { TTree *t = newcharset(L); loopset(i, treebuffer(t)[i] = st1.cs[i] | st2.cs[i]); } else if (nofail(t1) || t2->tag == TFalse) lua_pushvalue(L, 1); /* true / x => true, x / false => x */ else if (t1->tag == TFalse) lua_pushvalue(L, 2); /* false / x => x */ else newroot2sib(L, TChoice); return 1; } /* ** p^n */ static int lp_star (lua_State *L) { int size1; int n = (int)luaL_checkinteger(L, 2); TTree *tree1 = getpatt(L, 1, &size1); if (n >= 0) { /* seq tree1 (seq tree1 ... (seq tree1 (rep tree1))) */ TTree *tree = newtree(L, (n + 1) * (size1 + 1)); if (nullable(tree1)) luaL_error(L, "loop body may accept empty string"); while (n--) /* repeat 'n' times */ tree = seqaux(tree, tree1, size1); tree->tag = TRep; memcpy(sib1(tree), tree1, size1 * sizeof(TTree)); } else { /* choice (seq tree1 ... choice tree1 true ...) true */ TTree *tree; n = -n; /* size = (choice + seq + tree1 + true) * n, but the last has no seq */ tree = newtree(L, n * (size1 + 3) - 1); for (; n > 1; n--) { /* repeat (n - 1) times */ tree->tag = TChoice; tree->u.ps = n * (size1 + 3) - 2; sib2(tree)->tag = TTrue; tree = sib1(tree); tree = seqaux(tree, tree1, size1); } tree->tag = TChoice; tree->u.ps = size1 + 1; sib2(tree)->tag = TTrue; memcpy(sib1(tree), tree1, size1 * sizeof(TTree)); } copyktable(L, 1); return 1; } /* ** #p == &p */ static int lp_and (lua_State *L) { newroot1sib(L, TAnd); return 1; } /* ** -p == !p */ static int lp_not (lua_State *L) { newroot1sib(L, TNot); return 1; } /* ** [t1 - t2] == Seq (Not t2) t1 ** If t1 and t2 are charsets, make their difference. */ static int lp_sub (lua_State *L) { Charset st1, st2; int s1, s2; TTree *t1 = getpatt(L, 1, &s1); TTree *t2 = getpatt(L, 2, &s2); if (tocharset(t1, &st1) && tocharset(t2, &st2)) { TTree *t = newcharset(L); loopset(i, treebuffer(t)[i] = st1.cs[i] & ~st2.cs[i]); } else { TTree *tree = newtree(L, 2 + s1 + s2); tree->tag = TSeq; /* sequence of... */ tree->u.ps = 2 + s2; sib1(tree)->tag = TNot; /* ...not... */ memcpy(sib1(sib1(tree)), t2, s2 * sizeof(TTree)); /* ...t2 */ memcpy(sib2(tree), t1, s1 * sizeof(TTree)); /* ... and t1 */ joinktables(L, 1, sib1(tree), 2); } return 1; } static int lp_set (lua_State *L) { size_t l; const char *s = luaL_checklstring(L, 1, &l); TTree *tree = newcharset(L); while (l--) { setchar(treebuffer(tree), (byte)(*s)); s++; } return 1; } static int lp_range (lua_State *L) { int arg; int top = lua_gettop(L); TTree *tree = newcharset(L); for (arg = 1; arg <= top; arg++) { int c; size_t l; const char *r = luaL_checklstring(L, arg, &l); luaL_argcheck(L, l == 2, arg, "range must have two characters"); for (c = (byte)r[0]; c <= (byte)r[1]; c++) setchar(treebuffer(tree), c); } return 1; } /* ** Look-behind predicate */ static int lp_behind (lua_State *L) { TTree *tree; TTree *tree1 = getpatt(L, 1, NULL); int n = fixedlen(tree1); luaL_argcheck(L, n >= 0, 1, "pattern may not have fixed length"); luaL_argcheck(L, !hascaptures(tree1), 1, "pattern have captures"); luaL_argcheck(L, n <= MAXBEHIND, 1, "pattern too long to look behind"); tree = newroot1sib(L, TBehind); tree->u.n = n; return 1; } /* ** Create a non-terminal */ static int lp_V (lua_State *L) { TTree *tree = newleaf(L, TOpenCall); luaL_argcheck(L, !lua_isnoneornil(L, 1), 1, "non-nil value expected"); tree->key = addtonewktable(L, 0, 1); return 1; } /* ** Create a tree for a non-empty capture, with a body and ** optionally with an associated Lua value (at index 'labelidx' in the ** stack) */ static int capture_aux (lua_State *L, int cap, int labelidx) { TTree *tree = newroot1sib(L, TCapture); tree->cap = cap; tree->key = (labelidx == 0) ? 0 : addtonewktable(L, 1, labelidx); return 1; } /* ** Fill a tree with an empty capture, using an empty (TTrue) sibling. */ static TTree *auxemptycap (TTree *tree, int cap) { tree->tag = TCapture; tree->cap = cap; sib1(tree)->tag = TTrue; return tree; } /* ** Create a tree for an empty capture */ static TTree *newemptycap (lua_State *L, int cap) { return auxemptycap(newtree(L, 2), cap); } /* ** Create a tree for an empty capture with an associated Lua value */ static TTree *newemptycapkey (lua_State *L, int cap, int idx) { TTree *tree = auxemptycap(newtree(L, 2), cap); tree->key = addtonewktable(L, 0, idx); return tree; } /* ** Captures with syntax p / v ** (function capture, query capture, string capture, or number capture) */ static int lp_divcapture (lua_State *L) { switch (lua_type(L, 2)) { case LUA_TFUNCTION: return capture_aux(L, Cfunction, 2); case LUA_TTABLE: return capture_aux(L, Cquery, 2); case LUA_TSTRING: return capture_aux(L, Cstring, 2); case LUA_TNUMBER: { int n = lua_tointeger(L, 2); TTree *tree = newroot1sib(L, TCapture); luaL_argcheck(L, 0 <= n && n <= SHRT_MAX, 1, "invalid number"); tree->cap = Cnum; tree->key = n; return 1; } default: return luaL_argerror(L, 2, "invalid replacement value"); } } static int lp_substcapture (lua_State *L) { return capture_aux(L, Csubst, 0); } static int lp_tablecapture (lua_State *L) { return capture_aux(L, Ctable, 0); } static int lp_groupcapture (lua_State *L) { if (lua_isnoneornil(L, 2)) return capture_aux(L, Cgroup, 0); else return capture_aux(L, Cgroup, 2); } static int lp_foldcapture (lua_State *L) { luaL_checktype(L, 2, LUA_TFUNCTION); return capture_aux(L, Cfold, 2); } static int lp_simplecapture (lua_State *L) { return capture_aux(L, Csimple, 0); } static int lp_poscapture (lua_State *L) { newemptycap(L, Cposition); return 1; } static int lp_argcapture (lua_State *L) { int n = (int)luaL_checkinteger(L, 1); TTree *tree = newemptycap(L, Carg); tree->key = n; luaL_argcheck(L, 0 < n && n <= SHRT_MAX, 1, "invalid argument index"); return 1; } static int lp_backref (lua_State *L) { luaL_checkany(L, 1); newemptycapkey(L, Cbackref, 1); return 1; } /* ** Constant capture */ static int lp_constcapture (lua_State *L) { int i; int n = lua_gettop(L); /* number of values */ if (n == 0) /* no values? */ newleaf(L, TTrue); /* no capture */ else if (n == 1) newemptycapkey(L, Cconst, 1); /* single constant capture */ else { /* create a group capture with all values */ TTree *tree = newtree(L, 1 + 3 * (n - 1) + 2); newktable(L, n); /* create a 'ktable' for new tree */ tree->tag = TCapture; tree->cap = Cgroup; tree->key = 0; tree = sib1(tree); for (i = 1; i <= n - 1; i++) { tree->tag = TSeq; tree->u.ps = 3; /* skip TCapture and its sibling */ auxemptycap(sib1(tree), Cconst); sib1(tree)->key = addtoktable(L, i); tree = sib2(tree); } auxemptycap(tree, Cconst); tree->key = addtoktable(L, i); } return 1; } static int lp_matchtime (lua_State *L) { TTree *tree; luaL_checktype(L, 2, LUA_TFUNCTION); tree = newroot1sib(L, TRunTime); tree->key = addtonewktable(L, 1, 2); return 1; } /* }====================================================== */ /* ** {====================================================== ** Grammar - Tree generation ** ======================================================= */ /* ** push on the stack the index and the pattern for the ** initial rule of grammar at index 'arg' in the stack; ** also add that index into position table. */ static void getfirstrule (lua_State *L, int arg, int postab) { lua_rawgeti(L, arg, 1); /* access first element */ if (lua_isstring(L, -1)) { /* is it the name of initial rule? */ lua_pushvalue(L, -1); /* duplicate it to use as key */ lua_gettable(L, arg); /* get associated rule */ } else { lua_pushinteger(L, 1); /* key for initial rule */ lua_insert(L, -2); /* put it before rule */ } if (!testpattern(L, -1)) { /* initial rule not a pattern? */ if (lua_isnil(L, -1)) luaL_error(L, "grammar has no initial rule"); else luaL_error(L, "initial rule '%s' is not a pattern", lua_tostring(L, -2)); } lua_pushvalue(L, -2); /* push key */ lua_pushinteger(L, 1); /* push rule position (after TGrammar) */ lua_settable(L, postab); /* insert pair at position table */ } /* ** traverse grammar at index 'arg', pushing all its keys and patterns ** into the stack. Create a new table (before all pairs key-pattern) to ** collect all keys and their associated positions in the final tree ** (the "position table"). ** Return the number of rules and (in 'totalsize') the total size ** for the new tree. */ static int collectrules (lua_State *L, int arg, int *totalsize) { int n = 1; /* to count number of rules */ int postab = lua_gettop(L) + 1; /* index of position table */ int size; /* accumulator for total size */ lua_newtable(L); /* create position table */ getfirstrule(L, arg, postab); size = 2 + getsize(L, postab + 2); /* TGrammar + TRule + rule */ lua_pushnil(L); /* prepare to traverse grammar table */ while (lua_next(L, arg) != 0) { if (lua_tonumber(L, -2) == 1 || lp_equal(L, -2, postab + 1)) { /* initial rule? */ lua_pop(L, 1); /* remove value (keep key for lua_next) */ continue; } if (!testpattern(L, -1)) /* value is not a pattern? */ luaL_error(L, "rule '%s' is not a pattern", val2str(L, -2)); luaL_checkstack(L, LUA_MINSTACK, "grammar has too many rules"); lua_pushvalue(L, -2); /* push key (to insert into position table) */ lua_pushinteger(L, size); lua_settable(L, postab); size += 1 + getsize(L, -1); /* update size */ lua_pushvalue(L, -2); /* push key (for next lua_next) */ n++; } *totalsize = size + 1; /* TTrue to finish list of rules */ return n; } static void buildgrammar (lua_State *L, TTree *grammar, int frule, int n) { int i; TTree *nd = sib1(grammar); /* auxiliary pointer to traverse the tree */ for (i = 0; i < n; i++) { /* add each rule into new tree */ int ridx = frule + 2*i + 1; /* index of i-th rule */ int rulesize; TTree *rn = gettree(L, ridx, &rulesize); nd->tag = TRule; nd->key = 0; nd->cap = i; /* rule number */ nd->u.ps = rulesize + 1; /* point to next rule */ memcpy(sib1(nd), rn, rulesize * sizeof(TTree)); /* copy rule */ mergektable(L, ridx, sib1(nd)); /* merge its ktable into new one */ nd = sib2(nd); /* move to next rule */ } nd->tag = TTrue; /* finish list of rules */ } /* ** Check whether a tree has potential infinite loops */ static int checkloops (TTree *tree) { tailcall: if (tree->tag == TRep && nullable(sib1(tree))) return 1; else if (tree->tag == TGrammar) return 0; /* sub-grammars already checked */ else { switch (numsiblings[tree->tag]) { case 1: /* return checkloops(sib1(tree)); */ tree = sib1(tree); goto tailcall; case 2: if (checkloops(sib1(tree))) return 1; /* else return checkloops(sib2(tree)); */ tree = sib2(tree); goto tailcall; default: assert(numsiblings[tree->tag] == 0); return 0; } } } static int verifyerror (lua_State *L, int *passed, int npassed) { int i, j; for (i = npassed - 1; i >= 0; i--) { /* search for a repetition */ for (j = i - 1; j >= 0; j--) { if (passed[i] == passed[j]) { lua_rawgeti(L, -1, passed[i]); /* get rule's key */ return luaL_error(L, "rule '%s' may be left recursive", val2str(L, -1)); } } } return luaL_error(L, "too many left calls in grammar"); } /* ** Check whether a rule can be left recursive; raise an error in that ** case; otherwise return 1 iff pattern is nullable. ** The return value is used to check sequences, where the second pattern ** is only relevant if the first is nullable. ** Parameter 'nb' works as an accumulator, to allow tail calls in ** choices. ('nb' true makes function returns true.) ** Assume ktable at the top of the stack. */ static int verifyrule (lua_State *L, TTree *tree, int *passed, int npassed, int nb) { tailcall: switch (tree->tag) { case TChar: case TSet: case TAny: case TFalse: return nb; /* cannot pass from here */ case TTrue: case TBehind: /* look-behind cannot have calls */ return 1; case TNot: case TAnd: case TRep: /* return verifyrule(L, sib1(tree), passed, npassed, 1); */ tree = sib1(tree); nb = 1; goto tailcall; case TCapture: case TRunTime: /* return verifyrule(L, sib1(tree), passed, npassed, nb); */ tree = sib1(tree); goto tailcall; case TCall: /* return verifyrule(L, sib2(tree), passed, npassed, nb); */ tree = sib2(tree); goto tailcall; case TSeq: /* only check 2nd child if first is nb */ if (!verifyrule(L, sib1(tree), passed, npassed, 0)) return nb; /* else return verifyrule(L, sib2(tree), passed, npassed, nb); */ tree = sib2(tree); goto tailcall; case TChoice: /* must check both children */ nb = verifyrule(L, sib1(tree), passed, npassed, nb); /* return verifyrule(L, sib2(tree), passed, npassed, nb); */ tree = sib2(tree); goto tailcall; case TRule: if (npassed >= MAXRULES) return verifyerror(L, passed, npassed); else { passed[npassed++] = tree->key; /* return verifyrule(L, sib1(tree), passed, npassed); */ tree = sib1(tree); goto tailcall; } case TGrammar: return nullable(tree); /* sub-grammar cannot be left recursive */ default: assert(0); return 0; } } static void verifygrammar (lua_State *L, TTree *grammar) { int passed[MAXRULES]; TTree *rule; /* check left-recursive rules */ for (rule = sib1(grammar); rule->tag == TRule; rule = sib2(rule)) { if (rule->key == 0) continue; /* unused rule */ verifyrule(L, sib1(rule), passed, 0, 0); } assert(rule->tag == TTrue); /* check infinite loops inside rules */ for (rule = sib1(grammar); rule->tag == TRule; rule = sib2(rule)) { if (rule->key == 0) continue; /* unused rule */ if (checkloops(sib1(rule))) { lua_rawgeti(L, -1, rule->key); /* get rule's key */ luaL_error(L, "empty loop in rule '%s'", val2str(L, -1)); } } assert(rule->tag == TTrue); } /* ** Give a name for the initial rule if it is not referenced */ static void initialrulename (lua_State *L, TTree *grammar, int frule) { if (sib1(grammar)->key == 0) { /* initial rule is not referenced? */ int n = lua_rawlen(L, -1) + 1; /* index for name */ lua_pushvalue(L, frule); /* rule's name */ lua_rawseti(L, -2, n); /* ktable was on the top of the stack */ sib1(grammar)->key = n; } } static TTree *newgrammar (lua_State *L, int arg) { int treesize; int frule = lua_gettop(L) + 2; /* position of first rule's key */ int n = collectrules(L, arg, &treesize); TTree *g = newtree(L, treesize); luaL_argcheck(L, n <= MAXRULES, arg, "grammar has too many rules"); g->tag = TGrammar; g->u.n = n; lua_newtable(L); /* create 'ktable' */ lua_setuservalue(L, -2); buildgrammar(L, g, frule, n); lua_getuservalue(L, -1); /* get 'ktable' for new tree */ finalfix(L, frule - 1, g, sib1(g)); initialrulename(L, g, frule); verifygrammar(L, g); lua_pop(L, 1); /* remove 'ktable' */ lua_insert(L, -(n * 2 + 2)); /* move new table to proper position */ lua_pop(L, n * 2 + 1); /* remove position table + rule pairs */ return g; /* new table at the top of the stack */ } /* }====================================================== */ static Instruction *prepcompile (lua_State *L, Pattern *p, int idx) { lua_getuservalue(L, idx); /* push 'ktable' (may be used by 'finalfix') */ finalfix(L, 0, NULL, p->tree); lua_pop(L, 1); /* remove 'ktable' */ return compile(L, p); } static int lp_printtree (lua_State *L) { TTree *tree = getpatt(L, 1, NULL); int c = lua_toboolean(L, 2); if (c) { lua_getuservalue(L, 1); /* push 'ktable' (may be used by 'finalfix') */ finalfix(L, 0, NULL, tree); lua_pop(L, 1); /* remove 'ktable' */ } printktable(L, 1); printtree(tree, 0); return 0; } static int lp_printcode (lua_State *L) { Pattern *p = getpattern(L, 1); printktable(L, 1); if (p->code == NULL) /* not compiled yet? */ prepcompile(L, p, 1); printpatt(p->code, p->codesize); return 0; } /* ** Get the initial position for the match, interpreting negative ** values from the end of the subject */ static size_t initposition (lua_State *L, size_t len) { lua_Integer ii = luaL_optinteger(L, 3, 1); if (ii > 0) { /* positive index? */ if ((size_t)ii <= len) /* inside the string? */ return (size_t)ii - 1; /* return it (corrected to 0-base) */ else return len; /* crop at the end */ } else { /* negative index */ if ((size_t)(-ii) <= len) /* inside the string? */ return len - ((size_t)(-ii)); /* return position from the end */ else return 0; /* crop at the beginning */ } } /* ** Main match function */ static int lp_match (lua_State *L) { Capture capture[INITCAPSIZE]; const char *r; size_t l; const char *s; Pattern *p = (getpatt(L, 1, NULL), getpattern(L, 1)); Instruction *code = (p->code != NULL) ? p->code : prepcompile(L, p, 1); if (lua_type (L, SUBJIDX) == LUA_TSTRING) { s = luaL_checklstring (L, SUBJIDX, &l); } else if (lua_type (L, SUBJIDX) == LUA_TUSERDATA) { struct rspamd_lua_text *t = lua_check_text (L, SUBJIDX); if (!t) { return luaL_error (L, "invalid argument (not a text)"); } s = t->start; l = t->len; if (s == NULL) { lua_pushnil(L); return 1; } } else { return luaL_error (L, "invalid argument: %s", lua_typename (L, lua_type (L, SUBJIDX))); } size_t i = initposition(L, l); int ptop = lua_gettop(L), rs; lua_pushnil(L); /* initialize subscache */ lua_pushlightuserdata(L, capture); /* initialize caplistidx */ lua_getuservalue(L, 1); /* initialize penvidx */ r = match(L, s, s + i, s + l, code, capture, ptop); if (r == NULL) { lua_pushnil(L); return 1; } rs = getcaptures(L, s, r, ptop); return rs; } /* ** {====================================================== ** Library creation and functions not related to matching ** ======================================================= */ /* maximum limit for stack size */ #define MAXLIM (INT_MAX / 100) static int lp_setmax (lua_State *L) { lua_Integer lim = luaL_checkinteger(L, 1); luaL_argcheck(L, 0 < lim && lim <= MAXLIM, 1, "out of range"); lua_settop(L, 1); lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); return 0; } static int lp_version (lua_State *L) { lua_pushstring(L, VERSION); return 1; } static int lp_type (lua_State *L) { if (testpattern(L, 1)) lua_pushliteral(L, "pattern"); else lua_pushnil(L); return 1; } int lp_gc (lua_State *L) { Pattern *p = getpattern(L, 1); realloccode(L, p, 0); /* delete code block */ return 0; } static void createcat (lua_State *L, const char *catname, int (catf) (int)) { TTree *t = newcharset(L); int i; for (i = 0; i <= UCHAR_MAX; i++) if (catf(i)) setchar(treebuffer(t), i); lua_setfield(L, -2, catname); } static int lp_locale (lua_State *L) { if (lua_isnoneornil(L, 1)) { lua_settop(L, 0); lua_createtable(L, 0, 12); } else { luaL_checktype(L, 1, LUA_TTABLE); lua_settop(L, 1); } createcat(L, "alnum", isalnum); createcat(L, "alpha", isalpha); createcat(L, "cntrl", iscntrl); createcat(L, "digit", isdigit); createcat(L, "graph", isgraph); createcat(L, "lower", islower); createcat(L, "print", isprint); createcat(L, "punct", ispunct); createcat(L, "space", isspace); createcat(L, "upper", isupper); createcat(L, "xdigit", isxdigit); return 1; } static struct luaL_Reg pattreg[] = { {"ptree", lp_printtree}, {"pcode", lp_printcode}, {"match", lp_match}, {"B", lp_behind}, {"V", lp_V}, {"C", lp_simplecapture}, {"Cc", lp_constcapture}, {"Cmt", lp_matchtime}, {"Cb", lp_backref}, {"Carg", lp_argcapture}, {"Cp", lp_poscapture}, {"Cs", lp_substcapture}, {"Ct", lp_tablecapture}, {"Cf", lp_foldcapture}, {"Cg", lp_groupcapture}, {"P", lp_P}, {"S", lp_set}, {"R", lp_range}, {"locale", lp_locale}, {"version", lp_version}, {"setmaxstack", lp_setmax}, {"type", lp_type}, {NULL, NULL} }; static struct luaL_Reg metareg[] = { {"__mul", lp_seq}, {"__add", lp_choice}, {"__pow", lp_star}, {"__gc", lp_gc}, {"__len", lp_and}, {"__div", lp_divcapture}, {"__unm", lp_not}, {"__sub", lp_sub}, {NULL, NULL} }; int luaopen_lpeg (lua_State *L) { luaL_newmetatable(L, PATTERN_T); lua_pushnumber(L, MAXBACK); /* initialize maximum backtracking */ lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); luaL_setfuncs(L, metareg, 0); luaL_newlib(L, pattreg); lua_pushvalue(L, -1); lua_setfield(L, -3, "__index"); return 1; } /* }====================================================== */