lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

My problem is this : I wish to combine 3 packages (socket, mime and ltn12) into a single dll. To do this, I've added a table "alias" to package, so if package.alias["mime"] = "socket", the c loader will look for mime in socket.dll, if it can't find it in mime.dll. This again can be implemented outside loadlib, at the cost of some code duplication.

Any problems with this approach ? It would certainly simplify distribution on windows.

I would suggest two alternatives that don't require changing any C code.

1) using package.preload

Let's say you have packages a, b, c, inside some DLL d. You can do
something like this

    -- untested code follows

    package.preload.a = rc_loader("a", "d")
    package.preload.b = rc_loader("b", "d")
    package.preload.b = rc_loader("c", "d")

    -- returns a function that when invoked will load the appropriate
    -- chunk from the resource and call it
    function rc_loader(module, bundle)
        return function()
            local f = rc_chunk(module, bundle)
            f()
        end
    end

    function rc_chunk(module, bundle)
        -- somehow obtain the chunk from the resource in the DLL
        -- perhaps calling require(bundle) helps find it?
    end


2) Alternatively, create a new loader

    -- untested code follows

    function rc_loader(bundle)
        return function(name)
            -- somehow obtain the chunk from the resource in the DLL
            -- perhaps calling require(bundle) helps find it?
            return f
        end
    end

    table.insert(package.loaders, rc_loader("d"))

Hope I didn't mess up any details.

Regards,
Diego.