lua-users home
lua-l archive

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

> Statically include libraries inside your application does not require
> any modification of your lua source, you can do all extra
> initializatioin at your application's startup. You can do that after
> the following line:
>     lua_State *L;
>     L = luaL_newstate();
>     luaL_openlibs(L); /* here you init the standard lua libs */
>     luaopen_foo(L); /* here you init your add-on lib */
>     luaopen_bar(L); /* here you init your add-on lib */
>     luaopen_baz(L); /* here you init your add-on lib */

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.
> If you are not embedding lua into your application, then the lua.c is
> the host, you can just find initialization code in your lua.c. It is
> better not to touch the files other than lua.c

It is much better to touch just (you own copy of) linit.c and not lua.c at all.
lua.c is not the simplest code around because it is an interactive program
with all the complications that ensue.