This code was extracted from the old POSIX binding.
static int Pgetenv(lua_State *L) { if (lua_isnone(L, 1)) { extern char **environ; char **e; if (*environ==NULL) lua_pushnil(L); else lua_newtable(L); for (e=environ; *e!=NULL; e++) { char *s=*e; char *eq=strchr(s, '='); if (eq==NULL) { lua_pushstring(L,s); lua_pushboolean(L,0); } else { lua_pushlstring(L,s,eq-s); lua_pushstring(L,eq+1); } lua_settable(L,-3); } } else lua_pushstring(L, getenv(luaL_checkstring(L, 1))); return 1; }
lhf
source share