|
Study the load() API. The basic thing to understand is that when load() handles a “chunk” it always treats it as though it were a function. So in your examples Lua effectively wraps the code in “function(…) <your code> end” before compiling it. What this means, is that when you load one of your files, what you get back from load() is a function (just like any other). When you then *execute* that function, it does whatever was in your file, which in the case of fileopen.lua will do a assignment to the global “table3”. For example: f = load(…..) f() print(table3.Value1) In fact, you can avoid having to declare the global names in the Lua files by changing the assignment to a return statement: return { Value1 = 1 … } Then, when you execute the compiled function, it will just return the table to your code, like this: f = load(….) table3 = f() print(table3.Value1) As others have noted, be careful when loading external files; if you don’t have control over the file contents, using load() can inject malicious code into your script. HTH —Tim |