lua-users home
lua-l archive

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


Hi,

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));
}

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.

Now I can see that luaL_loadbuffer() gets the right contents and the
right length for the script, but if I try to load something simple like
a Lua script:

    module(..., package.seeall)
    print "Hello world"

I don't see the printout of "Hello world".

Can any one shed some light on what I am doing wrong here?


Thanks in advance,

// Oliver