0
테이블을 교체 할 수 있습니까? 예 :C : 통화에서 테이블 바꾸기
lua_createtable(L,0,0);
lua_replace(L,2); // is the 2nd parameter of a function call
테이블을 교체 할 수 있습니까? 예 :C : 통화에서 테이블 바꾸기
lua_createtable(L,0,0);
lua_replace(L,2); // is the 2nd parameter of a function call
당신은 상단에 무엇이든에 지정된 인덱스에있는 루아 값을 lua_replace
수 있습니다 :이 작업을 얻을 수 없습니다.
const char *lprint =
"function lprint(...)"
" local _, arg2 = ..."
" print(...)"
" return ..."
" end";
int printstack(lua_State *L)
{
const int argc = lua_gettop(L);
lua_getglobal(L, "lprint");
lua_insert(L, 1);
lua_call(L, argc, argc);
return argc;
}
:
int test_replace(lua_State *L)
{
lua_getglobal(L, "_VERSION");
lua_getglobal(L, "os");
lua_getglobal(L, "os");
printstack(L);
lua_createtable(L, 0, 0);
lua_replace(L, 2);
printstack(L);
return 0;
}
간단한 printstack
는 루아 스택에 무엇을 보여주기 위해 : 여기이 될 일이 무엇이든 새로운 빈 테이블을 받아 위치 2로 이동합니다 간단한 단위 테스트, 교체입니다 이제 test_replace
을 실행하면
luaL_dostring(L, lprint);
lua_pushcfunction(L, test_replace);
lua_call(L, 0, 0);
가능한 출력 :
이 5.2 테이블루아
: 00431A10 테이블 : 5.2 테이블 00431A10
루아 : 00431DD0 테이블 : 00431A10이 문제의 코드가 아닌
경우 그때 당신은 당신이 보여주지 않은 주변 환경에서 뭔가 잘못하고있는 것입니다.