"multiple Lua VMs detected" error with c module lua 5.3

我看过与"multiple Lua VMs detected"错误有关的所有帖子,但它们的答案都不起作用。我已经按照lua.org的构建指南编译了它,但仍然显示错误。使用Visual Studio 2019会引起未解决的外部符号错误,而不使用-llua的GCC命令也会引起未解决的符号。有任何想法吗?我正在使用提供的make文件编译的lua 5.3.2版本。

这是我尝试使用的代码

#include "lua.h"
#include "lauxlib.h"
#include <Windows.h>

int test_function(lua_State* L)
{

    return 0;
}

static const luaL_Reg testlib[] = {
    {"test_function", test_function},
    {NULL, NULL}
};

__declspec(dllexport) int __cdecl luaopen_testlib(lua_State* L)
{
    luaL_newlib(L, testlib);

    return 1;
};
local lib, err = package.loadlib([[module.dll]], "luaopen_testlib")

if lib ~= nil then
    --multiple Lua VMs detected
    lib()
else
    print(err)
end

原文链接 https://stackoverflow.com/questions/70132329

点赞