lua-users home
lua-l archive

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


I'm running into some issue with module() and / or environments. The
attached file is a dump of the package
table, just before an error gets thrown: "attempt to index global
'widgetops' (a nil value)".

All the standard libs (Lua libs, bit, jit, etc.) look like they
install correctly, on startup.

I first put a wrapper around module(), so I can debug without messing
with package.seeall or caching functions:

		local _G = _G
		local getfenv = getfenv
		local getmetatable = getmetatable
		local loaded = package.loaded
		local setfenv = setfenv
		local setmetatable = setmetatable
		local type = type

		-- Extend the module function.
		local old_module = module
		local imports = { gprintf_temp_at = true, messagef = true, printf =
true, vardump = true }

		function module (name, ...)
			old_module(name, ...)

			local mtable = loaded[name]
			local meta = getmetatable(mtable) or {}
			local index = meta.__index
			local itype = type(index)

			function meta.__index (t, k)
				if imports[k] then
					return _G[k]
				elseif itype == "function" then
					return index(t, k)
				elseif itype == "table" then
					return index[k]
				end
			end

			setmetatable(mtable, meta)
			setfenv(2, getfenv())
		end

This seems to work fine in LJ1 and stock Lua. If I skip this step the
error I'm describing here doesn't
seem to happen, but I then run into something else. :(

Next I start loading module files. I use module() but instead of
require() just loadfile() these files in order
and read the globals they emit. It may be relevant that my loader
setfenv()'s each chunk with a table I
provide, which is _G in all pre-error cases.

I first load up some base Lua modules: coroutine_ex, coroutineops,
varops, and a few more. These all
look okay.

I then load up some C++ modules via luaL_register(), and this seems
fine, as evidenced by math_ex.

At this point I go back Lua-side and something odd happens: effect,
graphicshelpers, list, etc. and finally
the offending widgetops are loaded. These do not look okay: each one
inserts itself into the previous table,
as seen about a third of the way down the file.

Their functions, on the other hand, inject themselves into _G (this is
most of the stuff from the
beginning of the file up to the "_G = CYCLE..." part).

So the roles seem to get reversed.

Any ideas? What seems most odd to me is the change from before to
after the luaL_register()...
table: {
   config = "\
;
?
!
-"
   cpath = ".\?.dll;c:\Repositories\Icebreakers\game\release\?.dll;c:\Repositories\Icebreakers\game\release\loadall.dll"
   loaded = {
      _G = {
         AddAfter = function: 0x031084fc
         AnimTexture = function: 0x0311573c
         Append = function: 0x0300159c
         AttachToRoot = function: 0x0301783c
         AugmentSignal = function: 0x0310c97c
         Back = function: 0x0300b3bc
         BackToFrontIter = function: 0x0301435c
         BoxInBox = function: 0x03000bfc
         BoxIntersection = function: 0x03100d3c
         BoxesIntersect = function: 0x03000b9c
         ButtonStyleRender = function: 0x030178bc
         Choose = function: 0x03101fbc
         ChooseMulti = function: 0x0310577c
         ClampIn = function: 0x03100dbc
         Clear = function: 0x030167dc
         DefineOwnedWidget = function: 0x0310cc7c
         Diagnostics = function: 0x0300007c
         DrawString = function: 0x03017b1c
         FrontToBackIter = function: 0x0301147c
         GetSize = function: 0x0300b4bc
         GetSortedKeys = function: 0x03107f3c
         GetSortedKeys_ = function: 0x03107f3c
         GetStringOps = function: 0x0310d1bc
         InRange = function: 0x03015d3c
         Insert = function: 0x030167fc
         IsEmpty = function: 0x0301683c
         LatticeUV = function: 0x031151fc
         ListenToTasks = function: 0x0301799c
         Load = function: 0x031007bc
         Messager = userdata: 0x030136b4
         MultiPicture = function: 0x031157bc
         NamedListSorter = function: 0x030162bc
         Next = function: 0x0300b49c
         Picture = function: 0x030152fc
         PointInBox = function: 0x03000edc
         Prev = function: 0x0301417c
         PurgeAttachList = function: 0x030179dc
         RangeOverlap = function: 0x03000efc
         Rect = function: 0x03000afc
         Remove = function: 0x031088bc
         RemoveFrom = function: 0x03112f7c
         Root = function: 0x0301685c
         RotateIndex = function: 0x03015cfc
         RotateIndexInRange = function: 0x03015d1c
         SetLocalRect = function: 0x030179fc
         SortPairs = function: 0x03015d5c
         StateSwitch = function: 0x03017a1c
         StringGetH = function: 0x03017b9c
         StringGetW = function: 0x03017c5c
         StringSize = function: 0x03017bfc
         SwapIf = function: 0x03015d7c
         Texture = function: 0x0301531c
         Trapezoid = function: 0x03015d9c
         XOR = function: 0x03015dbc
         _G = CYCLE, table: 0x02070ea0
         _VERSION = "Lua 5.1"
         assert = function: fast#2
         bUsingJIT = true
         bit = {
            arshift = function: fast#70
            band = function: fast#73
            bnot = function: fast#66
            bor = function: fast#74
            bswap = function: fast#67
            bxor = function: fast#75
            lshift = function: fast#68
            rol = function: fast#71
            ror = function: fast#72
            rshift = function: fast#69
            tobit = function: fast#65
            tohex = function: fast#76
         } (table: 0x020759d8)
         class = {
            Define = function: 0x03188efc
            Exists = function: 0x0300897c
            GetMember = function: 0x0300899c
            Hidden = {
            } (table: 0x03106a3c)
            IsInstance = function: 0x030089bc
            IsType = function: 0x03106fbc
            Linearization = function: 0x03106ffc
            New = function: 0x0310713c
            NewArray = function: 0x0310717c
            SuperCons = function: 0x0310707c
            Supers = function: 0x031071bc
            Type = function: 0x031071fc
            _M = CYCLE, table: 0x03106bbc
            _NAME = "class"
            _PACKAGE = ""
         } (table: 0x03106bbc)
         collectgarbage = function: fast#27
         coroutine = {
            create = function: fast#32
            resume = function: fast#34
            running = function: fast#31
            status = function: fast#30
            wrap = function: fast#36
            yield = function: fast#33
         } (table: 0x020729e0)
         coroutine_ex = {
            Create = function: 0x031860fc
            Reset = function: 0x031047fc
            _M = CYCLE, table: 0x031045fc
            _NAME = "coroutine_ex"
            _PACKAGE = ""
         } (table: 0x031045fc)
         coroutineops = {
            Wait = function: 0x030073bc
            WaitForMultipleSignals = function: 0x031056bc
            WaitForSignal = function: 0x0300745c
            WaitUntil = function: 0x0300747c
            WaitUntil_Method = function: 0x0300749c
            WaitWhile = function: 0x030074bc
            WaitWhile_Method = function: 0x030074dc
            _M = CYCLE, table: 0x0310557c
            _NAME = "coroutineops"
            _PACKAGE = ""
         } (table: 0x0310557c)
         debug = {
            debug = function: fast#144
            getfenv = function: fast#135
            gethook = function: fast#143
            getinfo = function: fast#137
            getlocal = function: fast#138
            getmetatable = function: fast#133
            getregistry = function: fast#132
            getupvalue = function: fast#140
            setfenv = function: fast#136
            sethook = function: fast#142
            setlocal = function: fast#139
            setmetatable = function: fast#134
            setupvalue = function: fast#141
            traceback = function: fast#145
         } (table: 0x02075510)
         dofile = function: fast#25
         effect = {
            _M = CYCLE, table: 0x03114dbc
            _NAME = "effect"
            _PACKAGE = ""
            graphicshelpers = {
               _M = CYCLE, table: 0x0311563c
               _NAME = "graphicshelpers"
               _PACKAGE = ""
               list = {
                  _M = CYCLE, table: 0x031027bc
                  _NAME = "list"
                  _PACKAGE = ""
                  nondeterminism_ops = {
                     _M = CYCLE, table: 0x03109c3c
                     _NAME = "nondeterminism_ops"
                     _PACKAGE = ""
                     numericops = {
                        _M = CYCLE, table: 0x031007fc
                        _NAME = "numericops"
                        _PACKAGE = ""
                        opbuilders = {
                           _M = CYCLE, table: 0x03107a7c
                           _NAME = "opbuilders"
                           _PACKAGE = ""
                           skewheap = {
                              _M = CYCLE, table: 0x0310867c
                              _NAME = "skewheap"
                              _PACKAGE = ""
                              widgetops = {
                                 _M = CYCLE, table: 0x0310c5bc
                                 _NAME = "widgetops"
                                 _PACKAGE = ""
                              } (table: 0x0310c5bc)
                           } (table: 0x0310867c)
                        } (table: 0x03107a7c)
                     } (table: 0x031007fc)
                  } (table: 0x03109c3c)
               } (table: 0x031027bc)
            } (table: 0x0311563c)
         } (table: 0x03114dbc)
         error = function: fast#19
         funcops = {
            Call = function: 0x030041bc
            CallMethod = function: 0x030041dc
            CallOrGet = function: 0x030041fc
            GetLastTraceback = function: 0x0300447c
            GetTimeLapseFunc = function: 0x0300443c
            Identity = function: 0x0300423c
            Identity_1 = function: 0x0300425c
            NoOp = function: 0x0300427c
            Proxy = function: 0x031027fc
            SetTimeLapseFunc = function: 0x03102a3c
            SetTracebackFunc = function: 0x031003fc
            StoreTraceback = function: 0x03100e7c
            WithResource = function: 0x031028bc
            _M = CYCLE, table: 0x0310207c
            _NAME = "funcops"
            _PACKAGE = ""
         } (table: 0x0310207c)
         gcinfo = function: fast#26
         getfenv = function: fast#6
         getmetatable = function: fast#4
         gprintf_temp_at = function: 0x031000bc
         io = {
            close = function: fast#111
            flush = function: fast#114
            input = function: fast#117
            lines = function: fast#116
            open = function: fast#109
            output = function: fast#118
            popen = function: fast#120
            read = function: fast#112
            stderr = file (0x728c1bb8)
            stdin = file (0x728c1b78)
            stdout = file (0x728c1b98)
            tmpfile = function: fast#110
            type = function: fast#119
            write = function: fast#113
         } (table: 0x02073ad0)
         ipairs = function: fast#18
         iterators = {
            APairs = function: 0x0310053c
            CachedCallback = function: 0x0310033c
            IPairsR = function: 0x03001b9c
            IPairsThenItem = function: 0x03100c3c
            ItemThenIPairs = function: 0x0310087c
            _M = CYCLE, table: 0x03102abc
            _NAME = "iterators"
            _PACKAGE = ""
         } (table: 0x03102abc)
         jit = {
            arch = "x86"
            attach = function: fast#150
            flush = function: fast#148
            off = function: fast#147
            on = function: fast#146
            opt = {
               start = function: fast#161
            } (table: 0x020766a0)
            status = function: fast#149
            util = {
               funcbc = function: fast#152
               funcinfo = function: fast#151
               funck = function: fast#153
               funcuvname = function: fast#154
               traceexitstub = function: fast#160
               traceinfo = function: fast#155
               traceir = function: fast#156
               tracek = function: fast#157
               tracemc = function: fast#159
               tracesnap = function: fast#158
            } (table: 0x02076168)
            version = "LuaJIT 2.0.0-beta1"
            version_num = 20000
         } (table: 0x02075ee8)
         load = function: fast#24
         loadfile = function: fast#23
         loadstring = function: fast#22
         math = {
            abs = function: fast#37
            acos = function: fast#48
            asin = function: fast#47
            atan = function: fast#49
            atan2 = function: fast#57
            ceil = function: fast#39
            cos = function: fast#45
            cosh = function: fast#51
            deg = function: fast#55
            exp = function: fast#43
            floor = function: fast#38
            fmod = function: fast#60
            frexp = function: fast#53
            huge = 1.#INF
            ldexp = function: fast#58
            log = function: fast#41
            log10 = function: fast#42
            max = function: fast#62
            min = function: fast#61
            mod = function: fast#60
            modf = function: fast#54
            pi = 3.1415926535898
            pow = function: fast#59
            rad = function: fast#56
            random = function: 0x0301111c
            randomseed = function: 0x0301113c
            sin = function: fast#44
            sinh = function: fast#50
            sqrt = function: fast#40
            tan = function: fast#46
            tanh = function: fast#52
         } (table: 0x02074a88)
         math_ex = {
            AABoxSegmentIntersectEx = function: 0x0301117c
            BQF = function: 0x0301119c
            CapsuleSegmentIntersect = function: 0x030111dc
            CosSin = function: 0x030111fc
            LookAt = function: 0x0301123c
            PointInSphere = function: 0x0301127c
            RBy = function: 0x0301137c
            Rand = function: 0x0301133c
            SegmentsIntersect = function: 0x030112bc
            SphereSegmentIntersectEx = function: 0x030112dc
            SpheresIntersect = function: 0x030112fc
            UPQuadSegmentIntersect = function: 0x0301131c
         } (table: 0x0310ecbc)
         messagef = function: 0x030000bc
         module = function: 0x0310127c
         newproxy = function: fast#28
         next = function: fast#15
         os = {
            clock = function: fast#127
            date = function: fast#128
            difftime = function: fast#130
            execute = function: fast#121
            exit = function: fast#126
            getenv = function: fast#125
            remove = function: fast#122
            rename = function: fast#123
            setlocale = function: fast#131
            time = function: fast#129
            tmpname = function: fast#124
         } (table: 0x02073ff8)
         package = CYCLE, table: 0x02072d30
         pairs = function: fast#16
         pcall = function: fast#20
         print = function: fast#29
         printf = function: 0x0300013c
         rawequal = function: fast#10
         rawget = function: fast#8
         rawset = function: fast#9
         require = function: 0x02073258
         select = function: fast#12
         setfenv = function: fast#7
         setmetatable = function: fast#5
         string = {
            byte = function: fast#78
            char = function: fast#79
            dump = function: fast#85
            find = function: fast#86
            format = function: fast#91
            gfind = function: fast#89
            gmatch = function: fast#89
            gsub = function: fast#90
            len = function: fast#77
            lower = function: fast#83
            match = function: fast#87
            rep = function: fast#81
            reverse = function: fast#82
            sub = function: fast#80
            upper = function: fast#84
         } (table: 0x02074468)
         table = {
            concat = function: fast#98
            foreach = function: fast#93
            foreachi = function: fast#92
            getn = function: fast#94
            insert = function: fast#96
            maxn = function: fast#95
            remove = function: fast#97
            sort = function: fast#99
         } (table: 0x020732b8)
         table_ex = {
            Clear = function: 0x0300591c
            Copy = function: 0x0300597c
            CopyK = function: 0x030059dc
            CullingForEach = function: 0x03005a1c
            DeepCopy = function: 0x03103cbc
            Equal = function: 0x03103d3c
            Find = function: 0x03005bbc
            FindNot = function: 0x03005bfc
            Find_N = function: 0x03005bdc
            ForEach = function: 0x03005c1c
            ForEachI_Cond = function: 0x03103d7c
            ForEachKV = function: 0x03005c3c
            GetFields = function: 0x03103dfc
            GetKeys = function: 0x03005d1c
            MakeSet = function: 0x03005d3c
            Map = function: 0x03103e3c
            MapArrayEx = function: 0x03103e7c
            MapK = function: 0x03005dfc
            MapKV = function: 0x03103ebc
            Move = function: 0x03103efc
            SubTablesOnDemand = function: 0x031041bc
            Weak = function: 0x031041fc
            WithBoundTable = function: 0x0310427c
            _M = CYCLE, table: 0x03103b7c
            _NAME = "table_ex"
            _PACKAGE = ""
         } (table: 0x03103b7c)
         tonumber = function: fast#13
         tostring = function: fast#14
         type = function: fast#3
         unpack = function: fast#11
         vardump = {
            Print = function: 0x03100bbc
            SetDefaultOutf = function: 0x03100abc
            _M = CYCLE, table: 0x031076fc
            _NAME = "vardump"
            _PACKAGE = ""
         } (table: 0x031076fc)
         varops = {
            ClearAndRecache = function: 0x030025bc
            ClearRange = function: 0x0300259c
            CollectArgsInto = function: 0x0300253c
            HasMeta = function: 0x030023bc
            IsCallable = function: 0x0300241c
            IsCountable = function: 0x0300247c
            IsInteger = function: 0x0300249c
            IsNaN = function: 0x030024dc
            SwapMember = function: 0x0300257c
            UnpackAndClear = function: 0x0300261c
            UnpackClearAndRecache = function: 0x0300267c
            _M = CYCLE, table: 0x03101dbc
            _NAME = "varops"
            _PACKAGE = ""
         } (table: 0x03101dbc)
         xpcall = function: fast#21
      } (table: 0x02070ea0)
      bit = CYCLE, table: 0x020759d8
      class = CYCLE, table: 0x03106bbc
      coroutine = CYCLE, table: 0x020729e0
      coroutine_ex = CYCLE, table: 0x031045fc
      coroutineops = CYCLE, table: 0x0310557c
      debug = CYCLE, table: 0x02075510
      effect = CYCLE, table: 0x03114dbc
      funcops = CYCLE, table: 0x0310207c
      graphicshelpers = CYCLE, table: 0x0311563c
      io = CYCLE, table: 0x02073ad0
      iterators = CYCLE, table: 0x03102abc
      jit = CYCLE, table: 0x02075ee8
      jit.opt = CYCLE, table: 0x020766a0
      jit.util = CYCLE, table: 0x02076168
      list = CYCLE, table: 0x031027bc
      math = CYCLE, table: 0x02074a88
      math_ex = CYCLE, table: 0x0310ecbc
      nondeterminism_ops = CYCLE, table: 0x03109c3c
      numericops = CYCLE, table: 0x031007fc
      opbuilders = CYCLE, table: 0x03107a7c
      os = CYCLE, table: 0x02073ff8
      package = CYCLE, table: 0x02072d30
      skewheap = CYCLE, table: 0x0310867c
      strict = true
      string = CYCLE, table: 0x02074468
      table = CYCLE, table: 0x020732b8
      table_ex = CYCLE, table: 0x03103b7c
      vardump = CYCLE, table: 0x031076fc
      varops = CYCLE, table: 0x03101dbc
      widgetops = CYCLE, table: 0x0310c5bc
   } (table: 0x02071f50)