Created
November 19, 2018 15:43
-
-
Save felipetavares/6e9a637beae94fe58826b53f93d6ec26 to your computer and use it in GitHub Desktop.
+= extension for Lua 5.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { | |
expdesc e; | |
check_condition(ls, vkisvar(lh->v.k), "syntax error"); | |
if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */ | |
struct LHS_assign nv; | |
nv.prev = lh; | |
suffixedexp(ls, &nv.v); | |
if (!vkisindexed(nv.v.k)) | |
check_conflict(ls, lh, &nv.v); | |
checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS, | |
"C levels"); | |
assignment(ls, &nv, nvars+1); | |
} | |
// Language extension begins here | |
// This is a extra token which matches '+=' | |
else if (testnext(ls, TK_PLUSEQ)) { | |
// Get the expression | |
expr(ls, &e); | |
// Get the value | |
expdesc infix = lh->v; | |
// Sum | |
luaK_infix(ls->fs, OPR_ADD, &infix); | |
luaK_posfix(ls->fs, OPR_ADD, &infix, &e, ls->linenumber); | |
// Store the result in the variable itself | |
luaK_storevar(ls->fs, &lh->v, &infix); | |
return; /* avoid default */ | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works for the simple case
x += 1
andx.y += 1
but not for:which fails with:
attempt to index a number value
.