diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-11-08 11:43:42 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-11-08 11:43:42 -0300 |
| commit | e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa (patch) | |
| tree | 090174ab9a66fbec195e9dd539710ab19370ec2f /lcode.c | |
| parent | f791bb69061c15f73395c5a95958ac18af5ef764 (diff) | |
| download | lua-e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa.tar.gz lua-e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa.tar.bz2 lua-e44f3a2ffc7ced5e75cca7657aaa60ef27da89aa.zip | |
Global initialization checks name conflict
Initialization "global a = 10" raises an error if global 'a' is already
defined, that is, it has a non-nil value.
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 16 |
1 files changed, 16 insertions, 0 deletions
| @@ -706,6 +706,22 @@ static void luaK_float (FuncState *fs, int reg, lua_Number f) { | |||
| 706 | 706 | ||
| 707 | 707 | ||
| 708 | /* | 708 | /* |
| 709 | ** Get the value of 'var' in a register and generate an opcode to check | ||
| 710 | ** whether that register is nil. 'k' is the index of the variable name | ||
| 711 | ** in the list of constants. If its value cannot be encoded in Bx, a 0 | ||
| 712 | ** will use '?' for the name. | ||
| 713 | */ | ||
| 714 | void luaK_codecheckglobal (FuncState *fs, expdesc *var, int k, int line) { | ||
| 715 | luaK_exp2anyreg(fs, var); | ||
| 716 | luaK_fixline(fs, line); | ||
| 717 | k = (k >= MAXARG_Bx) ? 0 : k + 1; | ||
| 718 | luaK_codeABx(fs, OP_ERRNNIL, var->u.info, k); | ||
| 719 | luaK_fixline(fs, line); | ||
| 720 | freeexp(fs, var); | ||
| 721 | } | ||
| 722 | |||
| 723 | |||
| 724 | /* | ||
| 709 | ** Convert a constant in 'v' into an expression description 'e' | 725 | ** Convert a constant in 'v' into an expression description 'e' |
| 710 | */ | 726 | */ |
| 711 | static void const2exp (TValue *v, expdesc *e) { | 727 | static void const2exp (TValue *v, expdesc *e) { |
