[lua] extras compability for lua 5.1, fixed a static link name conflict

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9864 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Gossage 2007-07-10 09:30:49 +00:00
commit f87371fe8c
15 changed files with 61 additions and 104 deletions

View file

@ -3,36 +3,22 @@
-- the lua 5.1 loading mechanism is simplicity itself
-- for now we need a bridge which will use the correct verion
function import_5_0(module)
function import_5_0(name)
-- imports the file into the program
-- for a module 'example'
-- this must load 'example.dll' or 'example.so'
-- and look for the fn 'Example_Init()' (note the capitalisation)
if rawget(_G,module)~=nil then return end -- module appears to be loaded
-- and look for the fn 'luaopen_example()'
if rawget(_G,name)~=nil then return end -- module appears to be loaded
-- capitialising the first letter
local c=string.upper(string.sub(module,1,1))
local fnname=c..string.sub(module,2).."_Init"
local suffix,lib
-- note: as there seems to be no way in lua to determine the platform
-- we will try loading all possible names
-- providing one works, we can load
for _,suffix in pairs{".dll",".so"} do
lib=loadlib(module..suffix,fnname)
if lib then -- found
break
end
end
assert(lib,"error loading module:"..module)
local lib=loadlib(name..'.dll','luaopen_'..name) or loadlib(name..'.so','luaopen_'..name)
assert(lib,"error loading module:"..name)
lib() -- execute the function: initalising the lib
local m=rawget(_G,module) -- gets the module object
assert(m~=nil,"no module table found")
assert(rawget(_G,name)~=nil,"no module table found")
end
function import_5_1(module)
require(module)
function import_5_1(name)
require(name)
end
if string.sub(_VERSION,1,7)=='Lua 5.0' then