lua-users home
lua-l archive

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


> Well, no. The official way to add static libraries is to edit linit.c
> and still call luaL_openlibs. The manual says that luaopen_* must be
> called via Lua, not via C. This is because some standard libraries
> need an environment. Your own libraries may not need one and you
> may get by calling them via C, but it's not part of the contract,
>
> Note that you edit linit.c and add it to your project, leaving the
> one in the Lua library untouched. The linker will use your version
> of luaL_openlibs.

Okay, then edit linit.c, as you wish.

If you dive into the source code of lua.c, and see how it calls the
luaL_openlibs you will found that it has no special environment
prepared for luaL_openlibs. (the only thing inside luaL_openlibs it to
push a string as module name, which is easy to do in the host program)

The advantage of not touching linit.c is: you will never need to
compile lua source code again and you can even remove lua source code
from your project. Just keep a static library of lua is enough.

Then you can add lots of 3rd part libraries statically in your project
without recompile the lua source code. Since you had done your
initialization inside the host program.

As the manual said: lua.c is not part of lua, it is just "a sample
host program". release lua stand-alone executable only if you do not
want to embed lua into your own program. So IMO you can freely modify
lua.c.