lua-users home
lua-l archive

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


I have a Lua build that compiles all my favourite personal modules (base{16,32,58,64}, json, logging, sorting, socket stuff, and so on) to Lua bytecode and embeds them in the binary. I suspect lots of other users do something similar or identical. I simply followed the preload comment in linit.c, namely:

---cut here---
/*
** If you embed Lua in your program and need to open the standard
** libraries, call luaL_openlibs in your program. If you need a  
** different set of libraries, copy this file to your project and edit
** it to suit your needs.
**
** You can also *preload* libraries, so that a later 'require' can
** open the library, which is already linked to the application.  
** For that, do the following code:
**
**  luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
**  lua_pushcfunction(L, luaopen_modname);                    
**  lua_setfield(L, -2, modname);
**  lua_pop(L, 1);  // remove PRELOAD table
*/
---cut here---

Given that this feels like a pretty mainstream (and very useful) thing to do, should LUA_PRELOAD_TABLE perhaps be documented in the Lua manual itself, maybe in the section on searchers and package.preload?

(There may be other widely-relied-on constants that could be documented too. This is just one I noticed because I was reviewing my code and decided to check how "official" LUA_PRELOAD_TABLE was. I was mildly surprised not to see it in the manual, don't know why.)