[Oddity] _G in package.loaded

17 views
Skip to first unread message

Martin Eden

unread,
9:34 AM (11 hours ago) 9:34 AM
to lu...@googlegroups.com
Hello list,

While working on my deploy generator I discovered that
"_G" is present in "package.loaded":

  $ lua
  Lua 5.5.0  Copyright (C) 1994-2025 Lua.org, PUC-Rio
  > package.loaded._G
  table: 0x55fb5ddbcbc0

I expect this table be name map for modules loaded via require().
(And no, I have no "require('_G')" in my code.)

Any ideas why it's so?

-- Martin

Luiz Henrique de Figueiredo

unread,
9:42 AM (11 hours ago) 9:42 AM
to lu...@googlegroups.com
> "_G" is present in "package.loaded":
> Any ideas why it's so?

https://www.lua.org/source/5.5/linit.c.html
https://www.lua.org/source/5.5/lauxlib.h.html#LUA_GNAME

Martin Eden

unread,
10:06 AM (10 hours ago) 10:06 AM
to lu...@googlegroups.com
Yeah but my "why" was aimed for different plane.

-- Martin

ppp vvv

unread,
10:39 AM (10 hours ago) 10:39 AM
to lua-l
> And no, I have no "require('_G')" in my code
you do have luaL_openlibs before your code.

string library is loaded into table called  'string'  -> package.loaded.string
os library is loaded into table called  'os' -> package.loaded.os
base library loaded directly into _G table


пятница, 12 июня 2026 г. в 16:06:39 UTC+2, Martin Eden:
Reply all
Reply to author
Forward
0 new messages