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

14
lcmd.h
View File

@@ -9,7 +9,17 @@
#include "lua.h"
int luaB_command (lua_State *L);
int luaB_interactive (lua_State *L);
/* Upvalue indices for shell functions on the main chunk.
** Index 0 is _ENV (standard). Indices 1-4 are lush shell functions. */
#define LUSH_UPVAL_COMMAND 1
#define LUSH_UPVAL_INTERACTIVE 2
#define LUSH_UPVAL_GETENV 3
#define LUSH_UPVAL_SETENV 4
#define LUSH_NUM_UPVALS 5 /* total: _ENV(0) + 4 shell functions */
int lushCmd_command (lua_State *L);
int lushCmd_interactive (lua_State *L);
int lushCmd_getenv (lua_State *L);
int lushCmd_setenv (lua_State *L);
#endif