[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:
parent
c3ec8fdce3
commit
f87371fe8c
15 changed files with 61 additions and 104 deletions
|
|
@ -6,7 +6,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ print("Testing the %import directive")
|
|||
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
function loadit(a,b)
|
||||
lib=loadlib(a..':dll',b) or loadlib(a..':so',b)
|
||||
function loadit(a)
|
||||
lib=loadlib(a..'.dll','luaopen_'..a) or loadlib(a..'.so','luaopen_'..a)
|
||||
assert(lib)()
|
||||
end
|
||||
loadit('base','Base_Init')
|
||||
loadit('foo','Foo_Init')
|
||||
loadit('bar','Bar_Init')
|
||||
loadit('spam','Spam_Init')
|
||||
loadit('base')
|
||||
loadit('foo')
|
||||
loadit('bar')
|
||||
loadit('spam')
|
||||
else
|
||||
-- lua 5.1 does
|
||||
require 'base'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue