Lua can link the DLL specially written for Lua and use require. But there is a small point to note. The following scenarios are available:
1. There is a script require. Lua, which is placed in the script directory.
2. There are two dll: Test. dll, Lua. dll, and test. dll depend on Lua. dll, which are placed in the bin directory.
3. The script and bin are directories of the same level.
To enable require. Lua to connect to test. dll, modify the path of the Lua Search Library in the script. The script content is as follows:
Package. cpath = "... \ bin \\?. DLL "require" test"
When the script is run, the following error occurs: error loading module 'test' from file' .. \ bin \ test. dll'
This error does not mean that test is not found. DLL, but loading test. an error occurred while loading the DLL. There are only two possible types: Lua Loads Test. DLL has problems. The first type is test. the DLL format is not the one that can be linked to Lua. For example, the exported function name is incorrect (the exported function name must be luaopen_xxxx ).
The latter can be easily ruled out.CodeClick OK. There are only 1st possibilities.
However, test. dll looks quite normal, and the Lua. dll it depends on is no problem ......
Wait, test. dll depends on Lua. dll? Is there a problem here? Although test. dll and Lua. dll are in the same directory, require. Lua and Lua. dll are not in the same directory.
Copy Lua. DLL to the script directory and make it in the same directory as require. Lua. Run the script. The result is normal and no error is reported.
As a matter of fact, I am not very familiar with the DLL Link Mechanism till now. I thought that if a depends on B, it would be nice to put AB together.
It seems that setting package. cpath only sets the search path of A, and the DLL that a depends on is still in the mainProgram(Here Is require. Lua.