aboutsummaryrefslogtreecommitdiff
path: root/ldebug.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 /ldebug.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 'ldebug.c')
-rw-r--r--ldebug.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ldebug.c b/ldebug.c
index 9110f437..abead91c 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -814,6 +814,14 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
814} 814}
815 815
816 816
817l_noret luaG_errnnil (lua_State *L, LClosure *cl, int k) {
818 const char *globalname = "?"; /* default name if k == 0 */
819 if (k > 0)
820 kname(cl->p, k - 1, &globalname);
821 luaG_runerror(L, "global '%s' already defined", globalname);
822}
823
824
817/* add src:line information to 'msg' */ 825/* add src:line information to 'msg' */
818const char *luaG_addinfo (lua_State *L, const char *msg, TString *src, 826const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
819 int line) { 827 int line) {