MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / check_readonly

Function check_readonly

lib/lua/src/lparser.c:277–305  ·  view source on GitHub ↗

** Raises an error if variable described by 'e' is read only */

Source from the content-addressed store, hash-verified

275** Raises an error if variable described by 'e' is read only
276*/
277static void check_readonly (LexState *ls, expdesc *e) {
278 FuncState *fs = ls->fs;
279 TString *varname = NULL; /* to be set if variable is const */
280 switch (e->k) {
281 case VCONST: {
282 varname = ls->dyd->actvar.arr[e->u.info].vd.name;
283 break;
284 }
285 case VLOCAL: {
286 Vardesc *vardesc = getlocalvardesc(fs, e->u.var.vidx);
287 if (vardesc->vd.kind != VDKREG) /* not a regular variable? */
288 varname = vardesc->vd.name;
289 break;
290 }
291 case VUPVAL: {
292 Upvaldesc *up = &fs->f->upvalues[e->u.info];
293 if (up->kind != VDKREG)
294 varname = up->name;
295 break;
296 }
297 default:
298 return; /* other cases cannot be read-only */
299 }
300 if (varname) {
301 const char *msg = luaO_pushfstring(ls->L,
302 "attempt to assign to const variable '%s'", getstr(varname));
303 luaK_semerror(ls, msg); /* error */
304 }
305}
306
307
308/*

Callers 2

restassignFunction · 0.85
funcstatFunction · 0.85

Calls 3

getlocalvardescFunction · 0.85
luaO_pushfstringFunction · 0.85
luaK_semerrorFunction · 0.85

Tested by

no test coverage detected