이전의 글과 다른 형태로 변경 하였습니다. 각 val_* 인터페이스는 강제적으로 추가 하게 하였고 윈도우 버젼에서는 val 함수를 강제로 뺐습니다. 각 대응함수는 이전의 글에서 설명을 드렸으므로 별도로 설명을 하지 않겠습니다. 소스는 아래의 경로에서 받으실 수 있습니다.
Microsoft Visual C++(이하 MSVC) 2002 버젼 이하에서 LuaRover(이하 LR)가 컴파일이 되지 않는다. MSVC 2002 이하 버젼에는 template 관련 버그가 있고 그것을 유발 할 수 있는 코드가 LR 포함되어 있기 때문이다. 물론 자체 테스트 역시 컴파일은 성공적으로 수행되지는 않았다.
문제가 되는 부분은 아래의 선언에 타입별로 구현된 부분이다.
template<typename T> T val() throw(LuaError);
int의 구현 부분을 예로 들면 아래와 같다.
template<> int LuaObject::val<int> () throw(LuaError) { ... }
구현 부분
성공적으로 컴파일을 하려면 버그를 유발하는 이 template는 코드를 수정하거나 버젼이 높은 버젼을 사용하여 컴파일 하는 방법 외엔 없다.
필자는 전자의 코드 수정 방법을 사용하여 이 버그를 피했다. 수정 내용은 아래와 같다.
template<typename T> T val() throw(LuaError);
->
#ifdef WIN32 int val_int() throw(LuaError); double val_double() throw(LuaError); std::string val_string() throw(LuaError); #else template<typename T> T val() throw(LuaError); #endif
LuaRover.hpp 수정
// 코드 추가 #ifdef WIN32 #define LuaRover_valFunc(type) type LuaObject::val_ ## type () throw(LuaError) #define luaRover_var(type) val_ ## type #else #define LuaRover_valFunc(type) template<> \ type LuaObject::val<type>() throw(LuaError)
#define luaRover_var(type) val<type> #endif
LuaRover.cpp에 추가할 코드
template<> int LuaObject::val<int>() throw(LuaError) { if (!lua_isnumber(lua_state_, -1)) throw LuaError(LuaError::NOT_A_NUMBER, last_key_ + " is Not A Number");
int result = lua_tointeger(lua_state_, -1); pop_stack(); return result; }
->
LuaRover_valFunc(int) { if (!lua_isnumber(lua_state_, -1)) throw LuaError(LuaError::NOT_A_NUMBER, last_key_ + " is Not A Number");
int result = lua_tointeger(lua_state_, -1); pop_stack(); return result; }