--
-- MAPPINGS.LUA
--
-- This file contains the SYSTEM mappings of module id's.
--
assert( LUAX_ROOT, "Missing Luax!" )

local binpath= ASSUME( lib.static.exepath )
local listdir= ASSUME( lib.static.listdir )
local fileexists= ASSUME( lib.static.fileinfo )

if binpath=="" then  -- luax_embed, must find out the path
    local tmp
               
    if WIN32 then
        tmp= "out_win32.gcc/"   -- try gcc first
        if not listdir( LUAX_ROOT..tmp ) then
            tmp= "out_win32.msc/"
        end
    elseif LINUX then
        tmp= "out_linux.x86/"
        --
    elseif DARWIN then
        tmp= "out_darwin/"
    end
    
    binpath= LUAX_ROOT..tmp
    ASSUME( listdir(binpath) )
end
local modules= binpath.."Modules/"   -- Binary modules ("Bin/" or "out_xxx/")

-- In development, wrappers are under "Modules/.../" subdirectories.
-- In deployment, they're under "Scripts/" (all in one dir).
--
local wrappers= nil

if listdir(LUAX_ROOT.."Modules/") then   -- Development layout
    wrappers= { }
    for _,v in listdir(LUAX_ROOT.."Modules/") do
        if string.sub(v,-1)=='/' then   -- is a dir
            table.insert( wrappers, LUAX_ROOT.."Modules/"..v )
        end
    end

--[[
    -- luaSocket has wrappers in deeper subdirs:
    --
    for _,v in listdir(LUAX_ROOT.."Modules/luaSocket/") do
        if string.find( v, "^luasocket%-.+%/$" ) the
            table.insert( wrappers, LUAX_ROOT.."Modules/luaSocket/"..v.."lua/" )
        end
    end
]]--
end

--
MAP_PATH( modules, LUAX_ROOT, LUAX_ROOT.."Scripts/", wrappers )

-----
-- Selftest modules:
--
MAP( 'lib.test', 'Scripts/hello.lua', 'sample_module' )

-----
-- Lua4 compatibility support (on 5.0 engine):
--
MAP( 'lua4_compat',     'compat.lua' )

-----
-- 'lib.*' modules:
--
MAP( 'lib.bitlib',      'bitlib_wrap.lua' )
MAP( 'lib.sys',         'sys_wrap.lua' )
MAP( 'lib.serial',      --'serial_wrap.lua' )   -- external wrapper
                        'serial_module' )   -- wrapper baked in :)
MAP( 'lib.gpib',        'gpib_wrap.lua' )
MAP( 'lib.dynacall',    'dynacall_module' )
MAP( 'lib.zlib',        'zlib_module' )
MAP( 'lib.sdl',         'sdl_wrap.lua' )
MAP( 'lib.sdl2',         'sdl2_wrap.lua' )
MAP( 'lib.sdl_mixer',   'sdl_mixer_wrap.lua' )
MAP( 'lib.smpeg',       'smpeg_wrap.lua' )
MAP( 'lib.vec2d',       'Scripts/vec2d.lua' )
MAP( 'lib.paragui',     'paragui_wrap.lua' )
MAP( 'lib.dialog',      'Scripts/dialog.lua' )

-- luaSocket stuff:
--
MAP( 'lib.ltn12',       'ltn12.lua' )
MAP( 'lib.mime',        'mime_wrap.lua' )
MAP( 'lib.socket',      'luasocket_wrap.lua' )
MAP( 'lib.socket.http', 'http.lua' )
MAP( 'lib.socket.url',  'url.lua' )
MAP( 'lib.socket.tp',   'tp.lua' )  -- for FTP & SMTP
MAP( 'lib.socket.ftp',  'ftp.lua' )
MAP( 'lib.socket.smtp', 'smtp.lua' )

-----
-- Misc. tool scripts:
--
MAP( 'lib.tools',       'Scripts/readconfig.lua' )
MAP( 'lib.tools',       'Scripts/weekday.lua' )
MAP( 'lib.tools',       'Scripts/dump.lua' )
MAP( 'luax_install',    'Scripts/luax_install.lua' )

-----
-- Platform specific:
--
MAP( 'lib.win32.regedit',   'Scripts/win32/regedit.lua' )
MAP( 'lib.osx.applescript', 'Scripts/darwin/applescript.lua' )
MAP( 'lib.osx.pashua',      'Scripts/darwin/pashua.lua' )

-----
-- Global modules:
--
MAP( 'globals',         'Scripts/globals.lua' )     -- Access checking
MAP( 'libext',          'Scripts/libext.lua' )      -- math.* extensions etc.
MAP( 'objects',         'Scripts/objects.lua' )
MAP( 'debug',           'Scripts/debug.lua' )

----
-- Load some default modules:
--
USES( 'libext', "quiet" )   -- extended 'lib.math.*' etc.

if false then   -- Lua 5.1 "-w" now takes care of this..?
  USES( 'globals', "quiet" )  -- enable global access checking (detects typing errors)
end

--
return true
