-
Anonymous
Невозможно правильно связать Lua в проекте C++.
Сообщение
Anonymous »
Код: Выделить всё
#pragma message("Lua include: " __FILE__)
#include "ScriptHandler.h"
#include
#include "SDL3/SDL_log.h"
bool ScriptHandler::DeclareLuaState()
{
luaState = luaL_newstate();
if (luaState != nullptr)
{
luaL_openlibs(luaState);
return true;
}
return false;
}
bool ScriptHandler::Init()
{
if (this->DeclareLuaState())
{
if (luaL_dofile(luaState, "../Game/hoved.lua") == LUA_OK)
{
lua_getglobal(luaState, "Init");
lua_pcall(luaState, 0, 1, 0);
bool initResult = true;
if (lua_isboolean(luaState, -1))
initResult = lua_toboolean(luaState, -1);
return initResult;
}
std::cout ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) void __cdecl lua_close(struct lua_State *)" (__imp_?lua_close@@YAXPEAUlua_State@@@Z) referenced in function "public: void __cdecl ScriptHandler::Liquidate(void)" (?Liquidate@ScriptHandler@@QEAAXXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_type(struct lua_State *,int)" (__imp_?lua_type@@YAHPEAUlua_State@@H@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_toboolean(struct lua_State *,int)" (__imp_?lua_toboolean@@YAHPEAUlua_State@@H@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_getglobal(struct lua_State *,char const *)" (__imp_?lua_getglobal@@YAHPEAUlua_State@@PEBD@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_pcallk(struct lua_State *,int,int,int,__int64,int (__cdecl*)(struct lua_State *,int,__int64))" (__imp_?lua_pcallk@@YAHPEAUlua_State@@HHH_JP6AH0H1@Z@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) void __cdecl luaL_openselectedlibs(struct lua_State *,int,int)" (__imp_?luaL_openselectedlibs@@YAXPEAUlua_State@@HH@Z) referenced in function "public: bool __cdecl ScriptHandler::DeclareLuaState(void)" (?DeclareLuaState@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl luaL_loadfilex(struct lua_State *,char const *,char const *)" (__imp_?luaL_loadfilex@@YAHPEAUlua_State@@PEBD1@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) struct lua_State * __cdecl luaL_newstate(void)" (__imp_?luaL_newstate@@YAPEAUlua_State@@XZ) referenced in function "public: bool __cdecl ScriptHandler::DeclareLuaState(void)" (?DeclareLuaState@ScriptHandler@@QEAA_NXZ) 0
Я действительно не знаю, где я ошибся — я добавил файлы lua в свои дополнительные каталоги включения и связал lua.lib через компоновщик...
Подробнее здесь:
https://stackoverflow.com/questions/798 ... -c-project
1772303890
Anonymous
[code]#pragma message("Lua include: " __FILE__)
#include "ScriptHandler.h"
#include
#include "SDL3/SDL_log.h"
bool ScriptHandler::DeclareLuaState()
{
luaState = luaL_newstate();
if (luaState != nullptr)
{
luaL_openlibs(luaState);
return true;
}
return false;
}
bool ScriptHandler::Init()
{
if (this->DeclareLuaState())
{
if (luaL_dofile(luaState, "../Game/hoved.lua") == LUA_OK)
{
lua_getglobal(luaState, "Init");
lua_pcall(luaState, 0, 1, 0);
bool initResult = true;
if (lua_isboolean(luaState, -1))
initResult = lua_toboolean(luaState, -1);
return initResult;
}
std::cout ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) void __cdecl lua_close(struct lua_State *)" (__imp_?lua_close@@YAXPEAUlua_State@@@Z) referenced in function "public: void __cdecl ScriptHandler::Liquidate(void)" (?Liquidate@ScriptHandler@@QEAAXXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_type(struct lua_State *,int)" (__imp_?lua_type@@YAHPEAUlua_State@@H@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_toboolean(struct lua_State *,int)" (__imp_?lua_toboolean@@YAHPEAUlua_State@@H@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_getglobal(struct lua_State *,char const *)" (__imp_?lua_getglobal@@YAHPEAUlua_State@@PEBD@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl lua_pcallk(struct lua_State *,int,int,int,__int64,int (__cdecl*)(struct lua_State *,int,__int64))" (__imp_?lua_pcallk@@YAHPEAUlua_State@@HHH_JP6AH0H1@Z@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) void __cdecl luaL_openselectedlibs(struct lua_State *,int,int)" (__imp_?luaL_openselectedlibs@@YAXPEAUlua_State@@HH@Z) referenced in function "public: bool __cdecl ScriptHandler::DeclareLuaState(void)" (?DeclareLuaState@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) int __cdecl luaL_loadfilex(struct lua_State *,char const *,char const *)" (__imp_?luaL_loadfilex@@YAHPEAUlua_State@@PEBD1@Z) referenced in function "public: bool __cdecl ScriptHandler::Init(void)" (?Init@ScriptHandler@@QEAA_NXZ) 0>ScriptHandler.obj: Error LNK2019 : unresolved external symbol "__declspec(dllimport) struct lua_State * __cdecl luaL_newstate(void)" (__imp_?luaL_newstate@@YAPEAUlua_State@@XZ) referenced in function "public: bool __cdecl ScriptHandler::DeclareLuaState(void)" (?DeclareLuaState@ScriptHandler@@QEAA_NXZ) 0
[/code]
Я действительно не знаю, где я ошибся — я добавил файлы lua в свои дополнительные каталоги включения и связал lua.lib через компоновщик...
Подробнее здесь: [url]https://stackoverflow.com/questions/79898551/cant-link-to-lua-correctly-in-c-project[/url]