2
votes

From the Lua 5.1 reference manual:

Once a loader is found, require calls the loader with a single argument, modname. If the loader returns any value, require assigns the returned value to package.loaded[modname]. If the loader returns no value and has not assigned any value to package.loaded[modname], then require assigns true to this entry. In any case, require returns the final value of package.loaded[modname]

In my opinion, it meas when you use require and success, package.loaded[modname] must have value no matter true or table which depend on loader function has return

so there is my test below

enter image description here

Where is my package.loaded["test"]? But when I change a line in test.lua

enter image description here

Here is my Lua interperter:

ZeroBraneStudioEduPack-1.40-win32/Project/Lua Interperter/Lua

Sorry my poor English

P.S.
Screenshots above are available at full resolution: 1, 2

1
This appears to be a deficiency in the debugger. In both cases, package.loaded.test is set to m_test as you expect. The debugger, however, appears not to expand the same table more than once (probably as a safeguard against infinite recursion). When declared as a global, m_test already appears in _G so it is not expanded again. - tehtmi
thks a lot, i just print _G later then think it's ide problem, but not explore the reason - 张洁勇

1 Answers

1
votes

ZeroBrane Studio limits the size of the content retrieved and shown in the Watch panel (as controlled by several debugger.* settings). In your case, referencing _G returns a large payload that pushes out some of the other content (it just happens to push different content out as the global variable is already listed in _G, that's why you see slightly different results).

Try adding the following as the second line in your script package.loaded._G = nil and you should see more elements shown and the results will be consistent between the two cases.