$MYVIMRC
is an environment variable that Vim adds to the current environment.
Environment variables are usually inherited by child processes from their parent process. For example, you can see $MYVIMRC
in a shell that is a child process of Vim:
:!printenv | grep MYVIMRC
(I use this form rather than just :!echo "$MYVIMRC"
to "prove" that the value is not inserted before the command is sent to the shell.)
I don't use lua in Vim but I know you can examine environment variables with os.getenv()
so, for instance, this will print the expected value:
:lua print(os.getenv("MYVIMRC"))
In other words, you don't need any special Vim API to get the value.