My question is: Am I asking for trouble by taking this approach?
Apologies for the long post. I did not have enough time to write a shorter one. ;-)
Rosie[1] is an application which exposes a CLI and a C API. The C API, librosie, can be
used from languages like Python, node.js, Ruby, Go, and others[2].
But what about Lua users? Rosie is written in Lua, so I wrote a proper Lua module in a file called 'rosie.lua' . (The 'rosie.lua' file is created from a template when
you install Rosie[3] and build the development branch, tranche-2, because it contains an explicit reference to the Rosie install directory.)
The 'rosie.lua' file can be copied to wherever the user keeps their Lua module files, such as /usr/local/lib/lua/5.3, and it will look in the Rosie installation directory
for everything needed to run Rosie. Thus a single installation of Rosie on a machine will be usable by CLI users, Lua developers, Python developers, etc.
Because Rosie uses C libraries like lpeg.so, 'rosie.lua' loads them from the Rosie installation directory, to ensure that exactly the supported versions are loaded[4].
This also simplifies things for the Lua user, who does not need to install those C libraries in their Lua environment, or who may have different versions of those libraries already installed.
The loading of Lua and C modules is done by a quick hack of a "private module system" that I wrote in an hour. It's literally around 40 lines of code[5] (yay, Lua!).
This quick hack does two things: (1) it loads code from the right place, and (2) it hides all the Rosie internals from the Lua user, including the fact that some C libraries
were loaded.