< p>For example, I want to do something like this:
-- My Lua File
include(myCppDll.dll)
function callCppFunctionFromDll ()
local result = myCppFunctionFromDll(arg1, arg2)
--Do something with result here
end
Is such a thing possible?
This can be done using a wrapper generator (such as Swig), which will write wrappers for Lua and many other scripting languages based on class and function declarations, usually only an existing .h file is required as input.
Lua is also simple enough code, because it may be easier to write your own wrapper manually in C. For this reason, create a Lua callable module in C starting from the standard recipe, and implement the function entry of transferring parameters from the Lua stack The form suitable for each API call, call the DLL, and push any results back to the Lua stack. This is also the use of Lua to be able to return more for those functions in the DLL that must use the output pointer to process the second (or more) return value There is a place for the ability of the results. The discussion of the issues and some sample codes are provided on the Lua user’s Wiki.
There is also a page dedicated to binding Lua to other languages on the Lua user’s Wiki.< /p>
I have a DLL written in C. It is a legacy code, and the source code cannot be modified. I want to be able to call some functions inside the DLL from Lua.
p>
For example, I want to do something like this:
-- My Lua File
include(myCppDll.dll)
function callCppFunctionFromDll()
local result = myCppFunctionFromDll(arg1, arg2)
--Do something with result here
end
Is such a thing possible?
If Alien cannot meet your needs, and if the DLL has a powerful object-oriented interface, you need to get the members and methods of the object and only call the exported Function, then it may not be easy to use, then you should look at generating a wrapper DLL, which connects the legacy API from the DLL to Lua.
This can use a wrapper generator (such as Swig) To complete it, it will write wrappers for Lua and many other scripting languages based on class and function declarations, usually only the existing .h file is required as input.
Lua is also simple enough code, because in It may be easier to write your own wrapper manually in C. For this reason, create a Lua callable module in C starting from the standard recipe, and implement the function of transferring parameters from the Lua stack into a form suitable for each API call, call the DLL, and Push any result back to the Lua stack. This is also the place to take advantage of Lua’s ability to return multiple results for those functions in the DLL that must use the output pointer to process the second (or more) return value. On the Lua user’s Wiki A discussion of the issues and some sample codes are provided.
There is also a page dedicated to binding Lua to other languages on the Lua user’s Wiki.
p>