lua-users home
lua-l archive

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


> You do get an error message. See below. Perhaps you could post a small
sample
> of what you mean.

test.lua
-------
function import (filename)
 local newenv = {}
 local oldenv = globals ()
 local oldtm = gettagmethod (tag (nil) , 'getglobal')
 settagmethod (tag (nil) , 'getglobal' , function (varname)
  return %oldenv[varname]
 end)
 globals (newenv)
 dofile (filename)
 globals (oldenv)
 settagmethod (tag (nil) , 'getglobal' , oldtm)
 return newenv
end

module = import ("module.lua")

foreach (module , print)

module.lua
-----------
local modname = "mod1"

function report ()
 print ("report in the module")
 print (modname)
end

When you run test.lua with module written this way, the function report
isn't printed. I presume this is because it's not stored in the globals
table. If, however, you make modname be a global, or change the line in
report () to read "print (%modname)" then report becomes a global.

Perhaps I'm just doing something wacky?