[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question on loader implementation ...
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Sat, 10 Nov 2012 03:51:19 +0000
2012/11/9 Oliver Schneider <lua@windirstat.info>:
> at the moment I am struggling to get a loader to work. What I have is this:
>
> static int luaC_myloader(lua_State* L)
> {
> // ... the function retrieves the script and its size
> return luaL_loadbuffer(L, scriptBuf, scriptLen, lua_tostring(L, 1));
> }
First you have to fix that as Drake Wilson suggested.
> this function is then registered as function c_loader() global.
>
> I then have a piece of Lua code that enumerates over the found scripts
> and then assigns the found module names to package.preload like this:
>
> package.preload[k:lower()] = function(...)
> return c_loader(k:upper())
> end
> package.preload[k:upper()] = package.preload[k:lower()]
>
> k is the name of the module to be loaded and can appear in upper or
> lowercase, which is why I set both variants in package.preload.
Here I disagree with Drake Wilson. I think it's easier to directly
call your c_loader function:
package.preload[k:lower()] = c_loader(k:upper())
package.preload[k:upper()] = package.preload[k:lower()]