SF patch #3394339 from Torsten Landschoff - new option -nomoduleglobal to disable installing the module table into the global namespace. Require call also returns the module table instead of a string

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12780 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-08-22 19:27:56 +00:00
commit 932f47a845
8 changed files with 87 additions and 11 deletions

View file

@ -11,12 +11,12 @@ top_builddir = @top_builddir@
# sorry, currently very few test cases work/have been written
#CPP_TEST_CASES += \
# cnum
CPP_TEST_CASES += \
lua_no_module_global \
#C_TEST_CASES += \
# file_test \
# nondynamic
C_TEST_CASES += \
lua_no_module_global \
include $(srcdir)/../common.mk
@ -25,7 +25,7 @@ include $(srcdir)/../common.mk
LIBS = -L.
# Custom tests - tests with additional commandline options
# none!
lua_no_module_global.%: SWIGOPT += -nomoduleglobal
# Rules for the different types of tests
%.cpptest:

View file

@ -0,0 +1,24 @@
-- require is only available in Lua 5.1
if string.sub(_VERSION,1,7)=='Lua 5.1' then
-- Initially the package should not be loaded
assert(package.loaded["lua_no_module_global"] == nil)
-- Load the module
the_module = require "lua_no_module_global"
-- require should return the module table
assert(the_module.hi_mom ~= nil)
assert(the_module.hi_mom() == "hi mom!")
-- But it should not end up in the global table _G, subject to
-- the -nomoduleglobal swig option.
assert(_G["lua_no_module_global"] == nil)
-- According to the Lua 5.1 reference manual, require should also
-- store the module table into package.loaded["name"]
assert(package.loaded["lua_no_module_global"] == the_module)
assert(package.loaded["lua_no_module_global"].hi_mom() == "hi mom!")
end