lua-users home
lua-l archive

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


>>>>> "Luiz" == Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> writes:

 >> Specifically, ll_loadlib relies on
 >> registry[&CLIBS], where &CLIBS is a lightuserdata with the address of a
 >> static var. If there are multiple copies of the interpreter and you call
 >> require or loadlib from one other than the one that created the state,
 >> it'll end up calling lua_getfield on a nil value, which will throw an
 >> error.

 Luiz> The first thing that luaopen_package does is to create an entry
 Luiz> registry[&CLIBS].

That's not the issue.

Suppose module A contains a copy of the lua interpreter, creates a
lua_State and runs luaL_openlibs etc.

Then it calls module B, which _also_ contains a copy of the (same
version) of the interpreter. B calls luaL_checkversion, which (in 5.4)
passes because it's the same version, even though it's a different copy
of the code with different addresses.

B calls require, and it errors out because B's &CLIBS is not the same
value as A's &CLIBS.

In 5.3, the luaL_checkversion would have failed, but in 5.4 it does not.

-- 
Andrew.