import source from 1.3.40
[external/swig.git] / Examples / test-suite / lua / import.lua
1 -- import
2 -- the lua 5.0 loading mechanism is rather poor & relies upon the loadlib() fn
3 -- the lua 5.1 loading mechanism is simplicity itself
4 -- for now we need a bridge which will use the correct verion
5
6 function import_5_0(name)
7         -- imports the file into the program
8         -- for a module 'example'
9         -- this must load 'example.dll' or 'example.so'
10         -- and look for the fn 'luaopen_example()'
11         if rawget(_G,name)~=nil then return end -- module appears to be loaded
12                 
13         local lib=loadlib(name..'.dll','luaopen_'..name) or loadlib(name..'.so','luaopen_'..name)
14         assert(lib,"error loading module:"..name)
15         
16         lib() -- execute the function: initalising the lib
17         assert(rawget(_G,name)~=nil,"no module table found")
18 end
19
20 function import_5_1(name)
21         require(name)
22 end
23
24 if string.sub(_VERSION,1,7)=='Lua 5.0' then
25         import=import_5_0
26 else
27         import=import_5_1
28 end