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
> of what you mean.

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

module = import ("module.lua")

foreach (module , print)

local modname = "mod1"

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

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?