Windows 64环境,lua调用C接口,程序crash
lua版本:Lua 5.3.4 Copyright (C) 1994-2017 , PUC-Rio
C代码:
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#pragma comment(lib, "liblua53.a")
int foo(lua_State* L)
{
printf("hello foo\n");
return 0;
}
static const struct luaL_Reg funcs[] ={
{"foo", foo},
{NULL, NULL}
};
__declspec(dllexport) int luaopen_LuaFoo(lua_State* L)
{
luaL_newlib(L, funcs);
return 1;
}
Lua代码:
require("LuaFoo")
Crash堆栈:
0000000300905a4d()
> LuaFoo.dll!luaopen_LuaFoo(lua_State * L=0x00000000003eec00) 行20 + 0x16 字节 C
lua53.dll!0000000070406bd0()
[下面的框架可能不正确和/或缺失,没有为 lua53.dll 加载符号]
说明:
require("LuaFoo")会调用luaopen_LuaFoo
只要访问lua_State 就crash
linux环境能正常运行
[此贴子已经被作者于2018-10-27 17:31编辑过]