aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-11-08 11:43:42 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-11-08 11:43:42 -0300
commite44f3a2ffc7ced5e75cca7657aaa60ef27da89aa (patch)
tree090174ab9a66fbec195e9dd539710ab19370ec2f /lcode.c
parentf791bb69061c15f73395c5a95958ac18af5ef764 (diff)
downloadlua-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.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lcode.c b/lcode.c
index f09edb5f..d82f8263 100644
--- a/lcode.c
+++ b/lcode.c
@@ -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*/
714void 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*/
711static void const2exp (TValue *v, expdesc *e) { 727static void const2exp (TValue *v, expdesc *e) {