2012-05-26 1 views
2

내 게임 엔진에 루아를 임베드하려고합니다. 지금까지는 모두 잘 돌아갔다. 게임 엔진과 인터페이스하기 위해 함수를 등록하기 시작했습니다 (예 : 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) 
]; 

즉 원래의 문제에 도움이 아닌지 모르겠어요,하지만 난 정보가 아프지 않을 수 더 생각! :)

답변

2

루아 바인드 예외를 포착 할 때 오류 메시지에 대한 잘못된 값이 표시됩니다. 나는 luabind (set_pcall_callback)에 의해 사용되는 에러 핸들러를 설정함으로써 예외를 던지기 전에 발생하는 에러 (그리고 콜 스택)를 프린트하도록 문제를 해결했다. 그것은 나를 위해 잘 작동합니다.

예외를 잡는 경우 스택의 상단이 오류 메시지를 포함하지 않는 이유는 누군가가 실제로 알고 있다면, 나는 여기

그것이 도움이 될 수 있습니다 나는 경우에 사용하는 오류 핸들러 관심이 너무 :-) 해요 누군가 (여기서 "print"는 std :: string을 기록 할 수있는 사용자 정의 함수입니다) :

int luabindErrorHandler(lua_State* L) 
{ 
    // log the error message 
    luabind::object msg(luabind::from_stack(L, -1)); 
    std::ostringstream str; 
    str << "lua> run-time error: " << msg; 
    print(str.str()); 

    // log the callstack 
    std::string traceback = luabind::call_function<std::string>(luabind::globals(L)["debug"]["traceback"]); 
    traceback = std::string("lua> ") + traceback; 
    print(traceback.c_str()); 

    // return unmodified error object 
    return 1; 
} 
관련 문제