简体   繁体   中英

Three null characters after start of string in Lua bytecode?

I'm reading up on Lua bytecode. I understand that strings begin with the length of it, then the string is stored. The string then is ended by a null character. However, I'm having an issue. It says the string length is 124, including the null character at the end. However, there are three null characters preceding the string (after the length). This makes the actual length of the string 127.

Does anyone know why this happens?

Thank you.

The bytecode you've posted starts with

\27\76\117\97\81\0\1\4\4\4\8\0\124\0\0\0...

or in hex

0000000: 1b4c 7561 5100 0104 0404 0800 7c00 0000  .LuaQ.......|...
0000010: 3d70 7269 6e74 2828 2727 292e 6475 6d70  =print(('').dump

The length of the string is not a single byte, it's the four bytes 7c00 0000 .

In general, the number of bytes used to represent the length of a string is the second 04 in the first line, at offset 8.

See luaU_header in the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM