I'm going to assume that char* newData; = (char
is a typo in your question because such code would not compile.
I believe the problem is that you are trying to print the bytecode as a string of characters. If you give a std stream (like std::cout) a pointer to a character, the stream will print all the characters, starting at that memory location, up to but not including the first null character it finds after that memory address. Now I have never looked at Lua bytecode but I suspect that Lua bytecode can have null bytes, which would cause the printout to appear incomplete. You were just lucky in your "complete" example, that there were no null bytes.
Since a lot of the bytecodes will be unprintable characters, you might as well print their decimal value instead. Replace std::cout << "bytecode: " << bytecode << std::endl;
by:
std::cout << "bytecode: ";
for (int i=0; i<bytecode_len; i++)
std::cout << int(bytecode[i]) << " ";
std::cout << std::endl;