MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / check_readonly

Function check_readonly

third-party/lua-5.5.0/src/lparser.c:286–322  ·  view source on GitHub ↗

** Raises an error if variable described by 'e' is read only; moreover, ** if 'e' is t[exp] where t is the vararg parameter, change it to index ** a real table. (Virtual vararg tables cannot be changed.) */

Source from the content-addressed store, hash-verified

284** a real table. (Virtual vararg tables cannot be changed.)
285*/
286static void check_readonly (LexState *ls, expdesc *e) {
287 FuncState *fs = ls->fs;
288 TString *varname = NULL; /* to be set if variable is const */
289 switch (e->k) {
290 case VCONST: {
291 varname = ls->dyd->actvar.arr[e->u.info].vd.name;
292 break;
293 }
294 case VLOCAL: case VVARGVAR: {
295 Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx);
296 if (vardesc->vd.kind != VDKREG) /* not a regular variable? */
297 varname = vardesc->vd.name;
298 break;
299 }
300 case VUPVAL: {
301 Upvaldesc *up = &fs->f->upvalues[e->u.info];
302 if (up->kind != VDKREG)
303 varname = up->name;
304 break;
305 }
306 case VVARGIND: {
307 needvatab(fs->f); /* function will need a vararg table */
308 e->k = VINDEXED;
309 } /* FALLTHROUGH */
310 case VINDEXUP: case VINDEXSTR: case VINDEXED: { /* global variable */
311 if (e->u.ind.ro) /* read-only? */
312 varname = tsvalue(&fs->f->k[e->u.ind.keystr]);
313 break;
314 }
315 default:
316 lua_assert(e->k == VINDEXI); /* this one doesn't need any check */
317 return; /* integer index cannot be read-only */
318 }
319 if (varname)
320 luaK_semerror(ls, "attempt to assign to const variable '%s'",
321 getstr(varname));
322}
323
324
325/*

Callers 2

restassignFunction · 0.70
funcstatFunction · 0.70

Calls 2

getlocalvardescFunction · 0.70
luaK_semerrorFunction · 0.70

Tested by

no test coverage detected