Forums » Suggestions

Lua - Allow dofile() to pass variables into a file

Dec 08, 2022 draugath link
I would like the ability to use dofile() to pass variables into a file when it's loaded.
For a longtime it's been common practice to just use a global table to share all plugin relevant data. However, once in a while it's nice to be able to share functions or tables or other values with other files without them being made public.

I've been able to accomplish the same with loadfile(), but this is a rather clunky way to approach the issue.

Since loadfile() creates a function out of the file, variables can be passed into the file directly and assigned to file local variables with a "local var1, var2 = ...".

If this same functionality were available with dofile() it would be a lot simpler.