问题描述
我需要在Lua中加载一个DLL文件来连接不同的API。我知道C类型的dll可以加载,但我有一个dll文件在C + +。
I need to load a DLL file in Lua to connect different APIs. I know that C type dlls can be loaded, but what I have is a dll file produced in C++.
生成此库的代码(在C ++中)的格式为:
The code (in C++) that produced this library was of the form:
// MyAPI.h
namespace MyAPI
{
public class MyFirstClass
{
public:
MyFirstClass();
void performSomeMethod(int arg);
}
}
然后生成dll文件 MyAPI.dll
。当我现在尝试导入这个在Lua,使用:
which then produced the dll file MyAPI.dll
. When I now try to import this in Lua, using:
require "MyAPI"
它立即给出错误:错误加载模块'MyAPI'从文件'.\MyAPI.dll':指定找不到过程
。我不明白这是什么意思,或者如何摆脱它。一般来说,C ++库通常不会被Lua包含(也就是说,我应该写另一个C包装吗?)还是有办法做到这一点?
it immediately gives the error: error loading module 'MyAPI' from file '.\MyAPI.dll': The specified procedure could not be found
. I do not understand what this means, or how to get rid of it. Can C++ libraries in general not be included by Lua (i.e. should I write another C wrapper?) or is there a way to do this?
推荐答案
是的,可以做到。公开一个C函数装载器 luaopen_MyAPI
,其中可以调用使用任何类型的C ++ Lua包装器的函数,例如,
- pugilua_lib.h - 模块载入器API
- pugilua_lib.cpp - 包装类和LuaBridge绑定
- pugilua.cpp - 调用模块加载器的绑定
这篇关于可以在Lua中加载C ++ dll文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!