请问 lua5.2调用c++dll问题
lua吧
全部回复
仅看楼主
level 2
天尊鸿钧 楼主
cpp 代码
#include "ELuna.h"
/**/
#define DEBUG_ENGINE
#ifdef DEBUG_ENGINE
//#pragma comment(lib,"../Lib/Lib/Debug/Lua52")
#pragma comment(lib,"../Lib/Debug/Lua52")
#else
#pragma comment(lib,"../Lib/Release/Lua52")
#endif
extern "C" static int Add(lua_State*L)
{
lua_pushnumber(L, 10);
return 1;
}
extern "C" static int Sub(lua_State*L)
{
lua_pushnumber(L, -10);
return 1;
}
static const struct luaL_Reg testlib[] = {
{ "Add", Add },
{ "Sub", Sub },
{ NULL, NULL }
};
extern "C" __dec
lsp
ec(dllexport) int luaopen_TestDll(lua_State* L)
{
luaL_newlib(L, testlib);
return 1;
}
运行结果如下
C:\Users\chenxu>lua
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio
> require("TestDll")
multiple Lua VMs detected
stack traceback:
[C]: in ?
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
>
2014年06月26日 05点06分 1
level 8
你的TestDll静态链接了Lua的库,而lua程序本身也是静态链接lua的库,所以在你的程序中就存在两份Lua的库,从而报multiple Lua VMs detected(检测到多个Lua虚拟机)。把lua程序和TestDll都改成动态链接lua库就好了。
2014年06月26日 07点06分 2
thanks ,我已经解决了,貌似lua解释器不能连接dll,不能在解释器上调用TestDll,但是能在其他动态链接的应用程序上调用,搞这个弄了半天。
2014年06月26日 09点06分
回复 天尊鸿钧 :貌似lua解释器不能链接动态库
2014年06月26日 09点06分
回复 天尊鸿钧 :可以的。
2014年06月26日 11点06分
level 1
我遇到了同样的问题,请问楼主这么解决的。。[啊]
2015年02月02日 09点02分 3
readme.md 中有 定义一个宏#define LUA_BUILD_AS_DLL 编译即可
2015年02月03日 05点02分
回复 天尊鸿以上是编译lua,用到lua的时候用动态链接
2015年02月03日 05点02分
编译lua解析器的时候加#define LUA_BUILD_AS_DLL?加在哪里?
2015年02月04日 11点02分
level 2
能具体说下怎么解决的吗,谢谢
2018年08月21日 01点08分 4
1