[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question on loader implementation ...
- From: Drake Wilson <drake@...>
- Date: Fri, 9 Nov 2012 02:33:24 -0600
Quoth Oliver Schneider <lua@windirstat.info>, on 2012-11-09 03:53:15 +0000:
> 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));
> }
That "return" will not do what you think; you need to check the result
of luaL_loadbuffer for an error code yourself, then probably
luaL_error or return 1. Remember that Lua values are not directly
accessed from C, so the return value of your function should be a
count of Lua values to return.
> 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
And then you're taking the script function (note that "load" does not
mean "execute" in this case) and returning it from the preload
function, thus causing the script function to be treated _as_ the
module. But you intend to execute it, so you need
c_loader(k:upper())()
to call the function afterwards.
---> Drake Wilson