|
Diego Nehab wrote:
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
you have described by lua prototype almost exactly :) or for lazy loading: package.preload.a = function(x) return assert(rcloader("a"))(x) 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"))
that is almost exactly how i set up the resource search, to look for "socket.ftp" as a resource in socket.dll.
Thanks - that is very similar to my initial prototype; if i require "socket", it sets up the preloader for "mime", "ltn12", etc.Hope I didn't mess up any details. Regards, Diego.
I'm playing with "package.alias" so i can set up a mapping (eg. via luainit), so that require"ltn12" knows to look in socket.dll, without having to require (and load) socket.
ps no c code need be modified; require"rcloadlib" will insert the new loader etc., it just needs duplicates of several loadlib internal fn's, like findfile() etc.
Adrian