뭐 모듈 시스템이 변경됬느니, 가비지 컬렉션이 어떻게 됬느니하는 이야기는 접어두고, 일단 기존의 코드를 변환하면서 문제가 된 것들이다.
1. LUA_PATH 문제
require 문을 위한 검색 경로를 설정할 때, 이전에는 전역 변수인 LUA_PATH 문자열 값을 이용했으나, 이제 package 테이블 안의 path 변수를 이용해야한다. 자세한 건 http://serious-code.net/moin.cgi/LuaSnippets 페이지 참고
2. _TRACEBACK 함수 문제
lua_pcall 함수를 호출할 때, 전역 테이블에서 "_TRACEBACK" 함수를 가져와서 사용했었는데, 없어져버렸다. debug.traceback의 alias였는지 아닌지는 잘 모르겠다만...
int errfunc = lua_gettop(L);
lua_getglobal(L, "_TRACEBACK");
lua_insert(L, errfunc);
int status = lua_pcall(L, 0, 0, errfunc);
if (status != 0)
{
cerr << "ERROR: " << lua_tostring(L, -1) << endl;
lua_pop(L, 1);
}
lua_remove(L, errfunc);
lua_getglobal(L, "_TRACEBACK");
lua_insert(L, errfunc);
int status = lua_pcall(L, 0, 0, errfunc);
if (status != 0)
{
cerr << "ERROR: " << lua_tostring(L, -1) << endl;
lua_pop(L, 1);
}
lua_remove(L, errfunc);
이걸 해결하기 위해서...
int traceback(lua_State* L)
{
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
return 1;
}
lua_getfield(L, -1, "traceback");
if (!lua_isfunction(L, -1)) {
lua_pop(L, 2);
return 1;
}
lua_pushvalue(L, 1); // pass error message
lua_pushinteger(L, 2); // skip this function and traceback
lua_call(L, 2, 1); // call debug.traceback
return 1;
}
int base = lua_gettop(L);
lua_pushcfunction(L, traceback);
lua_insert(L, base);
int status = lua_pcall(L, 0, 0, base);
lua_remove(L, base);
if (status != 0)
{
cerr << "ERROR: " << lua_tostring(L, -1) << endl;
lua_pop(L, 1);
}
{
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
if (!lua_istable(L, -1)) {
lua_pop(L, 1);
return 1;
}
lua_getfield(L, -1, "traceback");
if (!lua_isfunction(L, -1)) {
lua_pop(L, 2);
return 1;
}
lua_pushvalue(L, 1); // pass error message
lua_pushinteger(L, 2); // skip this function and traceback
lua_call(L, 2, 1); // call debug.traceback
return 1;
}
int base = lua_gettop(L);
lua_pushcfunction(L, traceback);
lua_insert(L, base);
int status = lua_pcall(L, 0, 0, base);
lua_remove(L, base);
if (status != 0)
{
cerr << "ERROR: " << lua_tostring(L, -1) << endl;
lua_pop(L, 1);
}
3. 기본 라이브러리 열기 함수 변경
루아 라이브러리를 여는 함수들이 변경되었다. 원래는 lua_baselibopen 같은 이름이였는데, luaopen_base 와 같은 이름으로 변경되었다. 그런데 문제는 이 라이브러리들을 하나씩 로드하니 AV가 일어난다. 함수 호출 순서가 상관있나? 혹시나 싶어서 모든 라이브러리를 열어주는 함수 luaL_openlibs 를 이용하니 잘 된다. 뭘까...
luaL_openlibs(L);
/*
luaopen_base(L);
luaopen_table(L);
luaopen_os(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(L);
luaopen_debug(L);
luaopen_package(L);
*/
/*
luaopen_base(L);
luaopen_table(L);
luaopen_os(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(L);
luaopen_debug(L);
luaopen_package(L);
*/
개인적으로 루아의 아주 작은 부분 집합만을 사용하기에, 뭐하러 버전업한 건지 이유를 모르게 되어버렸다.

글
댓글을 달아 주세요
댓글 RSS 주소 : http://serious-code.net/tc/rss/comment/3댓글 ATOM 주소 : http://serious-code.net/tc/atom/comment/3
이 글에 큰 도움을 받았습니다 감사합니다 ^^