/trunk/Examples/test-suite/lua/lua_no_module_global_runme.lua

# · Lua · 24 lines · 9 code · 7 blank · 8 comment · 7 complexity · 82a69c9d72dfa5ad7e02024e4151289e MD5 · raw file

  1. -- require is only available in Lua 5.1
  2. if string.sub(_VERSION,1,7)=='Lua 5.1' then
  3. -- Initially the package should not be loaded
  4. assert(package.loaded["lua_no_module_global"] == nil)
  5. -- Load the module
  6. the_module = require "lua_no_module_global"
  7. -- require should return the module table
  8. assert(the_module.hi_mom ~= nil)
  9. assert(the_module.hi_mom() == "hi mom!")
  10. -- But it should not end up in the global table _G, subject to
  11. -- the -nomoduleglobal swig option.
  12. assert(_G["lua_no_module_global"] == nil)
  13. -- According to the Lua 5.1 reference manual, require should also
  14. -- store the module table into package.loaded["name"]
  15. assert(package.loaded["lua_no_module_global"] == the_module)
  16. assert(package.loaded["lua_no_module_global"].hi_mom() == "hi mom!")
  17. end