큰 일에는 진지하게 대하지만 작은 일에는 손을 빼는 것이 당연하다고 생각하는 것, 몰락은 언제나 여기에서 시작된다. -헤르만 헤세
흠... 굳이 luabind에 국한된 내용은 아닙니다. 개인적으로 다음과 같은 부분이 필요해서 테스트를 해보았습니다.
이것이 가능하면 다음과 같은 작업이 가능합니다. (훨씬 많을수도 있겠죠)
- 루아 문자열안에 NULL 문자가 포함되어있어도 처음 설정한 길이만큼 메모리를 유지하는가?
- 위와 같은 문자열을 C -> 루아 이동 및 루아 -> C 이동이 가능한가?
이것이 가능하면 다음과 같은 작업이 가능합니다. (훨씬 많을수도 있겠죠)
- 루아에서 이진화일을 읽어온 후 일부분을 C에서 처리가능
- 이진데이타(예:UDP청크)의 파싱 및 조립부분을 루아에서 어느정도 처리가능
extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" } #include <luabind/luabind.hpp> ... lua_State *L_; static luabind::object test_string() { luabind::object o_(L_); lua_pushlstring(L_, "12345\0 abcde", 12); o_.set(); return o_; } static int test_strlen(const luabind::object &o_) { static char buf_[255]; o_.pushvalue(); int ret_ = lua_strlen(L_, -1); // const char *t_ = lua_tostring(L_, -1); o_.set(); const char *t_ = luabind::object_cast<const char *>(o_); lua_dostring(L_, "print[[test_strlen() start]]"); for (int i = 0; i < ret_; i++) { if (t_[i] == '\0') sprintf(buf_, "print[[%2d -> NULL]]", i); else sprintf(buf_, "print[[%2d -> %c]]", i, t_[i]); lua_dostring(L_, buf_); } lua_dostring(L_, "print[[test_strlen() end]]"); return ret_; } ... // ~S~]~@~D module(L_) [ def("teststr", test_string), def("teststrlen", test_strlen) ]
실험결과 lua_tostring() 및 luabind::object_cast<const char *>() 모두 동작하였습니다. 중간에 \0문자 추가한 부분을 눈여겨 보시길... 실행결과는 다음과 같습니다.
>> print(teststrlen(teststr())) test_strlen() start 0 -> 1 1 -> 2 2 -> 3 3 -> 4 4 -> 5 5 -> NULL 6 -> 7 -> a 8 -> b 9 -> c 10 -> d 11 -> e test_strlen() end 12









![[http]](/wiki/imgs/http.png)
