lua-users home
lua-l archive

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


Andrew, thank you to point me out luaL_requiref and to suggest me to see the source code.

This it luaL_openlibs source code, very instructive:
    for (lib = loadedlibs; lib->func; lib++) {
        luaL_requiref(L, lib->name, lib->func, 1);
        lua_pop(L, 1);  /* remove lib */


So the solution for LUA 5.3 is
     luaL_requiref(L, "_G", luaopen_base, 1);
     luaL_requiref(L, LUA_STRLIBNAME, luaopen_string, 1);

And for LUA 5.4 :
     luaL_requiref(L,  LUA_GNAME, luaopen_base, 1);
     luaL_requiref(L, LUA_STRLIBNAME, luaopen_string, 1);

M

On Mon, 11 May 2020 at 18:24, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
>>>>> "Massimo" == Massimo Sala <massimo.sala.71@gmail.com> writes:

 Massimo> Hi
 Massimo> I am using this code to load the two libraries:

 Massimo> luaopen_base(L);
 Massimo> lua_pop(L, 1);
 Massimo> luaopen_string(L);
 Massimo> lua_setglobal(L, "string");

You shouldn't be doing that; see luaL_openlibs if you want all the
libraries, or see luaL_requiref (and the code for luaL_openlibs in
linit.c) to load only specific ones.

--
Andrew.
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org