[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: 5.4 luaL_checkversion vs. loadlib()
- From: Andrew Gierth <andrew@...>
- Date: Tue, 16 Jul 2019 17:05:34 +0100
>>>>> "Luiz" == Luiz Henrique de Figueiredo <firstname.lastname@example.org> 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
Luiz> The first thing that luaopen_package does is to create an entry
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.