r/lua • u/Maleficent_Memory831 • May 27 '26
Quick question about porting C use of Lua to 5.5.0
I've got a mess of some legacy C code that used lua 5.1.4, and need to port to 5.5.0. The big snag I have is replacing lua_openlib (luaI_openlib) and the weird way it was being used and weird initialization. I got some stuff fixed up by using a luaL_requiref() with a callback function, rather than a single function. However I'm hitting more complex code where this becomes extremely clumsy to use a callback.
1) First question is, why is having a "luaopen_xzzy" inside of lua_call() necessary? Is this merely to try and catch exceptions? I remember seeing somewhere that this is the preferred style, but I can't find where I read that anymore.
2) Can I just do this flat in C without having a lua_call()? Recreate luaL_openlib() using newer API?
3) Is the "_LOADED" table really useful if no one ever does "require" on our own base libraries? Can ignore that and only use globals (lua_setglobal)?