lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 02/08/2007, at 5:48 PM, Tom Miles wrote:

code from environment 1:

utils = require "Utilities"

utils.g_var = 1
print(utils.g_var)

-----------------------------------------------------

code from environment 2:

utils = require "Utilities"

print(utils.g_var)

In the lua code example given, env 1 and env 2 would both inherit a common host environment, which itself is a child of the main state. i.e.

main->host->env 1
                     ->env 2


OK, here is another guess. :)

env1 and env2 both have their own states with a metatable entry for __index for Lua globals. However under that setup "utils" is a local variable to both env1 and env2. That is, they both have their own "utils" variable. Thus you are not sharing "utils", and an attempt to print(utils.g_var) will not reference the other "utils".

What *may* work is to do this at the global state (that is, not in a sub-environment):

utils = require "Utilities"

This establishes utils at global scope.

- Nick