MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / check_readonly

Function check_readonly

extlibs/lua/src/lparser.c:270–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

restassignFunction · 0.85

Calls 3

getlocalvardescFunction · 0.85
luaO_pushfstringFunction · 0.85
luaK_semerrorFunction · 0.85

Tested by

no test coverage detected