PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/lua/import.lua

#
Lua | 28 lines | 15 code | 5 blank | 8 comment | 2 complexity | 56ed2e6d14ce814a177a3ad3545f2d9d MD5 | raw file
 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
 6function 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")
18end
19
20function import_5_1(name)
21	require(name)
22end
23
24if string.sub(_VERSION,1,7)=='Lua 5.0' then
25	import=import_5_0
26else
27	import=import_5_1
28end