From b93b3593bf4eabd6def74007d9bad4ef5618c302 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 12 Sep 2005 22:14:37 +0000 Subject: [PATCH] Lua fixes to work on Unix as well as windows. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7433 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/lua/class/runme.lua | 9 ++++++--- SWIG/Examples/lua/simple/runme.lua | 9 ++++++--- SWIG/Examples/lua/variables/runme.lua | 9 ++++++--- SWIG/Examples/test-suite/lua/Makefile.in | 2 +- SWIG/Examples/test-suite/lua/import.lua | 13 ++++++++----- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/SWIG/Examples/lua/class/runme.lua b/SWIG/Examples/lua/class/runme.lua index 5ccc8783b..58d430538 100644 --- a/SWIG/Examples/lua/class/runme.lua +++ b/SWIG/Examples/lua/class/runme.lua @@ -3,10 +3,13 @@ -- This file illustrates class C++ interface generated -- by SWIG. --- importing (lua doesnt have a nice way to do this) -if example==nil then - assert(loadlib("example.dll","Example_Init"))() +-- importing (lua does not have a nice way to do this) +loadlibrary = loadlib("example.so","Example_Init") +if loadlibrary == nil then + loadlibrary = loadlib("example.dll","Example_Init") end +assert(loadlibrary, "could not find dynamic libray") +loadlibrary() ----- Object creation ----- diff --git a/SWIG/Examples/lua/simple/runme.lua b/SWIG/Examples/lua/simple/runme.lua index 71ec6054a..d072cd4c4 100644 --- a/SWIG/Examples/lua/simple/runme.lua +++ b/SWIG/Examples/lua/simple/runme.lua @@ -1,9 +1,12 @@ -- file: runme.lua --- importing (lua doesnt have a nice way to do this) -if example==nil then - assert(loadlib("example.dll","Example_Init"))() +-- importing (lua does not have a nice way to do this) +loadlibrary = loadlib("example.so","Example_Init") +if loadlibrary == nil then + loadlibrary = loadlib("example.dll","Example_Init") end +assert(loadlibrary, "could not find dynamic libray") +loadlibrary() -- Call our gcd() function print("hello world") diff --git a/SWIG/Examples/lua/variables/runme.lua b/SWIG/Examples/lua/variables/runme.lua index 6dd71fb56..75235a33e 100644 --- a/SWIG/Examples/lua/variables/runme.lua +++ b/SWIG/Examples/lua/variables/runme.lua @@ -1,9 +1,12 @@ -- file: example.lua --- importing (lua doesnt have a nice way to do this) -if example==nil then - assert(loadlib("example.dll","Example_Init"))() +-- importing (lua does not have a nice way to do this) +loadlibrary = loadlib("example.so","Example_Init") +if loadlibrary == nil then + loadlibrary = loadlib("example.dll","Example_Init") end +assert(loadlibrary, "could not find dynamic libray") +loadlibrary() -- Try to set the values of some global variables diff --git a/SWIG/Examples/test-suite/lua/Makefile.in b/SWIG/Examples/test-suite/lua/Makefile.in index 733e1891a..398ba64fc 100644 --- a/SWIG/Examples/test-suite/lua/Makefile.in +++ b/SWIG/Examples/test-suite/lua/Makefile.in @@ -45,7 +45,7 @@ LIBS = -L. # a file is found which has _runme.lua appended after the testcase name. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \ - $(LUA) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(LUA) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \ fi; # Clean: (does nothing, we dont generate extra lua code) diff --git a/SWIG/Examples/test-suite/lua/import.lua b/SWIG/Examples/test-suite/lua/import.lua index 9a53ea9af..7158e612a 100644 --- a/SWIG/Examples/test-suite/lua/import.lua +++ b/SWIG/Examples/test-suite/lua/import.lua @@ -2,17 +2,20 @@ function import(module,intoglobal) -- imports the file into the program -- for a module example - -- this must load 'example.dll' + -- this must load 'example.dll' or 'example.so' -- and look for the fn 'Example_Init()' (note the capitalisation) - local libname=module..".dll" -- windows - --libname=module..".so" -- unix - -- capitialising the first letter local c=string.upper(string.sub(module,1,1)) local fnname=c..string.sub(module,2).."_Init" - assert(loadlib(libname,fnname),"error loading module:"..module)() + -- attempt to load the module using Unix and Windows dll/shared object + local loadlibrary = loadlib(module..".so",fnname) + if loadlibrary == nil then + loadlibrary = loadlib(module..".dll",fnname) + end + assert(loadlibrary~=nil,"could not load module") + loadlibrary() -- moving to global namespace if intoglobal then