It is important to understand how the require machine works, and therefore why your code does not work.
require designed to search for Lua scripts in the file system and DLL . Static libraries are not DLLs; indeed, with C / C ++, once you finish linking, static libraries are no different from compiling these .c / .cpp files into your application directly.
When require finds a DLL with the appropriate name, it loads it and tries to find a function called luaopen_<modname> , where <modname> is the name of the module. When this happens, it will execute this function and save the value returned by it in the internal database of loaded modules.
Calling require for the module will return all returned functions; if the module is already loaded, then the return value is pulled from the database and returned directly.
Just calling luaopen_foo will not do any of this. Indeed, simply calling this function is a bad idea; it is a Lua function and should be called as a Lua function (i.e. you need to push it onto the Lua stack using lua_pushcfunction and call it using lua_call , etc.).
If you want to create a local module (one of them is not in a Lua script or DLL, but presented from your code), you need to use Lua tools for this. In particular, use luaL_requiref :
luaL_requiref(L, "foo", luaopen_foo, 0);
Call this instead of calling luaopen_foo directly. This will automatically register the return value from luaopen_foo with require internal database of loaded modules. Thus, subsequent calls to require "foo" will return this table.
One more thing: do is a keyword in Lua; You should not use keywords for Lua table key names. You can, but you should always quote them (i.e. your script must do foo["do"](...) to call it).