Best way to omit Lua standard libraries?

前端 未结 3 1369
终归单人心
终归单人心 2021-01-02 00:51

What is the best way to remove or omit a Lua standard library package? For example remove the os library functions in a particular environment. The project in question is

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 01:18

    Let's say you only want to open the base and package libraries. In Lua 5.2, the most concise way is

    luaL_requiref(L, "_G", luaopen_base, 1);
    luaL_requiref(L, "package", luaopen_package, 1);
    lua_pop(L, 2);
    

    This is how the luaL_openlibs function in linit.c works, except that it loads everything.

提交回复
热议问题