For what it's worth, here's how I do putenv() on Windows:
int
lputenv(lua_State *L)
{
int n = lua_gettop(L); /* number of arguments */
if (n != 1) {
lua_pushstring(L, "wrong number of arguments to function `putenv'");
lua_error(L);
} else {
if (_putenv(lua_tostring(L, 1)) != 0) {
lua_pushstring(L, "calling function `putenv' failed");
lua_error(L);
}
}
return 0;
}
And then add
lua_register(L, "putenv", lputenv);
after creating your Lua state and before invoking your Lua program.
And use it like
putenv "env_var=value"