Hide shell functions from _G using upvalues on the main chunk

Store __command, __interactive, __getenv, __setenv as upvalues
populated by lua_load() from the registry, keeping them invisible
to user code while accessible to the parser's codegen.
This commit is contained in:
Cormac Shannon
2026-03-12 22:46:56 +00:00
parent 34bfabccbd
commit f88b17959f
8 changed files with 134 additions and 77 deletions

View File

@@ -155,5 +155,9 @@ void luaopen_builtins (lua_State *L) {
lua_setfield(L, -2, "exec");
lua_pushcfunction(L, builtin_umask);
lua_setfield(L, -2, "umask");
lua_setglobal(L, "__builtins");
/* Store as __lush.builtins in registry */
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_LUSH);
lua_insert(L, -2);
lua_setfield(L, -2, "builtins");
lua_pop(L, 1);
}