내 게임 엔진에 루아를 임베드하려고합니다. 지금까지는 모두 잘 돌아갔다. 게임 엔진과 인터페이스하기 위해 함수를 등록하기 시작했습니다 (예 : move_object (id, x, y)). 등록이 정상적으로 작동했습니다. 다음으로 이런 식으로 사용하려고했습니다 :lua + luabind, "런타임 오류"후 스택 맨 위에 오류 정보 없음
handlers={}
handlers["update"] = function(objId)
-- print(objId)
move_object(objId, 0, 0)
end
이렇게하면 루아 바인드에서 "런타임 오류"예외가 발생합니다. 어디에서나 검색했고 인터넷 (및 루아 바인드 소스)에 따르면 오류 메시지는 여전히 루아 스택 맨 위에 있어야합니다. 나는 luabind :: 오류 잡기, 스택의 상단과 같이 모두 인쇄를 시도 :
std::cout << "error: lua: " << luabind::object(luabind::from_stack(exc.state(), -1)) << std::endl
을 모두 인쇄이 :
error: lua: update
std::cout << "error: lua: " << lua_tostring(exc.state(), -1) << std::endl;
이 같은
핸드 헬드 테이블에서 update 함수를 호출했을 때 마지막으로 push 된 값입니다. 이 값은 오류가 발생하면 자세한 오류 문자열로 덮어 써야합니다.class error
의 정의에서 luabind 소스 파일 "error.hpp"에 따르면.
// this exception usually means that the lua function you called
// from C++ failed with an error code. You will have to
// read the error code from the top of the lua stack
// the reason why this exception class doesn't contain
// the message itself is that std::string's copy constructor
// may throw, if the copy constructor of an exception that is
// being thrown throws another exception, terminate will be called
// and the entire application is killed.
내 루아 코드에 문제가 내 move_object 함수의 등록을 실제로 믿고 (업데이트 기능은 실행 나는 이것을 알고 , 왜냐하면 이전에 그 print 호출의 주석을 풀었기 때문입니다.) 그러나 더 나은 에러 정보 없이는 확신 할 수 없습니다! 하하
어떤 도움이된다면 오류가 수정되었습니다.
luabind::module(m_L)[
luabind::def("move_object", &ScriptEntityManager::move_object)
];
을하지만 분명히, 당신은 luabind와 일반 함수로 정적 멤버 함수를 정의 할 수 없습니다 : 그래서 같은 move_object의 함수를 정의했다. 나는 (C에서 move_object
일반 전역 함수를 만든 ++)이 그것을 변경 :
luabind::module(m_L)[
luabind::def("move_object", move_object)
];
즉 원래의 문제에 도움이 아닌지 모르겠어요,하지만 난 정보가 아프지 않을 수 더 생각! :)