Untangling Lua & C code to make Lua dependency optional Untangling Lua & C code to make Lua dependency optional sqlite sqlite

Untangling Lua & C code to make Lua dependency optional


The most elegant way I have seen this issue approached is via dynamic loading. Instead of linking your program against lua, at runtime, attempt to load the library manually using the dlopen family of functions.

If this then fails you can set a global flag that you will need to resort to the other method of providing the functionality but if it succeeds use the dlsym function to get the functions out of the lua shared object and use them. You can produce a very elegant solution in which you populate some function pointers with either the lua or legacy versions, then you can simply make the decisions once and call the functions not caring which implementation is in use.